Add checks for HASP_USE_MQTT

This commit is contained in:
fvanroie 2020-03-25 13:45:43 +01:00
parent 3a965b18e5
commit dc82075a96
2 changed files with 80 additions and 50 deletions

View File

@ -12,11 +12,14 @@
#include "hasp_log.h"
#include "hasp_mdns.h"
#include "hasp_mqtt.h"
#include "hasp_config.h"
#include "hasp_conf.h"
#if HASP_USE_MQTT
#include "hasp_mqtt.h"
#endif
uint8_t mdnsEnabled = true;
const float haspVersion = 0.38;
void mdnsSetup(const JsonObject & settings)
{
@ -27,7 +30,11 @@ void mdnsSetup(const JsonObject & settings)
void mdnsStart()
{
if(mdnsEnabled) {
#if HASP_USE_MQTT > 0
String hasp2Node = mqttGetNodename();
#else
String hasp2Node = "unknown";
#endif
// Setup mDNS service discovery if enabled
/*if(debugTelnetEnabled) {
}
@ -46,8 +53,7 @@ void mdnsStart()
addServiceTxt("arduino", "tcp", "tcp_check", "no");
addServiceTxt("arduino", "tcp", "ssh_upload", "no");
addServiceTxt("arduino", "tcp", "board", ARDUINO_BOARD);
addServiceTxt("arduino", "tcp", "auth_upload", (auth) ? "yes" : "no");
*/
addServiceTxt("arduino", "tcp", "auth_upload", (auth) ? "yes" : "no");*/
} else {
errorPrintln(String(F("MDNS: %sResponder failed to start ")) + hasp2Node);
};

View File

@ -6,12 +6,17 @@
#include "hasp_debug.h"
#include "hasp_dispatch.h"
#include "hasp_ota.h"
#include "hasp_conf.h"
#if HASP_USE_MQTT
#include "hasp_mqtt.h"
#endif
#define F_OTA_URL F("otaurl")
std::string otaUrl = "http://10.1.0.3";
int8_t otaPrecentageComplete = -1;
int16_t otaPort = 3232;
void otaProgress()
{
@ -21,7 +26,6 @@ void otaProgress()
void otaSetup(JsonObject settings)
{
if(!settings[F_OTA_URL].isNull()) {
char buffer[128];
otaUrl = settings[F_OTA_URL].as<String>().c_str();
@ -29,9 +33,7 @@ void otaSetup(JsonObject settings)
debugPrintln(buffer);
}
ArduinoOTA.setHostname(String(mqttGetNodename()).c_str());
// ArduinoOTA.setPassword(configPassword);
if(otaPort > 0) {
ArduinoOTA.onStart([]() {
if(ArduinoOTA.getCommand() == U_FLASH) {
} else { // U_SPIFFS
@ -73,9 +75,31 @@ void otaSetup(JsonObject settings)
delay(5000);
// haspSendCmd("page " + String(nextionActivePage));
});
#if HASP_USE_MQTT > 0
ArduinoOTA.setHostname(String(mqttGetNodename()).c_str());
#else
ArduinoOTA.setHostname(String(mqttGetNodename()).c_str());
#endif
// ArduinoOTA.setPassword(configPassword);
ArduinoOTA.setPort(otaPort);
#if ESP32
#if HASP_USE_MDNS > 0
ArduinoOTA.setMdnsEnabled(true);
#else
ArduinoOTA.setMdnsEnabled(false);
#endif
// ArduinoOTA.setTimeout(1000);
#endif
ArduinoOTA.setRebootOnSuccess(true);
ArduinoOTA.begin();
debugPrintln(F("OTA: Over the Air firmware update ready"));
debugPrintln(F("OTA: Setup Complete"));
} else {
debugPrintln(F("OTA: Disabled"));
}
}
void otaLoop()