Fix unwanted WiZMote restart

This commit is contained in:
Theo Arends 2025-02-13 21:32:34 +01:00
parent cc14f721f9
commit f383c877c6
6 changed files with 22 additions and 17 deletions

View File

@ -44,7 +44,7 @@ protected:
* @brief Communication subsistem initialization
* @param peerType Role that peer plays into the system, node or gateway.
*/
virtual void initComms () = 0;
virtual bool initComms () = 0;
public:

View File

@ -46,8 +46,8 @@ bool QuickEspNow::begin (uint8_t channel, uint32_t wifi_interface, bool synchron
DEBUG_INFO (QESPNOW_TAG, ARDUHAL_LOG_COLOR (ARDUHAL_LOG_COLOR_RED) "Starting ESP-NOW in in channel %u interface %s", channel, wifi_if == WIFI_IF_STA ? "STA" : "AP");
this->channel = channel;
initComms ();
return true;
return initComms ();
}
void QuickEspNow::stop () {
@ -303,11 +303,12 @@ bool QuickEspNow::addPeer (const uint8_t* peer_addr) {
return error == ESP_OK;
}
void QuickEspNow::initComms () {
bool QuickEspNow::initComms () {
if (esp_now_init ()) {
DEBUG_ERROR (QESPNOW_TAG, "Failed to init ESP-NOW");
ESP.restart ();
delay (1);
// ESP.restart ();
// delay (1);
return false;
}
esp_now_register_recv_cb (rx_cb);
@ -328,6 +329,8 @@ void QuickEspNow::initComms () {
dataTPTimer = xTimerCreate ("espnow_tp_timer", pdMS_TO_TICKS (MEAS_TP_EVERY_MS), pdTRUE, NULL, tp_timer_cb);
xTimerStart (dataTPTimer, 0);
#endif // MEAS_TPUT
return true;
}
void QuickEspNow::espnowTxTask_cb (void* param) {

View File

@ -150,7 +150,7 @@ protected:
//uint8_t channel;
bool followWiFiChannel = false;
void initComms ();
bool initComms ();
bool addPeer (const uint8_t* peer_addr);
static void espnowTxTask_cb (void* param);
int32_t sendEspNowMessage (comms_tx_queue_item_t* message);

View File

@ -74,9 +74,8 @@ bool QuickEspNow::begin (uint8_t channel, uint32_t wifi_interface, bool synchron
DEBUG_INFO (QESPNOW_TAG, "Starting ESP-NOW in in channel %u interface %s", channel, wifi_if == WIFI_IF_STA ? "STA" : "AP");
this->channel = channel;
initComms ();
// addPeer (ESPNOW_BROADCAST_ADDRESS); // Not needed ?
return true;
return initComms ();
}
void QuickEspNow::stop () {
@ -261,11 +260,12 @@ void QuickEspNow::enableTransmit (bool enable) {
}
}
void QuickEspNow::initComms () {
bool QuickEspNow::initComms () {
if (esp_now_init ()) {
DEBUG_ERROR (QESPNOW_TAG, "Failed to init ESP-NOW");
ESP.restart ();
delay (1);
// ESP.restart ();
// delay (1);
return false;
}
if (wifi_if == WIFI_IF_STA) {
@ -288,6 +288,7 @@ void QuickEspNow::initComms () {
os_timer_arm (&dataTPTimer, MEAS_TP_EVERY_MS, true);
#endif // MEAS_TPUT
return true;
}
void QuickEspNow::espnowTxTask_cb (void* param) {

View File

@ -127,7 +127,7 @@ protected:
//uint8_t channel;
bool followWiFiChannel = false;
void initComms ();
bool initComms ();
static void espnowTxTask_cb (void* param);
static void espnowRxTask_cb (void* param);
int32_t sendEspNowMessage (comms_tx_queue_item_t* message);

View File

@ -156,9 +156,10 @@ void EspNowInit(void) {
#ifdef ESP32
// quickEspNow.setWiFiBandwidth (WIFI_IF_STA, WIFI_BW_HT20); // Only needed for ESP32 in case you need coexistence with ESP8266 in the same network
#endif //ESP32
quickEspNow.begin();
AddLog(LOG_LEVEL_INFO, PSTR("NOW: ESP-NOW started"));
WizMote.active = true;
if (quickEspNow.begin()) {
AddLog(LOG_LEVEL_INFO, PSTR("NOW: ESP-NOW started"));
WizMote.active = true;
}
}
}