Skip to content
Snippets Groups Projects
Commit 7eba5a1f authored by User expired's avatar User expired
Browse files

improved logging

parent 8bffe47d
No related branches found
No related tags found
3 merge requests!39Merge Develop into Main,!19development into master,!18Power management satellite
......@@ -9,6 +9,7 @@
LC709203F gg;
static const std::string TAG = "MAIN";
static const char *TAG = "MAIN";
ForteDR26 dr26_channel3;
ForteDR26 dr26_channel1;
......@@ -26,7 +27,7 @@ void setup() {
DeepSleep::print_wakeup_reason();
DeepSleep::bootCount++;
ESP_LOGD(TAG.c_str(), "Boot number: %d", DeepSleep::bootCount);
ESP_LOGD(TAG, "Boot number: %d", DeepSleep::bootCount);
gpio_set_level(GPIO_NUM_32, 1);
dr26_channel1.setup();
......
......@@ -26,7 +26,7 @@ void print_wakeup_reason()
ESP_LOGD(TAG.c_str(), "Wakeup caused by ULP program");
break;
default:
ESP_LOGD(TAG.c_str(), "Wakeup was not caused by deep sleep: %d\n", wakeup_reason);
ESP_LOGD(TAG.c_str(), "Wakeup was not caused by deep sleep: %d", wakeup_reason);
break;
}
}
......
#include "dr26.hpp"
static const char *TAG = "DR26";
void ForteDR26::setup() {
// This was changed by Bilal on november 25th from
......@@ -10,7 +11,7 @@ void ForteDR26::setup() {
// ads.begin() ? Serial.println("ADS initialized") : Serial.println("failed to initialize ADS");
ads1.setGain(GAIN_ONE);
ads1.begin() ? Serial.println("ADS initialized") : Serial.println("failed to initialize ADS");
ads1.begin() ? ESP_LOGD(TAG, "ADS initialized") : ESP_LOGE(TAG, "failed to initialize ADS");
delay(100);
channel = 0;
}
......
......@@ -38,13 +38,8 @@ esp_err_t add_host_to_peers(config received){
void on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t status)
{
ESP_LOGE(TAG, "Message sent to");
for(int i=0; i<6; i++){
Serial.print(mac_addr[i], HEX);
Serial.print(":");
}
Serial.println();
// go to sleep
ESP_LOGE(TAG, "Message sent to %02X:%02X:%02X:%02X:%02X:%02X", mac_addr[0],
mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
}
void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len)
......@@ -52,7 +47,7 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len)
// is msg host -> yes -> set bool
// assume host change not happening, rare event
// => on host change, broadcast
ESP_LOGE(TAG, "Message recieved");
ESP_LOGD(TAG, "Message received");
config received_msg;
memcpy(&received_msg, incomingData, sizeof(received_msg)); // TODO: check for valid mac
// all the esp32 macs so far use the same first 3(?) bytes so maybe use that
......@@ -89,7 +84,8 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len)
// add new host
preferences.begin("config", false);
if(preferences.putBytes("host", received_msg.host, sizeof(received_msg.host)) > 0){
ESP_LOGI(TAG, "Host Mac address saved to flash:");
ESP_LOGI(TAG, "Host MAC address saved to flash %02X:%02X:%02X:%02X:%02X:%02X", received_msg.host[0],
received_msg.host[1],received_msg.host[2],received_msg.host[3],received_msg.host[4],received_msg.host[5]);
}
else{
ESP_LOGI(TAG, "Couldn't save Host Mac to flash");
......@@ -111,6 +107,7 @@ esp_err_t espnow_setup()
result = esp_now_init();
if (result != ESP_OK) {
// initialization failed
ESP_LOGE(TAG, "ESPNow setup failed");
return result; // not sure about this
}
......@@ -127,5 +124,6 @@ esp_err_t espnow_setup()
esp_now_register_recv_cb(on_data_recv);
esp_now_register_send_cb(on_data_sent);
ESP_LOGI(TAG, "ESPNow started. MAC: %s", WiFi.macAddress().c_str());
return ESP_OK;
}
......@@ -4,7 +4,7 @@ static const char *TAG = "MESSAGE";
esp_err_t Message::send() const
{
ESP_LOGI(TAG, "Sending message");
ESP_LOGD(TAG, "Sending message");
esp_err_t success;
auto messageData = getMessageAsMinifiedJsonString();
......@@ -12,12 +12,11 @@ esp_err_t Message::send() const
success = esp_now_send(recipient, (uint8_t *)messageData.c_str(), (messageData.length() + 1) * sizeof(char));
if (success != ESP_OK) {
ESP_LOGE(TAG, "Error sending the data");
Serial.println(success, HEX);
// Removed caching from here, better do this in main
}
ESP_LOGE(TAG, "Sent data: %s", messageData.c_str());
ESP_LOGD(TAG, "Sent data: %s", messageData.c_str());
ESP_LOGD(TAG, "time sent: %l", clientDataPackage.getTimestamp());
ESP_LOGD(TAG, "Timestamp sent: %ld", clientDataPackage.getTimestamp());
ESP_LOGD(TAG, "send status: %d", success);
return success;
......
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