Publish gateway state (#207)
* add ssid, rssi and memory publishing to mqtt for ESP boards * add activated modules and uptime
This commit is contained in:
1 parent
d0820eb2db
commit
4ef82289e1
3 files changed
+115
-44
No files matched your search
+75
-8
@@ -641,18 +641,85 @@ void loop()
|
||||
trc(F("RFM69toMQTT OK"));
|
||||
#endif
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
unsigned long now = millis();
|
||||
if (now > (timer_sys_measures + TimeBetweenReadingSYS)) {//retriving value of memory ram every TimeBetweenReadingSYS
|
||||
timer_sys_measures = millis();
|
||||
trc("Remaining memory");
|
||||
uint32_t freeMem;
|
||||
freeMem = ESP.getFreeHeap();
|
||||
trc(freeMem);
|
||||
}
|
||||
stateMeasures();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
void stateMeasures(){
|
||||
unsigned long now = millis();
|
||||
if (now > (timer_sys_measures + TimeBetweenReadingSYS)) {//retriving value of memory ram every TimeBetweenReadingSYS
|
||||
timer_sys_measures = millis();
|
||||
StaticJsonBuffer<200> jsonBuffer;
|
||||
JsonObject& SYSdata = jsonBuffer.createObject();
|
||||
trc("Uptime (s)");
|
||||
unsigned long uptime = millis()/1000;
|
||||
trc(uptime);
|
||||
SYSdata["uptime"] = uptime;
|
||||
trc("Remaining memory");
|
||||
uint32_t freeMem;
|
||||
freeMem = ESP.getFreeHeap();
|
||||
SYSdata["freeMem"] = freeMem;
|
||||
trc(freeMem);
|
||||
trc("RSSI");
|
||||
long rssi = WiFi.RSSI();
|
||||
SYSdata["rssi"] = rssi;
|
||||
trc(rssi);
|
||||
trc("SSID");
|
||||
String SSID = WiFi.SSID();
|
||||
SYSdata["SSID"] = SSID;
|
||||
trc(SSID);
|
||||
trc("Activated modules");
|
||||
String modules = "";
|
||||
#ifdef ZgatewayRF
|
||||
modules = modules + ZgatewayRF;
|
||||
#endif
|
||||
#ifdef ZsensorBME280
|
||||
modules = modules + "," + ZsensorBME280;
|
||||
#endif
|
||||
#ifdef ZsensorBH1750
|
||||
modules = modules + "," + ZsensorBH1750;
|
||||
#endif
|
||||
#ifdef ZsensorTSL2561
|
||||
modules = modules + "," + ZsensorTSL2561;
|
||||
#endif
|
||||
#ifdef ZactuatorONOFF
|
||||
modules = modules + "," + ZactuatorONOFF;
|
||||
#endif
|
||||
#ifdef Zgateway2G
|
||||
modules = modules + "," + Zgateway2G;
|
||||
#endif
|
||||
#ifdef ZgatewayIR
|
||||
modules = modules + "," + ZgatewayIR;
|
||||
#endif
|
||||
#ifdef ZgatewayRF2
|
||||
modules = modules + "," + ZgatewayRF2;
|
||||
#endif
|
||||
#ifdef ZgatewaySRFB
|
||||
modules = modules + "," + ZgatewaySRFB;
|
||||
#endif
|
||||
#ifdef ZgatewayBT
|
||||
modules = modules + "," + ZgatewayBT;
|
||||
#endif
|
||||
#ifdef ZgatewayRFM69
|
||||
modules = modules + "," + ZgatewayRFM69;
|
||||
#endif
|
||||
#ifdef ZsensorINA226
|
||||
modules = modules + "," + ZsensorINA226;
|
||||
#endif
|
||||
#ifdef ZsensorHCSR501
|
||||
modules = modules + "," + ZsensorHCSR501;
|
||||
#endif
|
||||
SYSdata["modules"] = modules;
|
||||
trc(modules);
|
||||
char JSONmessageBuffer[100];
|
||||
SYSdata.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
|
||||
client.publish(subjectSYStoMQTT,JSONmessageBuffer);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void storeValue(long MQTTvalue){
|
||||
unsigned long now = millis();
|
||||
// find oldest value of the buffer
|
||||
|
||||
Reference in new issue
Block a user