Version 1.31

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

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};