From 21c3c2efdc502c9f2d9a88130d97caa9206b7421 Mon Sep 17 00:00:00 2001 From: esp8266nu Date: Sat, 23 May 2015 14:52:33 +0000 Subject: [PATCH] Some delay() modifications. DomoticzSend serial command. AnalogRead is broken in IDE? --- Controller.ino | 24 +++++---- Devices.ino | 3 +- ESPEasy.ino | 33 ++++++------ Serial.ino | 11 +++- WebServer.ino | 130 +++++++++++++++++++++++----------------------- Wifi.ino | 24 ++++----- _ReleaseNotes.ino | 12 ++++- 7 files changed, 129 insertions(+), 108 deletions(-) diff --git a/Controller.ino b/Controller.ino index f5c299f6a..14d9a2dc7 100644 --- a/Controller.ino +++ b/Controller.ino @@ -8,7 +8,7 @@ boolean Domoticz_getData(int idx, float *data) char host[20]; sprintf(host, "%u.%u.%u.%u", Settings.Controller_IP[0], Settings.Controller_IP[1], Settings.Controller_IP[2], Settings.Controller_IP[3]); - Serial.print("HTTP : Connecting to "); + Serial.print(F("HTTP : Connecting to ")); Serial.println(host); // Use WiFiClient class to create TCP connections @@ -16,7 +16,7 @@ boolean Domoticz_getData(int idx, float *data) if (!client.connect(host, Settings.ControllerPort)) { connectionFailures++; - Serial.println("HTTP : Connection failed"); + Serial.println(F("HTTP : Connection failed")); return false; } @@ -24,7 +24,7 @@ boolean Domoticz_getData(int idx, float *data) String url = "/json.htm?type=devices&rid="; url += idx; - Serial.print("HTTP : Requesting URL: "); + Serial.print(F("HTTP : Requesting URL: ")); Serial.println(url); // This will send the request to the server @@ -33,7 +33,8 @@ boolean Domoticz_getData(int idx, float *data) "Connection: close\r\n\r\n"); unsigned long timer = millis() + 200; - while (!client.available() && millis() < timer) {} + while (!client.available() && millis() < timer) + delay(1); // Read all the lines of the reply from server and print them to Serial @@ -51,7 +52,7 @@ boolean Domoticz_getData(int idx, float *data) success = true; } } - Serial.println("HTTP : Closing connection"); + Serial.println(F("HTTP : Closing connection")); return success; } @@ -61,7 +62,7 @@ boolean Domoticz_sendData(byte sensorType, int idx, byte varIndex) char host[20]; sprintf(host, "%u.%u.%u.%u", Settings.Controller_IP[0], Settings.Controller_IP[1], Settings.Controller_IP[2], Settings.Controller_IP[3]); - Serial.print("HTTP : Connecting to "); + Serial.print(F("HTTP : Connecting to ")); Serial.println(host); // Use WiFiClient class to create TCP connections @@ -69,12 +70,12 @@ boolean Domoticz_sendData(byte sensorType, int idx, byte varIndex) if (!client.connect(host, Settings.ControllerPort)) { connectionFailures++; - Serial.println("HTTP : Connection failed"); + Serial.println(F("HTTP : Connection failed")); return false; } // We now create a URI for the request - String url = "/json.htm?type=command¶m=udevice&idx="; + String url = F("/json.htm?type=command¶m=udevice&idx="); url += idx; switch(sensorType) { @@ -98,7 +99,7 @@ boolean Domoticz_sendData(byte sensorType, int idx, byte varIndex) break; } - Serial.print("HTTP : Requesting URL: "); + Serial.print(F("HTTP : Requesting URL: ")); Serial.println(url); // This will send the request to the server @@ -107,7 +108,8 @@ boolean Domoticz_sendData(byte sensorType, int idx, byte varIndex) "Connection: close\r\n\r\n"); unsigned long timer = millis() + 200; - while (!client.available() && millis() < timer) {} + while (!client.available() && millis() < timer) + delay(1); // Read all the lines of the reply from server and print them to Serial while (client.available()) { @@ -118,7 +120,7 @@ boolean Domoticz_sendData(byte sensorType, int idx, byte varIndex) success = true; } } - Serial.println("HTTP : Closing connection"); + Serial.println(F("HTTP : Closing connection")); return success; } diff --git a/Devices.ino b/Devices.ino index fb5d5d60b..92b516357 100644 --- a/Devices.ino +++ b/Devices.ino @@ -19,7 +19,8 @@ void pulseinit(byte Par1) boolean analog(byte Par1) { boolean success = false; - int value = analogRead(A0); + //int value = analogRead(A0); // crashes on latest release... + int value = millis()/1000; UserVar[Par1 - 1] = (float)value; Serial.print("ADC : Analog value: "); Serial.println(value); diff --git a/ESPEasy.ino b/ESPEasy.ino index 3308c9eed..867e484d7 100644 --- a/ESPEasy.ino +++ b/ESPEasy.ino @@ -51,7 +51,7 @@ #define ESP_PROJECT_PID 2015050101L #define VERSION 1 -#define BUILD 5 +#define BUILD 6 #define UDP_LISTEN_PORT 65500 #define REBOOT_ON_MAX_CONNECTION_FAILURES 30 @@ -117,7 +117,7 @@ unsigned long pulseCounter1=0; void setup() { Serial.begin(19200); - Serial.print("\nINIT : Booting Build nr:"); + Serial.print(F("\nINIT : Booting Build nr:")); Serial.println(BUILD); EEPROM.begin(4096); @@ -129,7 +129,7 @@ void setup() Serial.println(Settings.Version); if (Settings.Version != VERSION || Settings.PID != ESP_PROJECT_PID) { - Serial.println("INIT : Incorrect PID or version!"); + Serial.println(F("INIT : Incorrect PID or version!")); delay(10000); ResetFactory(); } @@ -137,31 +137,31 @@ void setup() // configure hardware pins according to eeprom settings. if (Settings.Pin_i2c_sda != -1) { - Serial.println("INIT : I2C"); + Serial.println(F("INIT : I2C")); Wire.begin(Settings.Pin_i2c_sda, Settings.Pin_i2c_scl); } if (Settings.Pin_wired_in_1 != -1) { - Serial.println("INIT : Input 1"); + Serial.println(F("INIT : Input 1")); pinMode(Settings.Pin_wired_in_1, INPUT_PULLUP); } if (Settings.Pin_wired_in_2 != -1) { - Serial.println("INIT : Input 2"); + Serial.println(F("INIT : Input 2")); pinMode(Settings.Pin_wired_in_2, INPUT_PULLUP); } if (Settings.Pin_wired_out_1 != -1) { - Serial.println("INIT : Output 1"); + Serial.println(F("INIT : Output 1")); pinMode(Settings.Pin_wired_out_1, OUTPUT); } if (Settings.Pin_wired_out_2 != -1) { - Serial.println("INIT : Output 2"); + Serial.println(F("INIT : Output 2")); pinMode(Settings.Pin_wired_out_2, OUTPUT); } @@ -203,7 +203,7 @@ void setup() IPAddress ip = WiFi.localIP(); if (ip[0]==0) // dhcp issue ? { - Serial.println("No IP!"); + Serial.println(F("No IP!")); delayedReboot(60); } } @@ -214,13 +214,12 @@ void setup() WifiAPMode(true); } - Serial.println("INIT : Boot OK"); + Serial.println(F("INIT : Boot OK")); syslog((char*)"Boot"); } void loop() { - yield(); server.handleClient(); if (Serial.available()) @@ -279,9 +278,11 @@ void loop() if(connectionFailures > REBOOT_ON_MAX_CONNECTION_FAILURES) { - Serial.println("Too many connection failures"); + Serial.println(F("Too many connection failures")); delayedReboot(60); } + + delay(10); } void inputCheck() @@ -336,13 +337,13 @@ void SensorSend() float value=0; if (Domoticz_getData(Settings.Pulse1, &value)) { - Serial.print("Current Value:"); + Serial.print(F("Current Value:")); Serial.println(value); - Serial.print("Delta Value:"); + Serial.print(F("Delta Value:")); Serial.println(pulseCounter1); value=(value + pulseCounter1)*100; pulseCounter1=0; - Serial.print("New Value:"); + Serial.print(F("New Value:")); Serial.println(value); UserVar[9 - 1] = value; // store pulsecount to var 9 Domoticz_sendData(1, Settings.Pulse1, 9); @@ -371,7 +372,7 @@ void delayedReboot(int rebootDelay) { while (rebootDelay !=0 ) { - Serial.print("Delayed Reset "); + Serial.print(F("Delayed Reset ")); Serial.println(rebootDelay); rebootDelay--; delay(1000); diff --git a/Serial.ino b/Serial.ino index 10da1942e..84d2aeb56 100644 --- a/Serial.ino +++ b/Serial.ino @@ -11,7 +11,7 @@ void ExecuteCommand(char *Line) Command[0] = 0; int Par1 = 0; int Par2 = 0; - + GetArgv(Line, Command, 1); if (GetArgv(Line, TmpStr1, 2)) Par1 = str2int(TmpStr1); if (GetArgv(Line, TmpStr1, 3)) Par2 = str2int(TmpStr1); @@ -20,6 +20,15 @@ void ExecuteCommand(char *Line) // commands to execute io tasks // **************************************** + if (strcasecmp(Command, "DomoticzSend") == 0) + { + if (GetArgv(Line, TmpStr1, 4)) + { + UserVar[10 - 1] = atof(TmpStr1); + Domoticz_sendData(Par1, Par2, 10); + } + } + if (strcasecmp(Command, "UDP") == 0) { if (GetArgv(Line, TmpStr1, 2)) diff --git a/WebServer.ino b/WebServer.ino index 37c41d350..c919e532b 100644 --- a/WebServer.ino +++ b/WebServer.ino @@ -2,7 +2,7 @@ // Web Interface root page //******************************************************************************** void handle_root() { - Serial.print("HTTP : Webrequest : "); + Serial.print(F("HTTP : Webrequest : ")); String webrequest = server.arg("cmd"); webrequest.replace("%20", " "); Serial.println(webrequest); @@ -13,15 +13,15 @@ void handle_root() { if (strcasecmp(command, "wifidisconnect") != 0) { ExecuteCommand(command); - String reply = "
Welcome to ESP Easy"; - reply += "
Config"; - reply += "
Devices"; - reply += "
Hardware"; - reply += "
Reboot"; - reply += "
Disconnect"; - reply += "
Connect"; + String reply = F("Welcome to ESP Easy"); + reply += F("
Config"); + reply += F("
Devices"); + reply += F("
Hardware"); + reply += F("
Reboot"); + reply += F("
Disconnect"); + reply += F("
Connect"); - reply += "

