Version 1.31

Added gateway mode support.
This commit is contained in:
Alexey Zholtikov 2023-01-03 17:55:08 +03:00
parent 506acf1fc0
commit 62acd2a386
4 changed files with 9 additions and 8 deletions

View File

@ -25,7 +25,7 @@ A simple library for creating ESP-NOW based Mesh network for ESP8266/ESP32.
## Notes
1. Possibility uses WiFi AP or STA modes at the same time with ESP-NOW using the standard libraries.
2. For correct work at ESP-NOW + STA mode your WiFi router must be set on channel 1.
2. For correct work at ESP-NOW + STA mode your WiFi router must be set on channel 1 and set gateway mode.
## Function descriptions
@ -73,6 +73,7 @@ Note. If network name not set node will work with all ESP-NOW networks. If set n
```cpp
myNet.begin("ZHNetwork");
myNet.begin("ZHNetwork", true); // Gateway mode.
```
### Sends broadcast message to all nodes

View File

@ -1,5 +1,5 @@
name=ZHNetwork
version=1.3
version=1.31
author=Alexey Zholtikov
maintainer=Alexey Zholtikov
sentence=ESP-NOW based Mesh network for ESP8266/ESP32

View File

@ -31,7 +31,7 @@ ZHNetwork &ZHNetwork::setOnConfirmReceivingCallback(on_confirm_t onConfirmReceiv
return *this;
}
error_code_t ZHNetwork::begin(const char *netName)
error_code_t ZHNetwork::begin(const char *netName, const bool gateway)
{
randomSeed(analogRead(0));
if (strlen(netName) > 1 && strlen(netName) < 20)
@ -39,14 +39,14 @@ error_code_t ZHNetwork::begin(const char *netName)
#ifdef PRINT_LOG
Serial.begin(115200);
#endif
WiFi.mode(WIFI_STA);
WiFi.mode(gateway ? WIFI_AP_STA : WIFI_STA);
esp_now_init();
#if defined(ESP8266)
wifi_get_macaddr(STATION_IF, localMAC);
wifi_get_macaddr(gateway ? SOFTAP_IF : STATION_IF, localMAC);
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
#endif
#if defined(ESP32)
esp_wifi_get_mac((wifi_interface_t)ESP_IF_WIFI_STA, localMAC);
esp_wifi_get_mac(gateway ? (wifi_interface_t)ESP_IF_WIFI_AP : (wifi_interface_t)ESP_IF_WIFI_STA, localMAC);
#endif
esp_now_register_send_cb(onDataSent);
esp_now_register_recv_cb(onDataReceive);

View File

@ -80,7 +80,7 @@ public:
ZHNetwork &setOnUnicastReceivingCallback(on_message_t onUnicastReceivingCallback);
ZHNetwork &setOnConfirmReceivingCallback(on_confirm_t onConfirmReceivingCallback);
error_code_t begin(const char *netName = "");
error_code_t begin(const char *netName = "", const bool gateway = false);
void sendBroadcastMessage(const char *data);
void sendUnicastMessage(const char *data, const uint8_t *target, const bool confirm = false);
@ -115,7 +115,7 @@ private:
static uint16_t lastMessageID[10];
static char netName_[20];
const char *firmware{"1.3"};
const char *firmware{"1.31"};
const uint8_t broadcastMAC[6]{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
uint8_t maxNumberOfAttempts_{3};
uint8_t maxWaitingTimeBetweenTransmissions_{50};