Compare commits

...
Author SHA1 Message Date
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
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
ESPEasy release bot d4259f4e23 automatically updated release notes for mega-20180915 2018-09-15 04:00:15 +02:00
Gijs NoorlanderandGitHub aef45c06f6 Merge pull request #1747 from TD-er/bugfix/sunrise
[#1698] Incorrect sunrise value southern hemisphere
2018-09-15 00:19:42 +02:00
Gijs NoorlanderandGitHub 828f9e6a30 Merge pull request #1746 from TD-er/feature/hostname_settings
Validate settings + hostname format option
2018-09-15 00:14:30 +02:00
TD-er e79d778cf4 [#1698] Incorrect sunrise value southern hemisphere
See #1698
2018-09-15 00:10:45 +02:00
TD-er 965eb2d994 [#1713] Make hostname-unitnumber optional & validate settings
See #1713
Also added validation check for some values in the settings at load/save of settings.
This could be extended later on for task settings.
2018-09-14 23:44:58 +02:00
Gijs NoorlanderandGitHub 657fccf49f Merge pull request #1641 from svmac/mega
Fix elseif & Add if-elseif-else nesting levels
2018-09-14 23:27:00 +02:00
Gijs NoorlanderandGitHub 228b41a1ac Merge pull request #1742 from giig1967g/new/not
Added 2 new operators in Calculate() function
2018-09-14 23:26:25 +02:00
Gijs NoorlanderandGitHub 3bba294eb7 Merge pull request #1745 from TD-er/bugfix/commands_not_using_scheduler
[Scheduler] Disable command scheduler
2018-09-14 23:22:21 +02:00
TD-er 0254181b3e [Controller settings] Validate settings on load/save
Make sure new values are set to proper defaults and within valid range.
2018-09-14 22:54:23 +02:00
Gijs NoorlanderandGitHub 3b67282abb Merge branch 'mega' into mega 2018-09-14 21:26:21 +02:00
TD-er 38af765935 [Scheduler] Disable command scheduler
For now the commands will no longer use the scheduler.
Commands running asynchronous is causing too much issues.
2018-09-14 21:23:09 +02:00
Plebs ff180b085c Added 2 new operators in Calculate
hi,
added 2 new operators for calculations:

!: Logical NOT:
returns 1 if operand is = 0
returns 0 if operand is != 0

%: MOD:
converts operands in integers and calculates the remainder of the division
2018-09-14 16:44:11 +02:00
Gijs NoorlanderandGitHub ac6d85e214 Merge branch 'mega' into mega 2018-09-12 21:54:50 +02:00
svmac 5511ee9f38 fix mistake 2018-08-15 05:22:27 +02:00
svmac 427a22d23b some code optimization 2018-08-15 04:54:29 +02:00
svmac d271898968 reenabled code about ! 2018-08-14 03:52:29 +02:00
svmac 4051f0bd2e Fix elseif & Add if-elseif-else nesting levels
- The implementation of elseif is not correct. See this example:

Rule:
On SYSVAL do
if %syssec% < 10
publish %sysname%/IP,%ip%
elseif %syssec% < 20
publish %sysname%/Uptime/min,%uptime%
elseif %syssec% < 30
publish %sysname%/Systime/time,%systime%
elseif %syssec% < 40
publish %sysname%/RSSI/dB,%rssi%
elseif %syssec% < 50
publish %sysname%/Sunrise/time,%sunrise%
else
publish %sysname%/Sunset/time,%sunset-30m%
endif
endon

Result:
109360661 : EVENT: SYSVAL
109360668 : [if 11 < 10]=false
109360675 : [elseif 11 < 20]=true //THIS IS CORRECT
109360677 : ACT : publish Wemos51/Uptime/min,1823
109360686 : Command: publish
109360692 : [elseif 11 < 30]=false
109360697 : [elseif 11 < 40]=false
109360703 : [elseif 11 < 50]=false
109360705 : ReplacementString SunTime: %sunrise% offset: 0
109360708 : else = true //THIS IS NOT CORRECT
109360710 : ReplacementString SunTime: %sunset-30m% offset: -1800
109360712 : ACT : publish Wemos51/Sunset/time,20:46
109360723 : Command: publish
109360729 : EVENT: SYSVAL Processing time:68 milliSeconds

- Added also nesting levels to if-elseif-else clausules define in RULES_IF_MAX_NESTING_LEVEL declaration. Example:

Rule:
On SYSVAL do
if %eventvalue% > 1
publish %sysname%/Sunrise/time,%sunrise+1h%
else
if %syssec% < 10
publish %sysname%/IP,%ip%
elseif %syssec% < 20
publish %sysname%/Uptime/min,%uptime%
elseif %syssec% < 30
publish %sysname%/Systime/time,%systime%
elseif %syssec% < 40
publish %sysname%/eventvalue,%eventvalue%
elseif %syssec% < 50
publish %sysname%/Sunrise/time,%sunrise%
else
publish %sysname%/Sunset/time,%sunset-30m%
endif
endif
endon

Result:
>event,SYSVAL=-5
4977875 : Command: event
4977876 : EVENT: SYSVAL=-5
4977883 : Lev.1: [if -5 > 1]=false
4977886 : ReplacementString SunTime: %sunrise+1h% offset: 3600
4977889 : Lev.1: [else]=true
4977893 : Lev.2: [if 30 < 10]=false
4977900 : Lev.2: [elseif 30 < 20]=false
4977906 : Lev.2: [elseif 30 < 30]=false
4977913 : Lev.2: [elseif 30 < 40]=true
4977916 : ACT : publish Wemos49/eventvalue,-5
4977932 : ReplacementString SunTime: %sunrise% offset: 0
4977935 : Lev.2: [else]=false
4977938 : ReplacementString SunTime: %sunset-30m% offset: -1800
4977944 : EVENT: SYSVAL=-5 Processing time:67 milliSeconds

- Finally, the substitution of %eventvalue% is done earlier so that it can be used in if sentence too.
2018-08-11 16:51:56 +02:00
22 changed files with 303 additions and 105 deletions
+4
View File
@@ -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
+55 -1
View File
@@ -1,3 +1,57 @@
-------------------------------------------------
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 +61,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):
+2 -2
View File
@@ -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()) {
@@ -309,7 +309,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);
+31 -1
View File
@@ -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,
@@ -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
View File
@@ -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
View File
@@ -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);
}
+166 -71
View File
@@ -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
View File
@@ -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);
}
+5 -3
View File
@@ -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");
+1 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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"));
+1 -1
View File
@@ -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
View File
@@ -368,7 +368,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 {