diff --git a/.travis.yml b/.travis.yml index fc2a483..7b0e58e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ install: - python get.py - cd /usr/local/share/arduino/OpenMQTTGateway - arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs - - arduino --install-boards esp8266:esp8266 + - arduino --install-boards esp8266:esp8266:2.4.2 - arduino --board $BD --save-prefs script: - arduino --verify --board $BD $PWD/OpenMQTTGateway.ino diff --git a/OpenMQTTGateway.ino b/OpenMQTTGateway.ino index 9a370db..d386422 100644 --- a/OpenMQTTGateway.ino +++ b/OpenMQTTGateway.ino @@ -69,11 +69,9 @@ // array to store previous received RFs, IRs codes and their timestamps #if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__) - #define MQTT_MAX_PACKET_SIZE 1024 #define array_size 12 unsigned long ReceivedSignal[array_size][2] ={{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}; #else // boards with smaller memory - #define MQTT_MAX_PACKET_SIZE 256 #define array_size 4 unsigned long ReceivedSignal[array_size][2] ={{0,0},{0,0},{0,0},{0,0}}; #endif @@ -207,10 +205,6 @@ boolean reconnect() { pub(will_Topic,Gateway_AnnouncementMsg,will_Retain); // publish version pub(version_Topic,OMG_VERSION,will_Retain); - //home assistant discovery - #ifdef ZmqttDiscovery - pubMqttDiscovery(); - #endif //Subscribing to topic if (client.subscribe(subjectMQTTtoX)) { @@ -419,6 +413,8 @@ void setup() trc(F("MQTT_MAX_PACKET_SIZE")); trc(MQTT_MAX_PACKET_SIZE); + trc(F("JSON_MSG_BUFFER")); + trc(JSON_MSG_BUFFER); trc(F("Setup OpenMQTTGateway end")); } @@ -793,6 +789,7 @@ void stateMeasures(){ #endif #ifdef ZmqttDiscovery modules = modules + ZmqttDiscovery; + pubMqttDiscovery(); #endif SYSdata["modules"] = modules; trc(modules); @@ -873,7 +870,6 @@ void receivingMQTT(char * topicOri, char * datacallback) { //YELLOW ON digitalWrite(led_send, LOW); - trc(F("Creating Json buffer")); StaticJsonBuffer jsonBuffer; JsonObject& jsondata = jsonBuffer.parseObject(datacallback); @@ -903,37 +899,37 @@ void receivingMQTT(char * topicOri, char * datacallback) { #ifdef ZgatewayRFM69 MQTTtoRFM69(topicOri, jsondata); #endif - #ifdef ZactuatorONOFF + #endif + #ifdef ZactuatorONOFF // outside the jsonpublishing macro due to the fact that we need to use simplepublishing with HA discovery MQTTtoONOFF(topicOri, jsondata); #endif - #endif } else { // not a json object --> simple decoding - #ifdef simplePublishing - #ifdef ZgatewayRF - MQTTtoRF(topicOri, datacallback); - #endif - #ifdef ZgatewayRF315 - MQTTtoRF315(topicOri, datacallback); - #endif - #ifdef ZgatewayRF2 - MQTTtoRF2(topicOri, datacallback); - #endif - #ifdef Zgateway2G - MQTTto2G(topicOri, datacallback); - #endif - #ifdef ZgatewaySRFB - MQTTtoSRFB(topicOri, datacallback); - #endif - #ifdef ZgatewayIR - MQTTtoIR(topicOri, datacallback); - #endif - #ifdef ZgatewayRFM69 - MQTTtoRFM69(topicOri, datacallback); - #endif - #ifdef ZactuatorONOFF - MQTTtoONOFF(topicOri, datacallback); - #endif - #endif + #ifdef simplepublishing + #ifdef ZgatewayRF + MQTTtoRF(topicOri, datacallback); + #endif + #ifdef ZgatewayRF315 + MQTTtoRF315(topicOri, datacallback); + #endif + #ifdef ZgatewayRF2 + MQTTtoRF2(topicOri, datacallback); + #endif + #ifdef Zgateway2G + MQTTto2G(topicOri, datacallback); + #endif + #ifdef ZgatewaySRFB + MQTTtoSRFB(topicOri, datacallback); + #endif + #ifdef ZgatewayIR + MQTTtoIR(topicOri, datacallback); + #endif + #ifdef ZgatewayRFM69 + MQTTtoRFM69(topicOri, datacallback); + #endif + #endif + #ifdef ZactuatorONOFF + MQTTtoONOFF(topicOri, datacallback); + #endif } //YELLOW OFF digitalWrite(led_send, HIGH); @@ -1054,7 +1050,7 @@ void pub(char * topicori, JsonObject& data){ #if defined(ESP8266) yield(); #endif - if (p.value.is() || p.value.is()) { + if (p.value.is() && strcmp(p.key, "rssi") != 0) { //test rssi , bypass solution due to the fact that a int is considered as an unsigned long trc(p.key); trc(p.value.as()); if (strcmp(p.key, "value") == 0){ // if data is a value we don't integrate the name into the topic @@ -1062,6 +1058,10 @@ void pub(char * topicori, JsonObject& data){ }else{ // if data is not a value we integrate the name into the topic pub(topic + "/" + String(p.key),p.value.as()); } + }else if (p.value.is()) { + trc(p.key); + trc(p.value.as()); + pub(topic + "/" + String(p.key),p.value.as()); } else if (p.value.is()) { trc(p.key); trc(p.value.as()); diff --git a/ZactuatorONOFF.ino b/ZactuatorONOFF.ino index 3902903..08c0bb1 100644 --- a/ZactuatorONOFF.ino +++ b/ZactuatorONOFF.ino @@ -38,14 +38,13 @@ void setupONOFF(){ trc(F("ZactuatorONOFF setup done ")); } -#ifdef simplePublishing void MQTTtoONOFF(char * topicOri, char * datacallback){ - bool boolSWITCHTYPE; - boolSWITCHTYPE = to_bool(datacallback); - String topic = topicOri; - - if (topic == subjectMQTTtoONOFF){ + int boolSWITCHTYPE; + if (strcmp(datacallback, "ON") == 0) boolSWITCHTYPE = 1; + if (strcmp(datacallback, "OFF") == 0) boolSWITCHTYPE = 0; + + if (strcmp(topicOri,subjectMQTTtoONOFF) == 0){ trc(F("MQTTtoONOFF data analysis")); trc(boolSWITCHTYPE); digitalWrite(ACTUATOR_ONOFF_PIN, boolSWITCHTYPE); @@ -53,14 +52,9 @@ void setupONOFF(){ pub(subjectGTWONOFFtoMQTT, datacallback); } } -#endif - -#ifdef jsonPublishing void MQTTtoONOFF(char * topicOri, JsonObject& ONOFFdata){ - String topic = topicOri; - - if (topic == subjectMQTTtoONOFF){ + if (strcmp(topicOri,subjectMQTTtoONOFF) == 0){ trc(F("MQTTtoONOFF json data analysis")); int boolSWITCHTYPE = ONOFFdata["switchType"] | 99; if (boolSWITCHTYPE != 99) { @@ -75,4 +69,3 @@ void setupONOFF(){ } } #endif -#endif diff --git a/Zgateway2G.ino b/Zgateway2G.ino index bc5cb86..e4d0a09 100644 --- a/Zgateway2G.ino +++ b/Zgateway2G.ino @@ -135,8 +135,7 @@ boolean _2GtoMQTT(){ #ifdef jsonPublishing void MQTTto2G(char * topicOri, JsonObject& SMSdata) { - String topic = topicOri; - if (topic == subjectMQTTto2G) { + if (strcmp(topicOri,subjectMQTTto2G) == 0){ const char * sms = SMSdata["message"]; const char * phone = SMSdata["phone"]; trc(F("MQTTto2G json data analysis")); diff --git a/ZgatewayBT.ino b/ZgatewayBT.ino index b8d3d2f..e33ccd9 100644 --- a/ZgatewayBT.ino +++ b/ZgatewayBT.ino @@ -89,10 +89,10 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht char service_data[returnedString.length()+1]; returnedString.toCharArray(service_data,returnedString.length()+1); service_data[returnedString.length()] = '\0'; - BLEdata.set("servicedata", service_data); - - BLEdata.set("servicedatauuid", (char *)advertisedDevice.getServiceDataUUID().toString().c_str()); - + #ifdef pubBLEServiceData + BLEdata.set("servicedata", service_data); + BLEdata.set("servicedatauuid", (char *)advertisedDevice.getServiceDataUUID().toString().c_str()); + #endif pub((char *)mactopic.c_str(),BLEdata); if (strstr(BLEdata["servicedatauuid"].as(),"fe95") != NULL){ @@ -259,7 +259,9 @@ boolean BTtoMQTT() { #endif String Service_data(d[5].extract); Service_data = Service_data.substring(14); - BLEdata.set("servicedata", (char *)Service_data.c_str()); + #ifdef pubBLEServiceData + BLEdata.set("servicedata", (char *)Service_data.c_str()); + #endif pub((char *)topic.c_str(),BLEdata); if (strcmp(d[4].extract, "fe95") == 0) { int pos = -1; diff --git a/ZgatewayPilight.ino b/ZgatewayPilight.ino index bf4e1b3..a1dda36 100644 --- a/ZgatewayPilight.ino +++ b/ZgatewayPilight.ino @@ -62,10 +62,10 @@ void pilightCallback(const String &protocol, const String &message, int status, } void MQTTtoPilight(char * topicOri, JsonObject& Pilightdata) { -String topic = topicOri; + int result = 0; - -if (topic == subjectMQTTtoPilight) { + + if (strcmp(topicOri,subjectMQTTtoPilight) == 0){ trc(F("MQTTtoPilight json data analysis")); const char * message = Pilightdata["message"]; const char * protocol = Pilightdata["protocol"]; diff --git a/ZgatewayRF.ino b/ZgatewayRF.ino index 71679d0..8e773b3 100644 --- a/ZgatewayRF.ino +++ b/ZgatewayRF.ino @@ -68,7 +68,10 @@ void RFtoMQTT(){ unsigned long MQTTvalue = RFdata.get("value"); if (!isAduplicate(MQTTvalue) && MQTTvalue!=0) {// conditions to avoid duplications of RF -->MQTT - trc(F("Adv data RFtoMQTT")); + trc(F("Adv data RFtoMQTT")); + #ifdef ZmqttDiscovery //component creation for HA + RFtoMQTTdiscovery(MQTTvalue); + #endif pub(subjectRFtoMQTT,RFdata); if (repeatRFwMQTT){ trc(F("Publish RF for repeat")); @@ -78,6 +81,24 @@ void RFtoMQTT(){ } } +#ifdef ZmqttDiscovery +void RFtoMQTTdiscovery(unsigned long MQTTvalue){//on the fly switch creation from received RF values + char val[11]; + sprintf(val, "%lu", MQTTvalue); + trc(F("switchRFDiscovery")); + char * switchRF[8] = {"switch", val, "", "","",val, "", ""}; + //component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement + + trc(F("CreateDiscoverySwitch")); + trc(switchRF[1]); + createDiscovery(switchRF[0], + subjectRFtoMQTT, switchRF[1], (char *)getUniqueId(switchRF[1], switchRF[2]).c_str(), + will_Topic, switchRF[3], switchRF[4], + switchRF[5], switchRF[6], switchRF[7], + true, false, 0,"","",true,subjectMQTTtoRF); +} +#endif + #ifdef simplePublishing void MQTTtoRF(char * topicOri, char * datacallback) { @@ -137,9 +158,7 @@ void MQTTtoRF(char * topicOri, char * datacallback) { #ifdef jsonPublishing void MQTTtoRF(char * topicOri, JsonObject& RFdata) { // json object decoding - String topic = topicOri; - - if (topic == subjectMQTTtoRF) { + if (strcmp(topicOri,subjectMQTTtoRF) == 0){ trc(F("MQTTtoRF json data analysis")); unsigned long data = RFdata["value"]; if (data != 0) { diff --git a/ZgatewayRF2.ino b/ZgatewayRF2.ino index 78f046d..e267614 100644 --- a/ZgatewayRF2.ino +++ b/ZgatewayRF2.ino @@ -217,9 +217,7 @@ void rf2Callback(unsigned int period, unsigned long address, unsigned long group #ifdef jsonPublishing void MQTTtoRF2(char * topicOri, JsonObject& RF2data) { // json object decoding - String topic = topicOri; - - if (topic == subjectMQTTtoRF2) { + if (strcmp(topicOri,subjectMQTTtoRF2) == 0){ trc(F("MQTTtoRF2 json data analysis")); int boolSWITCHTYPE = RF2data["switchType"] | 99; if (boolSWITCHTYPE != 99) { diff --git a/ZgatewayRF315.ino b/ZgatewayRF315.ino index 645e7cb..e83ed69 100644 --- a/ZgatewayRF315.ino +++ b/ZgatewayRF315.ino @@ -136,9 +136,7 @@ boolean RF315toMQTT(){ #ifdef jsonPublishing void MQTTtoRF315(char * topicOri, JsonObject& RF315data) { // json object decoding - String topic = topicOri; - - if (topic == subjectMQTTtoRF315) { + if (strcmp(topicOri,subjectMQTTtoRF315) == 0){ trc(F("MQTTtoRF315 json data analysis")); unsigned long data = RF315data["value"]; if (data != 0) { diff --git a/ZgatewayRFM69.ino b/ZgatewayRFM69.ino index 0b31d0c..873c938 100644 --- a/ZgatewayRFM69.ino +++ b/ZgatewayRFM69.ino @@ -231,9 +231,7 @@ boolean RFM69toMQTT(void) { #ifdef jsonPublishing void MQTTtoRFM69(char * topicOri, JsonObject& RFM69data) { - String topic = topicOri; - - if (topic == subjectMQTTtoRFM69) { + if (strcmp(topicOri,subjectMQTTtoRFM69) == 0){ const char * data = RFM69data["data"]; trc(F("MQTTtoRFM69 json data analysis")); if(data){ diff --git a/ZgatewaySRFB.ino b/ZgatewaySRFB.ino index 4a94c6c..1975f50 100644 --- a/ZgatewaySRFB.ino +++ b/ZgatewaySRFB.ino @@ -272,10 +272,9 @@ bool _rfbToChar(byte * in, char * out) { void MQTTtoSRFB(char * topicOri, JsonObject& SRFBdata) { // RF DATA ANALYSIS - String topic = topicOri; const char * raw = SRFBdata["raw"]; int valueRPT = SRFBdata["repeat"]|1; - if (topic == subjectMQTTtoSRFB){ + if (strcmp(topicOri,subjectMQTTtoSRFB) == 0){ trc(F("MQTTtoSRFB json data analysis")); if (raw){ // send raw in priority when defined in the json trc(F("MQTTtoSRFB raw ok")); diff --git a/ZmqttDiscovery.ino b/ZmqttDiscovery.ino index cbd18b0..3d6b2c2 100644 --- a/ZmqttDiscovery.ino +++ b/ZmqttDiscovery.ino @@ -28,120 +28,359 @@ void pubMqttDiscovery() { -#ifdef omgStatus trc(F("omgStatusDiscovery")); createDiscovery("binary_sensor", //set sensorType - will_Topic, DEVICENAME, getUniqueId("omg", "status"), //set state_topic,name,uniqueId - "", "connectivity", "", //set availability_topic,device_class,value_template, - Gateway_AnnouncementMsg, will_Message, "", //set,payload_on,payload_off,unit_of_meas, - true, false, 0); //set optimistic,retain, off_delay -#endif -#ifdef discBme280 + will_Topic, Gateway_Name, (char *)getUniqueId("", "").c_str(), //set state_topic,name,uniqueId + will_Topic, "connectivity", "", //set availability_topic,device_class,value_template, + Gateway_AnnouncementMsg, will_Message, "", //set,payload_on,payload_off,unit_of_meas, + false, true, 0, //set optimistic,retain, off_delay + Gateway_AnnouncementMsg, will_Message,false,"" //set,payload_avalaible,payload_not avalaible ,is a child device, command topic, state on, state off + ); + +#ifdef ZsensorBME280 + #define BMEparametersCount 6 trc(F("bme280Discovery")); - createDiscovery("sensor", - BME, "tempc", getUniqueId("bme", "tempc"), - will_Topic, "temperature", "{{ value_json.tempc }}", - "", "", "°C", - true, false, 0); - createDiscovery("sensor", - BME, "tempf", getUniqueId("bme", "tempf"), - will_Topic, "temperature", "{{ value_json.tempf }}", - "", "", "°F", - true, false, 0); - createDiscovery("sensor", - BME, "pa", getUniqueId("bme", "pa"), - will_Topic, "pressure", "{{ float(value_json.pa) * 0.01 }}", - "", "", "hPa", - true, false, 0); - createDiscovery("sensor", - BME, "hum", getUniqueId("bme", "hum"), - will_Topic, "humidity", "{{ value_json.hum }}", - "", "", "%", - true, false, 0); - createDiscovery("sensor", - BME, "altim", getUniqueId("bme", "altim"), - will_Topic, "", "{{ value_json.altim }}", - "", "", "m", - true, false, 0); - createDiscovery("sensor", - BME, "altift", getUniqueId("bme", "altift"), - will_Topic, "", "{{ value_json.altift }}", - "", "", "ft", - true, false, 0); + char * BMEsensor[BMEparametersCount][8] = { + {"sensor", "tempc", "bme","temperature","{{ value_json.tempc }}","", "", "°C"} , + {"sensor", "tempf", "bme","temperature","{{ value_json.tempf }}","", "", "°F"} , + {"sensor", "pa", "bme","","{{ float(value_json.pa) * 0.01 }}","", "", "hPa"} , + {"sensor", "hum", "bme","humidity","{{ value_json.hum }}","", "", "%"} , + {"sensor", "altim", "bme","","{{ value_json.altim }}","", "", "m"} , + {"sensor", "altift", "bme","","{{ value_json.altift }}","", "", "ft"} + //component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement + }; + + for (int i=0;i jsonBuffer3; - JsonObject &sensor = jsonBuffer3.createObject(); + StaticJsonBuffer jsonBuffer; + JsonObject &sensor = jsonBuffer.createObject(); sensor.set("stat_t", state_topic); //state_topic - sensor.set("name", name); //name + sensor.set("name", s_name); //name sensor.set("uniq_id", unique_id); //unique_id - if (availability_topic != "") - { - sensor.set("avty_t", availability_topic); //availability_topic - } - if (device_class != "") - { - sensor.set("dev_cla", device_class); //device_class - } - if (value_template != "") - { - sensor.set("val_tpl", value_template); //value_template - } - if (payload_on != "") - { - sensor.set("pl_on", payload_on); // payload_on - } - if (payload_off != "") - { - sensor.set("pl_off", payload_off); //payload_off - } - if (unit_of_meas != "") - { - sensor.set("unit_of_meas", unit_of_meas); //unit_of_measurement - } - if (optimistic != true) - { - sensor.set("opt", optimistic); //optimistic - } - if (retain != false) - { - sensor.set("ret", retain); //retain - } - if (off_delay > 0) - { - sensor.set("off_delay", off_delay); //off_delay - } + if (device_class[0]) sensor.set("dev_cla", device_class); //device_class + if (value_template[0]) sensor.set("val_tpl", value_template); //value_template + if (payload_on[0]) sensor.set("pl_on", payload_on); // payload_on + if (payload_off[0]) sensor.set("pl_off", payload_off); //payload_off + if (unit_of_meas[0]) sensor.set("unit_of_meas", unit_of_meas); //unit_of_measurement*/ + sensor.set("opt", optimistic)|false; //optimistic + sensor.set("ret", retain)|false; //retain + if (off_delay != 0) sensor.set("off_delay", off_delay); //off_delay + if (payload_available[0]) sensor.set("pl_avail", payload_available); // payload_on + if (payload_not_avalaible[0]) sensor.set("pl_not_avail", payload_not_avalaible); //payload_off + if (command_topic[0]) sensor.set("cmd_t", command_topic); //command_topic - char JSONmessageBuffer[JSON_MSG_BUFFER]; - StaticJsonBuffer jsonDeviceBuffer; - JsonObject &device = jsonDeviceBuffer.createObject(); - device.set("name", DEVICENAME); - device.set("manufacturer", DEVICEMANUFACTURER); - device.set("sw_version", OMG_VERSION); - JsonArray &identifiers = device.createNestedArray("identifiers"); - identifiers.add(getMacAddress()); +/*if (strcmp(s_name, Gateway_Name) == 0){ + JsonArray &json_attributes = sensor.createNestedArray("json_attributes"); + json_attributes.add("uptime"); + json_attributes.add("freemem"); + json_attributes.add("rssi"); + json_attributes.add("SSID"); +}*/ - sensor.set("device", device); //device sensor is connected to - String topic = (String)discovery_Topic + "/" + sensor_type + "/" + unique_id + "/config"; - pubDiscovery(topic, sensor); -} - -void pubDiscovery(String topicori, JsonObject &data) -{ - char JSONmessageBuffer[JSON_MSG_BUFFER]; - trc(F("Pub json into:")); - trc(topicori); - data.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer)); - trc(JSONmessageBuffer); - client.publish((char *)topicori.c_str(), JSONmessageBuffer, true); + if (child_device){ + StaticJsonBuffer jsonDeviceBuffer; + JsonObject &device = jsonDeviceBuffer.createObject(); + device.set("name", Gateway_Name); + device.set("manufacturer", DEVICEMANUFACTURER); + device.set("sw_version", OMG_VERSION); + JsonArray &identifiers = device.createNestedArray("identifiers"); + identifiers.add(getMacAddress()); + sensor.set("device", device); //device sensor is connected to + } + String topic = String(discovery_Topic) + "/" + String(sensor_type) + "/" + String(unique_id) + "/config"; + pub((char *)topic.c_str(), sensor); } String getMacAddress() diff --git a/ZsensorADC.ino b/ZsensorADC.ino index 6ec8058..04d2f61 100644 --- a/ZsensorADC.ino +++ b/ZsensorADC.ino @@ -37,12 +37,12 @@ unsigned long timeadc = 0; void MeasureADC(){ if (millis() > (timeadc + TimeBetweenReadingADC)) {//retriving value of temperature and humidity of the box from DHT every xUL + #if defined(ESP8266) + yield(); + #endif timeadc = millis(); static int persistedadc; int val = analogRead(ADC_PIN); - #if defined(ESP8266) || defined(ESP32) - yield(); - #endif if (isnan(val)) { trc(F("Failed to read from ADC !")); }else{ @@ -51,7 +51,7 @@ void MeasureADC(){ StaticJsonBuffer jsonBuffer; JsonObject& ADCdata = jsonBuffer.createObject(); ADCdata.set("adc", (int)val); - pub(ADC,ADCdata); + pub(ADCTOPIC,ADCdata); persistedadc = val; } } diff --git a/ZsensorBH1750.ino b/ZsensorBH1750.ino index 522c25a..ce73ff3 100644 --- a/ZsensorBH1750.ino +++ b/ZsensorBH1750.ino @@ -64,7 +64,7 @@ void MeasureLightIntensity() static float persistedlf; static float persistedlw; unsigned int Lux; - float FtCd; + float ftcd; float Wattsm2; // Check if reads failed and exit early (to try again). @@ -78,7 +78,7 @@ void MeasureLightIntensity() // Calculate the Values Lux = i/1.2; // Convert to Lux - FtCd = Lux/10.764; + ftcd = Lux/10.764; Wattsm2 = Lux/683.0; /* @@ -104,8 +104,8 @@ void MeasureLightIntensity() } // Generate FtCd - if(FtCd != persistedlf || bh1750_always){ - BH1750data.set("ftCd", (unsigned int)FtCd); + if(ftcd != persistedlf || bh1750_always){ + BH1750data.set("ftcd", (unsigned int)ftcd); }else{ trc(F("Same ftcd don't send it")); } @@ -119,7 +119,7 @@ void MeasureLightIntensity() if(BH1750data.size()>0) pub(subjectBH1750toMQTT,BH1750data); } persistedll = Lux; - persistedlf = FtCd; + persistedlf = ftcd; persistedlw = Wattsm2; } } diff --git a/ZsensorBME280.ino b/ZsensorBME280.ino index dc836be..385675a 100644 --- a/ZsensorBME280.ino +++ b/ZsensorBME280.ino @@ -173,7 +173,7 @@ void MeasureTempHumAndPressure() }else{ trc(F("Same Altitude Feet don't send it")); } - if(BME280data.size()>0) pub(BME,BME280data); + if(BME280data.size()>0) pub(BMETOPIC,BME280data); } persisted_bme_tempc = BmeTempC; persisted_bme_tempf = BmeTempF; diff --git a/ZsensorGPIOInput.ino b/ZsensorGPIOInput.ino index db03a0f..d51a854 100644 --- a/ZsensorGPIOInput.ino +++ b/ZsensorGPIOInput.ino @@ -71,6 +71,7 @@ void MeasureGPIOInput(){ if (InputState == LOW) { trc(F("GPIO LOW")); GPIOdata.set("gpio","LOW"); + pub(subjectGPIOInputtoMQTT,"LOW"); } if(GPIOdata.size()>0) pub(subjectGPIOInputtoMQTT,GPIOdata); } diff --git a/ZsensorINA226.ino b/ZsensorINA226.ino index 1038034..1da7ff3 100644 --- a/ZsensorINA226.ino +++ b/ZsensorINA226.ino @@ -81,9 +81,9 @@ void MeasureINA226(){ dtostrf(volt,6,3,volt_c); dtostrf(current,6,3,current_c); dtostrf(power,6,3,power_c); - INA226data.set("Volt", (char *)volt_c); - INA226data.set("Current", (char *)current_c); - INA226data.set("Power", (char *)power_c); + INA226data.set("volt", (char *)volt_c); + INA226data.set("current", (char *)current_c); + INA226data.set("power", (char *)power_c); pub(subjectINA226toMQTT,INA226data); } } diff --git a/config_ADC.h b/config_ADC.h index f25166f..366526a 100644 --- a/config_ADC.h +++ b/config_ADC.h @@ -26,12 +26,9 @@ /*----------------------------USER PARAMETERS-----------------------------*/ /*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/ -#define ADC Base_Topic Gateway_Name "/ADCtoMQTT" -#define TimeBetweenReadingADC 200 // time between 2 ADC readings, minimum 200 to let the time of the ESP to keep the connection +#define ADCTOPIC Base_Topic Gateway_Name "/ADCtoMQTT" +#define TimeBetweenReadingADC 500 // time between 2 ADC readings, minimum 200 to let the time of the ESP to keep the connection #define ThresholdReadingADC 50 // following the comparison between the previous value and the current one +- the threshold the value will be published or not /*-------------------PIN DEFINITIONS----------------------*/ #define ADC_PIN A0 //on nodeMCU this is D3 GPIO0 - - - diff --git a/config_BME280.h b/config_BME280.h index b114e9a..dccfbbe 100644 --- a/config_BME280.h +++ b/config_BME280.h @@ -35,13 +35,12 @@ ADD ---------> N/C (Not Connected) --> N/C (Not Connected) */ - -#define bme280_always true // if false when the current value for light Level (Lux) is the same as previous one don't send it by MQTT +#define bme280_always true // if false when the current value of the parameter is the same as previous one don't send it by MQTT #define TimeBetweenReadingbme280 30000 /*----------------------------USER PARAMETERS-----------------------------*/ /*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/ -#define BME Base_Topic Gateway_Name "/CLIMAtoMQTT/bme" +#define BMETOPIC Base_Topic Gateway_Name "/CLIMAtoMQTT/bme" //Time used to wait for an interval before resending measured values unsigned long timebme280 = 0; diff --git a/config_BT.h b/config_BT.h index b428d4d..06912b5 100644 --- a/config_BT.h +++ b/config_BT.h @@ -32,6 +32,7 @@ #define ZgatewayBT_v6xx // comment if you don't have a firmware version of HM10/11 >= v601 #define delimiter "4f4b2b444953413a" #define delimiter_length 16 +#define pubBLEServiceData true // comment if you don't want to publish service data (in case you are having too heavy service data) https://github.com/1technophile/OpenMQTTGateway/issues/318#issuecomment-446064707 /*-------------------HOME ASSISTANT ROOM PRESENCE ----------------------*/ // if not commented Home presence integration with HOME ASSISTANT is activated diff --git a/config_mqttDiscovery.h b/config_mqttDiscovery.h index 7d257a2..785e49d 100644 --- a/config_mqttDiscovery.h +++ b/config_mqttDiscovery.h @@ -25,8 +25,6 @@ */ #define discovery_Topic "homeassistant" -#define omgStatus //uncomment to create OMG status sensor -#define discBme280 //uncomment to enable bme280 sensors #define DEVICENAME "OpenMQTTGateway " Gateway_Name -#define DEVICEMANUFACTURER "AnimaVitis" +#define DEVICEMANUFACTURER "OMG_community"