Compare commits

..
Author SHA1 Message Date
ESPEasy release bot c3bde94f7a automaticly updated release notes for mega-20180403 2018-04-03 04:00:14 +02:00
GrovkillenandGitHub 080be1ad0a Update _P029_Output.ino 2018-04-02 20:41:22 +02:00
GrovkillenandGitHub 232ca4f215 Update _P038_NeoPixel.ino 2018-04-02 20:40:08 +02:00
mvdbro bfa6eac538 ESP32 prep for RTOS multitasking 2018-04-02 15:59:01 +02:00
ESPEasy release bot 5d41bf9e73 automaticly updated release notes for mega-20180402 2018-04-02 04:00:10 +02:00
Gijs Noorlander dc5a2fd956 Revert "Merge pull request #1205 from s0170071/SerialSwap"
This reverts commit 46586e5355.
2018-04-01 10:47:50 +02:00
ESPEasy release bot b20f05305b automaticly updated release notes for mega-20180401 2018-04-01 04:00:08 +02:00
Gijs NoorlanderandGitHub 46586e5355 Merge pull request #1205 from s0170071/SerialSwap
Serial Swap function
2018-04-01 01:17:51 +02:00
Gijs NoorlanderandGitHub 7e8a751657 Merge pull request #1203 from TD-er/feature/mqtt_disconnect_event
[issue #1201] MQTT#Disconnected event and MQTT stability improvements
2018-04-01 01:14:55 +02:00
TD-er 7d61e55d34 [deepsleep] Allow for some minimum wifi connect time
In Deepsleep mode the wifi connect time is now minimum of 6 seconds.
Also the first loop after connect, the 'awake' timer will reset and start over. Without WiFi connection the set 'awake' timer starts at the moment the node boots.
2018-03-31 23:53:15 +02:00
GrovkillenandGitHub 2f663429a3 P0059 (rotary encoder) and P0063 (ttp229, keypad)
These two plugins are not in test but in normal.
2018-03-31 19:52:25 +02:00
TD-er 52e75ade78 Merge remote-tracking branch 'origin/feature/mqtt_disconnect_event' into feature/mqtt_disconnect_event 2018-03-31 01:42:19 +02:00
TD-er 525a0ba0a1 [issue #1201] MQTT#Disconnected event and MQTT stability improvements
While looking for issues regarding DeepSleep + MQTT and issue #1195, I came across a number of other issues related to high CPU load and WiFi disconnects when a MQTT controller cannot reach the MQTT broker or is set to be no longer enabled.

These fixes improve CPU load and WiFi stability and also send the following events:
- `MQTT#Connected` 
- `MQTT#Disconnected`
- `MQTTimport#Connected` 
- `MQTTimport#Disconnected`

The MQTTimport plugin still has some major issues which have to be taken care of, so #1195 is not fixed yet.
2018-03-31 01:34:50 +02:00
s0170071 eba1fb3388 Serial Swap function
swaps Serial Pins *and* keeps track of it.
2018-03-30 08:47:55 +02:00
TD-er 3583db3e22 [issue #1201] MQTT#Disconnected event and MQTT stability improvements
While looking for issues regarding DeepSleep + MQTT and issue #1195, I came across a number of other issues related to high CPU load and WiFi disconnects when a MQTT controller cannot reach the MQTT broker or is set to be no longer enabled.

These fixes improve CPU load and WiFi stability and also send the following events:
- `MQTT#Connected` 
- `MQTT#Disconnected`
- `MQTTimport#Connected` 
- `MQTTimport#Disconnected`

The MQTTimport plugin still has some major issues which have to be taken care of, so #1195 is not fixed yet.
2018-03-30 02:48:23 +02:00
10 changed files with 180 additions and 45 deletions
+42
View File
@@ -1,3 +1,45 @@
-------------------------------------------------
Changes in release mega-20180403 (since mega-20180402)
-------------------------------------------------
Release date: Tue Apr 3 04:00:14 CEST 2018
Grovkillen (2):
Update _P038_NeoPixel.ino
Update _P029_Output.ino
mvdbro (1):
ESP32 prep for RTOS multitasking
-------------------------------------------------
Changes in release mega-20180402 (since mega-20180401)
-------------------------------------------------
Release date: Mon Apr 2 04:00:10 CEST 2018
Gijs Noorlander (1):
Revert "Merge pull request #1205 from s0170071/SerialSwap"
-------------------------------------------------
Changes in release mega-20180401 (since mega-20180331)
-------------------------------------------------
Release date: Sun Apr 1 04:00:08 CEST 2018
Grovkillen (1):
P0059 (rotary encoder) and P0063 (ttp229, keypad)
TD-er (3):
[issue #1201] MQTT#Disconnected event and MQTT stability improvements
[issue #1201] MQTT#Disconnected event and MQTT stability improvements
[deepsleep] Allow for some minimum wifi connect time
s0170071 (1):
Serial Swap function
-------------------------------------------------
Changes in release mega-20180331 (since mega-20180330)
-------------------------------------------------
+6 -8
View File
@@ -120,8 +120,10 @@ bool MQTTConnect(int controller_idx)
LoadControllerSettings(controller_idx, (byte*)&ControllerSettings, sizeof(ControllerSettings));
if (!ControllerSettings.checkHostReachable(true))
return false;
if (MQTTclient.connected())
if (MQTTclient.connected()) {
MQTTclient.disconnect();
updateMQTTclient_connected();
}
if (ControllerSettings.UseDNS) {
MQTTclient.setServer(ControllerSettings.getHost().c_str(), ControllerSettings.Port);
} else {
@@ -166,11 +168,7 @@ bool MQTTConnect(int controller_idx)
addLog(LOG_LEVEL_INFO, log);
if (MQTTclient.publish(LWTTopic.c_str(), "Connected", 1)) {
if (Settings.UseRules)
{
String event = F("MQTT#Connected");
rulesProcessing(event);
}
updateMQTTclient_connected();
statusLED(true);
return true; // end loop if succesfull
}
@@ -183,8 +181,9 @@ bool MQTTConnect(int controller_idx)
\*********************************************************************************************/
bool MQTTCheck(int controller_idx)
{
if (!WiFiConnected(10))
if (!WiFiConnected(10)) {
return false;
}
byte ProtocolIndex = getProtocolIndex(Settings.Protocol[controller_idx]);
if (Protocol[ProtocolIndex].usesMQTT)
{
@@ -193,7 +192,6 @@ bool MQTTCheck(int controller_idx)
if (MQTTclient_should_reconnect) {
addLog(LOG_LEVEL_ERROR, F("MQTT : Intentional reconnect"));
} else {
addLog(LOG_LEVEL_ERROR, F("MQTT : Connection lost"));
connectionFailures += 2;
}
return MQTTConnect(controller_idx);
+5
View File
@@ -55,6 +55,10 @@
// --- Advanced Settings ---------------------------------------------------------------------------------
#if defined(ESP32)
#define USE_RTOS_MULTITASKING
#endif
#define DEFAULT_USE_RULES false // (true|false) Enable Rules?
#define DEFAULT_MQTT_RETAIN false // (true|false) Retain MQTT messages?
@@ -459,6 +463,7 @@ MDNSResponder mdns;
WiFiClient mqtt;
PubSubClient MQTTclient(mqtt);
bool MQTTclient_should_reconnect = true;
bool MQTTclient_connected = false;
// udp protocol stuff (syslog, global sync, node info list, ntp time)
WiFiUDP portUDP;
+79 -24
View File
@@ -221,7 +221,7 @@ void setup()
timer100ms = 0; // timer for periodic actions 10 x per/sec
timer1s = 0; // timer for periodic actions once per/sec
timerwd = 0; // timer for watchdog once per 30 sec
timermqtt = 0; // Timer for the MQTT keep alive loop.
timermqtt = 10000; // Timer for the MQTT keep alive loop, initial value can be high, since it will be set as soon as IP is set.
timermqtt_interval = 250; // Interval for checking MQTT
timerAwakeFromDeepSleep = millis();
@@ -276,8 +276,35 @@ void setup()
writeDefaultCSS();
#ifdef USE_RTOS_MULTITASKING
xTaskCreatePinnedToCore(RTOS_TaskServers, "RTOS_TaskServers", 8192, NULL, 1, NULL, 1);
xTaskCreatePinnedToCore(RTOS_TaskSerial, "RTOS_TaskSerial", 8192, NULL, 1, NULL, 1);
#endif
}
#ifdef USE_RTOS_MULTITASKING
void RTOS_TaskServers( void * parameter )
{
while (true){
delay(100);
WebServer.handleClient();
checkUDP();
}
}
void RTOS_TaskSerial( void * parameter )
{
while (true){
delay(100);
if (Settings.UseSerial)
if (Serial.available())
if (!PluginCall(PLUGIN_SERIAL_IN, 0, dummyString))
serial();
}
}
#endif
int firstEnabledMQTTController() {
for (byte i = 0; i < CONTROLLER_MAX; ++i) {
byte ProtocolIndex = getProtocolIndex(Settings.Protocol[i]);
@@ -312,24 +339,26 @@ void loop()
if (wifiStatus >= ESPEASY_WIFI_CONNECTED) processConnect();
if (wifiStatus >= ESPEASY_WIFI_GOT_IP) processGotIP();
if (wifiStatus == ESPEASY_WIFI_DISCONNECTED) processDisconnect();
} else if (WiFi.status() != WL_CONNECTED) {
// Somehow the WiFi has entered a limbo state.
resetWiFi();
}
// Deep sleep mode, just run all tasks one time and go back to sleep as fast as possible
if (firstLoop && isDeepSleepEnabled())
bool firstLoopWiFiConnected = wifiStatus == ESPEASY_WIFI_SERVICES_INITIALIZED && firstLoop;
if (firstLoopWiFiConnected) {
firstLoop = false;
timerAwakeFromDeepSleep = millis(); // Allow to run for "awake" number of seconds, now we have wifi.
}
// Deep sleep mode, just run all tasks one (more) time and go back to sleep as fast as possible
if ((firstLoopWiFiConnected || readyForSleep()) && isDeepSleepEnabled())
{
// Setup MQTT Client
// Controller index is forced to the first enabled MQTT controller.
// This is normally done via frequent checks, but there's no time for in deepsleep.
int enabledMqttController = firstEnabledMQTTController();
if (enabledMqttController >= 0) {
MQTTConnect(enabledMqttController);
}
runPeriodicalMQTT();
// Now run all frequent tasks
run50TimesPerSecond();
run10TimesPerSecond();
runEach30Seconds();
runOncePerSecond();
runPeriodicalMQTT();
}
//normal mode, run each task when its time
else
@@ -366,28 +395,52 @@ void loop()
deepSleep(Settings.Delay);
//deepsleep will never return, its a special kind of reboot
}
firstLoop = false;
}
void runPeriodicalMQTT() {
// MQTT_KEEPALIVE = 15 seconds.
timermqtt = millis() + timermqtt_interval;
if (!WiFiConnected(10)) {
updateMQTTclient_connected();
return;
}
//dont do this in backgroundtasks(), otherwise causes crashes. (https://github.com/letscontrolit/ESPEasy/issues/683)
int enabledMqttController = firstEnabledMQTTController();
if (enabledMqttController >= 0) {
if (!MQTTclient.loop()) {
if (!MQTTCheck(enabledMqttController)) {
// Check failed, no need to retry it immediately.
if (timermqtt_interval < 2000)
timermqtt_interval += 250;
} else {
timermqtt_interval = 250;
updateMQTTclient_connected();
if (MQTTCheck(enabledMqttController)) {
updateMQTTclient_connected();
}
}
} else {
if (MQTTclient.connected()) {
MQTTclient.disconnect();
updateMQTTclient_connected();
}
}
}
void updateMQTTclient_connected() {
if (MQTTclient_connected != MQTTclient.connected()) {
MQTTclient_connected = !MQTTclient_connected;
if (!MQTTclient_connected)
addLog(LOG_LEVEL_ERROR, F("MQTT : Connection lost"));
if (Settings.UseRules) {
String event = MQTTclient_connected ? F("MQTT#Connected") : F("MQTT#Disconnected");
rulesProcessing(event);
}
}
if (!MQTTclient_connected) {
if (timermqtt_interval < 2000) {
timermqtt_interval += 250;
}
} else {
timermqtt_interval = 250;
}
timermqtt = millis() + timermqtt_interval;
}
/*********************************************************************************************\
* Tasks that run 50 times per second
\*********************************************************************************************/
@@ -415,7 +468,9 @@ void run10TimesPerSecond()
eventBuffer = "";
}
elapsed = micros() - start;
WebServer.handleClient();
#ifndef USE_RTOS_MULTITASKING
WebServer.handleClient();
#endif
}
@@ -754,19 +809,19 @@ void backgroundtasks()
tcpCleanup();
#endif
#ifndef USE_RTOS_MULTITASKING
if (Settings.UseSerial)
if (Serial.available())
if (!PluginCall(PLUGIN_SERIAL_IN, 0, dummyString))
serial();
WebServer.handleClient();
checkUDP();
#endif
// process DNS, only used if the ESP has no valid WiFi config
if (wifiSetup)
dnsServer.processNextRequest();
WebServer.handleClient();
checkUDP();
#ifdef FEATURE_ARDUINO_OTA
if(Settings.ArduinoOTAEnable)
ArduinoOTA.handle();
+10 -1
View File
@@ -118,6 +118,8 @@ void processGotIP() {
if (Settings.UseNTP) {
initTime();
}
timermqtt_interval = 100;
timermqtt = millis() + timermqtt_interval;
if (Settings.UseRules)
{
String event = F("WiFi#Connected");
@@ -128,7 +130,14 @@ void processGotIP() {
processedGetIP = true;
}
void resetWiFi() {
WiFiMode_t currentMode = WiFi.getMode();
WiFi.mode(WIFI_OFF);
WiFi.mode(currentMode);
lastDisconnectMoment = millis();
processedDisconnect = false;
wifiStatus = ESPEASY_WIFI_DISCONNECTED;
}
//********************************************************************************
+4
View File
@@ -44,6 +44,10 @@ bool readyForSleep()
{
if (!isDeepSleepEnabled())
return false;
if (wifiStatus != ESPEASY_WIFI_SERVICES_INITIALIZED) {
// Allow 6 seconds to connect to WiFi
return timeOutReached(timerAwakeFromDeepSleep + 6000);
}
return timeOutReached(timerAwakeFromDeepSleep + 1000 * Settings.deepSleep);
}
+1 -1
View File
@@ -5,7 +5,7 @@
#define PLUGIN_029
#define PLUGIN_ID_029 29
#define PLUGIN_NAME_029 "Output - (Domoticz MQTT helper)"
#define PLUGIN_NAME_029 "Output - Domoticz MQTT Helper"
#define PLUGIN_VALUENAME1_029 "Output"
boolean Plugin_029(byte function, struct EventStruct *event, String& string)
{
+27 -8
View File
@@ -20,8 +20,26 @@
// Declare a Wifi client for this plugin only
// TODO TD-er: These must be kept in some vector to allow multiple instances of MQTT import.
WiFiClient espclient_037;
PubSubClient *MQTTclient_037;
PubSubClient *MQTTclient_037 = NULL;
bool MQTTclient_037_connected = false;
void Plugin_037_update_connect_status() {
bool connected = false;
if (MQTTclient_037 != NULL) {
connected = MQTTclient_037->connected();
}
if (MQTTclient_037_connected != connected) {
MQTTclient_037_connected = !MQTTclient_037_connected;
if (Settings.UseRules) {
String event = connected ? F("MQTTimport#Connected") : F("MQTTimport#Disconnected");
rulesProcessing(event);
}
if (!connected)
addLog(LOG_LEVEL_ERROR, F("IMPT : MQTT 037 Connection lost"));
}
}
boolean Plugin_037(byte function, struct EventStruct *event, String& string)
{
@@ -122,7 +140,9 @@ boolean Plugin_037(byte function, struct EventStruct *event, String& string)
case PLUGIN_TEN_PER_SECOND:
{
MQTTclient_037->loop(); // Listen out for callbacks
if (!MQTTclient_037->loop()) { // Listen out for callbacks
Plugin_037_update_connect_status();
}
success = true;
break;
}
@@ -134,13 +154,11 @@ boolean Plugin_037(byte function, struct EventStruct *event, String& string)
if (!MQTTclient_037->connected() || MQTTclient_should_reconnect) {
if (MQTTclient_should_reconnect) {
addLog(LOG_LEVEL_ERROR, F("IMPT : MQTT 037 Intentional reconnect"));
} else {
addLog(LOG_LEVEL_ERROR, F("IMPT : MQTT 037 Connection lost"));
}
MQTTclient_037->disconnect();
delay(1000);
Plugin_037_update_connect_status();
delay(250);
if (! MQTTConnect_037(ClientName)) {
success = false;
@@ -339,7 +357,8 @@ boolean MQTTConnect_037(String clientid)
if (MQTTclient_037->connected()) return true;
// define stuff for the client - this could also be done in the intial declaration of MQTTclient_037
if (!WiFiConnected(1000)) {
if (!WiFiConnected(100)) {
Plugin_037_update_connect_status();
return false; // Not connected, so no use in wasting time to connect to a host.
}
ControllerSettingsStruct ControllerSettings;
@@ -380,7 +399,7 @@ boolean MQTTConnect_037(String clientid)
delay(500);
}
Plugin_037_update_connect_status();
return MQTTclient_037->connected();
}
+1 -1
View File
@@ -27,7 +27,7 @@ Adafruit_NeoPixel *Plugin_038_pixels;
#define PLUGIN_038
#define PLUGIN_ID_038 38
#define PLUGIN_NAME_038 "Output - NeoPixel (basic)"
#define PLUGIN_NAME_038 "Output - NeoPixel (Basic)"
#define PLUGIN_VALUENAME1_038 ""
int MaxPixels = 0;
+5 -2
View File
@@ -350,6 +350,10 @@ To create/register a plugin, you have to :
#define USES_P049 // MHZ19
#define USES_P052 // SenseAir
#define USES_P059 // Encoder
#define USES_P063 // TTP229_KeyPad
#endif
@@ -388,12 +392,11 @@ To create/register a plugin, you have to :
#define USES_P056 // SDS011-Dust
#define USES_P057 // HT16K33_LED
#define USES_P058 // HT16K33_KeyPad
#define USES_P059 // Encoder
#define USES_P060 // MCP3221
#define USES_P061 // Keypad
#define USES_P062 // MPR121_KeyPad
#define USES_P063 // TTP229_KeyPad
#define USES_P064 // APDS9960
#define USES_P065 // DRF0299
#define USES_P066 // VEML6040