Merged mqtt

This commit is contained in:
Magnus Persson
2022-01-12 18:55:54 +01:00
parent aad35e20bd
commit a270faa480
3 changed files with 17 additions and 13 deletions

View File

@ -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();

View File

@ -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();