From a270faa480681db3e9f76ccf8cfef302fe1bfc44 Mon Sep 17 00:00:00 2001 From: Magnus Persson Date: Wed, 12 Jan 2022 18:55:54 +0100 Subject: [PATCH] Merged mqtt --- platformio.ini | 4 ++-- src/pushtarget.cpp | 5 +++-- src/wifi.cpp | 21 ++++++++++++--------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/platformio.ini b/platformio.ini index 604d26c..15282d8 100644 --- a/platformio.ini +++ b/platformio.ini @@ -39,7 +39,7 @@ build_flags = -D EMBED_HTML # If this is not used the html files needs to be on the file system (can be uploaded) -D USER_SSID=\""\"" # =\""myssid\"" -D USER_SSID_PWD=\""\"" # =\""mypwd\"" - -D CFG_APPVER="\"0.5.2\"" + -D CFG_APPVER="\"0.5.3\"" lib_deps = # Switched to forks for better version control. # Using local copy of this library #https://github.com/jrowberg/i2cdevlib.git# @@ -52,7 +52,7 @@ lib_deps = # Switched to forks for better version control. https://github.com/mp-se/OneWire#v2.3.6 # https://github.com/PaulStoffregen/OneWire https://github.com/mp-se/Arduino-Temperature-Control-Library#3.9.1 # https://github.com/milesburton/Arduino-Temperature-Control-Library https://github.com/mp-se/arduinoCurveFitting#v1.0.6 # https://github.com/Rotario/arduinoCurveFitting - https://github.com/256dpi/arduino-mqtt + https://github.com/mp-se/arduino-mqtt#v2.5.0 # https://github.com/256dpi/arduino-mqtt [env:gravity-debug] upload_speed = ${common_env_data.upload_speed} diff --git a/src/pushtarget.cpp b/src/pushtarget.cpp index 6f154e5..f57abc5 100644 --- a/src/pushtarget.cpp +++ b/src/pushtarget.cpp @@ -283,7 +283,7 @@ void PushTarget::sendMqtt(float angle, float gravity, float corrGravity, createIspindleFormat(doc, angle, gravity, corrGravity, temp, runTime); WiFiClient client; - MQTTClient mqtt(512); // Maximum message size + MQTTClient mqtt(512); // Maximum message size mqtt.begin(myConfig.getMqttUrl(), client); mqtt.connect(myConfig.getMDNS(), myConfig.getMqttUser(), @@ -301,7 +301,8 @@ void PushTarget::sendMqtt(float angle, float gravity, float corrGravity, if (mqtt.publish(myConfig.getMqttTopic(), json)) { Log.notice(F("PUSH: MQTT publish successful" CR)); } else { - Log.error(F("PUSH: MQTT publish failed err=%d, ret=%d" CR), mqtt.lastError(), mqtt.returnCode()); + Log.error(F("PUSH: MQTT publish failed err=%d, ret=%d" CR), + mqtt.lastError(), mqtt.returnCode()); } mqtt.disconnect(); diff --git a/src/wifi.cpp b/src/wifi.cpp index 2ff9567..e040735 100644 --- a/src/wifi.cpp +++ b/src/wifi.cpp @@ -87,11 +87,11 @@ bool WifiConnection::hasConfig() { // Check if there are stored WIFI Settings we can use. String ssid = WiFi.SSID(); if (ssid.length()) { - Log.notice(F("WIFI: Found credentials in EEPORM." CR)); - myConfig.setWifiSSID(WiFi.SSID()); - myConfig.setWifiPass(WiFi.psk()); - myConfig.saveFile(); - return true; + Log.notice(F("WIFI: Found credentials in EEPORM." CR)); + myConfig.setWifiSSID(WiFi.SSID()); + myConfig.setWifiPass(WiFi.psk()); + myConfig.saveFile(); + return true; } return false; } @@ -109,7 +109,9 @@ String WifiConnection::getIPAddress() { return WiFi.localIP().toString(); } // // Additional method to detect double reset. // -bool WifiConnection::isDoubleResetDetected() { return myDRD->detectDoubleReset(); } +bool WifiConnection::isDoubleResetDetected() { + return myDRD->detectDoubleReset(); +} // // Stop double reset detection @@ -171,16 +173,17 @@ void WifiConnection::connectAsync() { // Blocks until wifi connection has been found // bool WifiConnection::waitForConnection(int maxTime) { -#if DEBUG_LEVEL == 6 +#if DEBUG_LEVEL == 6 WiFi.printDiag(Serial); #endif int i = 0; while (WiFi.status() != WL_CONNECTED) { delay(100); - if ( i % 10 ) Serial.print("."); + if (i % 10) Serial.print("."); - if (i++ > (maxTime*10)) { // Try for maxTime seconds. Since delay is 100ms. + if (i++ > + (maxTime * 10)) { // Try for maxTime seconds. Since delay is 100ms. Log.error(F("WIFI: Failed to connect to wifi %d, aborting %s." CR), WiFi.status(), getIPAddress().c_str()); WiFi.disconnect();