[CODE] add a unique logger ID (additionally to the node name)
This commit is contained in:
parent
efd7af4b27
commit
28f4ba44c0
2 changed files with 42 additions and 30 deletions
|
@ -24,7 +24,7 @@
|
|||
|
||||
/* CONFIGURATION OPTIONS */
|
||||
#ifndef NODENAME
|
||||
#define NODENAME "env-esp32-01" /* IMPORTANT: CHANGE FOR EACH DEVICE */
|
||||
#define NODENAME "env-TODO" /* IMPORTANT: CHANGE FOR EACH DEVICE */
|
||||
#endif
|
||||
|
||||
#ifndef BOARD
|
||||
|
@ -41,6 +41,8 @@
|
|||
#error "unsupported board chosen"
|
||||
#endif
|
||||
|
||||
String loggerId = "esp-"; // prefix for the last 3 octets of the MAC address
|
||||
|
||||
/* SETTINGS */
|
||||
float tempOffset = +0.0;
|
||||
float humiOffset = +0.0;
|
||||
|
@ -66,8 +68,8 @@ String serviceUri = "/write?db=test";
|
|||
#endif
|
||||
|
||||
/* GLOBAL VARIABLES */
|
||||
const uint16_t wlanConnectCheckInterval = 250; /* milli seconds: poll wifi.state after wifi.begin() */
|
||||
const uint16_t wlanConnectTimeout = 15000; /* milli seconds */
|
||||
const uint16_t wlanConnectCheckInterval = 250; // milli seconds: poll wifi.state after wifi.begin()
|
||||
const uint16_t wlanConnectTimeout = 15000; // milli seconds
|
||||
RTC_DATA_ATTR uint8_t wlanConnectFailCnt = 0;
|
||||
|
||||
Si7021 si7021 = Si7021();
|
||||
|
@ -81,6 +83,8 @@ RTC_DATA_ATTR uint8_t sampleCnt = 0; // for average value
|
|||
RTC_DATA_ATTR float tempAccu = 0.0; // for average value
|
||||
RTC_DATA_ATTR float humiAccu = 0.0; // for average value
|
||||
|
||||
uint8_t chipid[6] = {0}; // WiFi MAC address
|
||||
|
||||
#ifdef PRINT_INFO
|
||||
#define INFO_PRINT(x) Serial.print(x)
|
||||
#define INFO_PRINTLN(x) Serial.println(x)
|
||||
|
@ -161,12 +165,20 @@ extern "C" void app_main() {
|
|||
pinMode(4, OUTPUT);
|
||||
digitalWrite(4, HIGH);
|
||||
|
||||
// set logger node unique ID with MAC address
|
||||
char macIdString[6] = {0};
|
||||
esp_efuse_mac_get_default(chipid);
|
||||
sprintf(macIdString, "%02x%02x%02x", chipid[3], chipid[4], chipid[5]);
|
||||
loggerId += macIdString;
|
||||
|
||||
#ifdef PRINT_INFO
|
||||
Serial.begin(115200);
|
||||
delay(100);
|
||||
Serial.println("");
|
||||
|
||||
Serial.print("[INFO ] Node ");
|
||||
Serial.print(loggerId);
|
||||
Serial.print(", Name: ");
|
||||
Serial.print(loggerName);
|
||||
Serial.print(", BoardType: ");
|
||||
Serial.println(BOARD);
|
||||
|
@ -222,7 +234,7 @@ extern "C" void app_main() {
|
|||
if (wlanConnect()) {
|
||||
|
||||
// send data to influxdb
|
||||
String influxDataLine = "weather,sensor=" + loggerName + " temp=" + String(temp, 2);
|
||||
String influxDataLine = "weather,id=" + loggerId + ",sensor=" + loggerName + " temp=" + String(temp, 2);
|
||||
influxDataLine += ",hum=" + String(humi, 2);
|
||||
influxDataLine += ",batRaw=" + String(battLevel);
|
||||
influxDataLine += ",bat=" + String(battPerc);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue