Merge remote-tracking branch 'origin/master'

This commit is contained in:
rtenklooster
2015-09-13 19:34:51 +02:00
5 changed files with 151 additions and 53 deletions
+53 -22
View File
@@ -77,11 +77,12 @@
// DO NOT CHANGE ANYTHING BELOW THIS LINE
// ********************************************************************************
#define ESP_PROJECT_PID 2015050101L
#define ESP_PROJECT_PID 2015050101L
#define ESP_EASY
#define VERSION 7
#define BUILD 19
#define VERSION 8
#define BUILD 20
#define REBOOT_ON_MAX_CONNECTION_FAILURES 30
#define EEPROM_SIZE 2048
#define PROTOCOL_DOMOTICZ_HTTP 1
#define PROTOCOL_DOMOTICZ_MQTT 2
@@ -115,16 +116,16 @@
#define SENSOR_TYPE_SWITCH 10
#define SENSOR_TYPE_DIMMER 11
#define PLUGIN_INIT_ALL 1
#define PLUGIN_INIT 2
#define PLUGIN_COMMAND 3
#define PLUGIN_ONCE_A_SECOND 4
#define PLUGIN_TEN_PER_SECOND 5
#define PLUGIN_DEVICE_ADD 6
#define PLUGIN_EVENTLIST_ADD 7
#define PLUGIN_WEBFORM_SAVE 8
#define PLUGIN_WEBFORM_LOAD 9
#define PLUGIN_WEBFORM_VALUES 10
#define PLUGIN_INIT_ALL 1
#define PLUGIN_INIT 2
#define PLUGIN_COMMAND 3
#define PLUGIN_ONCE_A_SECOND 4
#define PLUGIN_TEN_PER_SECOND 5
#define PLUGIN_DEVICE_ADD 6
#define PLUGIN_EVENTLIST_ADD 7
#define PLUGIN_WEBFORM_SAVE 8
#define PLUGIN_WEBFORM_LOAD 9
#define PLUGIN_WEBFORM_VALUES 10
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
@@ -188,6 +189,7 @@ struct SettingsStruct
boolean TaskDevicePin1PullUp[TASKS_MAX];
long TaskDevicePluginConfig[TASKS_MAX][PLUGIN_VAR_MAX];
boolean TaskDevicePin1Inversed[TASKS_MAX];
byte deepSleep;
} Settings;
struct EventStruct
@@ -249,7 +251,8 @@ String dummyString = "";
\*********************************************************************************************/
void setup()
{
EEPROM.begin(2048);
EEPROM.begin(EEPROM_SIZE);
emergencyReset();
LoadSettings();
@@ -272,7 +275,6 @@ void setup()
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG_MORE)
Serial.setDebugOutput(true);
WifiAPconfig();
WifiConnect();
@@ -285,12 +287,6 @@ void setup()
if (Settings.UDPPort != 0)
portRX.begin(Settings.UDPPort);
// Setup timers
timer = millis() + 30000; // startup delay 30 sec
timer100ms = millis() + 100; // timer for periodic actions 10 x per/sec
timer1s = millis() + 1000; // timer for periodic actions once per/sec
timerwd = millis() + 30000; // timer for watchdog once per 30 sec
// Setup LCD display
lcd.init(); // initialize the lcd
lcd.backlight();
@@ -303,6 +299,32 @@ void setup()
sendSysInfoUDP(3);
Serial.println(F("INIT : Boot OK"));
addLog(LOG_LEVEL_INFO, (char*)"Boot");
if(Settings.deepSleep)
Serial.println("Deep sleep enabled");
byte bootMode=0;
if (readFromRTC(&bootMode))
{
if (bootMode == 1)
Serial.println("reboot from deepsleep");
else
Serial.println("normal boot");
}
else
Serial.println("RTC not read");
saveToRTC(0);
// Setup timers
if (bootMode == 0)
timer = millis() + 30000; // startup delay 30 sec
else
timer = millis() + 0; // no startup from deepsleep wake up
timer100ms = millis() + 100; // timer for periodic actions 10 x per/sec
timer1s = millis() + 1000; // timer for periodic actions once per/sec
timerwd = millis() + 30000; // timer for watchdog once per 30 sec
}
@@ -316,7 +338,6 @@ void loop()
checkUDP();
if (cmd_within_mainloop != 0)
{
switch (cmd_within_mainloop)
@@ -379,6 +400,12 @@ void loop()
{
timer = millis() + Settings.Delay * 1000;
SensorSend();
if (Settings.deepSleep)
{
saveToRTC(1);
Serial.println("Enter deepsleep...");
ESP.deepSleep(Settings.Delay * 1000000, WAKE_RF_DEFAULT); // Sleep for set delay
}
}
if (connectionFailures > REBOOT_ON_MAX_CONNECTION_FAILURES)
@@ -389,6 +416,10 @@ void loop()
backgroundtasks();
if (Settings.deepSleep)
{
//ESP.deepSleep(Settings.Delay * 1000000, WAKE_RF_DEFAULT); // Sleep for set delay
}
}
+61 -30
View File
@@ -140,6 +140,14 @@ boolean LoadSettings()
void ResetFactory(void)
{
Serial.println("Reset!");
// First we clear the entire eeprom area and fill with zeros (better default than 0xff)
for (int i = 0; i < EEPROM_SIZE; i++)
EEPROM.write(i, 0);
EEPROM.commit();
LoadSettings();
// now we set all parameters that need to be non-zero as default value
Settings.PID = ESP_PROJECT_PID;
Settings.Version = VERSION;
Settings.Unit = UNIT;
@@ -148,50 +156,21 @@ void ResetFactory(void)
strcpy(Settings.WifiAPKey, DEFAULT_AP_KEY);
str2ip((char*)DEFAULT_SERVER, Settings.Controller_IP);
Settings.ControllerPort = DEFAULT_PORT;
Settings.IP_Octet = 0;
Settings.Delay = DEFAULT_DELAY;
Settings.Pin_i2c_sda = 4;
Settings.Pin_i2c_scl = 5;
Settings.Syslog_IP[0] = 0;
Settings.Syslog_IP[1] = 0;
Settings.Syslog_IP[2] = 0;
Settings.Syslog_IP[3] = 0;
Settings.UDPPort = 0;
Settings.Protocol = DEFAULT_PROTOCOL;
Settings.IP[0] = 0;
Settings.IP[1] = 0;
Settings.IP[2] = 0;
Settings.IP[3] = 0;
Settings.Gateway[0] = 0;
Settings.Gateway[1] = 0;
Settings.Gateway[2] = 0;
Settings.Gateway[3] = 0;
Settings.Subnet[0] = 0;
Settings.Subnet[1] = 0;
Settings.Subnet[2] = 0;
Settings.Subnet[3] = 0;
strcpy(Settings.Name, DEFAULT_NAME);
Settings.SyslogLevel = 0;
Settings.SerialLogLevel = 3;
Settings.WebLogLevel = 3;
Settings.BaudRate = 115200;
Settings.ControllerUser[0] = 0;
Settings.ControllerPassword[0] = 0;
Settings.Password[0] = 0;
Settings.MessageDelay = 1000;
Settings.deepSleep = false;
for (byte x = 0; x < TASKS_MAX; x++)
{
Settings.TaskDeviceNumber[x] = 0;
Settings.TaskDeviceID[x] = 0;
Settings.TaskDevicePin1[x] = -1;
Settings.TaskDevicePin2[x] = -1;
Settings.TaskDevicePin1PullUp[x] = true;
Settings.TaskDeviceName[x][0] = 0;
Settings.TaskDevicePort[x] = 0;
for (byte varNr = 0; varNr < VARS_PER_TASK; varNr++)
(Settings.TaskDeviceFormula[x][varNr][0] = 0);
for (byte y = 0; y < PLUGIN_VAR_MAX; y++)
Settings.TaskDevicePluginConfig[x][y] = 0;
Settings.TaskDevicePin1Inversed[x]=false;
}
Save_Settings();
@@ -200,6 +179,26 @@ void ResetFactory(void)
}
/********************************************************************************************\
* If RX and TX tied together, perform emergency reset to get the system out of boot loops
\*********************************************************************************************/
void emergencyReset()
{
Serial.begin(115200);
Serial.write(0xAA);
Serial.write(0x55);
delay(1);
if (Serial.available() == 2)
if (Serial.read() == 0xAA && Serial.read() == 0x55)
{
Serial.println("System will reset in 10 seconds...");
delay(10000);
ResetFactory();
}
}
/********************************************************************************************\
* Get free system mem
\*********************************************************************************************/
@@ -274,6 +273,38 @@ void delayedReboot(int rebootDelay)
}
/********************************************************************************************\
* Save a byte to RTC memory
\*********************************************************************************************/
#define RTC_BASE 28 // 64
void saveToRTC(byte Par1)
{
byte buf[3] = {0xAA,0x55,0};
buf[2] = Par1;
system_rtc_mem_write(RTC_BASE,buf,3);
}
/********************************************************************************************\
* Read a byte from RTC memory
\*********************************************************************************************/
boolean readFromRTC(byte* data)
{
byte buf[3] = {0,0,0};
system_rtc_mem_read(RTC_BASE,buf,3);
if (buf[0] == 0xAA && buf[1] == 0x55)
{
*data = buf[2];
Serial.println(buf[2]);
return true;
}
else
Serial.println("No data");
return false;
}
/********************************************************************************************\
* Calculate function for simple expressions
\*********************************************************************************************/
+16
View File
@@ -20,6 +20,22 @@ void ExecuteCommand(char *Line)
// commands to execute io tasks
// ****************************************
if (strcasecmp(Command, "Sleep") == 0)
{
ESP.deepSleep(10000000, WAKE_RF_DEFAULT); // Sleep for 10 seconds
}
if (strcasecmp(Command, "RTCsave") == 0)
{
saveToRTC(Par1);
}
if (strcasecmp(Command, "RTCread") == 0)
{
byte data=0;
readFromRTC(&data);
}
if (strcasecmp(Command, "GPIO") == 0)
{
if (Par1 >= 0 && Par1 <= 16)
+15 -1
View File
@@ -215,6 +215,7 @@ void handle_config() {
String controllerpassword = WebServer.arg("controllerpassword");
String sensordelay = WebServer.arg("delay");
String messagedelay = WebServer.arg("messagedelay");
String deepsleep = WebServer.arg("deepsleep");
String ip = WebServer.arg("ip");
String espip = WebServer.arg("espip");
String espgateway = WebServer.arg("espgateway");
@@ -257,6 +258,7 @@ void handle_config() {
Settings.Protocol = protocol.toInt();
Settings.Delay = sensordelay.toInt();
Settings.MessageDelay = messagedelay.toInt();
Settings.deepSleep = (deepsleep == "on");
Settings.IP_Octet = ip.toInt();
espip.toCharArray(tmpString, 26);
str2ip(tmpString, Settings.IP);
@@ -345,8 +347,13 @@ void handle_config() {
reply += Settings.Delay;
reply += F("'><TR><TD>Message Delay (ms):<TD><input type='text' name='messagedelay' value='");
reply += Settings.MessageDelay;
reply += F("'><TR><TD>Sleep Mode:<TD>");
if (Settings.deepSleep)
reply += F("<input type=checkbox name='deepsleep' checked>");
else
reply += F("<input type=checkbox name='deepsleep'>");
reply += F("'><TR bgcolor='#55bbff'><TD>Optional Settings<TD><TR><TD>Fixed IP Octet:<TD><input type='text' name='ip' value='");
reply += F("<TR bgcolor='#55bbff'><TD>Optional Settings<TD><TR><TD>Fixed IP Octet:<TD><input type='text' name='ip' value='");
reply += Settings.IP_Octet;
reply += F("'><TR><TD>ESP IP:<TD><input type='text' name='espip' value='");
@@ -573,6 +580,13 @@ void handle_devices() {
reply += "<TR><TD>Device:<TD>";
addDeviceSelect(reply,"taskdevicenumber",Settings.TaskDeviceNumber[index-1]);
if(Settings.TaskDeviceNumber[index-1] !=0 )
{
reply += F("<a class=\"button-link\" href=\"http://www.esp8266.nu/index.php/plugin");
reply += Settings.TaskDeviceNumber[index-1];
reply += F("\" target=\"_blank\">?</a>");
}
reply += F("<TR><TD>Name:<TD><input type='text' maxlength='25' name='taskdevicename' value='");
reply += Settings.TaskDeviceName[index-1];
+6
View File
@@ -1,3 +1,9 @@
// R20 13-09-2015
// Changed factory reset, first wipe entire eeprom size to zeros
// Added option to do a factory reset by connecting RX and TX pins during boot
// Added a help button on the device page that leads to the device specific page on our Wiki
// Preliminary support for deep_sleep
// R019 13-09-2015
// Added support for the HC-SR04 Ultrasonic distance sensor
// Input switch can now be set to send switch state or dimvalue