mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-28 12:17:05 +00:00
Compare commits
53
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b332a513b5 | ||
|
|
6e1cde343f | ||
|
|
cce9ddd2dc | ||
|
|
51be17a436 | ||
|
|
66d27a6697 | ||
|
|
a033e458fb | ||
|
|
494436bbff | ||
|
|
23bacd0762 | ||
|
|
f131254853 | ||
|
|
657d15d962 | ||
|
|
60910da48d | ||
|
|
6cee2d0f32 | ||
|
|
533cb88a64 | ||
|
|
ffa32fe851 | ||
|
|
b900cc9389 | ||
|
|
8e11c19af6 | ||
|
|
f33ca6df78 | ||
|
|
194a230d20 | ||
|
|
7a5a432016 | ||
|
|
07511fe144 | ||
|
|
9a390136f9 | ||
|
|
27a03f166a | ||
|
|
0a63aeb8f0 | ||
|
|
22c10ac615 | ||
|
|
ac83cfa249 | ||
|
|
6ef0c08bc4 | ||
|
|
1ee965067d | ||
|
|
e46a873fce | ||
|
|
784e956c96 | ||
|
|
b6eebb330a | ||
|
|
a4fe8d42d2 | ||
|
|
fa42cadfa1 | ||
|
|
17dc6fa859 | ||
|
|
1432726dec | ||
|
|
7ba6ffa407 | ||
|
|
ab555e4d6b | ||
|
|
d4259f4e23 | ||
|
|
aef45c06f6 | ||
|
|
828f9e6a30 | ||
|
|
e79d778cf4 | ||
|
|
965eb2d994 | ||
|
|
657fccf49f | ||
|
|
228b41a1ac | ||
|
|
3bba294eb7 | ||
|
|
0254181b3e | ||
|
|
3b67282abb | ||
|
|
38af765935 | ||
|
|
ff180b085c | ||
|
|
ac6d85e214 | ||
|
|
5511ee9f38 | ||
|
|
427a22d23b | ||
|
|
d271898968 | ||
|
|
4051f0bd2e |
@@ -18,3 +18,7 @@ lib/readme.txt
|
||||
src/Custom.h
|
||||
/ESPEasy
|
||||
test/output_export.cpp
|
||||
.vscode
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
|
||||
Vendored
+93
-1
@@ -1,3 +1,95 @@
|
||||
-------------------------------------------------
|
||||
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
|
||||
|
||||
TD-er (4):
|
||||
[Scheduler] Disable command scheduler
|
||||
[Controller settings] Validate settings on load/save
|
||||
[#1713] Make hostname-unitnumber optional & validate settings
|
||||
[#1698] Incorrect sunrise value southern hemisphere
|
||||
|
||||
svmac (4):
|
||||
Fix elseif & Add if-elseif-else nesting levels
|
||||
reenabled code about !
|
||||
some code optimization
|
||||
fix mistake
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20180914 (since mega-20180910)
|
||||
-------------------------------------------------
|
||||
@@ -7,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
@@ -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++
|
||||
|
||||
+11
-2
@@ -133,7 +133,7 @@ bool MQTTConnect(int controller_idx)
|
||||
{
|
||||
++mqtt_reconnect_count;
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(controller_idx, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(controller_idx, ControllerSettings);
|
||||
if (!ControllerSettings.checkHostReachable(true))
|
||||
return false;
|
||||
if (MQTTclient.connected()) {
|
||||
@@ -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)
|
||||
@@ -309,7 +318,7 @@ void MQTTStatus(String& status)
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
int enabledMqttController = firstEnabledMQTTController();
|
||||
if (enabledMqttController >= 0) {
|
||||
LoadControllerSettings(enabledMqttController, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(enabledMqttController, ControllerSettings);
|
||||
String pubname = ControllerSettings.Subscribe;
|
||||
pubname.replace(F("/#"), F("/status"));
|
||||
parseSystemVariables(pubname, false);
|
||||
|
||||
+33
-3
@@ -325,6 +325,8 @@
|
||||
#define RULESETS_MAX 4
|
||||
#define RULES_BUFFER_SIZE 64
|
||||
#define NAME_FORMULA_LENGTH_MAX 40
|
||||
#define RULES_IF_MAX_NESTING_LEVEL 4
|
||||
|
||||
#define UDP_PACKETSIZE_MAX 2048
|
||||
|
||||
#define PIN_MODE_UNDEFINED 0
|
||||
@@ -396,8 +398,9 @@
|
||||
#endif
|
||||
|
||||
// Forward declaration
|
||||
struct ControllerSettingsStruct;
|
||||
void scheduleNextDelayQueue(unsigned long id, unsigned long nextTime);
|
||||
String LoadControllerSettings(int ControllerIndex, byte* memAddress, int datasize);
|
||||
String LoadControllerSettings(int ControllerIndex, ControllerSettingsStruct& controller_settings);
|
||||
String get_formatted_Controller_number(int controller_index);
|
||||
bool loglevelActiveFor(byte logLevel);
|
||||
void addToLog(byte loglevel, const String& string);
|
||||
@@ -405,6 +408,9 @@ void addToLog(byte logLevel, const __FlashStringHelper* flashString);
|
||||
void statusLED(boolean traffic);
|
||||
void backgroundtasks();
|
||||
|
||||
bool getBitFromUL(uint32_t number, byte bitnr);
|
||||
void setBitToUL(uint32_t& number, byte bitnr, bool value);
|
||||
|
||||
enum SettingsType {
|
||||
BasicSettings_Type = 0,
|
||||
TaskSettings_Type,
|
||||
@@ -515,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
|
||||
@@ -662,6 +668,18 @@ struct SettingsStruct
|
||||
clearAll();
|
||||
}
|
||||
|
||||
// VariousBits1 defaults to 0, keep in mind when adding bit lookups.
|
||||
bool appendUnitToHostname() { return !getBitFromUL(VariousBits1, 1); }
|
||||
void appendUnitToHostname(bool value) { setBitToUL(VariousBits1, 1, !value); }
|
||||
|
||||
void validate() {
|
||||
if (UDPPort > 65535) UDPPort = 0;
|
||||
|
||||
if (Latitude < -90.0 || Latitude > 90.0) Latitude = 0.0;
|
||||
if (Longitude < -180.0 || Longitude > 180.0) Longitude = 0.0;
|
||||
if (VariousBits1 > (1 << 30)) VariousBits1 = 0;
|
||||
}
|
||||
|
||||
void clearAll() {
|
||||
PID = 0;
|
||||
Version = 0;
|
||||
@@ -704,6 +722,9 @@ struct SettingsStruct
|
||||
SyslogFacility = DEFAULT_SYSLOG_FACILITY;
|
||||
StructSize = 0;
|
||||
MQTTUseUnitNameAsClientId = 0;
|
||||
Latitude = 0.0;
|
||||
Longitude = 0.0;
|
||||
VariousBits1 = 0;
|
||||
|
||||
for (byte i = 0; i < CONTROLLER_MAX; ++i) {
|
||||
Protocol[i] = 0;
|
||||
@@ -830,6 +851,7 @@ struct SettingsStruct
|
||||
//TODO: document config.dat somewhere here
|
||||
float Latitude;
|
||||
float Longitude;
|
||||
uint32_t VariousBits1;
|
||||
|
||||
// FIXME @TD-er: As discussed in #1292, the CRC for the settings is now disabled.
|
||||
// make sure crc is the last value in the struct
|
||||
@@ -870,6 +892,14 @@ struct ControllerSettingsStruct
|
||||
unsigned int MaxRetry;
|
||||
boolean DeleteOldest; // Action to perform when buffer full, delete oldest, or ignore newest.
|
||||
|
||||
void validate() {
|
||||
if (Port > 65535) Port = 0;
|
||||
if (MinimalTimeBetweenMessages < 1) MinimalTimeBetweenMessages = 100;
|
||||
if (MinimalTimeBetweenMessages > 3600000) MinimalTimeBetweenMessages = 100;
|
||||
if (MaxQueueDepth > 25) MaxQueueDepth = 10;
|
||||
if (MaxRetry > 10) MaxRetry = 10;
|
||||
}
|
||||
|
||||
IPAddress getIP() const {
|
||||
IPAddress host(IP[0], IP[1], IP[2], IP[3]);
|
||||
return host;
|
||||
|
||||
+12
-5
@@ -147,6 +147,7 @@ String SaveSettings(void)
|
||||
// Settings have changed, save to file.
|
||||
memcpy(Settings.md5, tmp_md5, 16);
|
||||
*/
|
||||
Settings.validate();
|
||||
err=SaveToFile((char*)FILE_CONFIG, 0, (byte*)&Settings, sizeof(Settings));
|
||||
if (err.length())
|
||||
return(err);
|
||||
@@ -182,6 +183,7 @@ String LoadSettings()
|
||||
err=LoadFromFile((char*)FILE_CONFIG, 0, (byte*)&Settings, sizeof( SettingsStruct));
|
||||
if (err.length())
|
||||
return(err);
|
||||
Settings.validate();
|
||||
|
||||
// FIXME @TD-er: As discussed in #1292, the CRC for the settings is now disabled.
|
||||
/*
|
||||
@@ -433,20 +435,25 @@ String LoadCustomTaskSettings(int TaskIndex, byte* memAddress, int datasize)
|
||||
/********************************************************************************************\
|
||||
Save Controller settings to SPIFFS
|
||||
\*********************************************************************************************/
|
||||
String SaveControllerSettings(int ControllerIndex, byte* memAddress, int datasize)
|
||||
String SaveControllerSettings(int ControllerIndex, ControllerSettingsStruct& controller_settings)
|
||||
{
|
||||
checkRAM(F("SaveControllerSettings"));
|
||||
return SaveToFile(ControllerSettings_Type, ControllerIndex, (char*)FILE_CONFIG, memAddress, datasize);
|
||||
controller_settings.validate(); // Make sure the saved controller settings have proper values.
|
||||
return SaveToFile(ControllerSettings_Type, ControllerIndex,
|
||||
(char*)FILE_CONFIG, (byte*)&controller_settings, sizeof(controller_settings));
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************************************\
|
||||
Load Controller settings to SPIFFS
|
||||
\*********************************************************************************************/
|
||||
String LoadControllerSettings(int ControllerIndex, byte* memAddress, int datasize)
|
||||
{
|
||||
String LoadControllerSettings(int ControllerIndex, ControllerSettingsStruct& controller_settings) {
|
||||
checkRAM(F("LoadControllerSettings"));
|
||||
return(LoadFromFile(ControllerSettings_Type, ControllerIndex, (char*)FILE_CONFIG, memAddress, datasize));
|
||||
String result =
|
||||
LoadFromFile(ControllerSettings_Type, ControllerIndex,
|
||||
(char*)FILE_CONFIG, (byte*)&controller_settings, sizeof(controller_settings));
|
||||
controller_settings.validate(); // Make sure the loaded controller settings have proper values.
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+4
-2
@@ -418,8 +418,10 @@ void setWifiMode(WiFiMode_t wifimode) {
|
||||
String WifiGetAPssid()
|
||||
{
|
||||
String ssid(Settings.Name);
|
||||
ssid+=F("_");
|
||||
ssid+=Settings.Unit;
|
||||
if (Settings.appendUnitToHostname()) {
|
||||
ssid+=F("_");
|
||||
ssid+=Settings.Unit;
|
||||
}
|
||||
return (ssid);
|
||||
}
|
||||
|
||||
|
||||
+12
-4
@@ -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
|
||||
|
||||
+166
-71
@@ -206,6 +206,19 @@ boolean hasPinState(byte plugin, byte index)
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************\
|
||||
Bitwise operators
|
||||
\*********************************************************************************************/
|
||||
bool getBitFromUL(uint32_t number, byte bitnr) {
|
||||
return (number >> bitnr) & 1UL;
|
||||
}
|
||||
|
||||
void setBitToUL(uint32_t& number, byte bitnr, bool value) {
|
||||
uint32_t newbit = value ? 1UL : 0UL;
|
||||
number ^= (-newbit ^ number) & (1UL << bitnr);
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************\
|
||||
report pin mode & state (info table) using json
|
||||
\*********************************************************************************************/
|
||||
@@ -768,7 +781,7 @@ void ResetFactory(void)
|
||||
str2ip((char*)DEFAULT_SERVER, ControllerSettings.IP);
|
||||
ControllerSettings.HostName[0]=0;
|
||||
ControllerSettings.Port = DEFAULT_PORT;
|
||||
SaveControllerSettings(0, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
SaveControllerSettings(0, ControllerSettings);
|
||||
#endif
|
||||
checkRAM(F("ResetFactory2"));
|
||||
Serial.println(F("RESET: Succesful, rebooting. (you might need to press the reset button if you've justed flashed the firmware)"));
|
||||
@@ -1687,7 +1700,8 @@ float globalstack[STACK_SIZE];
|
||||
float *sp = globalstack - 1;
|
||||
float *sp_max = &globalstack[STACK_SIZE - 1];
|
||||
|
||||
#define is_operator(c) (c == '+' || c == '-' || c == '*' || c == '/' || c == '^')
|
||||
#define is_operator(c) (c == '+' || c == '-' || c == '*' || c == '/' || c == '^' || c == '%')
|
||||
#define is_unary_operator(c) (c == '!')
|
||||
|
||||
int push(float value)
|
||||
{
|
||||
@@ -1720,6 +1734,8 @@ float apply_operator(char op, float first, float second)
|
||||
return first * second;
|
||||
case '/':
|
||||
return first / second;
|
||||
case '%':
|
||||
return round(first) % round(second);
|
||||
case '^':
|
||||
return pow(first, second);
|
||||
default:
|
||||
@@ -1727,6 +1743,17 @@ float apply_operator(char op, float first, float second)
|
||||
}
|
||||
}
|
||||
|
||||
float apply_unary_operator(char op, float first)
|
||||
{
|
||||
switch (op)
|
||||
{
|
||||
case '!':
|
||||
return (round(first) == 0) ? 1 : 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
char *next_token(char *linep)
|
||||
{
|
||||
while (isspace(*(linep++)));
|
||||
@@ -1746,8 +1773,14 @@ int RPNCalculate(char* token)
|
||||
|
||||
if (push(apply_operator(token[0], first, second)))
|
||||
return CALCULATE_ERROR_STACK_OVERFLOW;
|
||||
}
|
||||
else // Als er nog een is, dan deze ophalen
|
||||
} else if (is_unary_operator(token[0]) && token[1] == 0)
|
||||
{
|
||||
float first = pop();
|
||||
|
||||
if (push(apply_unary_operator(token[0], first)))
|
||||
return CALCULATE_ERROR_STACK_OVERFLOW;
|
||||
|
||||
} else // Als er nog een is, dan deze ophalen
|
||||
if (push(atof(token))) // is het een waarde, dan op de stack plaatsen
|
||||
return CALCULATE_ERROR_STACK_OVERFLOW;
|
||||
|
||||
@@ -1763,10 +1796,13 @@ int op_preced(const char c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '!':
|
||||
return 4;
|
||||
case '^':
|
||||
return 3;
|
||||
case '*':
|
||||
case '/':
|
||||
case '%':
|
||||
return 2;
|
||||
case '+':
|
||||
case '-':
|
||||
@@ -1784,8 +1820,10 @@ bool op_left_assoc(const char c)
|
||||
case '/':
|
||||
case '+':
|
||||
case '-':
|
||||
case '%':
|
||||
return true; // left to right
|
||||
//case '!': return false; // right to left
|
||||
case '!':
|
||||
return false; // right to left
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1799,8 +1837,10 @@ unsigned int op_arg_count(const char c)
|
||||
case '/':
|
||||
case '+':
|
||||
case '-':
|
||||
case '%':
|
||||
return 2;
|
||||
//case '!': return 1;
|
||||
case '!':
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1841,7 +1881,7 @@ int Calculate(const char *input, float* result)
|
||||
}
|
||||
|
||||
// If the token is an operator, op1, then:
|
||||
else if (is_operator(c))
|
||||
else if (is_operator(c) || is_unary_operator(c))
|
||||
{
|
||||
*(TokenPos) = 0;
|
||||
error = RPNCalculate(token);
|
||||
@@ -2096,10 +2136,10 @@ String rulesProcessingFile(String fileName, String& event)
|
||||
bool match = false;
|
||||
bool codeBlock = false;
|
||||
bool isCommand = false;
|
||||
bool conditional = false;
|
||||
bool condition = false;
|
||||
bool ifBranche = false;
|
||||
bool ifBrancheJustMatch = false;
|
||||
bool condition[RULES_IF_MAX_NESTING_LEVEL];
|
||||
bool ifBranche[RULES_IF_MAX_NESTING_LEVEL];
|
||||
byte ifBlock = 0;
|
||||
byte fakeIfBlock = 0;
|
||||
|
||||
byte buf[RULES_BUFFER_SIZE];
|
||||
int len = 0;
|
||||
@@ -2122,9 +2162,9 @@ String rulesProcessingFile(String fileName, String& event)
|
||||
parseCompleteNonCommentLine(
|
||||
line, event, log,
|
||||
match, codeBlock, isCommand,
|
||||
conditional, condition,
|
||||
ifBranche, ifBrancheJustMatch);
|
||||
yield();
|
||||
condition, ifBranche,
|
||||
ifBlock, fakeIfBlock);
|
||||
backgroundtasks();
|
||||
}
|
||||
|
||||
line = "";
|
||||
@@ -2144,10 +2184,11 @@ void parseCompleteNonCommentLine(
|
||||
bool& match,
|
||||
bool& codeBlock,
|
||||
bool& isCommand,
|
||||
bool& conditional,
|
||||
bool& condition,
|
||||
bool& ifBranche,
|
||||
bool& ifBrancheJustMatch) {
|
||||
bool condition[],
|
||||
bool ifBranche[],
|
||||
byte& ifBlock,
|
||||
byte& fakeIfBlock)
|
||||
{
|
||||
isCommand = true;
|
||||
|
||||
// Strip comments
|
||||
@@ -2159,6 +2200,23 @@ void parseCompleteNonCommentLine(
|
||||
// only parse [xxx#yyy] if we have a matching ruleblock or need to eval the "on" (no codeBlock)
|
||||
// This to avoid waisting CPU time...
|
||||
line = parseTemplate(line, line.length());
|
||||
|
||||
if (match && !fakeIfBlock) {
|
||||
// substitution of %eventvalue% is made here so it can be used on if statement too
|
||||
if (event.charAt(0) == '!')
|
||||
{
|
||||
line.replace(F("%eventvalue%"), event); // substitute %eventvalue% with literal event string if starting with '!'
|
||||
}
|
||||
else
|
||||
{
|
||||
int equalsPos = event.indexOf("=");
|
||||
if (equalsPos > 0)
|
||||
{
|
||||
String tmpString = event.substring(equalsPos + 1);
|
||||
line.replace(F("%eventvalue%"), tmpString); // substitute %eventvalue% with the actual value from the event
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
line.trim();
|
||||
|
||||
@@ -2173,6 +2231,8 @@ void parseCompleteNonCommentLine(
|
||||
{
|
||||
if (line.startsWith(F("on ")))
|
||||
{
|
||||
ifBlock = 0;
|
||||
fakeIfBlock = 0;
|
||||
line = line.substring(3);
|
||||
int split = line.indexOf(F(" do"));
|
||||
if (split != -1)
|
||||
@@ -2209,6 +2269,8 @@ void parseCompleteNonCommentLine(
|
||||
isCommand = false;
|
||||
codeBlock = false;
|
||||
match = false;
|
||||
ifBlock = 0;
|
||||
fakeIfBlock = 0;
|
||||
}
|
||||
|
||||
if (Settings.SerialLogLevel == LOG_LEVEL_DEBUG_DEV){
|
||||
@@ -2225,8 +2287,8 @@ void parseCompleteNonCommentLine(
|
||||
processMatchedRule(
|
||||
lcAction, action, event, log,
|
||||
match, codeBlock, isCommand,
|
||||
conditional, condition,
|
||||
ifBranche, ifBrancheJustMatch);
|
||||
condition, ifBranche,
|
||||
ifBlock, fakeIfBlock);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2235,70 +2297,101 @@ void processMatchedRule(
|
||||
bool& match,
|
||||
bool& codeBlock,
|
||||
bool& isCommand,
|
||||
bool& conditional,
|
||||
bool& condition,
|
||||
bool& ifBranche,
|
||||
bool& ifBrancheJustMatch)
|
||||
bool condition[],
|
||||
bool ifBranche[],
|
||||
byte& ifBlock,
|
||||
byte& fakeIfBlock)
|
||||
{
|
||||
int split = lcAction.indexOf(F("if ")); // check for optional "if" condition
|
||||
if (!lcAction.startsWith(F("elseif "))) {
|
||||
if (split != -1)
|
||||
{ // There is some 'if ' in the string.
|
||||
conditional = true;
|
||||
String check = lcAction.substring(split + 3);
|
||||
|
||||
log = F("[if ");
|
||||
log += check;
|
||||
log += F("]=");
|
||||
condition = ifBrancheJustMatch == false && conditionMatchExtended(check);
|
||||
if(condition == true)
|
||||
{
|
||||
ifBrancheJustMatch = true;
|
||||
}
|
||||
ifBranche = true;
|
||||
if (fakeIfBlock)
|
||||
isCommand = false;
|
||||
else if (ifBlock)
|
||||
if (condition[ifBlock-1] != ifBranche[ifBlock-1])
|
||||
isCommand = false;
|
||||
log += toString(condition);
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
int split = lcAction.indexOf(F("elseif ")); // check for optional "elseif" condition
|
||||
if (split != -1)
|
||||
{
|
||||
isCommand = false;
|
||||
if (ifBlock && !fakeIfBlock)
|
||||
{
|
||||
if (ifBranche[ifBlock-1])
|
||||
{
|
||||
if (condition[ifBlock-1])
|
||||
ifBranche[ifBlock-1] = false;
|
||||
else
|
||||
{
|
||||
String check = lcAction.substring(split + 7);
|
||||
log = F("Lev.");
|
||||
log += String(ifBlock);
|
||||
log += F(": [elseif ");
|
||||
log += check;
|
||||
log += "]=";
|
||||
condition[ifBlock-1] = conditionMatchExtended(check);
|
||||
log += toString(condition[ifBlock-1]);
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // Starts with 'elseif '
|
||||
String check = lcAction.substring(7);
|
||||
log = F("[elseif ");
|
||||
log += check;
|
||||
log += "]=";
|
||||
condition = ifBrancheJustMatch == false && conditionMatchExtended(check);
|
||||
if(condition == true)
|
||||
{
|
||||
split = lcAction.indexOf(F("if ")); // check for optional "if" condition
|
||||
if (split != -1)
|
||||
{
|
||||
ifBrancheJustMatch = true;
|
||||
if (ifBlock < RULES_IF_MAX_NESTING_LEVEL)
|
||||
{
|
||||
if (isCommand)
|
||||
{
|
||||
ifBlock++;
|
||||
String check = lcAction.substring(split + 3);
|
||||
log = F("Lev.");
|
||||
log += String(ifBlock);
|
||||
log += F(": [if ");
|
||||
log += check;
|
||||
log += F("]=");
|
||||
condition[ifBlock-1] = conditionMatchExtended(check);
|
||||
ifBranche[ifBlock-1] = true;
|
||||
log += toString(condition[ifBlock-1]);
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
}
|
||||
else
|
||||
fakeIfBlock++;
|
||||
}
|
||||
else
|
||||
{
|
||||
fakeIfBlock++;
|
||||
log = F("Lev.");
|
||||
log += String(ifBlock);
|
||||
log = F(": Error: IF Nesting level exceeded!");
|
||||
addLog(LOG_LEVEL_ERROR, log);
|
||||
}
|
||||
isCommand = false;
|
||||
}
|
||||
ifBranche = true;
|
||||
isCommand = false;
|
||||
log += toString(condition);
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
}
|
||||
|
||||
if (lcAction == "else") // in case of an "else" block of actions, set ifBranche to false
|
||||
if ((lcAction == F("else")) && !fakeIfBlock) // in case of an "else" block of actions, set ifBranche to false
|
||||
{
|
||||
ifBranche = false;
|
||||
ifBranche[ifBlock-1] = false;
|
||||
isCommand = false;
|
||||
if (loglevelActiveFor(LOG_LEVEL_DEBUG)) {
|
||||
String log = F("else = ");
|
||||
log += toString(conditional && (condition == ifBranche));
|
||||
log = F("Lev.");
|
||||
log += String(ifBlock);
|
||||
log += F(": [else]=");
|
||||
log += toString(condition[ifBlock-1] == ifBranche[ifBlock-1]);
|
||||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
}
|
||||
}
|
||||
|
||||
if (lcAction == "endif") // conditional block ends here
|
||||
if (lcAction == F("endif")) // conditional block ends here
|
||||
{
|
||||
conditional = false;
|
||||
if (fakeIfBlock)
|
||||
fakeIfBlock--;
|
||||
else if (ifBlock)
|
||||
ifBlock--;
|
||||
isCommand = false;
|
||||
ifBranche = false;
|
||||
ifBrancheJustMatch = false;
|
||||
}
|
||||
|
||||
// process the action if it's a command and unconditional, or conditional and the condition matches the if or else block.
|
||||
if (isCommand && ((!conditional) || (conditional && (condition == ifBranche))))
|
||||
if (isCommand)
|
||||
{
|
||||
if (event.charAt(0) == '!')
|
||||
{
|
||||
@@ -2375,19 +2468,21 @@ boolean ruleMatch(String& event, String& rule)
|
||||
// Special handling of literal string events, they should start with '!'
|
||||
if (event.charAt(0) == '!')
|
||||
{
|
||||
int pos = rule.indexOf('#');
|
||||
if (pos == -1) // no # sign in rule, use 'wildcard' match on event 'source'
|
||||
{
|
||||
tmpEvent = event.substring(0,rule.length());
|
||||
tmpRule = rule;
|
||||
}
|
||||
|
||||
pos = rule.indexOf('*');
|
||||
int pos = rule.indexOf('*');
|
||||
if (pos != -1) // a * sign in rule, so use a'wildcard' match on message
|
||||
{
|
||||
tmpEvent = event.substring(0,pos-1);
|
||||
tmpRule = rule.substring(0,pos-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = rule.indexOf('#');
|
||||
if (pos == -1) // no # sign in rule, use 'wildcard' match on event 'source'
|
||||
{
|
||||
tmpEvent = event.substring(0,rule.length());
|
||||
tmpRule = rule;
|
||||
}
|
||||
}
|
||||
|
||||
if (tmpEvent.equalsIgnoreCase(tmpRule))
|
||||
return true;
|
||||
|
||||
+6
-2
@@ -61,8 +61,8 @@ void calcSunRiseAndSet() {
|
||||
float eqt = equationOfTime(doy);
|
||||
float dec = sunDeclination(doy);
|
||||
float da = diurnalArc(dec, Settings.Latitude);
|
||||
float rise = 12 - da - eqt - Settings.Longitude / 15.0;
|
||||
float set = 12 + da - eqt - Settings.Longitude / 15.0;
|
||||
float rise = 12 - da - eqt;
|
||||
float set = 12 + da - eqt;
|
||||
tsRise.Hour = (int)rise;
|
||||
tsRise.Minute = (rise - (int)rise) * 60.0;
|
||||
tsSet.Hour = (int)set;
|
||||
@@ -70,6 +70,10 @@ void calcSunRiseAndSet() {
|
||||
tsRise.Day = tsSet.Day = tm.Day;
|
||||
tsRise.Month = tsSet.Month = tm.Month;
|
||||
tsRise.Year = tsSet.Year = tm.Year;
|
||||
// Now apply the longitude
|
||||
int secOffset_longitude = -1.0 * (Settings.Longitude / 15.0) * 3600;
|
||||
tsSet = addSeconds(tsSet, secOffset_longitude, false);
|
||||
tsRise = addSeconds(tsRise, secOffset_longitude, false);
|
||||
breakTime(toLocal(makeTime(tsRise)), sunRise);
|
||||
breakTime(toLocal(makeTime(tsSet)), sunSet);
|
||||
}
|
||||
|
||||
+60
-24
@@ -1033,6 +1033,7 @@ void handle_config() {
|
||||
MQTTclient_should_reconnect = true;
|
||||
}
|
||||
strncpy(Settings.Name, name.c_str(), sizeof(Settings.Name));
|
||||
Settings.appendUnitToHostname(isFormItemChecked(F("appendunittohostname")));
|
||||
//strncpy(SecuritySettings.Password, password.c_str(), sizeof(SecuritySettings.Password));
|
||||
copyFormPassword(F("password"), SecuritySettings.Password, sizeof(SecuritySettings.Password));
|
||||
strncpy(SecuritySettings.WifiSSID, ssid.c_str(), sizeof(SecuritySettings.WifiSSID));
|
||||
@@ -1083,6 +1084,7 @@ void handle_config() {
|
||||
SecuritySettings.Password[25] = 0;
|
||||
addFormTextBox( F("Unit Name"), F("name"), Settings.Name, 25);
|
||||
addFormNumericBox( F("Unit Number"), F("unit"), Settings.Unit, 0, UNIT_NUMBER_MAX);
|
||||
addFormCheckBox(F("Append Unit Number to hostname"), F("appendunittohostname"), Settings.appendUnitToHostname());
|
||||
addFormPasswordBox(F("Admin Password"), F("password"), SecuritySettings.Password, 25);
|
||||
|
||||
addFormSubHeader(F("Wifi Settings"));
|
||||
@@ -1262,7 +1264,7 @@ void handle_controllers() {
|
||||
CPlugin_ptr[ProtocolIndex](CPLUGIN_INIT, &TempEvent, dummyString);
|
||||
}
|
||||
}
|
||||
addHtmlError(SaveControllerSettings(controllerindex, (byte*)&ControllerSettings, sizeof(ControllerSettings)));
|
||||
addHtmlError(SaveControllerSettings(controllerindex, ControllerSettings));
|
||||
addHtmlError(SaveSettings());
|
||||
}
|
||||
|
||||
@@ -1276,7 +1278,7 @@ void handle_controllers() {
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
for (byte x = 0; x < CONTROLLER_MAX; x++)
|
||||
{
|
||||
LoadControllerSettings(x, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(x, ControllerSettings);
|
||||
html_TR_TD();
|
||||
TXBuffer += F("<a class='button link' href=\"controllers?index=");
|
||||
TXBuffer += x + 1;
|
||||
@@ -1332,7 +1334,7 @@ void handle_controllers() {
|
||||
if (Settings.Protocol[controllerindex])
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(controllerindex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(controllerindex, ControllerSettings);
|
||||
byte choice = ControllerSettings.UseDNS;
|
||||
String options[2];
|
||||
options[0] = F("Use IP address");
|
||||
@@ -2598,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++)
|
||||
@@ -2609,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
|
||||
|
||||
@@ -4634,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"));
|
||||
@@ -4646,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
@@ -34,7 +34,7 @@ boolean CPlugin_001(byte function, struct EventStruct *event, String& string)
|
||||
case CPLUGIN_INIT:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
C001_DelayHandler.configureControllerSettings(ControllerSettings);
|
||||
break;
|
||||
}
|
||||
|
||||
+2
-2
@@ -36,7 +36,7 @@ boolean CPlugin_002(byte function, struct EventStruct *event, String& string)
|
||||
case CPLUGIN_INIT:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
MQTTDelayHandler.configureControllerSettings(ControllerSettings);
|
||||
break;
|
||||
}
|
||||
@@ -146,7 +146,7 @@ boolean CPlugin_002(byte function, struct EventStruct *event, String& string)
|
||||
if (event->idx != 0)
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
/*
|
||||
if (!ControllerSettings.checkHostReachable(true)) {
|
||||
success = false;
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ boolean CPlugin_003(byte function, struct EventStruct *event, String& string)
|
||||
case CPLUGIN_INIT:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
C003_DelayHandler.configureControllerSettings(ControllerSettings);
|
||||
break;
|
||||
}
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ boolean CPlugin_004(byte function, struct EventStruct *event, String& string)
|
||||
case CPLUGIN_INIT:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
C004_DelayHandler.configureControllerSettings(ControllerSettings);
|
||||
break;
|
||||
}
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ boolean CPlugin_005(byte function, struct EventStruct *event, String& string)
|
||||
case CPLUGIN_INIT:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
MQTTDelayHandler.configureControllerSettings(ControllerSettings);
|
||||
break;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ boolean CPlugin_005(byte function, struct EventStruct *event, String& string)
|
||||
case CPLUGIN_PROTOCOL_SEND:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
if (!ControllerSettings.checkHostReachable(true)) {
|
||||
success = false;
|
||||
break;
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ boolean CPlugin_006(byte function, struct EventStruct *event, String& string)
|
||||
case CPLUGIN_INIT:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
MQTTDelayHandler.configureControllerSettings(ControllerSettings);
|
||||
break;
|
||||
}
|
||||
@@ -91,7 +91,7 @@ boolean CPlugin_006(byte function, struct EventStruct *event, String& string)
|
||||
break;
|
||||
}
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
|
||||
statusLED(true);
|
||||
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ boolean CPlugin_007(byte function, struct EventStruct *event, String& string)
|
||||
case CPLUGIN_INIT:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
C007_DelayHandler.configureControllerSettings(ControllerSettings);
|
||||
break;
|
||||
}
|
||||
|
||||
+2
-2
@@ -35,7 +35,7 @@ boolean CPlugin_008(byte function, struct EventStruct *event, String& string)
|
||||
case CPLUGIN_INIT:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
C008_DelayHandler.configureControllerSettings(ControllerSettings);
|
||||
break;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ boolean CPlugin_008(byte function, struct EventStruct *event, String& string)
|
||||
PluginCall(PLUGIN_GET_DEVICEVALUENAMES, event, dummyString);
|
||||
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
|
||||
for (byte x = 0; x < valueCount; x++)
|
||||
{
|
||||
|
||||
+1
-1
@@ -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
@@ -46,7 +46,7 @@ boolean CPlugin_010(byte function, struct EventStruct *event, String& string)
|
||||
PluginCall(PLUGIN_GET_DEVICEVALUENAMES, event, dummyString);
|
||||
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
|
||||
for (byte x = 0; x < valueCount; x++)
|
||||
{
|
||||
|
||||
+1
-1
@@ -148,7 +148,7 @@ boolean Create_schedule_HTTP_C011(struct EventStruct *event)
|
||||
return false;
|
||||
}
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
|
||||
C011_ConfigStruct customConfig;
|
||||
LoadCustomControllerSettings(event->ControllerIndex,(byte*)&customConfig, sizeof(customConfig));
|
||||
|
||||
+2
-2
@@ -41,7 +41,7 @@ boolean CPlugin_012(byte function, struct EventStruct *event, String& string)
|
||||
PluginCall(PLUGIN_GET_DEVICEVALUENAMES, event, dummyString);
|
||||
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(event->ControllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
|
||||
for (byte x = 0; x < valueCount; x++)
|
||||
{
|
||||
@@ -83,7 +83,7 @@ boolean Blynk_get(const String& command, byte controllerIndex, float *data )
|
||||
}
|
||||
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(controllerIndex, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(controllerIndex, ControllerSettings);
|
||||
|
||||
if ((SecuritySettings.ControllerPassword[controllerIndex][0] == 0)) {
|
||||
addLog(LOG_LEVEL_ERROR, F("Blynk : No password set"));
|
||||
|
||||
@@ -324,7 +324,7 @@ ControllerDelayHandlerStruct<MQTT_queue_element> MQTTDelayHandler;
|
||||
C##NNN##_queue_element element; \
|
||||
if (!C##NNN##_DelayHandler.getNext(element)) return; \
|
||||
ControllerSettingsStruct ControllerSettings; \
|
||||
LoadControllerSettings(element.controller_idx, (byte*)&ControllerSettings, sizeof(ControllerSettings)); \
|
||||
LoadControllerSettings(element.controller_idx, ControllerSettings); \
|
||||
C##NNN##_DelayHandler.configureControllerSettings(ControllerSettings); \
|
||||
if (!WiFiConnected(100)) { \
|
||||
scheduleNextDelayQueue(TIMER_C##NNN##_DELAY_QUEUE, C##NNN##_DelayHandler.getNextScheduleTime()); \
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
@@ -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
@@ -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;
|
||||
|
||||
+64
-41
@@ -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) {
|
||||
@@ -368,7 +391,7 @@ boolean MQTTConnect_037(String clientid)
|
||||
return false; // Not connected, so no use in wasting time to connect to a host.
|
||||
}
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
LoadControllerSettings(enabledMqttController, (byte*)&ControllerSettings, sizeof(ControllerSettings));
|
||||
LoadControllerSettings(enabledMqttController, ControllerSettings);
|
||||
if (ControllerSettings.UseDNS) {
|
||||
MQTTclient_037->setServer(ControllerSettings.getHost().c_str(), ControllerSettings.Port);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user