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 = "";
+ 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 += "";
+ reply += F("'>
");
+ reply += F("
";
+ reply += F("
");
+ reply += F("