Skip to content
Snippets Groups Projects
Commit 2e536263 authored by Moritz Perschke's avatar Moritz Perschke
Browse files

small changes to how the host announces its mac

parent e8c36f04
No related branches found
No related tags found
3 merge requests!39Merge Develop into Main,!19development into master,!17Inital Host, initial Client
......@@ -72,6 +72,8 @@ typedef struct response{
}response;
uint8_t BROADCAST_MAC[6] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
esp_now_peer_info_t broadcast = {};
response announce = {};
ESP32Time rtc;
......@@ -152,7 +154,7 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len)
String macAddress = getMacAddressAsString(mac);
// add timestamp and mac address
doc["timestamp"] = rtc.getEpoch();
// doc["timestamp"] = rtc.getEpoch();
doc["clientMac"] = macAddress;
// serialize json document again
......@@ -316,11 +318,22 @@ void setup()
syncUTCTimeToRTC();
response announce = {};
broadcast.channel = 0;
broadcast.encrypt = false;
memcpy(&broadcast.peer_addr, &BROADCAST_MAC, sizeof(BROADCAST_MAC));
if(esp_now_add_peer(&broadcast) != ESP_OK){
esp_log_write(ESP_LOG_WARN, TAG_ESPNOW.c_str(), "Failed to add Broadcast Host");
}
announce.type = hostChange;
esp_read_mac(announce.mac, ESP_MAC_WIFI_STA);
announce.time = rtc.getEpoch();
esp_now_send(BROADCAST_MAC, (uint8_t *) &announce, sizeof(announce));
if(esp_now_send(BROADCAST_MAC, (uint8_t *) &announce, sizeof(announce)) != ESP_OK){
esp_log_write(ESP_LOG_WARN, TAG_ESPNOW.c_str(), "Failed to announce mac");
}
else{
esp_log_write(ESP_LOG_DEBUG, TAG_ESPNOW.c_str(), "Mac announced!");
}
}
void syncUTCTimeToRTC()
{
......@@ -392,6 +405,14 @@ void loop()
"Failed to restart modem, attempting to continue without restarting\n");
}
announce.time = rtc.getEpoch();
if(esp_now_send(BROADCAST_MAC, (uint8_t *) &announce, sizeof(announce)) != ESP_OK){
esp_log_write(ESP_LOG_WARN, TAG_ESPNOW.c_str(), "Failed to announce mac\n");
}
else{
esp_log_write(ESP_LOG_DEBUG, TAG_ESPNOW.c_str(), "Mac announced!\n");
}
String name = modem.getModemName();
delay(500);
esp_log_write(ESP_LOG_DEBUG, TAG.c_str(), "Modem Name %s\n", name.c_str());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment