Merge branch 'MQTT_refacto' into 'master'

Mqtt refacto

MQTT and EEPROM code simplification.
Save about 1k

See merge request !6
This commit is contained in:
Mathieu 2016-11-20 00:30:42 +01:00
commit 1a2d3a3eb6
6 changed files with 117 additions and 153 deletions

View File

@ -1,12 +1,23 @@
#pragma once #pragma once
int EepromSaveConfig(uint8_t bootMode, String ssid, String password, String host, typedef struct productConfig_t {
String mqttServer, String mqttUser, String mqttPasswd, uint8_t bootMode;
int mqttPort, int ip_config, uint32_t ip, uint32_t gw, char *ssid;
uint32_t mask, uint32_t dns, uint32_t dns2); char *password;
int EepromSaveBootMode(uint8_t bootMode); char *host;
void EepromReadConfig(uint8_t &bootMode, char **ssid, char **password, char **host, char *mqttServer;
char **mqttServer, char **mqttUser, char **mqttPasswd, char *mqttUser;
int &mqttPort, int &ip_config, uint32_t &ip, uint32_t &gw, char *mqttPasswd;
uint32_t &mask, uint32_t &dns, uint32_t &dns2); int mqttPort;
int ip_mode;
uint32_t ip;
uint32_t gw;
uint32_t mask;
uint32_t dns;
uint32_t dns2;
} productConfig;
int EepromSaveConfig(productConfig &config);
int EepromSaveBootMode(uint8_t bootMode);
void EepromReadConfig(productConfig &config);

View File

@ -8,19 +8,16 @@
char eeprom[CONFIG_EEPROM_SIZE]; char eeprom[CONFIG_EEPROM_SIZE];
int EepromSaveConfig(uint8_t bootMode, String ssid, String password, String host, int EepromSaveConfig(productConfig &config) {
String mqttServer, String mqttUser, String mqttPasswd,
int mqttPort, int ip_config, uint32_t ip, uint32_t gw,
uint32_t mask, uint32_t dns, uint32_t dns2) {
String eeprom; String eeprom;
eeprom = String(bootMode) + ";" + ssid + ";" + password + ";" eeprom = String(config.bootMode) + ";" + config.ssid + ";" + config.password + ";"
+ host + ";" + mqttServer + ";" + config.host + ";" + config.mqttServer + ";"
+ mqttUser + ";" + mqttPasswd + ";" + config.mqttUser + ";" + config.mqttPasswd + ";"
+ String(mqttPort) + ";" + String(config.mqttPort) + ";"
+ String(ip_config) + ";" + String(config.ip_mode) + ";"
+ ip + ";" + gw + ";" + mask + ";" + config.ip + ";" + config.gw + ";" + config.mask + ";"
+ dns + ";" + dns2 + ";"; + config.dns + ";" + config.dns2 + ";";
if (eeprom.length() > CONFIG_EEPROM_SIZE ) if (eeprom.length() > CONFIG_EEPROM_SIZE )
return -EMSGSIZE; return -EMSGSIZE;
@ -59,10 +56,7 @@ void readConfElement(char** element, int &i) {
} }
void EepromReadConfig(uint8_t &bootMode, char **ssid, char **password, char **host, void EepromReadConfig(productConfig &config) {
char **mqttServer, char **mqttUser, char **mqttPasswd,
int &mqttPort, int &ip_config, uint32_t &ip, uint32_t &gw,
uint32_t &mask, uint32_t &dns, uint32_t &dns2) {
int i = 2; int i = 2;
@ -70,34 +64,34 @@ void EepromReadConfig(uint8_t &bootMode, char **ssid, char **password, char **ho
char *tmpString; char *tmpString;
if (boot == '1') { if (boot == '1') {
bootMode = BOOTMODE_NORMAL; config.bootMode = BOOTMODE_NORMAL;
} else if (boot == '2') { } else if (boot == '2') {
bootMode = BOOTMODE_OTA; config.bootMode = BOOTMODE_OTA;
} else { } else {
//Do not need to parse EEPROM when not configured //Do not need to parse EEPROM when not configured
bootMode = BOOTMODE_SETUP; config.bootMode = BOOTMODE_SETUP;
return; return;
} }
readConfElement(ssid, i); readConfElement(&config.ssid, i);
readConfElement(password, i); readConfElement(&config.password, i);
readConfElement(host, i); readConfElement(&config.host, i);
readConfElement(mqttServer, i); readConfElement(&config.mqttServer, i);
readConfElement(mqttUser, i); readConfElement(&config.mqttUser, i);
readConfElement(mqttPasswd, i); readConfElement(&config.mqttPasswd, i);
readConfElement(&tmpString, i); readConfElement(&tmpString, i);
mqttPort = atoi(tmpString); config.mqttPort = atoi(tmpString);
readConfElement(&tmpString, i); readConfElement(&tmpString, i);
ip_config = atoi(tmpString); config.ip_mode = atoi(tmpString);
readConfElement(&tmpString, i); readConfElement(&tmpString, i);
ip = atoi(tmpString); config.ip = atoi(tmpString);
readConfElement(&tmpString, i); readConfElement(&tmpString, i);
gw = atoi(tmpString); config.gw = atoi(tmpString);
readConfElement(&tmpString, i); readConfElement(&tmpString, i);
mask = atoi(tmpString); config.mask = atoi(tmpString);
readConfElement(&tmpString, i); readConfElement(&tmpString, i);
dns = atoi(tmpString); config.dns = atoi(tmpString);
readConfElement(&tmpString, i); readConfElement(&tmpString, i);
dns2 = atoi(tmpString); config.dns2 = atoi(tmpString);
} }

View File

@ -6,10 +6,11 @@ Adafruit_MQTT_Publish *MqttCreatePublisher(const char *fmt, ...);
int MqttConnect(); int MqttConnect();
int MqttIsConnected(); int MqttIsConnected();
int MqttSetup(char *server, char *user, char *passwd, int port, char * hostname); int MqttSetup(char *server, char *user, char *passwd, int port, char * hostname);
int MqttPublish(double temp, double pressure); template<typename T> int MqttPublish(Adafruit_MQTT_Publish *publisher, T value);
int MqttDhtPublish(float temp, float humidity); int MqttPublishBMP180(double temp, double pressure);
int MqttDryPublish(int dry); int MqttPublishDHT(float temp, float humidity);
int MqttIPPublish(const String &ip); int MqttPublishDry(int dry);
int MqttPublishIp(const String &ip);
void MqttCheckSubscription(); void MqttCheckSubscription();
void MqttChangeGpioValue(int gpio, int value); void MqttChangeGpioValue(int gpio, int value);
void MqttChangePWMValue(int gpio, int value); void MqttChangePWMValue(int gpio, int value);
@ -18,10 +19,11 @@ bool MqttIsConfigured();
int MqttConnect(){return 0;} int MqttConnect(){return 0;}
int MqttIsConnected(){return 0;} int MqttIsConnected(){return 0;}
int MqttSetup(char *server, char *user, char *passwd, int port, char * hostname){return 0;} int MqttSetup(char *server, char *user, char *passwd, int port, char * hostname){return 0;}
int MqttPublish(double temp, double pressure){return 0;} template<typename T> int MqttPublish(Adafruit_MQTT_Publish *publisher, T value){return 0;}
int MqttDhtPublish(float temp, float humidity){return 0;} int MqttPublishBMP180(double temp, double pressure){return 0;}
int MqttDryPublish(int dry){return 0;} int MqttPublishDHT(float temp, float humidity){return 0;}
int MqttIPPublish(const String &ip){return 0;} int MqttPublishDry(int dry){return 0;}
int MqttPublishIP(const String &ip){return 0;}
void MqttCheckSubscription(){} void MqttCheckSubscription(){}
void MqttChangeGpioValue(int gpio, int value){} void MqttChangeGpioValue(int gpio, int value){}
void MqttChangePWMValue(int gpio, int value){} void MqttChangePWMValue(int gpio, int value){}

View File

@ -127,38 +127,28 @@ int MqttConnect() {
return 0; return 0;
} }
int MqttPublish(double temp, double pressure) { template<typename T> int MqttPublish(Adafruit_MQTT_Publish *publisher, T value){
if (MqttConnect() == 0) { if (MqttConnect() == 0) {
SKETCH_DEBUG_PRINTLN("publishing !"); publisher->publish(value);
mqtt_temp->publish(temp);
mqtt_pressure->publish(pressure);
}
return 0; return 0;
} }
return -1;
}
int MqttDryPublish(int dry) { int MqttPublishBMP180(double temp, double pressure) {
if (MqttConnect() == 0) { return MqttPublish(mqtt_temp, temp) + MqttPublish(mqtt_pressure, pressure);
SKETCH_DEBUG_PRINTLN("publishing dry!");
mqtt_dry->publish((dry*100)/1024);
}
return 0;
} }
int MqttIPPublish(const String &ip) { int MqttPublishDry(int dry) {
if (MqttConnect() == 0) { return MqttPublish(mqtt_dry, (dry*100)/1024);
SKETCH_DEBUG_PRINTLN("publishing IP!");
mqtt_ip->publish(ip.c_str());
}
return 0;
} }
int MqttDhtPublish(float temp, float humidity) { int MqttPublishIP(const String &ip) {
if (MqttConnect() == 0) { return MqttPublish(mqtt_ip, ip.c_str());
SKETCH_DEBUG_PRINTLN("publishing DHT!");
mqtt_dht_temp->publish(temp);
mqtt_dht_humidity->publish(humidity);
} }
return 0;
int MqttPublishDHT(float temp, float humidity) {
return MqttPublish(mqtt_dht_temp, temp) + MqttPublish(mqtt_dht_humidity, humidity);
} }
int getGpioFromSubscription(Adafruit_MQTT_Subscribe *subscription, const char *pattern) { int getGpioFromSubscription(Adafruit_MQTT_Subscribe *subscription, const char *pattern) {

View File

@ -9,7 +9,7 @@ void WebHandleRoot() {
server.send(200, "text/html", server.send(200, "text/html",
"<head><meta http-equiv=\"refresh\" content=\"" + String(CONFIG_SAMPLING_PERIODE_MS / 1000) + "\" ></head>" "<head><meta http-equiv=\"refresh\" content=\"" + String(CONFIG_SAMPLING_PERIODE_MS / 1000) + "\" ></head>"
"<h1>You are connected to " + String(hostName) + "</h1>" "<h1>You are connected to " + String(conf.host) + "</h1>"
"<fieldset>" "<fieldset>"
"<legend>Sensors</legend>" "<legend>Sensors</legend>"
#ifdef CONFIG_ENABLE_BMP180 #ifdef CONFIG_ENABLE_BMP180
@ -65,49 +65,33 @@ void WebBuildSSIDList(String &datalist){
} }
void WebHandleSetup() { void WebHandleSetup() {
uint8_t mode;
char *confSsid = "";
char *confPassword = "";
char *confHost = "";
char *mqttServer = "";
char *mqttUser = "";
char *mqttPasswd = "";
int mqttPort = 1883;
int ip_config = 0;
uint32_t ip = 0;
uint32_t gw = 0;
uint32_t mask = 0;
uint32_t dns = 0;
uint32_t dns2 = 0;
String ssidlist; String ssidlist;
WebBuildSSIDList(ssidlist); WebBuildSSIDList(ssidlist);
EepromReadConfig(mode, &confSsid, &confPassword, &confHost, &mqttServer, &mqttUser, &mqttPasswd, mqttPort, ip_config, ip, gw, mask, dns, dns2);
server.send(200, "text/html", "<form action=\"/save\" method=\"get\">" server.send(200, "text/html", "<form action=\"/save\" method=\"get\">"
"<fieldset>" "<fieldset>"
"<legend>Wifi configuration:</legend>" "<legend>Wifi configuration:</legend>"
"<div><label for=\"ssid\">Wifi SSID :</label> <br/><input list=\"scan_ssid\" type=\"text\" name=\"ssid\" value=\"" + String(confSsid) + "\" /></div>" "<div><label for=\"ssid\">Wifi SSID :</label> <br/><input list=\"scan_ssid\" type=\"text\" name=\"ssid\" value=\"" + String(conf.ssid) + "\" /></div>"
"" + ssidlist + "" "" + ssidlist + ""
"<div><label for=\"password\">Wifi Password :</label><br/><input type=\"password\" name=\"password\" style=\"border-color:red\" /> </div>" "<div><label for=\"password\">Wifi Password :</label><br/><input type=\"password\" name=\"password\" style=\"border-color:red\" /> </div>"
"<div><label for=\"host\">Hostname :</label><br/><input type=\"text\" name=\"host\" value=\"" + String(confHost) + "\" /> </div>" "<div><label for=\"host\">Hostname :</label><br/><input type=\"text\" name=\"host\" value=\"" + String(conf.host) + "\" /> </div>"
"</fieldset>" "</fieldset>"
"<fieldset>" "<fieldset>"
"<legend>IP Configuration</legend>" "<legend>IP Configuration</legend>"
"<div><input type=\"radio\" name=\"ip_config\" value=\"0\" checked>DHCP <input type=\"radio\" name=\"ip_config\" value=\"1\">Static</div>" "<div><input type=\"radio\" name=\"ip_config\" value=\"0\" checked>DHCP <input type=\"radio\" name=\"ip_config\" value=\"1\">Static</div>"
"<div><label for=\"ip\">Ip :</label><br/><input type=\"text\" name=\"ip\" value=\"" + (ip == 0 ? "192.168.0.123": IPAddress(ip).toString()) + "\" /> </div>" "<div><label for=\"ip\">Ip :</label><br/><input type=\"text\" name=\"ip\" value=\"" + (conf.ip == 0 ? "192.168.0.123": IPAddress(conf.ip).toString()) + "\" /> </div>"
"<div><label for=\"gw\">Gateway :</label><br/><input type=\"text\" name=\"gw\" value=\"" + (gw == 0 ? "192.168.0.250": IPAddress(gw).toString()) + "\" /> </div>" "<div><label for=\"gw\">Gateway :</label><br/><input type=\"text\" name=\"gw\" value=\"" + (conf.gw == 0 ? "192.168.0.250": IPAddress(conf.gw).toString()) + "\" /> </div>"
"<div><label for=\"mask\">Netmask :</label><br/><input type=\"text\" name=\"mask\" value=\"" + (mask == 0 ? "255.255.255.0": IPAddress(mask).toString()) + "\" /> </div>" "<div><label for=\"mask\">Netmask :</label><br/><input type=\"text\" name=\"mask\" value=\"" + (conf.mask == 0 ? "255.255.255.0": IPAddress(conf.mask).toString()) + "\" /> </div>"
"<div><label for=\"mask\">DNS :</label><br/><input type=\"text\" name=\"dns\" value=\"" + (dns == 0 ? "192.168.0.250": IPAddress(dns).toString()) + "\" /> </div>" "<div><label for=\"mask\">DNS :</label><br/><input type=\"text\" name=\"dns\" value=\"" + (conf.dns == 0 ? "192.168.0.250": IPAddress(conf.dns).toString()) + "\" /> </div>"
"<div><label for=\"mask\">DNS2 :</label><br/><input type=\"text\" name=\"dns2\" value=\"" + (dns2 == 0 ? "": IPAddress(dns2).toString()) + "\" /> </div>" "<div><label for=\"mask\">DNS2 :</label><br/><input type=\"text\" name=\"dns2\" value=\"" + (conf.dns2 == 0 ? "": IPAddress(conf.dns2).toString()) + "\" /> </div>"
"</fieldset>" "</fieldset>"
"<fieldset>" "<fieldset>"
"<legend>MQTT:</legend>" "<legend>MQTT:</legend>"
"<div><label for=\"mqttServer\">Server :</label><br/><input type=\"text\" name=\"mqttServer\" value=\"" + String(mqttServer) + "\" /> </div>" "<div><label for=\"mqttServer\">Server :</label><br/><input type=\"text\" name=\"mqttServer\" value=\"" + String(conf.mqttServer) + "\" /> </div>"
"<div><label for=\"mqttUser\">Username :</label><br/><input type=\"text\" name=\"mqttUser\" value=\"" + String(mqttUser) + "\" /> </div>" "<div><label for=\"mqttUser\">Username :</label><br/><input type=\"text\" name=\"mqttUser\" value=\"" + String(conf.mqttUser) + "\" /> </div>"
"<div><label for=\"mqttPasswd\">Password :</label><br/><input type=\"password\" name=\"mqttPasswd\" style=\"border-color:red\" /> </div>" "<div><label for=\"mqttPasswd\">Password :</label><br/><input type=\"password\" name=\"mqttPasswd\" style=\"border-color:red\" /> </div>"
"<div><label for=\"mqttPort\">Port :</label><br/><input type=\"text\" name=\"mqttPort\" value=\"" + String(mqttPort) + "\" /> (8883 for secure Mqtts) </div>" "<div><label for=\"mqttPort\">Port :</label><br/><input type=\"text\" name=\"mqttPort\" value=\"" + String(conf.mqttPort) + "\" /> (8883 for secure Mqtts) </div>"
"</fieldset>" "</fieldset>"
"<div class=\"button\"> <button type=\"submit\">Save</button></div>" "<div class=\"button\"> <button type=\"submit\">Save</button></div>"
"</form>"); "</form>");
@ -166,11 +150,12 @@ void WebHandleSave() {
} }
} }
if (EepromSaveConfig(BOOTMODE_NORMAL, server.arg("ssid"), server.arg("password"), productConfig newConf = {BOOTMODE_NORMAL, strdup(server.arg("ssid").c_str()), strdup(server.arg("password").c_str()),
server.arg("host"), server.arg("mqttServer"), server.arg("mqttUser"), strdup(server.arg("host").c_str()), strdup(server.arg("mqttServer").c_str()), strdup(server.arg("mqttUser").c_str()),
server.arg("mqttPasswd"), server.arg("mqttPort").toInt(), strdup(server.arg("mqttPasswd").c_str()), server.arg("mqttPort").toInt(),
server.arg("ip_config").toInt(), static_cast<uint32_t>(ip), static_cast<uint32_t>(gw), server.arg("ip_config").toInt(), static_cast<uint32_t>(ip), static_cast<uint32_t>(gw),
static_cast<uint32_t>(mask), static_cast<uint32_t>(dns), static_cast<uint32_t>(dns2)) < 0) { static_cast<uint32_t>(mask), static_cast<uint32_t>(dns), static_cast<uint32_t>(dns2)};
if (EepromSaveConfig(newConf) < 0) {
WebSendError("Cannot Save Credentials (Too long ?Contains \";\"?)\r\n"); WebSendError("Cannot Save Credentials (Too long ?Contains \";\"?)\r\n");
return; return;
} }

View File

@ -63,7 +63,7 @@ double temp, pressure;
float dhtTemp, dhtHumidity; float dhtTemp, dhtHumidity;
int dryness; int dryness;
uint8_t mode; uint8_t mode;
const char *hostName = ""; productConfig conf = {BOOTMODE_SETUP, "", "", "", "", "", "", 0, 0, 0, 0, 0, 0, 0};
/* Set these to your desired credentials. */ /* Set these to your desired credentials. */
const char *ssid = CONFIG_SSID_NAME; const char *ssid = CONFIG_SSID_NAME;
@ -91,38 +91,35 @@ void onLongButtonPressed(uint8_t pin){
} }
#endif #endif
void WifiSetup(int bootmode, char *confSsid, char *confPassword, char *confHost, int ip_config, uint32_t ip, uint32_t gw, uint32_t mask, uint32_t dns, uint32_t dns2) { void WifiSetup(productConfig conf) {
IPAddress myIP; IPAddress myIP;
if (bootmode == BOOTMODE_SETUP) { if (conf.bootMode == BOOTMODE_SETUP) {
SKETCH_DEBUG_PRINT("Configuring access point..."); SKETCH_DEBUG_PRINT("Configuring access point...");
SKETCH_DEBUG_PRINTLN(ssid); SKETCH_DEBUG_PRINTLN(conf.ssid);
/* You can set a password to the AP here */ /* You can set a password to the AP here */
WiFi.softAP(ssid); WiFi.softAP(conf.ssid);
myIP = WiFi.softAPIP(); myIP = WiFi.softAPIP();
} else { } else {
SKETCH_DEBUG_PRINTLN("Disable previous AP mode "); //Disable previous AP mode
WiFi.softAPdisconnect(true); WiFi.softAPdisconnect(true);
SKETCH_DEBUG_PRINTLN("Connecting to Wifi..."); SKETCH_DEBUG_PRINTLN("Connecting to Wifi...");
if(ip_config == 1){ if(conf.ip_mode == 1){
SKETCH_DEBUG_PRINTLN("Use static ip configuration"); SKETCH_DEBUG_PRINTLN("Use static ip configuration");
WiFi.config(IPAddress(ip), IPAddress(gw), IPAddress(mask), IPAddress(dns), IPAddress(dns2)); WiFi.config(IPAddress(conf.ip), IPAddress(conf.gw), IPAddress(conf.mask), IPAddress(conf.dns), IPAddress(conf.dns2));
} }
WiFi.begin(confSsid, confPassword); WiFi.begin(conf.ssid, conf.password);
while (WiFi.status() != WL_CONNECTED) { while (WiFi.status() != WL_CONNECTED) {
delay(500); delay(500);
SKETCH_DEBUG_PRINT("."); SKETCH_DEBUG_PRINT(".");
} }
SKETCH_DEBUG_PRINTLN(""); SKETCH_DEBUG_PRINTF("\nWiFi connected\n");
SKETCH_DEBUG_PRINTLN("WiFi connected");
#ifdef CONFIG_ENABLE_MDNS #ifdef CONFIG_ENABLE_MDNS
if (!MDNS.begin(confHost)) { if (!MDNS.begin(conf.host)) {
SKETCH_DEBUG_PRINTLN("Error setting up MDNS responder!"); SKETCH_DEBUG_PRINTLN("Error setting up MDNS responder!");
while (1) { } else {
delay(1000);
}
}
SKETCH_DEBUG_PRINTLN("mDNS responder started"); SKETCH_DEBUG_PRINTLN("mDNS responder started");
}
#endif #endif
myIP = WiFi.localIP(); myIP = WiFi.localIP();
} }
@ -130,6 +127,7 @@ void WifiSetup(int bootmode, char *confSsid, char *confPassword, char *confHost,
SKETCH_DEBUG_PRINT("My IP address: "); SKETCH_DEBUG_PRINT("My IP address: ");
SKETCH_DEBUG_PRINTLN(myIP); SKETCH_DEBUG_PRINTLN(myIP);
} }
void OTASetup() { void OTASetup() {
#ifndef CONFIF_DISABLE_OTA #ifndef CONFIF_DISABLE_OTA
// Port defaults to 8266 // Port defaults to 8266
@ -174,7 +172,7 @@ void OTASetup() {
}); });
ArduinoOTA.begin(); ArduinoOTA.begin();
SKETCH_DEBUG_PRINTLN("Ready"); SKETCH_DEBUG_PRINTLN("Ready");
SKETCH_DEBUG_PRINT("IP address: "); SKETCH_DEBUG_PRINTF("IP address: ");
SKETCH_DEBUG_PRINTLN(WiFi.localIP()); SKETCH_DEBUG_PRINTLN(WiFi.localIP());
SKETCH_DEBUG_PRINTF("Free Space: %d\n", ESP.getFreeSketchSpace()); SKETCH_DEBUG_PRINTF("Free Space: %d\n", ESP.getFreeSketchSpace());
#endif #endif
@ -183,20 +181,6 @@ void OTASetup() {
void setup() { void setup() {
pinMode(3, OUTPUT); pinMode(3, OUTPUT);
char *confSsid = "";
char *confPassword = "";
char *confHost = "";
char *mqttServer = "";
char *mqttUser = "";
char *mqttPasswd = "";
int mqttPort ;
int ip_mode = 0;
uint32_t ip = 0;
uint32_t gw = 0;
uint32_t mask = 0;
uint32_t dns = 0;
uint32_t dns2 = 0;
delay(1000); delay(1000);
SKETCH_DEBUG_INIT(115200); SKETCH_DEBUG_INIT(115200);
SKETCH_DEBUG_PRINTLN(); SKETCH_DEBUG_PRINTLN();
@ -210,35 +194,33 @@ void setup() {
#endif #endif
EEPROM.begin(CONFIG_EEPROM_SIZE); EEPROM.begin(CONFIG_EEPROM_SIZE);
EepromReadConfig(mode, &confSsid, &confPassword, &confHost, &mqttServer, &mqttUser, &mqttPasswd, mqttPort, ip_mode, ip, gw, mask, dns, dns2); EepromReadConfig(conf);
hostName = confHost; mode = conf.bootMode;
if (mode == BOOTMODE_NORMAL || mode == BOOTMODE_OTA) { if (mode == BOOTMODE_NORMAL || mode == BOOTMODE_OTA) {
SKETCH_DEBUG_PRINTLN("Configuration Found !:"); SKETCH_DEBUG_PRINTLN("Configuration Found !:");
SKETCH_DEBUG_PRINTLN(mode); SKETCH_DEBUG_PRINTLN(conf.bootMode);
SKETCH_DEBUG_PRINTLN(confSsid); SKETCH_DEBUG_PRINTLN(conf.ssid);
SKETCH_DEBUG_PRINTLN(confPassword); SKETCH_DEBUG_PRINTLN(conf.password);
SKETCH_DEBUG_PRINTLN(confHost); SKETCH_DEBUG_PRINTLN(conf.host);
SKETCH_DEBUG_PRINTLN(mqttServer); SKETCH_DEBUG_PRINTLN(conf.mqttServer);
SKETCH_DEBUG_PRINTLN(mqttUser); SKETCH_DEBUG_PRINTLN(conf.mqttUser);
SKETCH_DEBUG_PRINTLN(mqttPasswd); SKETCH_DEBUG_PRINTLN(conf.mqttPasswd);
SKETCH_DEBUG_PRINTLN(mqttPort); SKETCH_DEBUG_PRINTLN(conf.mqttPort);
SKETCH_DEBUG_PRINTLN(); SKETCH_DEBUG_PRINTLN();
} else { } else {
SKETCH_DEBUG_PRINTLN("No configuration saved"); SKETCH_DEBUG_PRINTLN("No configuration saved");
} }
SKETCH_DEBUG_PRINT("Force Setup Mode ? :"); SKETCH_DEBUG_PRINTF("Force Setup Mode ? : %s\n",txStatus ? "No" : "Yes");
SKETCH_DEBUG_PRINT(txStatus ? "No" : "Yes");
SKETCH_DEBUG_PRINTLN();
if(txStatus == 0){ if(txStatus == 0){
mode = BOOTMODE_SETUP; mode = BOOTMODE_SETUP;
} }
WifiSetup(mode, confSsid, confPassword, confHost, ip_mode, ip, gw, mask, dns, dns2); WifiSetup(conf);
if (mode == BOOTMODE_NORMAL) { if (mode == BOOTMODE_NORMAL) {
MqttSetup(mqttServer, mqttUser, mqttPasswd, mqttPort, confHost); MqttSetup(conf.mqttServer, conf.mqttUser, conf.mqttPasswd, conf.mqttPort, conf.host);
MqttIPPublish(WiFi.localIP().toString()); MqttPublishIP(WiFi.localIP().toString());
} }
if (mode == BOOTMODE_OTA) { if (mode == BOOTMODE_OTA) {
@ -281,7 +263,7 @@ void loop() {
SKETCH_DEBUG_PRINT(" Pressure mB "); SKETCH_DEBUG_PRINT(" Pressure mB ");
SKETCH_DEBUG_PRINTLN(pressure); SKETCH_DEBUG_PRINTLN(pressure);
if (mode == BOOTMODE_NORMAL) if (mode == BOOTMODE_NORMAL)
MqttPublish(temp, pressure); MqttPublishBMP180(temp, pressure);
} }
if (!DHTGetTempAndHumidity(dhtTemp, dhtHumidity)) { if (!DHTGetTempAndHumidity(dhtTemp, dhtHumidity)) {
SKETCH_DEBUG_PRINT("Current T°C "); SKETCH_DEBUG_PRINT("Current T°C ");
@ -289,14 +271,14 @@ void loop() {
SKETCH_DEBUG_PRINT(" Humidity "); SKETCH_DEBUG_PRINT(" Humidity ");
SKETCH_DEBUG_PRINTLN(dhtHumidity); SKETCH_DEBUG_PRINTLN(dhtHumidity);
if (mode == BOOTMODE_NORMAL) if (mode == BOOTMODE_NORMAL)
MqttDhtPublish(dhtTemp, dhtHumidity); MqttPublishDHT(dhtTemp, dhtHumidity);
} }
if (!DryGetMeasure(dryness)){ if (!DryGetMeasure(dryness)){
SKETCH_DEBUG_PRINT("Current dryness "); SKETCH_DEBUG_PRINT("Current dryness ");
SKETCH_DEBUG_PRINT((dryness*100)/1024); SKETCH_DEBUG_PRINT((dryness*100)/1024);
SKETCH_DEBUG_PRINTLN("%"); SKETCH_DEBUG_PRINTLN("%");
if (mode == BOOTMODE_NORMAL) if (mode == BOOTMODE_NORMAL)
MqttDryPublish(dryness); MqttPublishDry(dryness);
} }
nbCycle = 0; nbCycle = 0;
} }