From 3fab61513d45575dbb7f354ae4e263c29ceb3917 Mon Sep 17 00:00:00 2001 From: proddy Date: Sat, 23 Feb 2019 16:27:42 +0100 Subject: [PATCH] removed MDNS, now OTA works for both esp8266 and esp32 --- CHANGELOG.md | 4 ++++ README.md | 2 +- lib/myESP/MyESP.cpp | 46 +++++++++------------------------------------ lib/myESP/MyESP.h | 12 ++++-------- 4 files changed, 18 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36bd6a4a5..bcf1747a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added Bosch Easy thermostat, Buderus Logamax U122 - Support for changing boiler wwtemp via MQTT (merge #58 from egrekov). thanks! +### Removed + +- Custom MDNS support. Now handled much better in the new esp core under OTA + ## [1.5.2] 2019-02-04 ### Changed diff --git a/README.md b/README.md index 4cb323467..d4d4865a7 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ Every telegram sent is echo'd back to Rx, along the same Bus used for all Rx/Tx `ems_devices.h` has all the configuration for the known EMS devices currently supported. -`MyESP.cpp` is my custom library to handle WiFi, MQTT, MDNS and Telnet. Uses a modified version of [TelnetSpy](https://github.com/yasheena/telnetspy) +`MyESP.cpp` is my custom library to handle WiFi, MQTT and Telnet. Uses a modified version of [TelnetSpy](https://github.com/yasheena/telnetspy) ### Special EMS Types diff --git a/lib/myESP/MyESP.cpp b/lib/myESP/MyESP.cpp index a46cdd888..e01361904 100644 --- a/lib/myESP/MyESP.cpp +++ b/lib/myESP/MyESP.cpp @@ -1,5 +1,5 @@ /* - * MyESP - my ESP helper class to handle Wifi, MDNS, MQTT and Telnet + * MyESP - my ESP helper class to handle Wifi, MQTT and Telnet * * Paul Derbyshire - December 2018 * Version 1.1 - Feb 22 2019. Added support for ESP32 @@ -115,7 +115,7 @@ bool MyESP::getUseSerial() { return (_use_serial); } -// called when WiFi is connected, and used to start MDNS, OTA, MATT +// called when WiFi is connected, and used to start OTA, MQTT void MyESP::_wifiCallback(justwifi_messages_t code, char * parameter) { if ((code == MESSAGE_CONNECTED)) { #if defined(ARDUINO_ARCH_ESP32) @@ -134,14 +134,6 @@ void MyESP::_wifiCallback(justwifi_messages_t code, char * parameter) { myDebug_P(PSTR("[WIFI] DNS %s"), WiFi.dnsIP().toString().c_str()); myDebug_P(PSTR("[WIFI] HOST %s"), hostname.c_str()); - // start MDNS - if (MDNS.begin((char *)hostname.c_str())) { - _mdns_setup(); // MDNS setup - myDebug_P(PSTR("[MDNS] OK")); - } else { - myDebug_P(PSTR("[MDNS] FAIL")); - } - // start OTA ArduinoOTA.begin(); // moved to support esp32 myDebug_P(PSTR("[OTA] listening to %s.local:%u"), ArduinoOTA.getHostname().c_str(), OTA_PORT); @@ -305,31 +297,14 @@ void MyESP::_wifi_setup() { jw.addNetwork(_wifi_ssid, _wifi_password); // Add a network } -// MDNS setup -void MyESP::_mdns_setup() { - MDNS.addService("telnet", "tcp", TELNETSPY_PORT); - - // for OTA discovery -#if defined(ARDUINO_ARCH_ESP32) // TODO: doesn't work for esp32 - //MDNS.addServiceTxt("_arduino", "_tcp", "app_name", (const char *)_app_name); - //MDNS.addServiceTxt("_arduino", "_tcp", "app_version", (const char *)_app_version); - //MDNS.addServiceTxt("_arduino", "_tcp", "mac", WiFi.macAddress()); -#else - MDNS.addServiceTxt("arduino", "tcp", "app_name", (const char *)_app_name); - MDNS.addServiceTxt("arduino", "tcp", "app_version", (const char *)_app_version); - MDNS.addServiceTxt("arduino", "tcp", "mac", WiFi.macAddress()); -#endif -} - // OTA Setup void MyESP::_ota_setup() { if (!_wifi_ssid) { return; } - ArduinoOTA.setPort(OTA_PORT); + //ArduinoOTA.setPort(OTA_PORT); ArduinoOTA.setHostname(_app_hostname); - //ArduinoOTA.setMdnsEnabled(true); // because we're using our own MDNS ArduinoOTA.onStart([this]() { myDebug_P(PSTR("[OTA] Start")); }); ArduinoOTA.onEnd([this]() { myDebug_P(PSTR("[OTA] Done, restarting...")); }); @@ -344,15 +319,15 @@ void MyESP::_ota_setup() { ArduinoOTA.onError([this](ota_error_t error) { if (error == OTA_AUTH_ERROR) - myDebug_P(PSTR("Auth Failed")); + myDebug_P(PSTR("[OTA] Auth Failed")); else if (error == OTA_BEGIN_ERROR) - myDebug_P(PSTR("Begin Failed")); + myDebug_P(PSTR("[OTA] Begin Failed")); else if (error == OTA_CONNECT_ERROR) - myDebug_P(PSTR("Connect Failed")); + myDebug_P(PSTR("[OTA] Connect Failed")); else if (error == OTA_RECEIVE_ERROR) - myDebug_P(PSTR("Receive Failed")); + myDebug_P(PSTR("[OTA] Receive Failed")); else if (error == OTA_END_ERROR) - myDebug_P(PSTR("End Failed")); + myDebug_P(PSTR("[OTA] End Failed")); }); } @@ -700,7 +675,7 @@ void MyESP::_telnetHandle() { } break; case 0x04: // EOT, CTRL-D - myDebug_P(PSTR("* exiting telnet session")); + myDebug_P(PSTR("[TELNET] exiting telnet session")); SerialAndTelnet.disconnectClient(); break; default: @@ -1039,9 +1014,6 @@ void MyESP::begin(const char * app_hostname, const char * app_name, const char * _fs_setup(); // SPIFFS setup, do this first to get values _wifi_setup(); // WIFI setup _ota_setup(); - - // the other setups will be done after the wifi has connected - // _mqtt_setup() _mdns_setup() } /* diff --git a/lib/myESP/MyESP.h b/lib/myESP/MyESP.h index dc329ac05..2fd7f78df 100644 --- a/lib/myESP/MyESP.h +++ b/lib/myESP/MyESP.h @@ -18,12 +18,14 @@ #include // modified from https://github.com/yasheena/telnetspy #if defined(ARDUINO_ARCH_ESP32) -#include +//#include #include // added for ESP32 #define ets_vsnprintf vsnprintf // added for ESP32 +#define OTA_PORT 8266 #else -#include +//#include #include +#define OTA_PORT 3232 #endif #define MYEMS_CONFIG_FILE "/config.json" @@ -34,9 +36,6 @@ #define WIFI_CONNECT_TIMEOUT 10000 // Connecting timeout for WIFI in ms #define WIFI_RECONNECT_INTERVAL 60000 // If could not connect to WIFI, retry after this time in ms -// OTA -#define OTA_PORT 3232 // OTA port. Was 8266 - // MQTT #define MQTT_PORT 1883 // MQTT port #define MQTT_RECONNECT_DELAY_MIN 5000 // Try to reconnect in 5 seconds upon disconnection @@ -170,9 +169,6 @@ class MyESP { char * _wifi_password; bool _wifi_connected; - // mdns - void _mdns_setup(); - // ota void _ota_setup();