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:
Florian authored and GitHub committed 2018-05-24 23:01:31 +02:00
1 parent d0820eb2db
commit 4ef82289e1
3 files changed
+115 -44

No files matched your search

+75 -8
View File
@@ -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
+18 -15
View File
@@ -87,20 +87,21 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
/*-------------DEFINE THE MODULES YOU WANT BELOW----------------*/
//Addons and module management, comment the Z line
#define ZgatewayRF //ESP8266, Arduino, ESP32
#define ZgatewayIR //ESP8266, Arduino, Sonoff RF Bridge
#define ZgatewayBT //ESP8266, Arduino, ESP32
//#define ZgatewayRF2 //ESP8266, Arduino, ESP32
//#define ZgatewaySRFB // Sonoff RF Bridge
//#define ZactuatorONOFF //ESP8266, Arduino, ESP32, Sonoff RF Bridge
//#define ZsensorINA226 //ESP8266, Arduino, ESP32
//#define ZsensorHCSR501 //ESP8266, Arduino, ESP32, Sonoff RF Bridge
//#define ZsensorADC //ESP8266, Arduino, ESP32
//#define ZsensorBH1750 //ESP8266, Arduino, ESP32
//#define ZsensorTSL2561 //ESP8266, Arduino, ESP32
//#define ZsensorBME280 //ESP8266, Arduino, ESP32
//#define ZsensorDHT //ESP8266, Arduino, ESP32, Sonoff RF Bridge
//#define ZgatewayRFM69 //ESP8266, Arduino, ESP32
#define ZgatewayRF "RF" //ESP8266, Arduino, ESP32
#define ZgatewayIR "IR" //ESP8266, Arduino, Sonoff RF Bridge
#define ZgatewayBT "BT" //ESP8266, Arduino, ESP32
//#define ZgatewayRF2 "RF2" //ESP8266, Arduino, ESP32
//#define ZgatewaySRFB "SRFB" // Sonoff RF Bridge
//#define Zgateway2G "2G" //ESP8266, Arduino, ESP32
//#define ZactuatorONOFF "ONOFF" //ESP8266, Arduino, ESP32, Sonoff RF Bridge
//#define ZsensorINA226 "INA226" //ESP8266, Arduino, ESP32
//#define ZsensorHCSR501 "HCSR501" //ESP8266, Arduino, ESP32, Sonoff RF Bridge
//#define ZsensorADC "ADC" //ESP8266, Arduino, ESP32
//#define ZsensorBH1750 "BH1750" //ESP8266, Arduino, ESP32
//#define ZsensorTSL2561 "TSL2561" //ESP8266, Arduino, ESP32
//#define ZsensorBME280 "BME280" //ESP8266, Arduino, ESP32
//#define ZsensorDHT "DHT" //ESP8266, Arduino, ESP32, Sonoff RF Bridge
//#define ZgatewayRFM69 "RFM69" //ESP8266, Arduino, ESP32
/*----------------------------OTHER PARAMETERS-----------------------------*/
/*-------------------CHANGING THEM IS NOT COMPULSORY-----------------------*/
@@ -123,7 +124,9 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
//#define multiCore //uncomment to use multicore function of ESP32 for BLE
#endif
#define TimeBetweenReadingSYS 30000 // time between system readings (like memory)
#define TimeBetweenReadingSYS 120000 // time between system readings (like memory)
#define subjectSYStoMQTT Base_Topic Gateway_Name "/SYStoMQTT"
/*-------------------ACTIVATE TRACES----------------------*/
#define TRACE 1 // 0= trace off 1 = trace on
+22 -21
View File
@@ -85,37 +85,37 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
/*-------------DEFINE THE MODULES YOU WANT BELOW----------------*/
//Addons and module management, comment the Z line and the config file if you don't use
#ifdef ESP8266 // for nodemcu, weemos and esp8266
#define ZgatewayRF
#define ZgatewaySRFB
#define ZgatewayRF2
#define ZgatewayIR
#define ZgatewayBT
#define Zgateway2G
#define ZactuatorONOFF
#define ZsensorINA226
#define ZsensorHCSR501
#define ZsensorADC
#define ZsensorBH1750
#define ZsensorBME280
#define ZsensorTSL2561
#define ZsensorDHT // If you uncomment this you can't use I2C due to the fact that I2C use also D1
#define ZgatewayRFM69 // If you uncomment this you can't use RF and BT due to the fact that RF use also D8 and BT use also D6/D7
#define ZgatewayRF "RF"
#define ZgatewaySRFB "SRFB"
#define ZgatewayRF2 "RF2"
#define ZgatewayIR "IR"
#define ZgatewayBT "BT"
#define Zgateway2G "2G"
#define ZactuatorONOFF "ONOFF"
#define ZsensorINA226 "INA226"
#define ZsensorHCSR501 "HCSR501"
#define ZsensorADC "ADC"
#define ZsensorBH1750 "BH1750"
#define ZsensorBME280 "BME280"
#define ZsensorTSL2561 "TSL2561"
#define ZsensorDHT "DHT"// If you uncomment this you can't use I2C due to the fact that I2C use also D1
#define ZgatewayRFM69 "RFM69"// If you uncomment this you can't use RF and BT due to the fact that RF use also D8 and BT use also D6/D7
#elif ESP32
#define ZgatewayRF
#define ZgatewayRF2
#define ZgatewayRF "RF"
#define ZgatewayRF2 "RF2"
//#define Zgateway2G (not tested yet)
//#define ZgatewayIR
#define ZgatewayBT
#define ZactuatorONOFF
#define ZgatewayBT "BT"
#define ZactuatorONOFF "ONOFF"
//#define ZsensorINA226
//#define ZsensorHCSR501
//#define ZsensorADC
//#define ZsensorBH1750
//#define ZsensorBME280
#define ZsensorDHT // If you uncomment this you can't use I2C due to the fact that I2C use also D1
#define ZsensorDHT "DHT"// If you uncomment this you can't use I2C due to the fact that I2C use also D1
//#define ZgatewayRFM69 // If you uncomment this you can't use RF and BT due to the fact that RF use also D8 and BT use also D6/D7
#else // for arduino mega + W5100
#define ZgatewayRF
#define ZgatewayRF "RF"
//#define Zgateway2G (not tested yet)
//#define ZgatewayRF2 // too big for UNO
//#define ZgatewayRFM69 not tested
@@ -150,5 +150,6 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
#endif
#define TimeBetweenReadingSYS 30000 // time between system readings (like memory)
#define subjectSYStoMQTT Base_Topic Gateway_Name "/SYStoMQTT"
/*-------------------ACTIVATE TRACES----------------------*/
#define TRACE 1 // 0= trace off 1 = trace on