diff --git a/README.md b/README.md index a797492..5c32b6b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/library.properties b/library.properties index 75f703a..a5ebbe9 100644 --- a/library.properties +++ b/library.properties @@ -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 diff --git a/src/ZHNetwork.cpp b/src/ZHNetwork.cpp index 127cfe8..2e0b5cb 100644 --- a/src/ZHNetwork.cpp +++ b/src/ZHNetwork.cpp @@ -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); diff --git a/src/ZHNetwork.h b/src/ZHNetwork.h index eecd480..f34be6c 100644 --- a/src/ZHNetwork.h +++ b/src/ZHNetwork.h @@ -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};