Wifi managers improvements (#503)

* Add parameters to wifi manager: gateway name and base topic
Enable to restart the ESP and erase the parameters by MQTT
This commit is contained in:
Florian authored and GitHub committed 2019-12-07 10:18:42 +01:00
1 parent a05fd01505
commit 4b1f09b06b
41 files changed
+308 -196

No files matched your search

+23 -12
View File
@@ -50,6 +50,7 @@
#ifndef Gateway_Name
#define Gateway_Name "OpenMQTTGateway"
#endif
#define Base_Topic "home/"
/*-------------DEFINE YOUR NETWORK PARAMETERS BELOW----------------*/
#if defined(ESP8266)||defined(ESP32) // for nodemcu, weemos and esp8266
@@ -71,11 +72,14 @@
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
//MQTT Parameters definition
//#define mqtt_server_name "www.mqtt_broker.com" // instead of defining the server by its IP you can define it by its name, uncomment this line and set the correct MQTT server host name
char mqtt_user[20] = "your_username"; // not compulsory only if your broker needs authentication
char mqtt_pass[30] = "your_password"; // not compulsory only if your broker needs authentication
char mqtt_server[40] = "192.168.1.17";
#define parameters_size 20
#define mqtt_topic_max_size 100
char mqtt_user[parameters_size] = "your_username"; // not compulsory only if your broker needs authentication
char mqtt_pass[parameters_size] = "your_password"; // not compulsory only if your broker needs authentication
char mqtt_server[parameters_size] = "192.168.1.17";
char mqtt_port[6] = "1883";
char mqtt_topic[mqtt_topic_max_size] = Base_Topic;
char gateway_name[parameters_size * 2] = Gateway_Name;
//uncomment the line below to integrate msg value into the subject when receiving
//#define valueAsASubject true
@@ -119,9 +123,8 @@ const byte Dns[] = { 0, 0, 0, 0 }; //ip adress, if first value is different from
const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
/*-------------DEFINE YOUR MQTT ADVANCED PARAMETERS BELOW----------------*/
#define Base_Topic "home/"
#define version_Topic Base_Topic Gateway_Name "/version"
#define will_Topic Base_Topic Gateway_Name "/LWT"
#define version_Topic "/version"
#define will_Topic "/LWT"
#define will_QoS 0
#define will_Retain true
#define will_Message "offline"
@@ -182,9 +185,16 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
#endif
/*--------------MQTT general topics-----------------*/
// global MQTT subject listened by the gateway to execute commands (send RF, IR or others)
#define subjectMQTTtoX Base_Topic Gateway_Name "/commands/#"
#define subjectMultiGTWKey "toMQTT"
#define subjectGTWSendKey "MQTTto"
#define subjectMQTTtoX "/commands/#"
#define subjectMultiGTWKey "toMQTT"
#define subjectGTWSendKey "MQTTto"
// key used for launching commands to the gateway
#define restartCmd "restart"
#define eraseCmd "erase"
// define if we concatenate the values into the topic
//#define valueAsASubject true
//variables to avoid duplicates
#define time_avoid_duplicate 3000 // if you want to avoid duplicate mqtt message received set this to > 0, the value is the time in milliseconds during which we don't publish duplicates
@@ -197,9 +207,10 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
#endif
#define TimeBetweenReadingSYS 120000 // time between system readings (like memory)
#define subjectSYStoMQTT Base_Topic Gateway_Name "/SYStoMQTT"
#define subjectSYStoMQTT "/SYStoMQTT"
#define subjectMQTTtoSYSset "/commands/MQTTtoSYS/set"
//#define subjectTRACEtoMQTT Base_Topic Gateway_Name "/log" //uncomment if you want to see traces on /log topic
//#define subjectTRACEtoMQTT "OpenMQTTGateway/log" //uncomment if you want to see traces on OpenMQTTGateway/log topic
/*-------------------ACTIVATE TRACES----------------------*/
#define TRACE 1 // commented = trace off, uncommented = trace on
+7 -10
View File
@@ -127,14 +127,12 @@ void MQTTtoFASTLEDJSON(char *topicOri, JsonObject& jsonData)
{
trc(F("MQTTtoFASTLEDJSON: "));
currentLEDState = GENERAL;
String topic = topicOri;
trc(topic);
trc(topicOri);
//number = (long)strtol(&datacallback[1], NULL, 16);
if (topic == subjectMQTTtoFASTLEDsetled)
if (strstr(topicOri,catToMainTopic(subjectMQTTtoFASTLEDsetled)) != NULL)
{
trc(F("JSON parsed"));
int ledNr = jsonData["led"];
@@ -160,10 +158,9 @@ void MQTTtoFASTLED(char *topicOri, char *datacallback)
{
trc(F("MQTTtoFASTLED: "));
currentLEDState = GENERAL;
String topic = topicOri;
long number = 0;
trc(topic);
if (topic == subjectMQTTtoFASTLED)
trc(topicOri);
if (strstr(topicOri,catToMainTopic(subjectMQTTtoFASTLED)) != NULL)
{
number = (long)strtol(&datacallback[1], NULL, 16);
trc(number);
@@ -173,18 +170,18 @@ void MQTTtoFASTLED(char *topicOri, char *datacallback)
}
FastLED.show();
}
else if (topic == subjectMQTTtoFASTLEDsetbrightness)
else if (strstr(topicOri,catToMainTopic(subjectMQTTtoFASTLEDsetbrightness)) != NULL)
{
number = (long)strtol(&datacallback[1], NULL, 16);
trc(number);
FastLED.setBrightness(number);
FastLED.show();
}
else if (topic == subjectMQTTtoFASTLEDsetanimation)
else if (strstr(topicOri,catToMainTopic(subjectMQTTtoFASTLEDsetanimation)) != NULL)
{
String payload = datacallback;
trc(payload);
if (payload.equals("fire"))
if ( strstr(datacallback,"fire") != NULL)
{
currentLEDState = FIRE;
gPal = HeatColors_p;
+4 -3
View File
@@ -33,7 +33,7 @@
#ifdef jsonReceiving
void MQTTtoONOFF(char * topicOri, JsonObject& ONOFFdata){
if (strcmp(topicOri,subjectMQTTtoONOFF) == 0){
if (strstr(topicOri,catToMainTopic(subjectMQTTtoONOFF)) != NULL){
trc(F("MQTTtoONOFF json data analysis"));
int boolSWITCHTYPE = ONOFFdata["state"] | 99;
int pin = ONOFFdata["pin"] | ACTUATOR_ONOFF_PIN;
@@ -55,7 +55,7 @@ void MQTTtoONOFF(char * topicOri, JsonObject& ONOFFdata){
#ifdef simpleReceiving
void MQTTtoONOFF(char * topicOri, char * datacallback) {
if ((strstr(topicOri,subjectMQTTtoONOFF) != NULL) ){
if ((strstr(topicOri,catToMainTopic(subjectMQTTtoONOFF)) != NULL) ){
trc(F("MQTTtoONOFF"));
int pin = strtol(datacallback, NULL, 10); // we will not be able to pass values > 4294967295
@@ -69,7 +69,8 @@ void MQTTtoONOFF(char * topicOri, char * datacallback) {
digitalWrite(pin, ON);
// we acknowledge the sending by publishing the value to an acknowledgement topic
pub(subjectGTWONOFFtoMQTT, ON);
char b = ON;
pub(subjectGTWONOFFtoMQTT, &b);
}
}
#endif
+4 -4
View File
@@ -107,7 +107,7 @@ bool _2GtoMQTT(){
String data = datacallback;
String topic = topicOri;
if (topic == subjectMQTTto2G) {
if (strstr(topicOri,catToMainTopic(subjectMQTTto2G)) != NULL) {
trc(F("MQTTto2G data analysis"));
// 2G DATA ANALYSIS
String phone_number = "";
@@ -122,7 +122,7 @@ bool _2GtoMQTT(){
if (A6l.sendSMS(phone_number,data) == A6_OK ) {
trc(F("SMS OK"));
// Acknowledgement to the GTW2G topic
pub(subjectGTW2GtoMQTT, datacallback);// we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
pub(subjectGTW2GtoMQTT, "SMS OK");// we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
}else{
trc(F("SMS KO"));
// Acknowledgement to the GTW2G topic
@@ -138,7 +138,7 @@ bool _2GtoMQTT(){
#ifdef jsonReceiving
void MQTTto2G(char * topicOri, JsonObject& SMSdata) {
if (strcmp(topicOri,subjectMQTTto2G) == 0){
if (strstr(topicOri,catToMainTopic(subjectMQTTto2G)) != NULL){
const char * sms = SMSdata["message"];
const char * phone = SMSdata["phone"];
trc(F("MQTTto2G json data analysis"));
@@ -148,7 +148,7 @@ bool _2GtoMQTT(){
if (A6l.sendSMS(String(phone),String(sms)) == A6_OK ) {
trc(F("SMS OK"));
// Acknowledgement to the GTW2G topic
pub(subjectGTW2GtoMQTT, SMSdata);// we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
pub(subjectGTW2GtoMQTT, "SMS OK");// we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
}else{
trc(F("SMS KO"));
pub(subjectGTW2GtoMQTT, "SMS KO");// we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
+9 -3
View File
@@ -530,7 +530,12 @@ void MiBandDiscovery(char * mac){
while(true){
trc(taskMessage);
delay(BLEinterval);
BLEscan();
if (client.state() == 0) {
BLEscan();
}else{
trc("MQTT client disconnected no BLE scan");
delay(1000);
}
}
}
@@ -993,12 +998,13 @@ void haRoomPresence(JsonObject& HomePresence){
HomePresence["distance"] = distance;
trc(F("BLE DISTANCE :"));
trc(distance);
pub(subjectHomePresence,HomePresence);
String topic = String(Base_Topic) + "home_presence/" + String(gateway_name);
pub_custom_topic((char *)topic.c_str(),HomePresence);
}
#endif
void MQTTtoBT(char * topicOri, JsonObject& BTdata) { // json object decoding
if (strcmp(topicOri,subjectMQTTtoBTset) == 0){
if (strstr(topicOri,catToMainTopic(subjectMQTTtoBTset)) != NULL){
trc(F("MQTTtoBT json set"));
// Black list & white list set
+2 -2
View File
@@ -152,7 +152,7 @@ void IRtoMQTT(){
storeValue(MQTTvalue);
if (repeatIRwMQTT){
trc(F("Pub. IR for rpt"));
pub(subjectMQTTtoIR,MQTTvalue);
pubMQTT(subjectMQTTtoIR,MQTTvalue);
}
}
}
@@ -274,7 +274,7 @@ void IRtoMQTT(){
#ifdef jsonReceiving
void MQTTtoIR(char * topicOri, JsonObject& IRdata) {
if (strcmp(topicOri,subjectMQTTtoIR) == 0){
if (strstr(topicOri,catToMainTopic(subjectMQTTtoIR)) != NULL){
trc(F("MQTTtoIR json"));
uint64_t data = IRdata["value"];
const char * raw = IRdata["raw"];
+2 -2
View File
@@ -87,7 +87,7 @@ void LORAtoMQTT(){
#ifdef jsonReceiving
void MQTTtoLORA(char * topicOri, JsonObject& LORAdata) { // json object decoding
if (strcmp(topicOri,subjectMQTTtoLORA) == 0){
if (strstr(topicOri,catToMainTopic(subjectMQTTtoLORA)) != NULL){
trc(F("MQTTtoLORA json"));
const char * message = LORAdata["message"];
int txPower = LORAdata["txpower"]|LORA_TX_POWER;
@@ -120,7 +120,7 @@ void LORAtoMQTT(){
#endif
#ifdef simpleReceiving
void MQTTtoLORA(char * topicOri, char * LORAdata) { // json object decoding
if (strcmp(topicOri,subjectMQTTtoLORA) == 0){
if (strstr(topicOri,catToMainTopic(subjectMQTTtoLORA)) != NULL){
LoRa.beginPacket();
LoRa.print(LORAdata);
LoRa.endPacket();
+1 -1
View File
@@ -74,7 +74,7 @@ void MQTTtoPilight(char * topicOri, JsonObject& Pilightdata) {
int result = 0;
if (strcmp(topicOri,subjectMQTTtoPilight) == 0){
if (strstr(topicOri,catToMainTopic(subjectMQTTtoPilight)) != NULL){
trc(F("MQTTtoPilight json data analysis"));
const char * message = Pilightdata["message"];
const char * protocol = Pilightdata["protocol"];
+2 -3
View File
@@ -132,7 +132,7 @@ void MQTTtoRF(char * topicOri, char * datacallback) {
trc(valueBITS);
}
if ((topic == subjectMQTTtoRF) && (valuePRT == 0) && (valuePLSL == 0) && (valueBITS == 0)){
if ((strstr(topicOri,catToMainTopic(subjectMQTTtoRF)) != NULL) && (valuePRT == 0) && (valuePLSL == 0) && (valueBITS == 0)){
trc(F("MQTTtoRF dflt"));
mySwitch.setProtocol(1,350);
mySwitch.send(data, 24);
@@ -156,8 +156,7 @@ void MQTTtoRF(char * topicOri, char * datacallback) {
#ifdef jsonReceiving
void MQTTtoRF(char * topicOri, JsonObject& RFdata) { // json object decoding
if (strcmp(topicOri,subjectMQTTtoRF) == 0){
if (strstr(topicOri,catToMainTopic(subjectMQTTtoRF)) != NULL){
trc(F("MQTTtoRF json"));
unsigned long data = RFdata["value"];
if (data != 0) {
+3 -3
View File
@@ -202,11 +202,11 @@ void rf2Callback(unsigned int period, unsigned long address, unsigned long group
trc(F("Adv data MQTTtoRF2 push state via RF2toMQTT"));
if (isDimCommand) {
MQTTRF2string = subjectRF2toMQTT+String("/")+RF2codeKey+MQTTAddress+String("/")+RF2unitKey+MQTTunit+String("/")+RF2groupKey+MQTTgroupBit+String("/")+RF2dimKey+String("/")+RF2periodKey+MQTTperiod;
pub(MQTTRF2string,MQTTdimLevel);
pub((char *)MQTTRF2string.c_str(),(char *)MQTTdimLevel.c_str());
}
else {
MQTTRF2string = subjectRF2toMQTT+String("/")+RF2codeKey+MQTTAddress+String("/")+RF2unitKey+MQTTunit+String("/")+RF2groupKey+MQTTgroupBit+String("/")+RF2periodKey+MQTTperiod;
pub(MQTTRF2string,MQTTswitchType);
pub((char *)MQTTRF2string.c_str(),(char *)MQTTswitchType.c_str());
}
}
}
@@ -215,7 +215,7 @@ void rf2Callback(unsigned int period, unsigned long address, unsigned long group
#ifdef jsonReceiving
void MQTTtoRF2(char * topicOri, JsonObject& RF2data) { // json object decoding
if (strcmp(topicOri,subjectMQTTtoRF2) == 0){
if (strstr(topicOri,catToMainTopic(subjectMQTTtoRF2)) != NULL){
trc(F("MQTTtoRF2 json"));
int boolSWITCHTYPE = RF2data["switchType"] | 99;
if (boolSWITCHTYPE != 99) {
+2 -2
View File
@@ -184,7 +184,7 @@ bool RFM69toMQTT(void) {
#ifdef simpleReceiving
void MQTTtoRFM69(char * topicOri, char * datacallback) {
if(strstr(topicOri, subjectMQTTtoRFM69) != NULL){
if(strstr(topicOri,catToMainTopic(subjectMQTTtoRFM69)) != NULL){
trc(F("MQTTtoRFM69 data analysis"));
char data[RF69_MAX_DATA_LEN+1];
memcpy(data, (void *)datacallback, RF69_MAX_DATA_LEN);
@@ -215,7 +215,7 @@ bool RFM69toMQTT(void) {
#ifdef jsonReceiving
void MQTTtoRFM69(char * topicOri, JsonObject& RFM69data) {
if (strcmp(topicOri,subjectMQTTtoRFM69) == 0){
if (strstr(topicOri,catToMainTopic(subjectMQTTtoRFM69)) != NULL){
const char * data = RFM69data["data"];
trc(F("MQTTtoRFM69 json data analysis"));
if(data){
+1 -1
View File
@@ -280,7 +280,7 @@ bool _rfbToChar(byte * in, char * out) {
// RF DATA ANALYSIS
const char * raw = SRFBdata["raw"];
int valueRPT = SRFBdata["repeat"]|1;
if (strcmp(topicOri,subjectMQTTtoSRFB) == 0){
if (strstr(topicOri,catToMainTopic(subjectMQTTtoSRFB)) != NULL){
trc(F("MQTTtoSRFB json"));
if (raw){ // send raw in priority when defined in the json
trc(F("MQTTtoSRFB raw ok"));
+1 -1
View File
@@ -93,7 +93,7 @@ void createDiscovery(char * sensor_type,
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);
pub_custom_topic((char *)topic.c_str(), sensor);
}
void pubMqttDiscovery()
+3 -3
View File
@@ -32,9 +32,9 @@ extern void MQTTto2G(char * topicOri, char * datacallback);
extern void MQTTto2G(char * topicOri, JsonObject& SMSdata);
/*-------------------2G topics & parameters----------------------*/
//433Mhz MQTT Subjects and keys
#define subjectMQTTto2G Base_Topic Gateway_Name "/commands/MQTTto2G"
#define subject2GtoMQTT Base_Topic Gateway_Name "/2GtoMQTT"
#define subjectGTW2GtoMQTT Base_Topic Gateway_Name "/2GtoMQTT"
#define subjectMQTTto2G "/commands/MQTTto2G"
#define subject2GtoMQTT "/2GtoMQTT"
#define subjectGTW2GtoMQTT "/2GtoMQTT"
#define _2GPhoneKey "PHO_" // phone number define the phone number to send the SMS MQTT->2G
#define _2G_MODULE_BAUDRATE 9600
+1 -1
View File
@@ -30,7 +30,7 @@ extern void setupADC();
extern void ADCtoMQTT();
/*----------------------------USER PARAMETERS-----------------------------*/
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
#define ADCTOPIC Base_Topic Gateway_Name "/ADCtoMQTT"
#define ADCTOPIC "/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
+1 -1
View File
@@ -46,7 +46,7 @@ extern void BH1750toMQTT();
/*----------------------------USER PARAMETERS-----------------------------*/
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
#define subjectBH1750toMQTT Base_Topic Gateway_Name "/BH1750toMQTT"
#define subjectBH1750toMQTT "/BH1750toMQTT"
//Time used to wait for an interval before resending measured values
unsigned long timebh1750 = 0;
int BH1750_i2c_addr = 0x23; // Light Sensor I2C Address
+1 -1
View File
@@ -46,7 +46,7 @@ extern void BME280toMQTT();
/*----------------------------USER PARAMETERS-----------------------------*/
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
#define BMETOPIC Base_Topic Gateway_Name "/CLIMAtoMQTT/bme"
#define BMETOPIC "/CLIMAtoMQTT/bme"
//Time used to wait for an interval before resending measured values
unsigned long timebme280 = 0;
+4 -4
View File
@@ -30,10 +30,10 @@ extern void setupBT();
extern bool BTtoMQTT();
extern void MQTTtoBT(char * topicOri, JsonObject& RFdata);
/*----------------------BT topics & parameters-------------------------*/
#define subjectBTtoMQTT Base_Topic Gateway_Name "/BTtoMQTT/"
#define subjectMQTTtoBTset Base_Topic Gateway_Name "/commands/MQTTtoBT/set"
#define subjectBTtoMQTT "/BTtoMQTT/"
#define subjectMQTTtoBTset "/commands/MQTTtoBT/set"
#define TimeBtw_Read 55555 //define default time between 2 scans
#define MinimumRSSI -90 //default minimum rssi value, all the devices below -90 will not be reported
#define MinimumRSSI -100 //default minimum rssi value, all the devices below -90 will not be reported
#define Scan_duration 10 //define the time for a scan
#define HM-10
//#define HM-11 // uncomment this line if you use HM-11 and comment the line above
@@ -43,7 +43,7 @@ extern void MQTTtoBT(char * topicOri, JsonObject& RFdata);
/*-------------------HOME ASSISTANT ROOM PRESENCE ----------------------*/
// if not commented Home presence integration with HOME ASSISTANT is activated
#define subjectHomePresence Base_Topic "home_presence/" Gateway_Name // will send Home Assistant room presence message to this topic (first part is same for all rooms, second is room name)
#define subjectHomePresence "home_presence/" // will send Home Assistant room presence message to this topic (first part is same for all rooms, second is room name)
unsigned int BLEinterval ; //time between 2 scans
int Minrssi ; //minimum rssi value
+1 -1
View File
@@ -30,7 +30,7 @@ extern void setupDHT();
extern void DHTtoMQTT();
/*----------------------------USER PARAMETERS-----------------------------*/
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
#define DHTTOPIC Base_Topic Gateway_Name "/DHTtoMQTT/dht1"
#define DHTTOPIC "/DHTtoMQTT/dht1"
#define dht_always true // if false when the current value for temp or hum is the same as previous one don't send it by MQTT
#define TimeBetweenReadingDHT 30000 // time between 2 DHT readings
/*-------------DHT SENSOR TYPE-------------*/
+5 -10
View File
@@ -23,16 +23,11 @@
/*-------------------FASTLED topics & parameters----------------------*/
//FASTLED MQTT Subjects
#define subjectMQTTtoFASTLED Base_Topic Gateway_Name "/commands/MQTTtoFASTLED"
#define subjectMQTTtoFASTLEDsetled Base_Topic Gateway_Name "/commands/MQTTtoFASTLED/setled" //set only one LED with JSON struct {"led":0-x,"hex":"#000000","blink":true/false}
#define subjectMQTTtoFASTLEDsetbrightness Base_Topic Gateway_Name "/commands/MQTTtoFASTLED/setbrightness" //set the brightness 0-255
#define subjectMQTTtoFASTLEDsetanimation Base_Topic Gateway_Name "/commands/MQTTtoFASTLED/setanimation" //Animation Fire2012 by Mark Kriegsman
#define subjectGTWFASTLEDtoMQTT Base_Topic Gateway_Name "/FASTLEDtoMQTT" //same color on all LEDs in #RRGGBB
#define subjectMQTTtoFASTLED "/commands/MQTTtoFASTLED"
#define subjectMQTTtoFASTLEDsetled "/commands/MQTTtoFASTLED/setled" //set only one LED with JSON struct {"led":0-x,"hex":"#000000","blink":true/false}
#define subjectMQTTtoFASTLEDsetbrightness "/commands/MQTTtoFASTLED/setbrightness" //set the brightness 0-255
#define subjectMQTTtoFASTLEDsetanimation "/commands/MQTTtoFASTLED/setanimation" //Animation Fire2012 by Mark Kriegsman
#define subjectGTWFASTLEDtoMQTT "/FASTLEDtoMQTT" //same color on all LEDs in #RRGGBB
// How many leds in your strip?
#define FASTLED_NUM_LEDS 16
+1 -1
View File
@@ -30,7 +30,7 @@ extern void setupGPIOInput();
extern void GPIOInputtoMQTT();
/*----------------------------USER PARAMETERS-----------------------------*/
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
#define subjectGPIOInputtoMQTT Base_Topic Gateway_Name "/GPIOInputtoMQTT"
#define subjectGPIOInputtoMQTT "/GPIOInputtoMQTT"
#define GPIOInputDebounceDelay 60 //debounce time, increase if there are issues
/*-------------------PIN DEFINITIONS----------------------*/
+1 -1
View File
@@ -30,7 +30,7 @@ extern void setupGPIOKeyCode();
extern void GPIOKeyCodetoMQTT();
/*----------------------------USER PARAMETERS-----------------------------*/
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
#define subjectGPIOKeyCodetoMQTT Base_Topic Gateway_Name "/keycode"
#define subjectGPIOKeyCodetoMQTT "/keycode"
#define subjectGPIOKeyCodeStatetoMQTT subjectGPIOKeyCodetoMQTT "/status"
#define GPIOKeyCodeDebounceDelay 60 //debounce time, increase if there are issues
+1 -1
View File
@@ -45,7 +45,7 @@ extern void MeasureDistance();
/*----------------------------USER PARAMETERS-----------------------------*/
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
#define subjectHCSR04 Base_Topic Gateway_Name "/DISTtoMQTT/sr04"
#define subjectHCSR04 "/DISTtoMQTT/sr04"
/*-------------------PIN DEFINITIONS----------------------*/
#if defined(ESP8266)
+1 -1
View File
@@ -30,7 +30,7 @@ extern void setupHCSR501();
extern void HCSR501toMQTT();
/*----------------------------USER PARAMETERS-----------------------------*/
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
#define subjectHCSR501toMQTT Base_Topic Gateway_Name "/HCSR501toMQTT"
#define subjectHCSR501toMQTT "/HCSR501toMQTT"
#define TimeBeforeStartHCSR501 60000 //define the time necessary for HC SR501 init
+1 -1
View File
@@ -30,7 +30,7 @@ extern void setupINA226();
extern void INA226toMQTT();
/*----------------------------USER PARAMETERS-----------------------------*/
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
#define subjectINA226toMQTT Base_Topic Gateway_Name "/INA226toMQTT"
#define subjectINA226toMQTT "/INA226toMQTT"
#define TimeBetweenReadingINA226 30000 // time between 2 INA226 readings
#endif
+3 -3
View File
@@ -32,9 +32,9 @@ extern void MQTTtoIR(char * topicOri, char * datacallback);
extern void MQTTtoIR(char * topicOri, JsonObject& RFdata);
/*-------------------IR topics & parameters----------------------*/
//IR MQTT Subjects
#define subjectGTWIRtoMQTT Base_Topic Gateway_Name "/IRtoMQTT"
#define subjectIRtoMQTT Base_Topic Gateway_Name "/IRtoMQTT"
#define subjectMQTTtoIR Base_Topic Gateway_Name "/commands/MQTTtoIR"
#define subjectGTWIRtoMQTT "/IRtoMQTT"
#define subjectIRtoMQTT "/IRtoMQTT"
#define subjectMQTTtoIR "/commands/MQTTtoIR"
// subject monitored to listen traffic processed by other gateways to store data and avoid ntuple
#define subjectMultiGTWIR "+/+/IRtoMQTT"
+3 -3
View File
@@ -31,9 +31,9 @@ extern void LORAtoMQTT();
extern void MQTTtoLORA(char * topicOri, char * datacallback);
extern void MQTTtoLORA(char * topicOri, JsonObject& RFdata);
/*----------------------LORA topics & parameters-------------------------*/
#define subjectLORAtoMQTT Base_Topic Gateway_Name "/LORAtoMQTT"
#define subjectMQTTtoLORA Base_Topic Gateway_Name "/commands/MQTTtoLORA"
#define subjectGTWLORAtoMQTT Base_Topic Gateway_Name "/LORAtoMQTT"
#define subjectLORAtoMQTT "/LORAtoMQTT"
#define subjectMQTTtoLORA "/commands/MQTTtoLORA"
#define subjectGTWLORAtoMQTT "/LORAtoMQTT"
//Default parameters used when the parameters are not set in the json data
#define LORA_BAND 868E6
+2 -2
View File
@@ -31,8 +31,8 @@ extern void MQTTtoONOFF(char * topicOri, char * datacallback);
extern void MQTTtoONOFF(char * topicOri, JsonObject& RFdata);
/*----------------------------USER PARAMETERS-----------------------------*/
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
#define subjectMQTTtoONOFF Base_Topic Gateway_Name "/commands/MQTTtoONOFF"
#define subjectGTWONOFFtoMQTT Base_Topic Gateway_Name "/ONOFFtoMQTT"
#define subjectMQTTtoONOFF "/commands/MQTTtoONOFF"
#define subjectGTWONOFFtoMQTT "/ONOFFtoMQTT"
#define ONKey "setON"
#define OFFKey "setOFF"
+9 -9
View File
@@ -49,9 +49,9 @@
#endif
/*-------------------RF topics & parameters----------------------*/
//433Mhz MQTT Subjects and keys
#define subjectMQTTtoRF Base_Topic Gateway_Name "/commands/MQTTto433"
#define subjectRFtoMQTT Base_Topic Gateway_Name "/433toMQTT"
#define subjectGTWRFtoMQTT Base_Topic Gateway_Name "/433toMQTT"
#define subjectMQTTtoRF "/commands/MQTTto433"
#define subjectRFtoMQTT "/433toMQTT"
#define subjectGTWRFtoMQTT "/433toMQTT"
#define RFprotocolKey "433_" // protocol will be defined if a subject contains RFprotocolKey followed by a value of 1 digit
#define RFbitsKey "RFBITS_" // bits will be defined if a subject contains RFbitsKey followed by a value of 2 digits
#define repeatRFwMQTT false // do we repeat a received signal by using mqtt with RF gateway
@@ -73,9 +73,9 @@ RF supported protocols
/*-------------------RF2 topics & parameters----------------------*/
//433Mhz newremoteswitch MQTT Subjects and keys
#define subjectMQTTtoRF2 Base_Topic Gateway_Name "/commands/MQTTtoRF2"
#define subjectRF2toMQTT Base_Topic Gateway_Name "/RF2toMQTT"
#define subjectGTWRF2toMQTT Base_Topic Gateway_Name "/433toMQTT"
#define subjectMQTTtoRF2 "/commands/MQTTtoRF2"
#define subjectRF2toMQTT "/RF2toMQTT"
#define subjectGTWRF2toMQTT "/433toMQTT"
#define RF2codeKey "ADDRESS_" // code will be defined if a subject contains RF2codeKey followed by a value of 7 digits
#define RF2periodKey "PERIOD_" // period will be defined if a subject contains RF2periodKey followed by a value of 3 digits
#define RF2unitKey "UNIT_" // number of your unit value will be defined if a subject contains RF2unitKey followed by a value of 1-2 digits
@@ -84,9 +84,9 @@ RF supported protocols
/*-------------------ESPPiLight topics & parameters----------------------*/
//433Mhz Pilight MQTT Subjects and keys
#define subjectMQTTtoPilight Base_Topic Gateway_Name "/commands/MQTTtoPilight"
#define subjectPilighttoMQTT Base_Topic Gateway_Name "/PilighttoMQTT"
#define subjectGTWPilighttoMQTT Base_Topic Gateway_Name "/PilighttoMQTT"
#define subjectMQTTtoPilight "/commands/MQTTtoPilight"
#define subjectPilighttoMQTT "/PilighttoMQTT"
#define subjectGTWPilighttoMQTT "/PilighttoMQTT"
#define PilightRAW "RAW"
#define repeatPilightwMQTT false // do we repeat a received signal by using mqtt with Pilight gateway
+3 -3
View File
@@ -33,13 +33,13 @@ extern void MQTTtoRFM69(char * topicOri, JsonObject& RFdata);
/*----------------------RFM69 topics & parameters -------------------------*/
// Topic where the message from RFM69 will be published by the gateway,
// appended with the nodeID of the sender
#define subjectRFM69toMQTT Base_Topic Gateway_Name "/RFM69toMQTT"
#define subjectRFM69toMQTT "/RFM69toMQTT"
// Topic subscribed by the gateway. Messages received will be sent to RFM69
#define subjectMQTTtoRFM69 Base_Topic Gateway_Name "/commands/MQTTtoRFM69"
#define subjectMQTTtoRFM69 "/commands/MQTTtoRFM69"
#define RFM69receiverKey "RCV_" // receiver id will be defined if a subject contains RFM69receiverKey followed by a value of 3 digits
// On reception of an ack from RFM69, the message that has been sent is published here
#define subjectGTWRFM69toMQTT Base_Topic Gateway_Name "/RFM69toMQTT/acked"
#define subjectGTWRFM69toMQTT "/RFM69toMQTT/acked"
#define defaultRFM69ReceiverId 99
// Default values
+4 -4
View File
@@ -33,10 +33,10 @@ extern void MQTTtoSRFB(char * topicOri, char * datacallback);
extern void MQTTtoSRFB(char * topicOri, JsonObject& RFdata);
/*-------------------RF topics & parameters----------------------*/
//433Mhz MQTT Subjects and keys
#define subjectMQTTtoSRFB Base_Topic Gateway_Name "/commands/MQTTtoSRFB"
#define subjectMQTTtoSRFBRaw Base_Topic Gateway_Name "/commands/MQTTtoSRFB/Raw"
#define subjectSRFBtoMQTT Base_Topic Gateway_Name "/SRFBtoMQTT"
#define subjectGTWSRFBtoMQTT Base_Topic Gateway_Name "/SRFBtoMQTT"
#define subjectMQTTtoSRFB "/commands/MQTTtoSRFB"
#define subjectMQTTtoSRFBRaw "/commands/MQTTtoSRFB/Raw"
#define subjectSRFBtoMQTT "/SRFBtoMQTT"
#define subjectGTWSRFBtoMQTT "/SRFBtoMQTT"
#define SRFBRptKey "RPT_"
#define SRFBmaxipulselengthKey "Thigh_"
#define SRFBminipulselengthKey "Tlow_"
+1 -1
View File
@@ -46,7 +46,7 @@ extern void TSL2561toMQTT();
#define TimeBetweenReadingtsl2561 30000
/*----------------------------USER PARAMETERS-----------------------------*/
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
#define subjectTSL12561toMQTT Base_Topic Gateway_Name "/LIGHTtoMQTT"
#define subjectTSL12561toMQTT "/LIGHTtoMQTT"
//Time used to wait for an interval before resending measured values
unsigned long timetsl2561 = 0;
-1
View File
@@ -38,7 +38,6 @@ extern void createDiscovery(char * sensor_type,
#define discovery_Topic "homeassistant"
#define DEVICENAME "OpenMQTTGateway " Gateway_Name
#define DEVICEMANUFACTURER "OMG_community"
#endif
+133 -64
View File
@@ -204,7 +204,7 @@ void trc(String msg){
digitalWrite(led_info, HIGH);
#endif
#ifdef subjectTRACEtoMQTT
pub(subjectTRACEtoMQTT,msg);
pubMQTT(subjectTRACEtoMQTT,msg);
#endif
}
@@ -214,7 +214,7 @@ void trc(int msg){
digitalWrite(led_info, HIGH);
#endif
#ifdef subjectTRACEtoMQTT
pub(subjectTRACEtoMQTT,msg);
pubMQTT(subjectTRACEtoMQTT,msg);
#endif
}
@@ -224,7 +224,7 @@ void trc(unsigned int msg){
digitalWrite(led_info, HIGH);
#endif
#ifdef subjectTRACEtoMQTT
pub(subjectTRACEtoMQTT,msg);
pubMQTT(subjectTRACEtoMQTT,msg);
#endif
}
@@ -234,7 +234,7 @@ void trc(long msg){
digitalWrite(led_info, HIGH);
#endif
#ifdef subjectTRACEtoMQTT
pub(subjectTRACEtoMQTT,msg);
pubMQTT(subjectTRACEtoMQTT,msg);
#endif
}
@@ -244,7 +244,7 @@ void trc(unsigned long msg){
digitalWrite(led_info, HIGH);
#endif
#ifdef subjectTRACEtoMQTT
pub(subjectTRACEtoMQTT,msg);
pubMQTT(subjectTRACEtoMQTT,msg);
#endif
}
@@ -254,7 +254,7 @@ void trc(double msg){
digitalWrite(led_info, HIGH);
#endif
#ifdef subjectTRACEtoMQTT
pub(subjectTRACEtoMQTT,msg);
pubMQTT(subjectTRACEtoMQTT,msg);
#endif
}
@@ -264,25 +264,25 @@ void trc(float msg){
digitalWrite(led_info, HIGH);
#endif
#ifdef subjectTRACEtoMQTT
pub(subjectTRACEtoMQTT,msg);
pubMQTT(subjectTRACEtoMQTT,msg);
#endif
}
void trc(JsonObject& data){
char JSONmessageBuffer[JSON_MSG_BUFFER];
data.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
trc(JSONmessageBuffer);
char JSONmessageBuffer[JSON_MSG_BUFFER];
data.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
trc(JSONmessageBuffer);
}
void pub(char * topic, char * payload, bool retainFlag){
client.publish(topic, payload, retainFlag);
void pub(char * topicori, char * payload, bool retainFlag){
String topic = String(mqtt_topic) + String(topicori);
client.publish((char *)topic.c_str(), payload, retainFlag);
}
void pub(char * topicori, JsonObject& data){
if(client.connected()) {
digitalWrite(led_receive, HIGH);
String topic = topicori;
String topic = String(mqtt_topic) + String(topicori);
#ifdef valueAsASubject
unsigned long value = data["value"];
if (value != 0){
@@ -296,7 +296,7 @@ void pub(char * topicori, JsonObject& data){
trc(topic);
data.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
trc(JSONmessageBuffer);
pub(topic, JSONmessageBuffer);
pubMQTT(topic, JSONmessageBuffer);
#endif
#ifdef simplePublishing
@@ -310,22 +310,22 @@ void pub(char * topicori, JsonObject& data){
trc(p.key);
trc(p.value.as<unsigned long>());
if (strcmp(p.key, "value") == 0){ // if data is a value we don't integrate the name into the topic
pub(topic,p.value.as<unsigned long>());
pubMQTT(topic,p.value.as<unsigned long>());
}else{ // if data is not a value we integrate the name into the topic
pub(topic + "/" + String(p.key),p.value.as<unsigned long>());
pubMQTT(topic + "/" + String(p.key),p.value.as<unsigned long>());
}
}else if (p.value.is<int>()) {
trc(p.key);
trc(p.value.as<int>());
pub(topic + "/" + String(p.key),p.value.as<int>());
pubMQTT(topic + "/" + String(p.key),p.value.as<int>());
} else if (p.value.is<float>()) {
trc(p.key);
trc(p.value.as<float>());
pub(topic + "/" + String(p.key),p.value.as<float>());
pubMQTT(topic + "/" + String(p.key),p.value.as<float>());
} else if (p.value.is<char*>()) {
trc(p.key);
trc(p.value.as<const char*>());
pub(topic + "/" + String(p.key),p.value.as<const char*>());
pubMQTT(topic + "/" + String(p.key),p.value.as<const char*>());
}
}
#endif
@@ -334,76 +334,105 @@ void pub(char * topicori, JsonObject& data){
}
}
void pub(char * topic, char * payload){
void pub(char * topicori, char * payload){
if(client.connected()) {
String topic = String(mqtt_topic) + String(topicori);
trc(F("Pub ack into:"));
trc(topic);
pubMQTT(topic, payload);
}else{
trc("client not connected can't pub");
}
}
void pub_custom_topic(char * topicori, JsonObject& data){
if(client.connected()) {
char JSONmessageBuffer[JSON_MSG_BUFFER];
trc(F("Pub json discovery into:"));
trc(topicori);
data.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
trc(JSONmessageBuffer);
pubMQTT(topicori, JSONmessageBuffer);
}else{
trc("client not connected can't pub");
}
}
void pubMQTT(char * topic, char * payload){
client.publish(topic, payload);
}
void pub(String topic, char * payload){
void pubMQTT(String topic, char * payload){
client.publish((char *)topic.c_str(),payload);
}
void pub(char * topic, unsigned long payload){
void pubMQTT(char * topic, unsigned long payload){
char val[11];
sprintf(val, "%lu", payload);
client.publish(topic,val);
}
void pub(char * topic, String payload){
void pubMQTT(char * topic, String payload){
client.publish(topic,(char *)payload.c_str());
}
void pub(String topic, String payload){
void pubMQTT(String topic, String payload){
client.publish((char *)topic.c_str(),(char *)payload.c_str());
}
void pub(String topic, int payload){
void pubMQTT(String topic, int payload){
char val[12];
sprintf(val, "%d", payload);
client.publish((char *)topic.c_str(),val);
}
void pub(String topic, float payload){
void pubMQTT(String topic, float payload){
char val[12];
dtostrf(payload,3,1,val);
client.publish((char *)topic.c_str(),val);
}
void pub(char * topic, float payload){
void pubMQTT(char * topic, float payload){
char val[12];
dtostrf(payload,3,1,val);
client.publish(topic,val);
}
void pub(char * topic, int payload){
void pubMQTT(char * topic, int payload){
char val[6];
sprintf(val, "%d", payload);
client.publish(topic,val);
}
void pub(char * topic, unsigned int payload){
void pubMQTT(char * topic, unsigned int payload){
char val[6];
sprintf(val, "%u", payload);
client.publish(topic,val);
}
void pub(char * topic, long payload){
void pubMQTT(char * topic, long payload){
char val[11];
sprintf(val, "%l", payload);
client.publish(topic,val);
}
void pub(char * topic, double payload){
void pubMQTT(char * topic, double payload){
char val[16];
sprintf(val, "%d", payload);
client.publish(topic,val);
}
void pub(String topic, unsigned long payload){
void pubMQTT(String topic, unsigned long payload){
char val[11];
sprintf(val, "%lu", payload);
client.publish((char *)topic.c_str(),val);
}
char * catToMainTopic(char * toAdd){
String resultTopic = String(mqtt_topic) + String(toAdd);
return (char *)resultTopic.c_str();
}
void reconnect() {
#ifndef ESPWifiManualSetup
@@ -415,22 +444,18 @@ void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
trc(F("MQTT connection...")); //F function enable to decrease sram usage
if (client.connect(Gateway_Name, mqtt_user, mqtt_pass, will_Topic, will_QoS, will_Retain, will_Message)) {
if (client.connect(gateway_name, mqtt_user, mqtt_pass, will_Topic, will_QoS, will_Retain, will_Message)) {
trc(F("Connected to broker"));
failure_number = 0;
// Once connected, publish an announcement...
pub(will_Topic,Gateway_AnnouncementMsg,will_Retain);
// publish version
pub(version_Topic,OMG_VERSION,will_Retain);
//Subscribing to topic
if (client.subscribe(subjectMQTTtoX)) {
if (client.subscribe(catToMainTopic(subjectMQTTtoX))) {
#ifdef ZgatewayRF
client.subscribe(subjectMultiGTWRF); // subject on which other OMG will publish, this OMG will store these msg and by the way don't republish them if they have been already published
#endif
#ifdef ZgatewayRF315
client.subscribe(subjectMultiGTWRF315);// subject on which other OMG will publish, this OMG will store these msg and by the way don't republish them if they have been already published
#endif
#ifdef ZgatewayIR
client.subscribe(subjectMultiGTWIR);// subject on which other OMG will publish, this OMG will store these msg and by the way don't republish them if they have been already published
#endif
@@ -450,7 +475,7 @@ void reconnect() {
}
trc(F("failed, rc="));
trc(client.state());
delay(5000);
delay(10000);
}
}
}
@@ -473,6 +498,11 @@ void callback(char* topic, byte* payload, unsigned int length) {
free(p);
}
void setup_parameters()
{
strcat(mqtt_topic,gateway_name);
}
void setup()
{
//Launch serial for debugging purposes
@@ -563,6 +593,8 @@ void setup()
#endif
#endif
setup_parameters();
client.setCallback(callback);
delay(1500);
@@ -632,7 +664,7 @@ void setup()
trc(F("MQTT_MAX_PACKET_SIZE"));
trc(MQTT_MAX_PACKET_SIZE);
#if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
if(MQTT_MAX_PACKET_SIZE == 128) trc(F("WRONG PUBSUBCLIENT LIBRARY USED PLEASE INSTALL THE ONE FROM OMG LIB FOLDER"));
if(MQTT_MAX_PACKET_SIZE == 128) trc(F("WRONG PUBSUBCLIENT LIBRARY USED PLEASE INSTALL THE ONE FROM RELEASE PAGE"));
#endif
trc(F("Setup OpenMQTTGateway end"));
}
@@ -693,14 +725,26 @@ void checkButton(){ // code from tzapu/wifimanager examples
}
}
}
void eraseAndRestart(){
#if defined(ESP8266)
WiFi.disconnect(true);
#else
WiFi.disconnect(true,true);
#endif
trc("Formatting requested, result:");
trc(SPIFFS.format());
#if defined(ESP8266)
ESP.reset();
#else
ESP.restart();
#endif
}
void setup_wifimanager(bool reset_settings){
pinMode(TRIGGER_PIN, INPUT_PULLUP);
if(reset_settings) {
trc("Formatting requested, result:");
trc(SPIFFS.format());
}
if(reset_settings) eraseAndRestart();
WiFi.mode(WIFI_STA);
@@ -730,10 +774,12 @@ void setup_wifimanager(bool reset_settings){
json.printTo(Serial);
if (json.success()) {
trc(F("\nparsed json"));
strcpy(mqtt_server, json["mqtt_server"]);
strcpy(mqtt_port, json["mqtt_port"]);
strcpy(mqtt_user, json["mqtt_user"]);
strcpy(mqtt_pass, json["mqtt_pass"]);
if (json.containsKey("mqtt_server")) strcpy(mqtt_server, json["mqtt_server"]);
if (json.containsKey("mqtt_port")) strcpy(mqtt_port, json["mqtt_port"]);
if (json.containsKey("mqtt_user")) strcpy(mqtt_user, json["mqtt_user"]);
if (json.containsKey("mqtt_pass")) strcpy(mqtt_pass, json["mqtt_pass"]);
if (json.containsKey("mqtt_topic")) strcpy(mqtt_topic, json["mqtt_topic"]);
if (json.containsKey("gateway_name")) strcpy(gateway_name, json["gateway_name"]);
} else {
trc(F("failed to load json config"));
}
@@ -743,11 +789,13 @@ void setup_wifimanager(bool reset_settings){
// The extra parameters to be configured (can be either global or just in the setup)
// After connecting, parameter.getValue() will get you the configured value
// id/name placeholder/prompt default length
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, parameters_size);
WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 6);
WiFiManagerParameter custom_mqtt_user("user", "mqtt user", mqtt_user, 20);
WiFiManagerParameter custom_mqtt_pass("pass", "mqtt pass", mqtt_pass, 30);
WiFiManagerParameter custom_mqtt_user("user", "mqtt user", mqtt_user, parameters_size);
WiFiManagerParameter custom_mqtt_pass("pass", "mqtt pass", mqtt_pass, parameters_size);
WiFiManagerParameter custom_mqtt_topic("topic", "mqtt base topic", mqtt_topic, mqtt_topic_max_size);
WiFiManagerParameter custom_gateway_name("name", "gateway name", gateway_name, parameters_size * 2);
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
@@ -766,16 +814,9 @@ void setup_wifimanager(bool reset_settings){
wifiManager.addParameter(&custom_mqtt_port);
wifiManager.addParameter(&custom_mqtt_user);
wifiManager.addParameter(&custom_mqtt_pass);
wifiManager.addParameter(&custom_gateway_name);
wifiManager.addParameter(&custom_mqtt_topic);
if(reset_settings){
wifiManager.resetSettings();
wifiManager.erase();
#if defined(ESP8266)
ESP.reset();
#else
ESP.restart();
#endif
}
//set minimum quality of signal so it ignores AP's under that quality
wifiManager.setMinimumSignalQuality(MinimumWifiSignalQuality);
@@ -802,7 +843,9 @@ void setup_wifimanager(bool reset_settings){
strcpy(mqtt_port, custom_mqtt_port.getValue());
strcpy(mqtt_user, custom_mqtt_user.getValue());
strcpy(mqtt_pass, custom_mqtt_pass.getValue());
strcpy(mqtt_topic, custom_mqtt_topic.getValue());
strcpy(gateway_name, custom_gateway_name.getValue());
//save the custom parameters to FS
if (shouldSaveConfig) {
trc(F("saving config"));
@@ -812,6 +855,8 @@ void setup_wifimanager(bool reset_settings){
json["mqtt_port"] = mqtt_port;
json["mqtt_user"] = mqtt_user;
json["mqtt_pass"] = mqtt_pass;
json["mqtt_topic"] = mqtt_topic;
json["gateway_name"] = gateway_name;
File configFile = SPIFFS.open("/config.json", "w");
if (!configFile) {
@@ -1227,7 +1272,7 @@ void receivingMQTT(char * topicOri, char * datacallback) {
#ifdef ZactuatorFASTLED
MQTTtoFASTLEDJSON(topicOri, jsondata);
#endif
MQTTtoSYS(topicOri, jsondata);
} else { // not a json object --> simple decoding
#ifdef simpleReceiving
@@ -1269,3 +1314,27 @@ void receivingMQTT(char * topicOri, char * datacallback) {
//YELLOW OFF
digitalWrite(led_send, HIGH);
}
void MQTTtoSYS(char * topicOri, JsonObject& SYSdata) { // json object decoding
if (strstr(topicOri,catToMainTopic(subjectMQTTtoSYSset)) != NULL){
trc(F("MQTTtoSYS json set"));
#if defined(ESP8266) || defined(ESP32)
if (SYSdata.containsKey("cmd")){
trc(F("Command"));
const char * cmd = SYSdata["cmd"];
trc(cmd);
if (strstr(cmd,restartCmd) != NULL) {//restart
#if defined(ESP8266)
ESP.reset();
#else
ESP.restart();
#endif
}else if (strstr(cmd,eraseCmd) != NULL) {//erase and restart
setup_wifimanager(true);
}else{
trc(F("wrong command"));
}
}
#endif
}
}