System Info"; + reply += F("

System Info"); IPAddress ip = WiFi.localIP(); IPAddress gw = WiFi.gatewayIP(); @@ -32,16 +32,16 @@ void handle_root() { reply += str; sprintf(str, "%u.%u.%u.%u", gw[0], gw[1], gw[2], gw[3]); - reply += "
GW : "; + reply += F("
GW : "); reply += str; - reply += "
Build : "; + reply += F("
Build : "); reply += BUILD; - reply += "
Unit : "; + reply += F("
Unit : "); reply += Settings.Unit; - reply += "
"; + reply += F(""); server.send(200, "text/html", reply); delay(100); } @@ -50,7 +50,7 @@ void handle_root() { // have to disconnect from within the main loop // because the webconnection is still active at this point // disconnect would result into a crash/reboot... - Serial.println("WIFI : Disconnecting..."); + Serial.println(F("WIFI : Disconnecting...")); cmd_disconnect = true; } } @@ -61,7 +61,7 @@ void handle_root() { void handle_config() { char tmpstring[26]; - Serial.println("HTTP : Webconfig : "); + Serial.println(F("HTTP : Webconfig : ")); String ssid = server.arg("ssid"); String key = server.arg("key"); @@ -91,35 +91,35 @@ void handle_config() { LoadSettings(); } - String reply = ""; - reply += "
SSID:

