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

added esp_log library and replaced 'Serial.println()' statements with logging

parent bcb77765
No related branches found
No related tags found
5 merge requests!39Merge Develop into Main,!19development into master,!17Inital Host, initial Client,!10merge serial comm and sd write into espnow,!8merge sensor_readout into develop
#include "ram_caching.hpp"
static const char* TAG = "CACHING";
#include "esp_log.h"
RTC_DATA_ATTR int cachedAmount = -1;
RTC_DATA_ATTR ClientDataPackage backup[NUM_SENSORS];
......@@ -11,6 +14,7 @@ ClientDataPackage ram_cache_pop()
void ram_cache_push(ClientDataPackage data)
{
backup[++cachedAmount] = data;
ESP_LOGI(TAG, "ClientDataPackage saved");
}
bool ram_cache_is_empty()
......
#include "dr26.hpp"
static const char* TAG = "DR26";
#include "esp_log.h"
Adafruit_ADS1115 ads;
void Forte_DR26 ::setup()
{
Wire.begin(I2C_SDA, I2C_SCL);
// ads.setGain(0);
ads.begin() ? Serial.println("ADS initialized") : Serial.println("failed to initialize ADS");
if(ads.begin()){
ESP_LOGI(TAG, "ADS initialized.");
}
else{
ESP_LOGW(TAG, "ADS initialization failed.");
}
delay(100);
}
......
#include <drs26.hpp>
static const char* TAG = "DRS26";
#include "esp_log.h"
/*
It happens for some reason that the sensor cant get reached every 2 time
Because the sensor use sdi12 protocoll we have to wait aproxemettly 1 secound between the commands
......
#include "ESPNow.hpp"
static const char* TAG = "ESPNOW";
#include "esp_log.h"
uint8_t BROADCAST_MAC[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
esp_now_peer_info_t hostInfo;
Preferences preferences;
......@@ -11,7 +14,7 @@ void get_host_mac(uint8_t *destination)
preferences.getBytes("host", destination, sizeof(uint8_t) * 6);
} else {
memcpy(destination, BROADCAST_MAC, sizeof(BROADCAST_MAC));
Serial.println("backup mac used");
ESP_LOGW(TAG, "Backup MAC address used");
}
preferences.end();
}
......@@ -22,7 +25,7 @@ void on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t status)
void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len)
{
Serial.println("message recieved");
ESP_LOGI(TAG, "Message recieved");
config new_config;
memcpy(&new_config, incomingData, sizeof(new_config)); // TODO: check for valid mac
......@@ -30,7 +33,7 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len)
preferences.begin("config", false);
if (!preferences.isKey("host")) {
preferences.putBytes("host", new_config.host, sizeof(new_config.host));
Serial.println("host mac saved to flash");
ESP_LOGI(TAG, "host MAC address saved to flash");
} // host change shouldn't be an issue
preferences.end();
// sync time
......
#include "Message.hpp"
static const char* TAG = "MESSAGE";
#include "esp_log.h"
void Message::add_data(float value, int identifier)
{
if (data.amountData < NUM_SENSORS) {
......@@ -11,7 +14,7 @@ void Message::add_data(float value, int identifier)
esp_err_t Message::send()
{
Serial.println("sending Message");
ESP_LOGI(TAG, "Sending message");
esp_err_t success;
success = esp_now_send(recipient, (uint8_t *)&data, sizeof(data));
// if(success != ESP_OK){
......@@ -22,11 +25,10 @@ esp_err_t Message::send()
for (int i = 0; i < data.amountData; i++) {
Serial.println(data.values[i]);
}
Serial.println((String) "time sent: " + data.timestamp);
Serial.println((String) "Send status: " + success);
Serial.println();
Serial.flush();
Serial.println("done");
ESP_LOGD(TAG, "time sent: " + data.timestamp);
ESP_LOGD(TAG, "send status: " + success);
return success;
}
......
#include "ina219.hpp"
static const char* TAG = "INA219";
#include "esp_log.h"
void Forte_INA219 ::setup()
{
Wire.begin(I2C_SDA, I2C_SCL);
if (!ina219.init()) {
// Sensor init went wrong
ESP_LOGW(TAG, "Initialization failed");
return;
}
}
......
#include "scd30.hpp"
static const char* TAG = "SCD30";
#include "esp_log.h"
void Forte_SCD30 ::setup()
{
Wire.begin(I2C_SDA, I2C_SCL);
if (!airSensor.begin()) {
// Sensor init went wrong
ESP_LOGW(TAG, "Initialization failed.");
return;
}
}
......
......@@ -4,12 +4,16 @@
#include <ina219.hpp>
#include <scd30.hpp>
static const char* TAG = "MAIN";
#include "esp_log.h"
Forte_DRS26 drs26;
void setup()
{
Serial.begin(9600);
drs26.setup();
ESP_LOGI(TAG, "Setup complete.");
}
void loop()
......@@ -24,14 +28,10 @@ void loop()
} catch (const NoDataAvailableException &e) {
std::cerr << e.what() << '\n';
}
Serial.print("Sensor Circumference: ");
Serial.println(data.circumference);
Serial.print("Temperature ");
Serial.println(data.temperatur);
Serial.print("Id ");
Serial.println(data.id);
Serial.println();
ESP_LOGI(TAG, "Sensor Circumference: " + data.circumference);
ESP_LOGI(TAG, "Temperature: " + data.temperatur);
ESP_LOGI(TAG, "Id: " + data.id);
delay(5000);
}
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