mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-04-10 04:49:16 +02:00
wifi connection retry displays on OLED
This commit is contained in:
parent
260ba51edb
commit
ff403395ee
@ -3,5 +3,6 @@ SRCS
|
||||
"connect.c"
|
||||
INCLUDE_DIRS
|
||||
"include"
|
||||
"../../main"
|
||||
REQUIRES nvs_flash
|
||||
)
|
@ -13,10 +13,9 @@
|
||||
#include "lwip/sys.h"
|
||||
|
||||
#include "connect.h"
|
||||
#include "miner.h"
|
||||
|
||||
|
||||
#define MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
|
||||
|
||||
#if CONFIG_ESP_WPA3_SAE_PWE_HUNT_AND_PECK
|
||||
#define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_HUNT_AND_PECK
|
||||
#define EXAMPLE_H2E_IDENTIFIER ""
|
||||
@ -60,14 +59,16 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
|
||||
esp_wifi_connect();
|
||||
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||
if (s_retry_num < MAXIMUM_RETRY) {
|
||||
if (s_retry_num < WIFI_MAXIMUM_RETRY) {
|
||||
esp_wifi_connect();
|
||||
s_retry_num++;
|
||||
ESP_LOGI(TAG, "retry to connect to the AP");
|
||||
MINER_set_wifi_status(WIFI_RETRYING, s_retry_num);
|
||||
} else {
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
|
||||
ESP_LOGI(TAG,"connect to the AP fail");
|
||||
MINER_set_wifi_status(WIFI_CONNECT_FAILED, 0);
|
||||
}
|
||||
ESP_LOGI(TAG,"connect to the AP fail");
|
||||
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
||||
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
|
||||
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
|
||||
|
@ -9,10 +9,22 @@
|
||||
#define WIFI_SSID CONFIG_ESP_WIFI_SSID
|
||||
#define WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
|
||||
|
||||
#define WIFI_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
|
||||
|
||||
/* The event group allows multiple bits for each event, but we only care about two events:
|
||||
* - we are connected to the AP with an IP
|
||||
* - we failed to connect after the maximum amount of retries */
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
#define WIFI_FAIL_BIT BIT1
|
||||
|
||||
//enum of wifi statuses
|
||||
typedef enum {
|
||||
WIFI_CONNECTED,
|
||||
WIFI_DISCONNECTED,
|
||||
WIFI_CONNECTING,
|
||||
WIFI_DISCONNECTING,
|
||||
WIFI_CONNECT_FAILED,
|
||||
WIFI_RETRYING,
|
||||
} wifi_status_t;
|
||||
|
||||
EventBits_t wifi_init_sta(const char * ssid, const char * pass);
|
@ -19,4 +19,5 @@ SRCS
|
||||
INCLUDE_DIRS
|
||||
"."
|
||||
"tasks"
|
||||
"../components/connect/include"
|
||||
)
|
||||
|
14
main/miner.c
14
main/miner.c
@ -4,7 +4,7 @@
|
||||
#include "nvs_flash.h"
|
||||
|
||||
//#include "protocol_examples_common.h"
|
||||
#include "connect.h"
|
||||
#include "miner.h"
|
||||
|
||||
|
||||
#include "stratum_task.h"
|
||||
@ -65,8 +65,6 @@ void app_main(void)
|
||||
free(wifi_ssid);
|
||||
free(wifi_pass);
|
||||
|
||||
|
||||
|
||||
queue_init(&GLOBAL_STATE.stratum_queue);
|
||||
queue_init(&GLOBAL_STATE.ASIC_jobs_queue);
|
||||
|
||||
@ -85,3 +83,13 @@ void app_main(void)
|
||||
|
||||
}
|
||||
|
||||
void MINER_set_wifi_status(wifi_status_t status, uint16_t retry_count) {
|
||||
if (status == WIFI_RETRYING) {
|
||||
snprintf(GLOBAL_STATE.SYSTEM_MODULE.wifi_status, 20, "Retrying: %d/%d", retry_count, WIFI_MAXIMUM_RETRY);
|
||||
return;
|
||||
} else if (status == WIFI_CONNECT_FAILED) {
|
||||
snprintf(GLOBAL_STATE.SYSTEM_MODULE.wifi_status, 20, "Connect Failed!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
8
main/miner.h
Normal file
8
main/miner.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef MINER_H_
|
||||
#define MINER_H_
|
||||
|
||||
#include "connect.h"
|
||||
|
||||
void MINER_set_wifi_status(wifi_status_t status, uint16_t retry_count);
|
||||
|
||||
#endif /* MINER_H_ */
|
@ -184,8 +184,8 @@ static void _init_connection(SystemModule* module) {
|
||||
|
||||
if (OLED_status()) {
|
||||
memset(module->oled_buf, 0, 20);
|
||||
snprintf(module->oled_buf, 20, "Connecting to:");
|
||||
OLED_writeString(0, 1, module->oled_buf);
|
||||
snprintf(module->oled_buf, 20, "Connecting to ssid:");
|
||||
OLED_writeString(0, 0, module->oled_buf);
|
||||
}
|
||||
|
||||
}
|
||||
@ -196,7 +196,7 @@ static void _update_connection(SystemModule* module) {
|
||||
OLED_clearLine(2);
|
||||
memset(module->oled_buf, 0, 20);
|
||||
snprintf(module->oled_buf, 20, "%s", module->ssid);
|
||||
OLED_writeString(0, 2, module->oled_buf);
|
||||
OLED_writeString(0, 1, module->oled_buf);
|
||||
|
||||
OLED_clearLine(3);
|
||||
memset(module->oled_buf, 0, 20);
|
||||
|
Loading…
x
Reference in New Issue
Block a user