WPA Key:

WPA Key:

Controller IP:

Controller IP:

Controller Port:

Controller Port:

Fixed IP Octet: (Optional)

Fixed IP Octet: (Optional)

Unit nr:

Unit nr:

WPA AP Mode Key:

WPA AP Mode Key:

Syslog IP:

Syslog IP:

"; - reply += "
"; + reply += F("'>
"); + reply += F(""); server.send(200, "text/html", reply); delay(1000); @@ -130,7 +130,7 @@ void handle_config() { //******************************************************************************** void handle_devices() { - Serial.println("HTTP : Webdevices : "); + Serial.println(F("HTTP : Webdevices : ")); String boardtype = server.arg("boardtype"); String sensordelay = server.arg("delay"); @@ -157,28 +157,28 @@ void handle_devices() { Save_Settings(); } - String reply = "
"; - reply += "Delay:

Dallas:

Dallas:

DHT:

DHT:

DHT Type:

DHT Type:

BMP:

BMP:

LUX:

LUX:

RFID:

RFID:

Analog:

Analog:

Pulse:

Pulse:

"; - reply += "
"; + reply += F("'>
"); + reply += F(""); server.send(200, "text/html", reply); delay(100); } @@ -188,7 +188,7 @@ void handle_devices() { //******************************************************************************** void handle_hardware() { - Serial.println("HTTP : Hardware : "); + Serial.println(F("HTTP : Hardware : ")); String boardtype = server.arg("boardtype"); @@ -242,20 +242,20 @@ void handle_hardware() { Save_Settings(); } - String reply = "
"; + String reply = F(""); reply +="Board Type:"; byte choice = Settings.BoardType; String options[5]; - options[0]="ESP-07/12"; - options[1]="ESP-01 I2C"; - options[2]="ESP-01 In/Out"; - options[3]="ESP-01 2 x In"; - options[4]="ESP-01 2 x Out"; - reply +="
"); for (byte x=0; x<5;x++) { - reply +="
"; + reply += F("
"); + reply += F(""); server.send(200, "text/html", reply); delay(100); } diff --git a/Wifi.ino b/Wifi.ino index 49a7259d6..c74cecf66 100644 --- a/Wifi.ino +++ b/Wifi.ino @@ -2,20 +2,20 @@ void WifiAPMode(boolean state) { if (state) { - Serial.println("WIFI : Starting AP Mode"); + Serial.println(F("WIFI : Starting AP Mode")); WiFi.softAP(ap_ssid, Settings.WifiAPKey); WiFi.mode(WIFI_AP_STA); } else { - Serial.println("WIFI : Ending AP Mode"); + Serial.println(F("WIFI : Ending AP Mode")); WiFi.mode(WIFI_STA); } } boolean WifiConnect() { - Serial.println("WIFI : Connecting..."); + Serial.println(F("WIFI : Connecting...")); if (WiFi.status() != WL_CONNECTED) { if (Settings.WifiSSID[0] != 0) @@ -40,13 +40,13 @@ boolean WifiConnect() IPAddress gw = WiFi.gatewayIP(); IPAddress subnet = WiFi.subnetMask(); ip[3] = Settings.IP_Octet; - Serial.print("IP : Fixed IP :"); + Serial.print(F("IP : Fixed IP :")); Serial.println(ip); WiFi.config(ip, gw, subnet); } } else - Serial.println("WIFI : No SSID!"); + Serial.println(F("WIFI : No SSID!")); } } @@ -57,20 +57,20 @@ boolean WifiDisconnect() void WifiScan() { - Serial.println("WIFI : SSID Scan start"); + Serial.println(F("WIFI : SSID Scan start")); int n = WiFi.scanNetworks(); - Serial.println("WIFI : Scan done"); + Serial.println(F("WIFI : Scan done")); if (n == 0) - Serial.println("WIFI : No networks found"); + Serial.println(F("WIFI : No networks found")); else { - Serial.print("WIFI : "); + Serial.print(F("WIFI : ")); Serial.print(n); - Serial.println(" networks found"); + Serial.println(F(" networks found")); for (int i = 0; i < n; ++i) { // Print SSID and RSSI for each network found - Serial.print("WIFI : "); + Serial.print(F("WIFI : ")); Serial.print(i + 1); Serial.print(": "); Serial.print(WiFi.SSID(i)); @@ -104,7 +104,7 @@ void WifiCheck() C_Count++; if (C_Count > 30) { - Serial.println("WIFI : Return to STA mode"); + Serial.println(F("WIFI : Return to STA mode")); NC_Count=0; AP_Mode=false; WifiAPMode(false); diff --git a/_ReleaseNotes.ino b/_ReleaseNotes.ino index c8c373ddc..353b2477f 100644 --- a/_ReleaseNotes.ino +++ b/_ReleaseNotes.ino @@ -28,6 +28,14 @@ // Sends "WD CF " to syslog if configured // Delayed reboot on empty IP adress (in case of DHCP issue) // Delayed reboot after 30 connection failures - -// R004 18-05-2015 + +// R005 21-05-2015 // Some fixes to be compabtible with Arduino 1.6.4 using ESP board addon 1.6.4.-628-g545ffde + +// R006 23-05-2015 +// Stored many constant strings to progmem +// delay(1) into http 'while' client check +// delay(10) in main loop instead of yield() +// DomoticzSend ,, test command (via serial) +// Disabled analogRead, seems broken in g8cd3697 (use millis()/1000 as demo value!) +