Compare commits

...
Author SHA1 Message Date
ESPEasy release bot b332a513b5 automatically updated release notes for mega-20180924 2018-09-24 04:00:20 +02:00
Gijs NoorlanderandGitHub 6e1cde343f Merge pull request #1791 from TD-er/bugfix/ESP32_I2C
[ESP32] Fix I2C handling to allow I2C devices to work
2018-09-23 22:14:43 +02:00
TD-er cce9ddd2dc [ESP32] Fix I2C handling to allow I2C devices to work
See this issue: [I2C repeated start broken](https://github.com/platformio/platform-espressif32/issues/126)
2018-09-23 21:17:55 +02:00
Gijs NoorlanderandGitHub 51be17a436 Merge pull request #1780 from clumsy-stefan/sensor_type_change
Change type of sensor for MCP and PCF devices
2018-09-23 20:18:38 +02:00
Gijs NoorlanderandGitHub 66d27a6697 Merge pull request #1776 from beigenmann/mega
Fix platformio
2018-09-23 20:17:33 +02:00
Gijs NoorlanderandGitHub a033e458fb Merge pull request #1782 from TD-er/bugfix/MQTT_reconnect_name
[MQTT] Work around for lost MQTT connection
2018-09-23 20:17:07 +02:00
Gijs NoorlanderandGitHub 494436bbff Merge pull request #1789 from sakinit/ESP32-to-core_esp32_1_3_0
ESP32: change to platform version core_esp32_1_3_0
2018-09-23 20:16:52 +02:00
sakinit 23bacd0762 change to platform version core_esp32_1_3_0 2018-09-23 17:49:47 +02:00
ESPEasy release bot f131254853 automatically updated release notes for mega-20180923 2018-09-23 04:00:12 +02:00
TD-er 657d15d962 [MQTT] Work around for lost MQTT connection
Maybe a fix for #1525
Meant to be a fix for #1530

It looks like the MQTT broker is refusing to accept a new connection from a specific client ID, as long as the broker thinks a client with that ID is still connected.
This work around adds the number of wifi reconnects to the clientID, to make the ID unique when a reconnect has to be made.
2018-09-23 00:54:55 +02:00
Gijs NoorlanderandGitHub 60910da48d Merge pull request #1749 from sakinit/ESP32-P1WifiGateway-updates
Esp32 p1 wifi gateway updates
2018-09-22 20:59:32 +02:00
Gijs NoorlanderandGitHub 6cee2d0f32 Merge pull request #1779 from TD-er/bugfix/BME280_slow_reading
[BME280] Fix slow reading of BME280 causing watchdog resets
2018-09-22 20:45:20 +02:00
stefan 533cb88a64 Change type of sensor for MCP and PCF devices
MCP and PCF devices should be of type SWNSOR_TYPE_SWITCH instead of SENSOR_TYPE_SINGLE so that the controllers can identify them correctly as switches (for GPIO related functions)
2018-09-22 20:41:53 +02:00
TD-er ffa32fe851 [BME280] Fix slow reading of BME280 causing watchdog resets
The plugin still had some delay and an active polling to see if the reading was ready.
This  took more than 1.5 sec per reading, which could trigger a Watchdog reset.
2018-09-22 20:34:56 +02:00
Gijs NoorlanderandGitHub b900cc9389 Merge pull request #1777 from TD-er/bugfix/MQTTimport
[MQTT import] Fix crash at boot when plugin is enabled
2018-09-22 19:13:25 +02:00
TD-er 8e11c19af6 [MQTT import] Fix crash at boot when plugin is enabled
See #1722
Inspired by [this comment](https://github.com/letscontrolit/ESPEasy/issues/1722#issuecomment-422191721) of @kainhofer
2018-09-22 16:39:16 +02:00
Benno Eigenmann f33ca6df78 Fix platformio 2018-09-22 15:57:09 +02:00
ESPEasy release bot 194a230d20 automatically updated release notes for mega-20180922 2018-09-22 04:00:22 +02:00
Gijs NoorlanderandGitHub 7a5a432016 Merge pull request #1773 from TD-er/reapply_reverts
Reapply reverts
2018-09-22 02:04:30 +02:00
TD-er 07511fe144 Revert "Revert "Fix elseif & Add if-elseif-else nesting levels""
This reverts commit a4fe8d42d2.
2018-09-21 22:15:13 +02:00
Gijs Noorlander 9a390136f9 Revert "Revert "Added 2 new operators in Calculate() function""
This reverts commit fa42cadfa1.
2018-09-21 22:14:30 +02:00
Gijs NoorlanderandGitHub 27a03f166a Merge pull request #1770 from TD-er/bugfix/revert_disable_command_scheduler_0915
Revert "[Scheduler] Disable command scheduler"
2018-09-21 22:10:50 +02:00
TD-er 0a63aeb8f0 Revert "[Scheduler] Disable command scheduler"
This reverts commit 38af765935.
2018-09-20 23:20:19 +02:00
sakinit 22c10ac615 ESP32 platform updated to 1.2.0; Webserver replaced by platform one 2018-09-16 16:44:25 +02:00
ESPEasy release bot ac83cfa249 automatically updated release notes for mega-20180916 2018-09-16 04:00:11 +02:00
Gijs NoorlanderandGitHub 6ef0c08bc4 Merge pull request #1754 from TD-er/bugfix/backgroundtasks_rules
[HW Watchdog] Backgroundtasks instead of yield during rules handling
2018-09-16 01:19:47 +02:00
TD-er 1ee965067d [HW Watchdog] Backgroundtasks instead of yield during rules handling 2018-09-16 01:19:14 +02:00
Gijs NoorlanderandGitHub e46a873fce Merge pull request #1753 from letscontrolit/revert-1641-mega
Revert "Fix elseif & Add if-elseif-else nesting levels"
2018-09-16 01:15:04 +02:00
Gijs NoorlanderandGitHub 784e956c96 Merge pull request #1752 from letscontrolit/revert-1742-new/not
Revert "Added 2 new operators in Calculate() function"
2018-09-16 01:14:32 +02:00
Gijs NoorlanderandGitHub b6eebb330a Added warning to release notes 20180915 2018-09-16 01:13:49 +02:00
Gijs NoorlanderandGitHub a4fe8d42d2 Revert "Fix elseif & Add if-elseif-else nesting levels" 2018-09-16 01:08:42 +02:00
Gijs NoorlanderandGitHub fa42cadfa1 Revert "Added 2 new operators in Calculate() function" 2018-09-16 01:04:37 +02:00
sakinit 17dc6fa859 Reverted Webserver change 2018-09-15 16:22:58 +02:00
sakinit 1432726dec ESP32: Split webserver spiffs filelist into pages 2018-09-15 12:14:33 +02:00
sakinit 7ba6ffa407 Fix ESP32 stack overflow in addPinSelect when called from P1WifiGateway
In addFormPinSelect move local variables from the stack to the heap
because when it is called from the P1WifiGateway there is not enough
stack space resulting in a stack overflow.
2018-09-15 12:14:27 +02:00
sakinit ab555e4d6b ESP32 build issues fixed
- Compiler issue of comment within comment
 - ESP32Webserver renamed to Webserver in ESP32 Arduino library
2018-09-15 12:14:22 +02:00
13 changed files with 228 additions and 93 deletions
+71 -1
View File
@@ -1,8 +1,78 @@
-------------------------------------------------
Changes in release mega-20180924 (since mega-20180923)
-------------------------------------------------
Release date: Mon Sep 24 04:00:20 CEST 2018
Benno Eigenmann (1):
Fix platformio
TD-er (2):
[MQTT] Work around for lost MQTT connection
[ESP32] Fix I2C handling to allow I2C devices to work
sakinit (1):
change to platform version core_esp32_1_3_0
stefan (1):
Change type of sensor for MCP and PCF devices
-------------------------------------------------
Changes in release mega-20180923 (since mega-20180922)
-------------------------------------------------
Release date: Sun Sep 23 04:00:12 CEST 2018
TD-er (2):
[MQTT import] Fix crash at boot when plugin is enabled
[BME280] Fix slow reading of BME280 causing watchdog resets
sakinit (5):
ESP32 build issues fixed
Fix ESP32 stack overflow in addPinSelect when called from P1WifiGateway
ESP32: Split webserver spiffs filelist into pages
Reverted Webserver change
ESP32 platform updated to 1.2.0; Webserver replaced by platform one
-------------------------------------------------
Changes in release mega-20180922 (since mega-20180916)
-------------------------------------------------
Release date: Sat Sep 22 04:00:22 CEST 2018
Gijs Noorlander (1):
Revert "Revert "Added 2 new operators in Calculate() function""
TD-er (2):
Revert "[Scheduler] Disable command scheduler"
Revert "Revert "Fix elseif & Add if-elseif-else nesting levels""
-------------------------------------------------
Changes in release mega-20180916 (since mega-20180915)
-------------------------------------------------
Release date: Sun Sep 16 04:00:11 CEST 2018
Gijs Noorlander (3):
Revert "Added 2 new operators in Calculate() function"
Revert "Fix elseif & Add if-elseif-else nesting levels"
Added warning to release notes 20180915
TD-er (1):
[HW Watchdog] Backgroundtasks instead of yield during rules handling
-------------------------------------------------
Changes in release mega-20180915 (since mega-20180914)
-------------------------------------------------
Release date: Sat Sep 15 04:00:15 CEST 2018
Known issue:
Causes reboots. (see [#1748](https://github.com/letscontrolit/ESPEasy/issues/1748) )
Plebs (1):
Added 2 new operators in Calculate
@@ -29,7 +99,7 @@ Release date: Fri Sep 14 04:00:17 CEST 2018
Gijs Noorlander (1):
Added PayPal link
Markus Gloede (1):
giddyhup (1):
Fix IR plugin passing received code
Plebs (7):
+4 -4
View File
@@ -65,6 +65,7 @@ platform = https://github.com/platformio/platform-espressif8266
[core_esp32_0_12_0]
platform = espressif32@0.12.0
lib_deps = "ESP32WebServer"
[core_esp32_1_2_0]
platform = espressif32@1.2.0
@@ -76,12 +77,11 @@ platform = espressif32@1.3.0
platform = https://github.com/platformio/platform-espressif32.git#feature/stage
[core_esp32]
platform = ${core_esp32_0_12_0.platform}
platform = ${core_esp32_1_3_0.platform}
build_unflags = -Wall
build_flags = -D BUILD_GIT='"${sysenv.TRAVIS_TAG}"'
-lstdc++ -lsupc++
lib_ignore = AS_BH1750, ESP8266WiFi, ESP8266Ping, ESP8266WebServer, ESP8266HTTPUpdateServer, ESP8266mDNS, IRremoteESP8266, ESPEasy_ESP8266Ping, SerialSensors, SDM
lib_deps = ESP32WebServer
lib_deps = ""
monitor_speed = 115200
@@ -104,7 +104,7 @@ monitor_speed = 115200
[common]
board_build.f_cpu = 80000000L
build_unflags = ""
build_unflags =
build_flags = -D BUILD_GIT='"${sysenv.TRAVIS_TAG}"'
-D NDEBUG
-lstdc++ -lsupc++
+1 -5
View File
@@ -222,20 +222,16 @@ void ExecuteCommand(byte source, const char *Line)
if (GetArgv(Line, TmpStr1, 5)) TempEvent.Par4 = CalculateParam(TmpStr1);
if (GetArgv(Line, TmpStr1, 6)) TempEvent.Par5 = CalculateParam(TmpStr1);
// FIXME: TD-er Disabling scheduling commands.
// Gives too much issues.
// if (source == VALUE_SOURCE_WEB_FRONTEND) {
if (source == VALUE_SOURCE_WEB_FRONTEND) {
// Must run immediately, to see result in web frontend
String status = doExecuteCommand((char*)&cmd[0], &TempEvent, Line);
yield();
SendStatus(source, status);
yield();
/*
} else {
// Schedule to run async
schedule_command_timer((char*)&cmd[0], &TempEvent, Line);
}
*/
}
#ifdef FEATURE_SD
+9
View File
@@ -161,6 +161,15 @@ bool MQTTConnect(int controller_idx)
clientid = F("ESPClient_");
clientid += WiFi.macAddress();
}
// Work-around for 'lost connections' to the MQTT broker.
// If the broker thinks the connection is still alive, a reconnect from the
// client will be refused.
// To overcome this issue, append the number of reconnects to the client ID to
// make it different from the previous one.
if (wifi_reconnects >= 1) {
clientid += F("_");
clientid += wifi_reconnects;
}
String LWTTopic = ControllerSettings.MQTTLwtTopic;
if(LWTTopic.length() == 0)
+2 -2
View File
@@ -521,10 +521,10 @@ bool showSettingsFileLayout = false;
#define FILE_RULES "/rules1.txt"
#include <WiFi.h>
#include "esp32_ping.h"
#include <ESP32WebServer.h>
#include <WebServer.h>
#include "SPIFFS.h"
#include <rom/rtc.h>
ESP32WebServer WebServer(80);
WebServer WebServer(80);
#ifdef FEATURE_MDNS
#include <ESPmDNS.h>
#endif
+12 -4
View File
@@ -11,6 +11,12 @@ bool I2C_read_words(uint8_t i2caddr, I2Cdata_words& data) {
return size == i2cdev.readWords(i2caddr, data.getRegister(), size, data.get());
}
// See https://github.com/platformio/platform-espressif32/issues/126
#ifdef ESP32
#define END_TRANSMISSION_FLAG true
#else
#define END_TRANSMISSION_FLAG false
#endif
//**************************************************************************/
// Wake up I2C device
@@ -66,7 +72,7 @@ uint8_t I2C_read8_reg(uint8_t i2caddr, byte reg, bool * is_ok) {
Wire.beginTransmission(i2caddr);
Wire.write((uint8_t)reg);
Wire.endTransmission(false);
Wire.endTransmission(END_TRANSMISSION_FLAG);
byte count = Wire.requestFrom(i2caddr, (byte)1);
if (is_ok != NULL) {
*is_ok = (count == 1);
@@ -84,7 +90,7 @@ uint16_t I2C_read16_reg(uint8_t i2caddr, byte reg) {
Wire.beginTransmission(i2caddr);
Wire.write((uint8_t)reg);
Wire.endTransmission(false);
Wire.endTransmission(END_TRANSMISSION_FLAG);
Wire.requestFrom(i2caddr, (byte)2);
value = (Wire.read() << 8) | Wire.read();
@@ -99,7 +105,7 @@ int32_t I2C_read24_reg(uint8_t i2caddr, byte reg) {
Wire.beginTransmission(i2caddr);
Wire.write((uint8_t)reg);
Wire.endTransmission(false);
Wire.endTransmission(END_TRANSMISSION_FLAG);
Wire.requestFrom(i2caddr, (byte)3);
value = (((int32_t)Wire.read()) << 16) | (Wire.read() << 8) | Wire.read();
@@ -114,7 +120,7 @@ int32_t I2C_read32_reg(uint8_t i2caddr, byte reg) {
Wire.beginTransmission(i2caddr);
Wire.write((uint8_t)reg);
Wire.endTransmission(false);
Wire.endTransmission(END_TRANSMISSION_FLAG);
Wire.requestFrom(i2caddr, (byte)3);
value = (((int32_t)Wire.read()) <<24) | (((uint32_t)Wire.read()) << 16) | (Wire.read() << 8) | Wire.read();
@@ -139,3 +145,5 @@ int16_t I2C_readS16_reg(uint8_t i2caddr, byte reg) {
int16_t I2C_readS16_LE_reg(uint8_t i2caddr, byte reg) {
return (int16_t)I2C_read16_LE_reg(i2caddr, reg);
}
#undef END_TRANSMISSION_FLAG
+1 -1
View File
@@ -2164,7 +2164,7 @@ String rulesProcessingFile(String fileName, String& event)
match, codeBlock, isCommand,
condition, ifBranche,
ifBlock, fakeIfBlock);
yield();
backgroundtasks();
}
line = "";
+55 -21
View File
@@ -2600,8 +2600,8 @@ void addPinSelect(boolean forI2C, String name, int choice)
//********************************************************************************
void addPinSelect(boolean forI2C, String name, int choice)
{
String options[PIN_D_MAX+1];
int optionValues[PIN_D_MAX+1];
String * options = new String[PIN_D_MAX+1];
int * optionValues = new int[PIN_D_MAX+1];
options[0] = F("- None -");
optionValues[0] = -1;
for(byte x=1; x < PIN_D_MAX+1; x++)
@@ -2611,6 +2611,8 @@ void addPinSelect(boolean forI2C, String name, int choice)
optionValues[x] = x;
}
renderHTMLForPinSelect(options, optionValues, forI2C, name, choice, PIN_D_MAX+1);
delete[] optionValues;
delete[] options;
}
#endif
@@ -4636,8 +4638,8 @@ void handle_filelist() {
TXBuffer += F("\">Next</a>");
}
TXBuffer += F("<BR><BR>");
sendHeadandTail(F("TmplStd"),true);
TXBuffer.endStream();
sendHeadandTail(F("TmplStd"),true);
TXBuffer.endStream();
#endif
#if defined(ESP32)
String fdelete = WebServer.arg(F("delete"));
@@ -4648,35 +4650,67 @@ void handle_filelist() {
// flashCount();
}
const int pageSize = 25;
int startIdx = 0;
String fstart = WebServer.arg(F("start"));
if (fstart.length() > 0)
{
startIdx = atoi(fstart.c_str());
}
int endIdx = startIdx + pageSize - 1;
TXBuffer += F("<table class='multirow' border=1px frame='box' rules='all'><TH><TH>Filename<TH>Size");
File root = SPIFFS.open("/");
File file = root.openNextFile();
while (file)
int count = -1;
while (file and count < endIdx)
{
if(!file.isDirectory()){
html_TR_TD();
if (strcmp(file.name(), FILE_CONFIG) != 0 && strcmp(file.name(), FILE_SECURITY) != 0 && strcmp(file.name(), FILE_NOTIFICATION) != 0)
{
TXBuffer += F("<a class='button link' href=\"filelist?delete=");
TXBuffer += file.name();
TXBuffer += F("\">Del</a>");
}
++count;
TXBuffer += F("<TD><a href=\"");
TXBuffer += file.name();
TXBuffer += F("\">");
TXBuffer += file.name();
TXBuffer += F("</a>");
html_TD();
TXBuffer += file.size();
file = root.openNextFile();
if (count >= startIdx)
{
html_TR_TD();
if (strcmp(file.name(), FILE_CONFIG) != 0 && strcmp(file.name(), FILE_SECURITY) != 0 && strcmp(file.name(), FILE_NOTIFICATION) != 0)
{
TXBuffer += F("<a class='button link' href=\"filelist?delete=");
TXBuffer += file.name();
if (startIdx > 0)
{
TXBuffer += F("&start=");
TXBuffer += startIdx;
}
TXBuffer += F("\">Del</a>");
}
TXBuffer += F("<TD><a href=\"");
TXBuffer += file.name();
TXBuffer += F("\">");
TXBuffer += file.name();
TXBuffer += F("</a>");
html_TD();
TXBuffer += file.size();
}
}
file = root.openNextFile();
}
TXBuffer += F("</table></form>");
TXBuffer += F("<BR><a class='button link' href=\"/upload\">Upload</a><BR><BR>");
TXBuffer += F("<BR><a class='button link' href=\"/upload\">Upload</a>");
if (startIdx > 0)
{
TXBuffer += F("<a class='button link' href=\"/filelist?start=");
TXBuffer += startIdx < pageSize ? 0 : startIdx - pageSize;
TXBuffer += F("\">Previous</a>");
}
if (count >= endIdx and file)
{
TXBuffer += F("<a class='button link' href=\"/filelist?start=");
TXBuffer += endIdx + 1;
TXBuffer += F("\">Next</a>");
}
TXBuffer += F("<BR><BR>");
sendHeadandTail(F("TmplStd"),true);
TXBuffer.endStream();
#endif
+1 -1
View File
@@ -24,7 +24,7 @@
- removed obsolete http get url code
- v1.04
- added build options and node_type_id to JSON/device
/******************************************************************************/
******************************************************************************/
#define CPLUGIN_009
#define CPLUGIN_ID_009 9
+1 -1
View File
@@ -20,7 +20,7 @@ boolean Plugin_009(byte function, struct EventStruct *event, String& string)
{
Device[++deviceCount].Number = PLUGIN_ID_009;
Device[deviceCount].Type = DEVICE_TYPE_I2C;
Device[deviceCount].VType = SENSOR_TYPE_SINGLE;
Device[deviceCount].VType = SENSOR_TYPE_SWITCH;
Device[deviceCount].Ports = 16;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
+1 -1
View File
@@ -20,7 +20,7 @@ boolean Plugin_019(byte function, struct EventStruct *event, String& string)
{
Device[++deviceCount].Number = PLUGIN_ID_019;
Device[deviceCount].Type = DEVICE_TYPE_I2C;
Device[deviceCount].VType = SENSOR_TYPE_SINGLE;
Device[deviceCount].VType = SENSOR_TYPE_SWITCH;
Device[deviceCount].Ports = 8;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
+7 -12
View File
@@ -382,8 +382,10 @@ bool Plugin_028_update_measurements(const uint8_t i2cAddress, float tempOffset,
return false;
}
if (!timeOutReached(sensor.last_measurement + 1000)) {
// Must wait one second to make sure the filtered values stabilize.
// It takes at least 1.587 sec for valit measurements to complete.
// The datasheet names this the "T63" moment.
// 1 second = 63% of the time needed to perform a measurement.
if (!timeOutReached(sensor.last_measurement + 1587)) {
return false;
}
if (!Plugin_028_readUncompensatedData(i2cAddress)) {
@@ -510,7 +512,7 @@ bool Plugin_028_begin(uint8_t i2cAddress) {
I2C_write8_reg(i2cAddress, BMx280_REGISTER_SOFTRESET, 0xB6);
delay(2); // Startup time is 2 ms (datasheet)
Plugin_028_readCoefficients(i2cAddress);
delay(65); //May be needed here as well to fix first wrong measurement?
// delay(65); //May be needed here as well to fix first wrong measurement?
return true;
}
@@ -548,8 +550,8 @@ void Plugin_028_readCoefficients(uint8_t i2cAddress)
bool Plugin_028_readUncompensatedData(uint8_t i2cAddress) {
// wait until measurement has been completed, otherwise we would read
// the values from the last measurement
while (I2C_read8_reg(i2cAddress, BMx280_REGISTER_STATUS) & 0x08)
delay(1);
if (I2C_read8_reg(i2cAddress, BMx280_REGISTER_STATUS) & 0x08)
return false;
I2Cdata_bytes BME280_data(BME280_P_T_H_DATA_LEN, BME280_DATA_ADDR);
bool allDataRead = I2C_read_bytes(i2cAddress, BME280_data);
@@ -642,13 +644,6 @@ float Plugin_028_readHumidity(uint8_t i2cAddress)
// No support for humidity
return 0.0;
}
// It takes at least 1.587 sec for valit measurements to complete.
// The datasheet names this the "T63" moment.
// 1 second = 63% of the time needed to perform a measurement.
unsigned long difTime = millis() - sensor.last_measurement;
if (difTime < 1587) {
delay(1587 - difTime);
}
int32_t adc_H = sensor.uncompensated.humidity;
int32_t v_x1_u32r;
+63 -40
View File
@@ -24,6 +24,36 @@
WiFiClient espclient_037;
PubSubClient *MQTTclient_037 = NULL;
bool MQTTclient_037_connected = false;
int reconnectCount = 0;
String getClientName() {
//
// Generate the MQTT import client name from the system name and a suffix
//
String tmpClientName = F("%sysname%-Import");
String ClientName = parseTemplate(tmpClientName, 20);
if (reconnectCount != 0) ClientName += reconnectCount;
return ClientName;
}
void Plugin_037_try_connect() {
Plugin_037_update_connect_status();
if (MQTTclient_037_connected) return;
// workaround see: https://github.com/esp8266/Arduino/issues/4497#issuecomment-373023864
espclient_037 = WiFiClient();
if (MQTTclient_037 == NULL) {
MQTTclient_037 = new PubSubClient(espclient_037);
}
if (MQTTConnect_037())
{
// Subscribe to ALL the topics from ALL instance of this import module
MQTTSubscribe_037();
} else {
MQTTclient_037->disconnect();
}
Plugin_037_update_connect_status();
}
void Plugin_037_update_connect_status() {
bool connected = false;
@@ -39,6 +69,7 @@ void Plugin_037_update_connect_status() {
if (!connected) {
// workaround see: https://github.com/esp8266/Arduino/issues/4497#issuecomment-373023864
espclient_037 = WiFiClient();
++reconnectCount;
addLog(LOG_LEVEL_ERROR, F("IMPT : MQTT 037 Connection lost"));
}
}
@@ -49,11 +80,6 @@ boolean Plugin_037(byte function, struct EventStruct *event, String& string)
boolean success = false;
char deviceTemplate[4][41]; // variable for saving the subscription topics
//
// Generate the MQTT import client name from the system name and a suffix
//
String tmpClientName = F("%sysname%-Import");
String ClientName = parseTemplate(tmpClientName, 20);
switch (function)
{
@@ -121,30 +147,23 @@ boolean Plugin_037(byte function, struct EventStruct *event, String& string)
case PLUGIN_INIT:
{
if (!MQTTclient_037) {
MQTTclient_037 = new PubSubClient(espclient_037);
}
success = false;
// When we edit the subscription data from the webserver, the plugin is called again with init.
// In order to resubscribe we have to disconnect and reconnect in order to get rid of any obsolete subscriptions
MQTTclient_037->disconnect();
if (MQTTConnect_037(ClientName))
{
// Subscribe to ALL the topics from ALL instance of this import module
MQTTSubscribe_037();
success = true;
}
else
{
success = false;
if (MQTTclient_037 != NULL) {
MQTTclient_037->disconnect();
if (MQTTConnect_037())
{
// Subscribe to ALL the topics from ALL instance of this import module
MQTTSubscribe_037();
success = true;
}
}
}
case PLUGIN_TEN_PER_SECOND:
{
if (!MQTTclient_037->loop()) { // Listen out for callbacks
if (MQTTclient_037 != NULL && !MQTTclient_037->loop()) { // Listen out for callbacks
Plugin_037_update_connect_status();
}
success = true;
@@ -154,25 +173,26 @@ boolean Plugin_037(byte function, struct EventStruct *event, String& string)
case PLUGIN_ONCE_A_SECOND:
{
// Here we check that the MQTT client is alive.
Plugin_037_try_connect();
if (MQTTclient_037 != NULL) {
if (!MQTTclient_037->connected() || MQTTclient_should_reconnect) {
if (MQTTclient_should_reconnect) {
addLog(LOG_LEVEL_ERROR, F("IMPT : MQTT 037 Intentional reconnect"));
}
if (!MQTTclient_037->connected() || MQTTclient_should_reconnect) {
if (MQTTclient_should_reconnect) {
addLog(LOG_LEVEL_ERROR, F("IMPT : MQTT 037 Intentional reconnect"));
MQTTclient_037->disconnect();
Plugin_037_update_connect_status();
delay(250);
if (! MQTTConnect_037()) {
success = false;
break;
}
MQTTSubscribe_037();
}
MQTTclient_037->disconnect();
Plugin_037_update_connect_status();
delay(250);
if (! MQTTConnect_037(ClientName)) {
success = false;
break;
}
MQTTSubscribe_037();
success = true;
}
success = true;
break;
}
@@ -260,6 +280,7 @@ boolean Plugin_037(byte function, struct EventStruct *event, String& string)
}
boolean MQTTSubscribe_037()
{
if (!MQTTclient_037_connected) return false;
// Subscribe to the topics requested by ALL calls to this plugin.
// We do this because if the connection to the broker is lost, we want to resubscribe for all instances.
@@ -283,7 +304,7 @@ boolean MQTTSubscribe_037()
if (subscribeTo.length() > 0)
{
parseSystemVariables(subscribeTo, false);
if (MQTTclient_037->subscribe(subscribeTo.c_str()))
if (MQTTclient_037 != NULL && MQTTclient_037->subscribe(subscribeTo.c_str()))
{
String log = F("IMPT : [");
LoadTaskSettings(y);
@@ -350,9 +371,11 @@ void mqttcallback_037(char* c_topic, byte* b_payload, unsigned int length)
// For some reason this seems to failduring the call in INIT- however it succeeds later during recovery
// It would be nice to understand this....
boolean MQTTConnect_037(String clientid)
boolean MQTTConnect_037()
{
boolean result = false;
if (MQTTclient_037 == NULL) return false;
String clientid = getClientName();
// @ToDo TD-er: Plugin allows for more than one MQTT controller, but we're now using only the first enabled one.
int enabledMqttController = firstEnabledMQTTController();
if (enabledMqttController < 0) {