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

moved retrieval of host mac from flash to seperate function

parent e6707cf2
No related branches found
No related tags found
5 merge requests!39Merge Develop into Main,!19development into master,!17Inital Host, initial Client,!3Merge Branch `develop` into `sensor_readout`,!1Espnow
...@@ -41,15 +41,7 @@ esp_err_t espnow_setup(){ ...@@ -41,15 +41,7 @@ esp_err_t espnow_setup(){
return result; // not sure about this return result; // not sure about this
} }
preferences.begin("config", false); get_host_mac(hostInfo.peer_addr); // check if there is a host saved in flash mem, broadcast otherwise
if(preferences.isKey("host")){
preferences.getBytes("host", hostInfo.peer_addr, sizeof(hostInfo.peer_addr));
Serial.println("Mac used from flash");
}
else{
memcpy(hostInfo.peer_addr, BROADCAST_MAC, sizeof(hostInfo.peer_addr));
}
preferences.end(); // check if there is a host saved in flash mem, broadcast otherwise
hostInfo.channel = 0; hostInfo.channel = 0;
hostInfo.encrypt = 0; hostInfo.encrypt = 0;
...@@ -92,15 +84,8 @@ esp_err_t Message::send(){ ...@@ -92,15 +84,8 @@ esp_err_t Message::send(){
Message :: Message(){ Message :: Message(){
data = (data_struct*) malloc(sizeof(data_struct)); data = (data_struct*) malloc(sizeof(data_struct));
preferences.begin("config", true); // check for existing host mac address, use broadcast otherwise
if(preferences.isKey("host")){ get_host_mac(recipient);
preferences.getBytes("host", recipient, sizeof(uint8_t) * 6);
}
else{
memcpy(recipient, BROADCAST_MAC, sizeof(BROADCAST_MAC));
Serial.println("backup mac used");
}
preferences.end();
data->amountData = 0; data->amountData = 0;
data->timestamp = rtc.getMillis(); // I am assuming we are not sending data from Unix Epoch data->timestamp = rtc.getMillis(); // I am assuming we are not sending data from Unix Epoch
...@@ -108,18 +93,21 @@ Message :: Message(){ ...@@ -108,18 +93,21 @@ Message :: Message(){
Message :: Message(data_struct old_data){ Message :: Message(data_struct old_data){
memcpy(data, &old_data, sizeof(data)); memcpy(data, &old_data, sizeof(data));
get_host_mac(recipient);
}
Message :: ~Message(){
free((void*) data);
}
void get_host_mac(uint8_t* destination){
preferences.begin("config", true); preferences.begin("config", true);
if(preferences.isKey("host")){ if(preferences.isKey("host")){
preferences.getBytes("host", recipient, sizeof(uint8_t) * 6); preferences.getBytes("host", destination, sizeof(uint8_t) * 6);
} }
else{ else{
memcpy(recipient, BROADCAST_MAC, sizeof(BROADCAST_MAC)); memcpy(destination, BROADCAST_MAC, sizeof(BROADCAST_MAC));
Serial.println("backup mac used"); Serial.println("backup mac used");
} }
preferences.end(); preferences.end();
}
Message :: ~Message(){
free((void*) data);
} }
\ No newline at end of file
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