removed MDNS, now OTA works for both esp8266 and esp32

This commit is contained in:
proddy
2019-02-23 16:27:42 +01:00
parent 23d3517f27
commit 3fab61513d
4 changed files with 18 additions and 46 deletions

View File

@@ -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 - Added Bosch Easy thermostat, Buderus Logamax U122
- Support for changing boiler wwtemp via MQTT (merge #58 from egrekov). thanks! - 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 ## [1.5.2] 2019-02-04
### Changed ### Changed

View File

@@ -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. `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 ### Special EMS Types

View File

@@ -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 * Paul Derbyshire - December 2018
* Version 1.1 - Feb 22 2019. Added support for ESP32 * Version 1.1 - Feb 22 2019. Added support for ESP32
@@ -115,7 +115,7 @@ bool MyESP::getUseSerial() {
return (_use_serial); 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) { void MyESP::_wifiCallback(justwifi_messages_t code, char * parameter) {
if ((code == MESSAGE_CONNECTED)) { if ((code == MESSAGE_CONNECTED)) {
#if defined(ARDUINO_ARCH_ESP32) #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] DNS %s"), WiFi.dnsIP().toString().c_str());
myDebug_P(PSTR("[WIFI] HOST %s"), hostname.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 // start OTA
ArduinoOTA.begin(); // moved to support esp32 ArduinoOTA.begin(); // moved to support esp32
myDebug_P(PSTR("[OTA] listening to %s.local:%u"), ArduinoOTA.getHostname().c_str(), OTA_PORT); 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 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 // OTA Setup
void MyESP::_ota_setup() { void MyESP::_ota_setup() {
if (!_wifi_ssid) { if (!_wifi_ssid) {
return; return;
} }
ArduinoOTA.setPort(OTA_PORT); //ArduinoOTA.setPort(OTA_PORT);
ArduinoOTA.setHostname(_app_hostname); ArduinoOTA.setHostname(_app_hostname);
//ArduinoOTA.setMdnsEnabled(true); // because we're using our own MDNS
ArduinoOTA.onStart([this]() { myDebug_P(PSTR("[OTA] Start")); }); ArduinoOTA.onStart([this]() { myDebug_P(PSTR("[OTA] Start")); });
ArduinoOTA.onEnd([this]() { myDebug_P(PSTR("[OTA] Done, restarting...")); }); ArduinoOTA.onEnd([this]() { myDebug_P(PSTR("[OTA] Done, restarting...")); });
@@ -344,15 +319,15 @@ void MyESP::_ota_setup() {
ArduinoOTA.onError([this](ota_error_t error) { ArduinoOTA.onError([this](ota_error_t error) {
if (error == OTA_AUTH_ERROR) if (error == OTA_AUTH_ERROR)
myDebug_P(PSTR("Auth Failed")); myDebug_P(PSTR("[OTA] Auth Failed"));
else if (error == OTA_BEGIN_ERROR) else if (error == OTA_BEGIN_ERROR)
myDebug_P(PSTR("Begin Failed")); myDebug_P(PSTR("[OTA] Begin Failed"));
else if (error == OTA_CONNECT_ERROR) else if (error == OTA_CONNECT_ERROR)
myDebug_P(PSTR("Connect Failed")); myDebug_P(PSTR("[OTA] Connect Failed"));
else if (error == OTA_RECEIVE_ERROR) else if (error == OTA_RECEIVE_ERROR)
myDebug_P(PSTR("Receive Failed")); myDebug_P(PSTR("[OTA] Receive Failed"));
else if (error == OTA_END_ERROR) 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; break;
case 0x04: // EOT, CTRL-D case 0x04: // EOT, CTRL-D
myDebug_P(PSTR("* exiting telnet session")); myDebug_P(PSTR("[TELNET] exiting telnet session"));
SerialAndTelnet.disconnectClient(); SerialAndTelnet.disconnectClient();
break; break;
default: 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 _fs_setup(); // SPIFFS setup, do this first to get values
_wifi_setup(); // WIFI setup _wifi_setup(); // WIFI setup
_ota_setup(); _ota_setup();
// the other setups will be done after the wifi has connected
// _mqtt_setup() _mdns_setup()
} }
/* /*

View File

@@ -18,12 +18,14 @@
#include <TelnetSpy.h> // modified from https://github.com/yasheena/telnetspy #include <TelnetSpy.h> // modified from https://github.com/yasheena/telnetspy
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
#include <ESPmDNS.h> //#include <ESPmDNS.h>
#include <SPIFFS.h> // added for ESP32 #include <SPIFFS.h> // added for ESP32
#define ets_vsnprintf vsnprintf // added for ESP32 #define ets_vsnprintf vsnprintf // added for ESP32
#define OTA_PORT 8266
#else #else
#include <ESP8266mDNS.h> //#include <ESP8266mDNS.h>
#include <ESPAsyncTCP.h> #include <ESPAsyncTCP.h>
#define OTA_PORT 3232
#endif #endif
#define MYEMS_CONFIG_FILE "/config.json" #define MYEMS_CONFIG_FILE "/config.json"
@@ -34,9 +36,6 @@
#define WIFI_CONNECT_TIMEOUT 10000 // Connecting timeout for WIFI in ms #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 #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 // MQTT
#define MQTT_PORT 1883 // MQTT port #define MQTT_PORT 1883 // MQTT port
#define MQTT_RECONNECT_DELAY_MIN 5000 // Try to reconnect in 5 seconds upon disconnection #define MQTT_RECONNECT_DELAY_MIN 5000 // Try to reconnect in 5 seconds upon disconnection
@@ -170,9 +169,6 @@ class MyESP {
char * _wifi_password; char * _wifi_password;
bool _wifi_connected; bool _wifi_connected;
// mdns
void _mdns_setup();
// ota // ota
void _ota_setup(); void _ota_setup();