Update build

This commit is contained in:
mvdbro
2017-08-12 13:33:42 +02:00
parent b384979b06
commit 2230b39171
6 changed files with 90 additions and 86 deletions

View File

@@ -74,7 +74,7 @@
#define socketdebug false
#define ARDUINO_PROJECT_PID 2016110201L
#define VERSION 2
#define BUILD 147
#define BUILD 150
#define BUILD_NOTES ""
#define NODE_TYPE_ID_ESP_EASY_STD 1

View File

@@ -64,17 +64,20 @@ void SendStatus(byte source, String status)
\*********************************************************************************************/
// handle MQTT messages
void callback(char* c_topic, byte* b_payload, unsigned int length) {
char log[256];
char c_payload[256];
char c_payload[384];
strncpy(c_payload,(char*)b_payload,length);
c_payload[length] = 0;
statusLED(true);
sprintf_P(log, PSTR("%s%s"), "MQTT : Topic: ", c_topic);
addLog(LOG_LEVEL_DEBUG, log);
sprintf_P(log, PSTR("%s%s"), "MQTT : Payload: ", c_payload);
String log;
log=F("MQTT : Topic: ");
log+=c_topic;
addLog(LOG_LEVEL_DEBUG, log);
log=F("MQTT : Payload: ");
log+=c_payload;
addLog(LOG_LEVEL_DEBUG, log);
struct EventStruct TempEvent;
TempEvent.String1 = c_topic;
TempEvent.String2 = c_payload;
@@ -98,7 +101,7 @@ void MQTTConnect()
String subscribeTo = "";
String LWTTopic = Settings.MQTTsubscribe;
LWTTopic.replace("/#", "/status");
LWTTopic.replace(F("/#"), F("/status"));
LWTTopic.replace(F("%sysname%"), Settings.Name);
for (byte x = 1; x < 3; x++)
@@ -106,10 +109,11 @@ void MQTTConnect()
String log = "";
boolean MQTTresult = false;
String msg = F("Connection Lost");
if ((SecuritySettings.ControllerUser[0] != 0) && (SecuritySettings.ControllerPassword[0] != 0))
MQTTresult = MQTTclient.connect(clientid.c_str(), SecuritySettings.ControllerUser, SecuritySettings.ControllerPassword, LWTTopic.c_str(), 0, 0, "Connection Lost");
MQTTresult = MQTTclient.connect(clientid.c_str(), SecuritySettings.ControllerUser, SecuritySettings.ControllerPassword, LWTTopic.c_str(), 0, 0, msg.c_str());
else
MQTTresult = MQTTclient.connect(clientid.c_str(), LWTTopic.c_str(), 0, 0, "Connection Lost");
MQTTresult = MQTTclient.connect(clientid.c_str(), LWTTopic.c_str(), 0, 0, msg.c_str());
if (MQTTresult)
{
@@ -161,7 +165,7 @@ void MQTTCheck()
void MQTTStatus(String& status)
{
String pubname = Settings.MQTTsubscribe;
pubname.replace("/#", "/status");
pubname.replace(F("/#"), F("/status"));
pubname.replace(F("%sysname%"), Settings.Name);
MQTTclient.publish(pubname.c_str(), status.c_str(),Settings.MQTTRetainFlag);
}

View File

@@ -572,8 +572,8 @@ boolean str2ip(char *string, byte* IP)
\*********************************************************************************************/
void SaveSettings(void)
{
SaveToFile((char*)"config.txt", 0, (byte*)&Settings, sizeof(struct SettingsStruct));
SaveToFile((char*)"security.txt", 0, (byte*)&SecuritySettings, sizeof(struct SecurityStruct));
SaveToFile(F("config.txt"), 0, (byte*)&Settings, sizeof(struct SettingsStruct));
SaveToFile(F("security.txt"), 0, (byte*)&SecuritySettings, sizeof(struct SecurityStruct));
}
@@ -582,8 +582,8 @@ void SaveSettings(void)
\*********************************************************************************************/
boolean LoadSettings()
{
LoadFromFile((char*)"config.txt", 0, (byte*)&Settings, sizeof(struct SettingsStruct));
LoadFromFile((char*)"security.txt", 0, (byte*)&SecuritySettings, sizeof(struct SecurityStruct));
LoadFromFile(F("config.txt"), 0, (byte*)&Settings, sizeof(struct SettingsStruct));
LoadFromFile(F("security.txt"), 0, (byte*)&SecuritySettings, sizeof(struct SecurityStruct));
}
@@ -593,7 +593,7 @@ boolean LoadSettings()
void SaveTaskSettings(byte TaskIndex)
{
ExtraTaskSettings.TaskIndex = TaskIndex;
SaveToFile((char*)"config.txt", 4096 + (TaskIndex * 1024), (byte*)&ExtraTaskSettings, sizeof(struct ExtraTaskSettingsStruct));
SaveToFile(F("config.txt"), 4096 + (TaskIndex * 1024), (byte*)&ExtraTaskSettings, sizeof(struct ExtraTaskSettingsStruct));
}
@@ -605,7 +605,7 @@ void LoadTaskSettings(byte TaskIndex)
if (ExtraTaskSettings.TaskIndex == TaskIndex)
return;
LoadFromFile((char*)"config.txt", 4096 + (TaskIndex * 1024), (byte*)&ExtraTaskSettings, sizeof(struct ExtraTaskSettingsStruct));
LoadFromFile(F("config.txt"), 4096 + (TaskIndex * 1024), (byte*)&ExtraTaskSettings, sizeof(struct ExtraTaskSettingsStruct));
ExtraTaskSettings.TaskIndex = TaskIndex; // Needed when an empty task was requested
}
@@ -617,7 +617,7 @@ void SaveCustomTaskSettings(int TaskIndex, byte* memAddress, int datasize)
{
if (datasize > 512)
return;
SaveToFile((char*)"config.txt", 4096 + (TaskIndex * 1024) + 512, memAddress, datasize);
SaveToFile(F("config.txt"), 4096 + (TaskIndex * 1024) + 512, memAddress, datasize);
}
@@ -628,7 +628,7 @@ void LoadCustomTaskSettings(int TaskIndex, byte* memAddress, int datasize)
{
if (datasize > 512)
return;
LoadFromFile((char*)"config.txt", 4096 + (TaskIndex * 1024) + 512, memAddress, datasize);
LoadFromFile(F("config.txt"), 4096 + (TaskIndex * 1024) + 512, memAddress, datasize);
}
@@ -639,7 +639,7 @@ void SaveCustomControllerSettings(byte* memAddress, int datasize)
{
if (datasize > 4096)
return;
SaveToFile((char*)"config.txt", 28672, memAddress, datasize);
SaveToFile(F("config.txt"), 28672, memAddress, datasize);
}
@@ -650,14 +650,14 @@ void LoadCustomControllerSettings(byte* memAddress, int datasize)
{
if (datasize > 4096)
return;
LoadFromFile((char*)"config.txt", 28672, memAddress, datasize);
LoadFromFile(F("config.txt"), 28672, memAddress, datasize);
}
/********************************************************************************************\
Save data into config file on SPIFFS
\*********************************************************************************************/
void SaveToFile(char* fname, int index, byte* memAddress, int datasize)
void SaveToFile(const __FlashStringHelper* fname, int index, byte* memAddress, int datasize)
{
File f = SD.open(fname, FILE_WRITE);
if (f)
@@ -679,7 +679,7 @@ void SaveToFile(char* fname, int index, byte* memAddress, int datasize)
/********************************************************************************************\
Load data from config file on SPIFFS
\*********************************************************************************************/
void LoadFromFile(char* fname, int index, byte* memAddress, int datasize)
void LoadFromFile( const __FlashStringHelper* fname, int index, byte* memAddress, int datasize)
{
File f = SD.open(fname);
if (f)
@@ -702,10 +702,10 @@ void LoadFromFile(char* fname, int index, byte* memAddress, int datasize)
void ResetFactory(void)
{
// Direct Serial is allowed here, since this is only an emergency task.
SD.remove("config.txt");
SD.remove("security.txt");
SD.remove("rules.txt");
File f = SD.open("config.txt", FILE_WRITE);
SD.remove(F("config.txt"));
SD.remove(F("security.txt"));
SD.remove(F("rules.txt"));
File f = SD.open(F("config.txt"), FILE_WRITE);
if (f)
{
for (unsigned long x = 0; x < 32768; x++)
@@ -713,14 +713,14 @@ void ResetFactory(void)
f.close();
}
f = SD.open("security.txt", FILE_WRITE);
f = SD.open(F("security.txt"), FILE_WRITE);
if (f)
{
for (int x = 0; x < 512; x++)
f.write((byte)0);
f.close();
}
f = SD.open("rules.txt", FILE_WRITE);
f = SD.open(F("rules.txt"), FILE_WRITE);
f.close();
LoadSettings();
@@ -842,7 +842,7 @@ void addLog(byte loglevel, const char *line)
if (loglevel <= Settings.SDLogLevel)
{
File logFile = SD.open("log.txt", FILE_WRITE);
File logFile = SD.open(F("log.txt"), FILE_WRITE);
if (logFile)
{
String time = "";
@@ -855,7 +855,7 @@ void addLog(byte loglevel, const char *line)
if (second() < 10)
time += "0";
time += second();
time += " : ";
time += F(" : ");
logFile.print(time);
logFile.println(line);
}
@@ -1060,7 +1060,7 @@ String parseTemplate(String &tmpString, byte lineSize)
}
// replace other system variables like %sysname%, %systime%, %ip%
newString.replace("%sysname%", Settings.Name);
newString.replace(F("%sysname%"), Settings.Name);
String strTime = "";
if (hour() < 10)
@@ -1070,16 +1070,16 @@ String parseTemplate(String &tmpString, byte lineSize)
if (minute() < 10)
strTime += "0";
strTime += minute();
newString.replace("%systime%", strTime);
newString.replace(F("%systime%"), strTime);
newString.replace("%uptime%", String(wdcounter / 2));
newString.replace(F("%uptime%"), String(wdcounter / 2));
IPAddress ip = Ethernet.localIP();
char strIP[20];
sprintf_P(strIP, PSTR("%u.%u.%u.%u"), ip[0], ip[1], ip[2], ip[3]);
newString.replace("%ip%", strIP);
newString.replace(F("%ip%"), strIP);
newString.replace("%sysload%", String(100 - (100 * loopCounterLast / loopCounterMax)));
newString.replace(F("%sysload%"), String(100 - (100 * loopCounterLast / loopCounterMax)));
// padding spaces
while (newString.length() < lineSize)
@@ -1610,7 +1610,7 @@ void rulesProcessing(String& event)
if (data == NULL)
{
data = new uint8_t[RULES_MAX_SIZE];
File f = SD.open("rules.txt");
File f = SD.open(F("rules.txt"));
if (f)
{
byte *pointerToByteToRead = data;
@@ -1664,7 +1664,7 @@ void rulesProcessing(String& event)
if (line.startsWith("on "))
{
line = line.substring(3);
int split = line.indexOf(" do");
int split = line.indexOf(F(" do"));
if (split != -1)
{
eventTrigger = line.substring(0, split);
@@ -1699,7 +1699,7 @@ void rulesProcessing(String& event)
if (match) // rule matched for one action or a block of actions
{
int split = lcAction.indexOf("if "); // check for optional "if" condition
int split = lcAction.indexOf(F("if ")); // check for optional "if" condition
if (split != -1)
{
conditional = true;
@@ -1709,13 +1709,13 @@ void rulesProcessing(String& event)
isCommand = false;
}
if (lcAction == "else") // in case of an "else" block of actions, set ifBranche to false
if (lcAction == F("else")) // in case of an "else" block of actions, set ifBranche to false
{
ifBranche = false;
isCommand = false;
}
if (lcAction == "endif") // conditional block ends here
if (lcAction == F("endif")) // conditional block ends here
{
conditional = false;
isCommand = false;
@@ -1728,7 +1728,7 @@ void rulesProcessing(String& event)
if (equalsPos > 0)
{
String tmpString = event.substring(equalsPos + 1);
action.replace("%eventvalue%", tmpString); // substitute %eventvalue% in actions with the actual value from the event
action.replace(F("%eventvalue%"), tmpString); // substitute %eventvalue% in actions with the actual value from the event
}
log = F("ACT : ");
log += action;
@@ -1736,10 +1736,10 @@ void rulesProcessing(String& event)
struct EventStruct TempEvent;
parseCommandString(&TempEvent, action);
yield();
//yield();
if (!PluginCall(PLUGIN_WRITE, &TempEvent, action))
ExecuteCommand(VALUE_SOURCE_SYSTEM, action.c_str());
yield();
//yield();
}
}
}
@@ -1776,7 +1776,7 @@ boolean ruleMatch(String& event, String& rule)
return false;
}
if (event.startsWith("Clock#Time")) // clock events need different handling...
if (event.startsWith(F("Clock#Time"))) // clock events need different handling...
{
int pos1 = event.indexOf("=");
int pos2 = rule.indexOf("=");

View File

@@ -283,9 +283,9 @@ void handle_root(EthernetClient client, String &post) {
{
reply += F("<TR><TD>System Time:<TD>");
reply += hour();
reply += ":";
reply += F(":");
if (minute() < 10)
reply += "0";
reply += F("0");
reply += minute();
}
@@ -400,10 +400,10 @@ void handle_config(EthernetClient client, String &post) {
{
reply += F("<option value='");
reply += Protocol[x].Number;
reply += "'";
reply += F("'");
if (choice == Protocol[x].Number)
reply += F(" selected");
reply += ">";
reply += F(">");
String ProtocolName = "";
CPlugin_ptr[x](CPLUGIN_GET_DEVICENAME, 0, ProtocolName);
@@ -432,10 +432,10 @@ void handle_config(EthernetClient client, String &post) {
{
reply += F("<option value='");
reply += optionValues[x];
reply += "'";
reply += F("'");
if (choice == optionValues[x])
reply += F(" selected");
reply += ">";
reply += F(">");
reply += options[x];
reply += F("</option>");
}
@@ -689,15 +689,15 @@ void addPinStateSelect(String& str, String name, int choice)
str += F("<select name='");
str += name;
str += "'>";
str += F("'>");
for (byte x = 0; x < 4; x++)
{
str += F("<option value='");
str += optionValues[x];
str += "'";
str += F("'");
if (choice == optionValues[x])
str += F(" selected");
str += ">";
str += F(">");
str += options[x];
str += F("</option>");
}
@@ -1228,10 +1228,10 @@ void addDeviceSelect(String& str, String name, int choice)
Plugin_ptr[index](PLUGIN_GET_DEVICENAME, 0, deviceName);
str += F("<option value='");
str += Device[index].Number;
str += "'";
str += F("'");
if (choice == Device[index].Number)
str += F(" selected");
str += ">";
str += F(">");
str += deviceName;
str += F("</option>");
}
@@ -1356,7 +1356,7 @@ void addPinSelect(boolean forI2C, String& str, String name, int choice)
{
str += F("<option value='");
str += optionValues[x];
str += "'";
str += F("'");
if (optionValues[x] != -1) // empty selection can never be disabled...
{
//if (Settings.UseSerial && ((optionValues[x] == 1) || (optionValues[x] == 3)))
@@ -1364,7 +1364,7 @@ void addPinSelect(boolean forI2C, String& str, String name, int choice)
}
if (choice == optionValues[x])
str += F(" selected");
str += ">";
str += F(">");
str += options[x];
str += F("</option>");
}
@@ -1397,16 +1397,16 @@ void addTaskSelect(String& str, String name, int choice)
LoadTaskSettings(x);
str += F("<option value='");
str += x;
str += "'";
str += F("'");
if (choice == x)
str += F(" selected");
if (Settings.TaskDeviceNumber[x] == 0)
str += F(" disabled");
str += ">";
str += F(">");
str += x + 1;
str += " - ";
str += F(" - ");
str += deviceName;
str += " - ";
str += F(" - ");
str += ExtraTaskSettings.TaskDeviceName;
str += F("</option>");
}
@@ -1420,7 +1420,7 @@ void addTaskValueSelect(String& str, String name, int choice, byte TaskIndex)
{
str += F("<select name='");
str += name;
str += "'>";
str += F("'>");
byte DeviceIndex = getDeviceIndex(Settings.TaskDeviceNumber[TaskIndex]);
@@ -1428,10 +1428,10 @@ void addTaskValueSelect(String& str, String name, int choice, byte TaskIndex)
{
str += F("<option value='");
str += x;
str += "'";
str += F("'");
if (choice == x)
str += F(" selected");
str += ">";
str += F(">");
str += ExtraTaskSettings.TaskDeviceValueNames[x];
str += F("</option>");
}
@@ -2155,9 +2155,9 @@ void handle_sysinfo(EthernetClient client, String path) {
{
reply += F("<TR><TD>System Time:<TD>");
reply += hour();
reply += ":";
reply += F(":");
if (minute() < 10)
reply += "0";
reply += F("0");
reply += minute();
}
@@ -2278,7 +2278,7 @@ void addSelector(String& str, const String& id, int optionCount, const String op
str += F(" ");
str += attr[x];
}
str += ">";
str += F(">");
str += options[x];
str += F("</option>");
}
@@ -2309,7 +2309,7 @@ void addSelector_Item(String& str, const String& option, int index, boolean sele
str += F(" ");
str += attr;
}
str += ">";
str += F(">");
str += option;
str += F("</option>");
}

View File

@@ -35,7 +35,7 @@ boolean CPlugin_001(byte function, struct EventStruct *event, String& string)
{
base64 encoder;
String auth = SecuritySettings.ControllerUser;
auth += ":";
auth += F(":");
auth += SecuritySettings.ControllerPassword;
authHeader = F("Authorization: Basic ");
authHeader += encoder.encode(auth);
@@ -83,29 +83,29 @@ boolean CPlugin_001(byte function, struct EventStruct *event, String& string)
case SENSOR_TYPE_DUAL: // any sensor that uses two simple values
url += F("&svalue=");
url += toString(UserVar[event->BaseVarIndex],ExtraTaskSettings.TaskDeviceValueDecimals[0]);
url += ";";
url += F(";");
url += toString(UserVar[event->BaseVarIndex + 1],ExtraTaskSettings.TaskDeviceValueDecimals[1]);
break;
case SENSOR_TYPE_TEMP_HUM: // temp + hum + hum_stat, used for DHT11
url += F("&svalue=");
url += toString(UserVar[event->BaseVarIndex],ExtraTaskSettings.TaskDeviceValueDecimals[0]);
url += ";";
url += F(";");
url += toString(UserVar[event->BaseVarIndex + 1],ExtraTaskSettings.TaskDeviceValueDecimals[1]);
url += ";0";
url += F(";0");
break;
case SENSOR_TYPE_TEMP_BARO: // temp + hum + hum_stat + bar + bar_fore, used for BMP085
url += F("&svalue=");
url += toString(UserVar[event->BaseVarIndex],ExtraTaskSettings.TaskDeviceValueDecimals[0]);
url += F(";0;0;");
url += toString(UserVar[event->BaseVarIndex + 1],ExtraTaskSettings.TaskDeviceValueDecimals[1]);
url += ";0";
url += F(";0");
break;
case SENSOR_TYPE_TEMP_HUM_BARO: // temp + hum + hum_stat + bar + bar_fore, used for BME280
url += F("&svalue=");
url += toString(UserVar[event->BaseVarIndex],ExtraTaskSettings.TaskDeviceValueDecimals[0]);
url += ";";
url += F(";");
url += toString(UserVar[event->BaseVarIndex + 1],ExtraTaskSettings.TaskDeviceValueDecimals[1]);
url += ";0;";
url += F(";0;");
url += toString(UserVar[event->BaseVarIndex + 2],ExtraTaskSettings.TaskDeviceValueDecimals[2]);
url += ";0";
break;

View File

@@ -70,7 +70,7 @@ boolean CPlugin_002(byte function, struct EventStruct *event, String& string)
{
String action = F("inputSwitchState,");
action += x;
action += ",";
action += F(",");
action += nvalue;
struct EventStruct TempEvent;
parseCommandString(&TempEvent, action);
@@ -86,7 +86,7 @@ boolean CPlugin_002(byte function, struct EventStruct *event, String& string)
int pwmValue = UserVar[baseVar];
action = F("pwm,");
action += Settings.TaskDevicePin1[x];
action += ",";
action += F(",");
switch ((int)nvalue)
{
case 0:
@@ -107,7 +107,7 @@ boolean CPlugin_002(byte function, struct EventStruct *event, String& string)
UserVar[baseVar] = nvalue;
action = F("gpio,");
action += Settings.TaskDevicePin1[x];
action += ",";
action += F(",");
action += nvalue;
}
parseCommandString(&TempEvent, action);
@@ -155,27 +155,27 @@ boolean CPlugin_002(byte function, struct EventStruct *event, String& string)
case SENSOR_TYPE_TEMP_HUM: // temp + hum + hum_stat, used for DHT11
root[F("nvalue")] = 0;
values = toString(UserVar[event->BaseVarIndex],ExtraTaskSettings.TaskDeviceValueDecimals[0]);
values += ";";
values += F(";");
values += toString(UserVar[event->BaseVarIndex + 1],ExtraTaskSettings.TaskDeviceValueDecimals[1]);
values += ";0";
values += F(";0");
values.toCharArray(str, 80);
root[F("svalue")] = str;
break;
case SENSOR_TYPE_TEMP_BARO: // temp + hum + hum_stat + bar + bar_fore, used for BMP085
root[F("nvalue")] = 0;
values = toString(UserVar[event->BaseVarIndex],ExtraTaskSettings.TaskDeviceValueDecimals[0]);
values += ";0;0;";
values += F(";0;0;");
values += toString(UserVar[event->BaseVarIndex + 1],ExtraTaskSettings.TaskDeviceValueDecimals[1]);
values += ";0";
values += F(";0");
values.toCharArray(str, 80);
root[F("svalue")] = str;
break;
case SENSOR_TYPE_TEMP_HUM_BARO: // temp + hum + hum_stat + bar + bar_fore, used for BME280
root[F("nvalue")] = 0;
values = toString(UserVar[event->BaseVarIndex],ExtraTaskSettings.TaskDeviceValueDecimals[0]);
values += ";";
values += F(";");
values += toString(UserVar[event->BaseVarIndex + 1],ExtraTaskSettings.TaskDeviceValueDecimals[1]);
values += ";0;";
values += F(";0;");
values += toString(UserVar[event->BaseVarIndex + 2],ExtraTaskSettings.TaskDeviceValueDecimals[2]);
values += ";0";
values.toCharArray(str, 80);
@@ -184,9 +184,9 @@ boolean CPlugin_002(byte function, struct EventStruct *event, String& string)
case SENSOR_TYPE_SWITCH:
root[F("command")] = String(F("switchlight"));
if (UserVar[event->BaseVarIndex] == 0)
root[F("switchcmd")] = "Off";
root[F("switchcmd")] = F("Off");
else
root[F("switchcmd")] = "On";
root[F("switchcmd")] = F("On");
break;
case SENSOR_TYPE_DIMMER:
root[F("command")] = String(F("switchlight"));