mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-27 19:57:38 +00:00
UDP Syslog, Hardware config
This commit is contained in:
+8
-4
@@ -13,7 +13,9 @@ boolean Domoticz_getData(int idx, float *data)
|
||||
|
||||
// Use WiFiClient class to create TCP connections
|
||||
WiFiClient client;
|
||||
if (!client.connect(host, Settings.ControllerPort)) {
|
||||
if (!client.connect(host, Settings.ControllerPort))
|
||||
{
|
||||
connectionFailures++;
|
||||
Serial.println("HTTP : Connection failed");
|
||||
return false;
|
||||
}
|
||||
@@ -64,7 +66,9 @@ boolean Domoticz_sendData(byte sensorType, int idx, byte varIndex)
|
||||
|
||||
// Use WiFiClient class to create TCP connections
|
||||
WiFiClient client;
|
||||
if (!client.connect(host, Settings.ControllerPort)) {
|
||||
if (!client.connect(host, Settings.ControllerPort))
|
||||
{
|
||||
connectionFailures++;
|
||||
Serial.println("HTTP : Connection failed");
|
||||
return false;
|
||||
}
|
||||
@@ -88,7 +92,7 @@ boolean Domoticz_sendData(byte sensorType, int idx, byte varIndex)
|
||||
case 3: // temp + hum + hum_stat + bar + bar_fore, used for BMP085
|
||||
url += "&svalue=";
|
||||
url += UserVar[varIndex-1];
|
||||
url += ";0;0";
|
||||
url += ";0;0;";
|
||||
url += UserVar[varIndex];
|
||||
url += ";0";
|
||||
break;
|
||||
@@ -108,7 +112,7 @@ boolean Domoticz_sendData(byte sensorType, int idx, byte varIndex)
|
||||
// Read all the lines of the reply from server and print them to Serial
|
||||
while (client.available()) {
|
||||
String line = client.readStringUntil('\n');
|
||||
if (line.substring(0, 15) == "HTTP/1.0 200 OK")
|
||||
if (line.substring(0, 15) == "HTTP/1.1 200 OK")
|
||||
{
|
||||
Serial.println("HTTP : Succes!");
|
||||
success = true;
|
||||
|
||||
+2
-2
@@ -278,7 +278,7 @@ boolean dallas(byte Par1, byte Par2)
|
||||
byte var = Par2; // Variable to be set.
|
||||
byte RelativePort = Par1 - 1;
|
||||
|
||||
DallasPin = PIN_WIRED_OUT_1 + Par1 - 1;
|
||||
DallasPin = Settings.Pin_wired_out_1 + Par1 - 1;
|
||||
|
||||
noInterrupts();
|
||||
while (!(bitRead(Call_Status, RelativePort)))
|
||||
@@ -338,7 +338,7 @@ byte read_dht_dat(void)
|
||||
boolean dht(byte type, byte Par1, byte Par2)
|
||||
{
|
||||
boolean success = false;
|
||||
DHT_Pin = PIN_WIRED_OUT_1 + Par1 - 1;
|
||||
DHT_Pin = Settings.Pin_wired_out_1 + Par1 - 1;
|
||||
byte dht_dat[5];
|
||||
byte dht_in;
|
||||
byte i;
|
||||
|
||||
+135
-26
@@ -51,16 +51,13 @@
|
||||
|
||||
#define ESP_PROJECT_PID 2015050101L
|
||||
#define VERSION 1
|
||||
#define BUILD 3
|
||||
#define BUILD 4
|
||||
|
||||
#define PIN_I2C_SDA 0
|
||||
#define PIN_I2C_SCL 2
|
||||
#define PIN_WIRED_IN_1 4
|
||||
#define PIN_WIRED_IN_2 5
|
||||
#define PIN_WIRED_OUT_1 12
|
||||
#define PIN_WIRED_OUT_2 13
|
||||
#define UDP_LISTEN_PORT 65500
|
||||
#define REBOOT_ON_MAX_CONNECTION_FAILURES 30
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <EEPROM.h>
|
||||
#include <Wire.h>
|
||||
@@ -68,7 +65,10 @@
|
||||
|
||||
ESP8266WebServer server(80);
|
||||
|
||||
void(*Reboot)(void) = 0;
|
||||
// syslog stuff
|
||||
char packetBuffer[255];
|
||||
WiFiUDP portRX;
|
||||
WiFiUDP portTX;
|
||||
|
||||
struct SettingsStruct
|
||||
{
|
||||
@@ -90,17 +90,27 @@ struct SettingsStruct
|
||||
unsigned int RFID;
|
||||
unsigned int Analog;
|
||||
unsigned int Pulse1;
|
||||
byte BoardType;
|
||||
int8_t Pin_i2c_sda;
|
||||
int8_t Pin_i2c_scl;
|
||||
int8_t Pin_wired_in_1;
|
||||
int8_t Pin_wired_in_2;
|
||||
int8_t Pin_wired_out_1;
|
||||
int8_t Pin_wired_out_2;
|
||||
byte Syslog_IP[4];
|
||||
} Settings;
|
||||
|
||||
float UserVar[15];
|
||||
unsigned long timer;
|
||||
unsigned long timer100ms;
|
||||
unsigned long timer1s;
|
||||
unsigned long timerwd;
|
||||
unsigned int NC_Count = 0;
|
||||
unsigned int C_Count = 0;
|
||||
boolean AP_Mode = false;
|
||||
char ap_ssid[20];
|
||||
boolean cmd_disconnect = false;
|
||||
unsigned long connectionFailures;
|
||||
|
||||
unsigned long pulseCounter1=0;
|
||||
|
||||
@@ -111,15 +121,7 @@ void setup()
|
||||
Serial.println(BUILD);
|
||||
|
||||
EEPROM.begin(4096);
|
||||
|
||||
Wire.pins(PIN_I2C_SDA, PIN_I2C_SCL);
|
||||
Wire.begin();
|
||||
|
||||
pinMode(PIN_WIRED_IN_1, INPUT_PULLUP);
|
||||
pinMode(PIN_WIRED_IN_2, INPUT_PULLUP);
|
||||
pinMode(PIN_WIRED_OUT_1, OUTPUT);
|
||||
pinMode(PIN_WIRED_OUT_2, OUTPUT);
|
||||
|
||||
|
||||
LoadSettings();
|
||||
// if different version, eeprom settings structure has changed. Full Reset needed
|
||||
// on a fresh ESP module eeprom values are set to 255. Version results into -1 (signed int)
|
||||
@@ -132,6 +134,38 @@ void setup()
|
||||
ResetFactory();
|
||||
}
|
||||
|
||||
// configure hardware pins according to eeprom settings.
|
||||
if (Settings.Pin_i2c_sda != -1)
|
||||
{
|
||||
Serial.println("INIT : I2C");
|
||||
Wire.pins(Settings.Pin_i2c_sda, Settings.Pin_i2c_scl);
|
||||
Wire.begin();
|
||||
}
|
||||
|
||||
if (Settings.Pin_wired_in_1 != -1)
|
||||
{
|
||||
Serial.println("INIT : Input 1");
|
||||
pinMode(Settings.Pin_wired_in_1, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
if (Settings.Pin_wired_in_2 != -1)
|
||||
{
|
||||
Serial.println("INIT : Input 2");
|
||||
pinMode(Settings.Pin_wired_in_2, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
if (Settings.Pin_wired_out_1 != -1)
|
||||
{
|
||||
Serial.println("INIT : Output 1");
|
||||
pinMode(Settings.Pin_wired_out_1, OUTPUT);
|
||||
}
|
||||
|
||||
if (Settings.Pin_wired_out_2 != -1)
|
||||
{
|
||||
Serial.println("INIT : Output 2");
|
||||
pinMode(Settings.Pin_wired_out_2, OUTPUT);
|
||||
}
|
||||
|
||||
// create unique AP SSID
|
||||
ap_ssid[0] = 0;
|
||||
strcpy(ap_ssid, "ESP_");
|
||||
@@ -144,28 +178,45 @@ void setup()
|
||||
server.on("/", handle_root);
|
||||
server.on("/config", handle_config);
|
||||
server.on("/devices", handle_devices);
|
||||
server.on("/hardware", handle_hardware);
|
||||
server.on("/json.htm", handle_json);
|
||||
server.begin();
|
||||
|
||||
// Syslog
|
||||
portRX.begin(UDP_LISTEN_PORT);
|
||||
|
||||
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
|
||||
|
||||
if (Settings.RFID > 0)
|
||||
rfidinit(PIN_WIRED_IN_1, PIN_WIRED_IN_2);
|
||||
rfidinit(Settings.Pin_wired_in_1, Settings.Pin_wired_in_2);
|
||||
|
||||
if (Settings.Pulse1 > 0)
|
||||
pulseinit(PIN_WIRED_IN_1);
|
||||
pulseinit(Settings.Pin_wired_in_1);
|
||||
|
||||
// if a SSID is configured, try to connect to Wifi network
|
||||
if (strcasecmp(Settings.WifiSSID, "ssid") != 0)
|
||||
WifiConnect();
|
||||
{
|
||||
WifiConnect();
|
||||
// check if we got an ip address.
|
||||
IPAddress ip = WiFi.localIP();
|
||||
if (ip[0]==0) // dhcp issue ?
|
||||
{
|
||||
Serial.println("No IP!");
|
||||
delayedReboot(60);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Start Access Point for first config steps...
|
||||
AP_Mode = true;
|
||||
WifiAPMode(true);
|
||||
}
|
||||
{
|
||||
// Start Access Point for first config steps...
|
||||
AP_Mode = true;
|
||||
WifiAPMode(true);
|
||||
}
|
||||
|
||||
Serial.println("INIT : Boot OK");
|
||||
syslog((char*)"Boot");
|
||||
}
|
||||
|
||||
void loop()
|
||||
@@ -176,12 +227,36 @@ void loop()
|
||||
if (Serial.available())
|
||||
serial();
|
||||
|
||||
// upd events
|
||||
int packetSize = portRX.parsePacket();
|
||||
if (packetSize)
|
||||
{
|
||||
Serial.print("UDP : " );
|
||||
int len = portRX.read(packetBuffer, 255);
|
||||
if (len > 0) packetBuffer[len] = 0;
|
||||
{
|
||||
Serial.println(packetBuffer);
|
||||
ExecuteCommand(packetBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd_disconnect == true)
|
||||
{
|
||||
cmd_disconnect = false;
|
||||
WifiDisconnect();
|
||||
}
|
||||
|
||||
// Watchdog trigger
|
||||
if (millis() > timerwd)
|
||||
{
|
||||
timerwd = millis() + 30000;
|
||||
char str[40];
|
||||
str[0]=0;
|
||||
sprintf(str,"WD %u CF %u FM %u", millis()/1000, connectionFailures, FreeMem());
|
||||
Serial.println(str);
|
||||
syslog(str);
|
||||
}
|
||||
|
||||
// Perform regular checks, 10 times/sec
|
||||
if (millis() > timer100ms)
|
||||
{
|
||||
@@ -196,12 +271,18 @@ void loop()
|
||||
WifiCheck();
|
||||
}
|
||||
|
||||
// Check sensors and send data to controller when timer has elapsed
|
||||
// Check sensors and send data to controller when sensor timer has elapsed
|
||||
if (millis() > timer)
|
||||
{
|
||||
timer = millis() + Settings.Delay * 1000;
|
||||
SensorSend();
|
||||
}
|
||||
|
||||
if(connectionFailures > REBOOT_ON_MAX_CONNECTION_FAILURES)
|
||||
{
|
||||
Serial.println("Too many connection failures");
|
||||
delayedReboot(60);
|
||||
}
|
||||
}
|
||||
|
||||
void inputCheck()
|
||||
@@ -270,4 +351,32 @@ void SensorSend()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void syslog(char *message)
|
||||
{
|
||||
if (Settings.Syslog_IP[0] != 0)
|
||||
{
|
||||
IPAddress broadcastIP(Settings.Syslog_IP[0],Settings.Syslog_IP[1],Settings.Syslog_IP[2],Settings.Syslog_IP[3]);
|
||||
portTX.beginPacket(broadcastIP,514);
|
||||
char str[80];
|
||||
str[0]=0;
|
||||
sprintf(str,"<7>ESP Unit: %u : %s",Settings.Unit,message);
|
||||
Serial.print("SYSLG: ");
|
||||
Serial.println(str);
|
||||
portTX.write(str);
|
||||
portTX.endPacket();
|
||||
}
|
||||
}
|
||||
|
||||
void delayedReboot(int rebootDelay)
|
||||
{
|
||||
while (rebootDelay !=0 )
|
||||
{
|
||||
Serial.print("Delayed Reset ");
|
||||
Serial.println(rebootDelay);
|
||||
rebootDelay--;
|
||||
delay(1000);
|
||||
}
|
||||
ESP.reset();
|
||||
}
|
||||
|
||||
|
||||
+52
-20
@@ -1,3 +1,18 @@
|
||||
//********************************************************************************
|
||||
// workaround for strcasecmp, issue with lib of header files.??????
|
||||
//********************************************************************************
|
||||
int strcasecmp(const char * str1, const char * str2) {
|
||||
int d = 0;
|
||||
while (1) {
|
||||
int c1 = tolower(*str1++);
|
||||
int c2 = tolower(*str2++);
|
||||
if (((d = c1 - c2) != 0) || (c2 == '\0')) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
//********************************************************************************
|
||||
// Serial Interface to configure and save settings to eeprom
|
||||
//********************************************************************************
|
||||
@@ -5,9 +20,9 @@
|
||||
#define INPUT_COMMAND_SIZE 80
|
||||
void ExecuteCommand(char *Line)
|
||||
{
|
||||
char TmpStr1[40];
|
||||
char TmpStr1[80];
|
||||
TmpStr1[0] = 0;
|
||||
char Command[40];
|
||||
char Command[80];
|
||||
Command[0] = 0;
|
||||
int Par1 = 0;
|
||||
int Par2 = 0;
|
||||
@@ -20,6 +35,17 @@ void ExecuteCommand(char *Line)
|
||||
// commands to execute io tasks
|
||||
// ****************************************
|
||||
|
||||
if (strcasecmp(Command, "UDP") == 0)
|
||||
{
|
||||
if (GetArgv(Line, TmpStr1, 2))
|
||||
{
|
||||
IPAddress broadcastIP(255,255,255,255);
|
||||
portTX.beginPacket(broadcastIP,UDP_LISTEN_PORT);
|
||||
portTX.write(TmpStr1);
|
||||
portTX.endPacket();
|
||||
}
|
||||
}
|
||||
|
||||
if (strcasecmp(Command, "ExtWiredOut") == 0)
|
||||
{
|
||||
mcp23017(Par1, Par2);
|
||||
@@ -65,6 +91,9 @@ void ExecuteCommand(char *Line)
|
||||
if (strcasecmp(Command, "Delay") == 0)
|
||||
Settings.Delay = Par1;
|
||||
|
||||
if (strcasecmp(Command, "Pulse") == 0)
|
||||
Settings.Pulse1 = Par1;
|
||||
|
||||
if (strcasecmp(Command, "ControllerIP") == 0)
|
||||
{
|
||||
if (GetArgv(Line, TmpStr1, 2))
|
||||
@@ -117,7 +146,6 @@ void ExecuteCommand(char *Line)
|
||||
if (strcasecmp(Command, "Reboot") == 0)
|
||||
{
|
||||
ESP.reset();
|
||||
//Reboot();
|
||||
}
|
||||
|
||||
if (strcasecmp(Command, "Reset") == 0)
|
||||
@@ -138,7 +166,14 @@ void ExecuteCommand(char *Line)
|
||||
Serial.println("System Info");
|
||||
IPAddress ip = WiFi.localIP();
|
||||
sprintf(str, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]);
|
||||
Serial.print(" IP Address : "); Serial.println(str);
|
||||
Serial.print(" IP Address : "); Serial.println(str);
|
||||
Serial.print(" Board Type : "); Serial.println((int)Settings.BoardType);
|
||||
Serial.print(" SDA : "); Serial.println((int)Settings.Pin_i2c_sda);
|
||||
Serial.print(" SCL : "); Serial.println((int)Settings.Pin_i2c_scl);
|
||||
Serial.print(" In 1 : "); Serial.println((int)Settings.Pin_wired_in_1);
|
||||
Serial.print(" In 2 : "); Serial.println((int)Settings.Pin_wired_in_2);
|
||||
Serial.print(" Out 1 : "); Serial.println((int)Settings.Pin_wired_out_1);
|
||||
Serial.print(" Out 2 : "); Serial.println((int)Settings.Pin_wired_out_2);
|
||||
Serial.println();
|
||||
|
||||
Serial.println("Generic settings");
|
||||
@@ -172,21 +207,6 @@ void ExecuteCommand(char *Line)
|
||||
}
|
||||
#define INPUT_BUFFER_SIZE 128
|
||||
|
||||
//********************************************************************************
|
||||
// workaround for strcasecmp, issue with lib of header files.??????
|
||||
//********************************************************************************
|
||||
int strcasecmp(const char * str1, const char * str2) {
|
||||
int d = 0;
|
||||
while (1) {
|
||||
int c1 = tolower(*str1++);
|
||||
int c2 = tolower(*str2++);
|
||||
if (((d = c1 - c2) != 0) || (c2 == '\0')) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
byte SerialInByte;
|
||||
int SerialInByteCounter = 0;
|
||||
char InputBuffer_Serial[INPUT_BUFFER_SIZE + 2];
|
||||
@@ -340,6 +360,7 @@ 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.Dallas = DEFAULT_DALLAS_IDX;
|
||||
Settings.DHT = DEFAULT_DHT_IDX;
|
||||
@@ -349,9 +370,20 @@ void ResetFactory(void)
|
||||
Settings.RFID = DEFAULT_RFID_IDX;
|
||||
Settings.Analog = DEFAULT_ANALOG_IDX;
|
||||
Settings.Pulse1 = DEFAULT_PULSE1_IDX;
|
||||
Settings.BoardType = 0;
|
||||
Settings.Pin_i2c_sda = 0;
|
||||
Settings.Pin_i2c_scl = 2;
|
||||
Settings.Pin_wired_in_1 = 4;
|
||||
Settings.Pin_wired_in_2 = 5;
|
||||
Settings.Pin_wired_out_1 = 12;
|
||||
Settings.Pin_wired_out_2 = 13;
|
||||
Settings.Syslog_IP[0] = 0;
|
||||
Settings.Syslog_IP[1] = 0;
|
||||
Settings.Syslog_IP[2] = 0;
|
||||
Settings.Syslog_IP[3] = 0;
|
||||
Save_Settings();
|
||||
WifiDisconnect();
|
||||
Reboot();
|
||||
ESP.reset();
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
+247
-68
@@ -16,6 +16,7 @@ void handle_root() {
|
||||
String reply = "<body><form>Welcome to ESP Easy";
|
||||
reply += "<BR><a href='/config'>Config</a>";
|
||||
reply += "<BR><a href='/devices'>Devices</a>";
|
||||
reply += "<BR><a href='/hardware'>Hardware</a>";
|
||||
reply += "<BR><a href='/?cmd=reboot'>Reboot</a>";
|
||||
reply += "<BR><a href='/?cmd=wifidisconnect'>Disconnect</a>";
|
||||
reply += "<BR><a href='/?cmd=wificonnect'>Connect</a>";
|
||||
@@ -58,20 +59,7 @@ void handle_root() {
|
||||
// Web Interface config page
|
||||
//********************************************************************************
|
||||
void handle_config() {
|
||||
char c_ssid[26];
|
||||
c_ssid[0] = 0;
|
||||
char c_key[26];
|
||||
c_key[0] = 0;
|
||||
char c_controllerip[26];
|
||||
c_controllerip[0] = 0;
|
||||
char c_controllerport[26];
|
||||
c_controllerport[0] = 0;
|
||||
char c_ip_octet[26];
|
||||
c_ip_octet[0] = 0;
|
||||
char c_unit[26];
|
||||
c_unit[0] = 0;
|
||||
char c_apkey[26];
|
||||
c_apkey[0] = 0;
|
||||
char tmpstring[26];
|
||||
|
||||
Serial.println("HTTP : Webconfig : ");
|
||||
|
||||
@@ -82,23 +70,23 @@ void handle_config() {
|
||||
String ip = server.arg("ip");
|
||||
String unit = server.arg("unit");
|
||||
String apkey = server.arg("apkey");
|
||||
String syslogip = server.arg("syslogip");
|
||||
|
||||
if (ssid[0] != 0)
|
||||
{
|
||||
ssid.toCharArray(c_ssid, 25);
|
||||
strcpy(Settings.WifiSSID, c_ssid);
|
||||
key.toCharArray(c_key, 25);
|
||||
strcpy(Settings.WifiKey, c_key);
|
||||
controllerip.toCharArray(c_controllerip, 25);
|
||||
str2ip(c_controllerip, Settings.Controller_IP);
|
||||
controllerport.toCharArray(c_controllerport, 25);
|
||||
Settings.ControllerPort = str2int(c_controllerport);
|
||||
ip.toCharArray(c_ip_octet, 25);
|
||||
Settings.IP_Octet = str2int(c_ip_octet);
|
||||
unit.toCharArray(c_unit, 25);
|
||||
Settings.Unit = str2int(c_unit);
|
||||
apkey.toCharArray(c_apkey, 25);
|
||||
strcpy(Settings.WifiAPKey, c_apkey);
|
||||
ssid.toCharArray(tmpstring, 25);
|
||||
strcpy(Settings.WifiSSID, tmpstring);
|
||||
key.toCharArray(tmpstring, 25);
|
||||
strcpy(Settings.WifiKey, tmpstring);
|
||||
controllerip.toCharArray(tmpstring, 25);
|
||||
str2ip(tmpstring, Settings.Controller_IP);
|
||||
Settings.ControllerPort = controllerport.toInt();
|
||||
Settings.IP_Octet = ip.toInt();
|
||||
Settings.Unit = unit.toInt();
|
||||
apkey.toCharArray(tmpstring, 25);
|
||||
strcpy(Settings.WifiAPKey, tmpstring);
|
||||
syslogip.toCharArray(tmpstring, 25);
|
||||
str2ip(tmpstring, Settings.Syslog_IP);
|
||||
Save_Settings();
|
||||
LoadSettings();
|
||||
}
|
||||
@@ -125,6 +113,11 @@ void handle_config() {
|
||||
reply += "'><BR>WPA AP Mode Key:<BR><input type='text' name='apkey' value='";
|
||||
reply += Settings.WifiAPKey;
|
||||
|
||||
reply += "'><BR>Syslog IP:<BR><input type='text' name='syslogip' value='";
|
||||
str[0]=0;
|
||||
sprintf(str, "%u.%u.%u.%u", Settings.Syslog_IP[0], Settings.Syslog_IP[1], Settings.Syslog_IP[2], Settings.Syslog_IP[3]);
|
||||
reply += str;
|
||||
|
||||
reply += "'><BR><input type='submit' value='Submit'>";
|
||||
reply += "</form></body>";
|
||||
server.send(200, "text/html", reply);
|
||||
@@ -136,28 +129,11 @@ void handle_config() {
|
||||
// Web Interface device page
|
||||
//********************************************************************************
|
||||
void handle_devices() {
|
||||
char c_delay[10];
|
||||
c_delay[0] = 0;
|
||||
char c_dallas[10];
|
||||
c_dallas[0] = 0;
|
||||
char c_dht[10];
|
||||
c_dht[0] = 0;
|
||||
char c_dhttype[10];
|
||||
c_dhttype[0] = 0;
|
||||
char c_bmp[10];
|
||||
c_bmp[0] = 0;
|
||||
char c_lux[10];
|
||||
c_lux[0] = 0;
|
||||
char c_rfid[10];
|
||||
c_rfid[0] = 0;
|
||||
char c_analog[10];
|
||||
c_analog[0] = 0;
|
||||
char c_pulse1[10];
|
||||
c_pulse1[0] = 0;
|
||||
|
||||
Serial.println("HTTP : Webdevices : ");
|
||||
|
||||
String sdelay = server.arg("delay");
|
||||
String boardtype = server.arg("boardtype");
|
||||
String sensordelay = server.arg("delay");
|
||||
String dallas = server.arg("dallas");
|
||||
String dht = server.arg("dht");
|
||||
String dhttype = server.arg("dhttype");
|
||||
@@ -167,31 +143,22 @@ void handle_devices() {
|
||||
String analog = server.arg("analog");
|
||||
String pulse1 = server.arg("pulse1");
|
||||
|
||||
if (sdelay[0] != 0)
|
||||
if (sensordelay.toInt() != 0)
|
||||
{
|
||||
sdelay.toCharArray(c_delay, 9);
|
||||
Settings.Delay = str2int(c_delay);
|
||||
dallas.toCharArray(c_dallas, 9);
|
||||
Settings.Dallas = str2int(c_dallas);
|
||||
dht.toCharArray(c_dht, 9);
|
||||
Settings.DHT = str2int(c_dht);
|
||||
dhttype.toCharArray(c_dhttype, 9);
|
||||
Settings.DHTType = str2int(c_dhttype);
|
||||
bmp.toCharArray(c_bmp, 9);
|
||||
Settings.BMP = str2int(c_bmp);
|
||||
lux.toCharArray(c_lux, 9);
|
||||
Settings.LUX = str2int(c_lux);
|
||||
rfid.toCharArray(c_rfid, 9);
|
||||
Settings.RFID = str2int(c_rfid);
|
||||
analog.toCharArray(c_analog, 9);
|
||||
Settings.Analog = str2int(c_analog);
|
||||
pulse1.toCharArray(c_pulse1, 9);
|
||||
Settings.Pulse1 = str2int(c_pulse1);
|
||||
Settings.Delay = sensordelay.toInt();
|
||||
Settings.Dallas = dallas.toInt();
|
||||
Settings.DHT = dht.toInt();
|
||||
Settings.DHTType = dhttype.toInt();
|
||||
Settings.BMP = bmp.toInt();
|
||||
Settings.LUX = lux.toInt();
|
||||
Settings.RFID = rfid.toInt();
|
||||
Settings.Analog = analog.toInt();
|
||||
Settings.Pulse1 = pulse1.toInt();
|
||||
Save_Settings();
|
||||
}
|
||||
|
||||
String reply = "<body>";
|
||||
reply += "<form>Delay:<BR><input type='text' name='delay' value='";
|
||||
String reply = "<body><form>";
|
||||
reply += "Delay:<BR><input type='text' name='delay' value='";
|
||||
reply += Settings.Delay;
|
||||
reply += "'><BR>Dallas:<BR><input type='text' name='dallas' value='";
|
||||
reply += Settings.Dallas;
|
||||
@@ -215,4 +182,216 @@ void handle_devices() {
|
||||
server.send(200, "text/html", reply);
|
||||
delay(100);
|
||||
}
|
||||
|
||||
//********************************************************************************
|
||||
// Web Interface hardware page
|
||||
//********************************************************************************
|
||||
void handle_hardware() {
|
||||
|
||||
Serial.println("HTTP : Hardware : ");
|
||||
|
||||
String boardtype = server.arg("boardtype");
|
||||
|
||||
if (boardtype.length() != 0)
|
||||
{
|
||||
Settings.BoardType = boardtype.toInt();
|
||||
switch (Settings.BoardType)
|
||||
{
|
||||
case 0:
|
||||
Settings.Pin_i2c_sda = 0;
|
||||
Settings.Pin_i2c_scl = 2;
|
||||
Settings.Pin_wired_in_1 = 4;
|
||||
Settings.Pin_wired_in_2 = 5;
|
||||
Settings.Pin_wired_out_1 = 12;
|
||||
Settings.Pin_wired_out_2 = 13;
|
||||
break;
|
||||
case 1:
|
||||
Settings.Pin_i2c_sda = 0;
|
||||
Settings.Pin_i2c_scl = 2;
|
||||
Settings.Pin_wired_in_1 = -1;
|
||||
Settings.Pin_wired_in_2 = -1;
|
||||
Settings.Pin_wired_out_1 = -1;
|
||||
Settings.Pin_wired_out_2 = -1;
|
||||
break;
|
||||
case 2:
|
||||
Settings.Pin_i2c_sda = -1;
|
||||
Settings.Pin_i2c_scl = -1;
|
||||
Settings.Pin_wired_in_1 = 0;
|
||||
Settings.Pin_wired_in_2 = -1;
|
||||
Settings.Pin_wired_out_1 = 2;
|
||||
Settings.Pin_wired_out_2 = -1;
|
||||
break;
|
||||
case 3:
|
||||
Settings.Pin_i2c_sda = -1;
|
||||
Settings.Pin_i2c_scl = -1;
|
||||
Settings.Pin_wired_in_1 = 0;
|
||||
Settings.Pin_wired_in_2 = 2;
|
||||
Settings.Pin_wired_out_1 = -1;
|
||||
Settings.Pin_wired_out_2 = -1;
|
||||
break;
|
||||
case 4:
|
||||
Settings.Pin_i2c_sda = -1;
|
||||
Settings.Pin_i2c_scl = -1;
|
||||
Settings.Pin_wired_in_1 = -1;
|
||||
Settings.Pin_wired_in_2 = -1;
|
||||
Settings.Pin_wired_out_1 = 0;
|
||||
Settings.Pin_wired_out_2 = 2;
|
||||
break;
|
||||
|
||||
}
|
||||
Save_Settings();
|
||||
}
|
||||
|
||||
String reply = "<body><form>";
|
||||
|
||||
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 +="<BR><select name='boardtype'>";
|
||||
for (byte x=0; x<5;x++)
|
||||
{
|
||||
reply +="<option value='";
|
||||
reply +=x;
|
||||
reply +="'";
|
||||
if (choice==x)
|
||||
reply +=" selected";
|
||||
reply +=">";
|
||||
reply +=options[x];
|
||||
reply+="</option>";
|
||||
}
|
||||
reply +="</select>";
|
||||
|
||||
|
||||
|
||||
switch (Settings.BoardType)
|
||||
{
|
||||
case 0:
|
||||
reply +="<BR>SDA: ";
|
||||
reply += Settings.Pin_i2c_sda;
|
||||
reply +="<BR>SCL: ";
|
||||
reply += Settings.Pin_i2c_scl;
|
||||
reply +="<BR>Input 1: ";
|
||||
reply += Settings.Pin_wired_in_1;
|
||||
reply +="<BR>Input 2: ";
|
||||
reply += Settings.Pin_wired_in_2;
|
||||
reply +="<BR>Output 1: ";
|
||||
reply += Settings.Pin_wired_out_1;
|
||||
reply +="<BR>Output 2: ";
|
||||
reply += Settings.Pin_wired_out_2;
|
||||
break;
|
||||
case 1:
|
||||
reply +="<BR>SDA: ";
|
||||
reply += Settings.Pin_i2c_sda;
|
||||
reply +="<BR>SCL: ";
|
||||
reply += Settings.Pin_i2c_scl;
|
||||
break;
|
||||
case 2:
|
||||
reply +="<BR>Input 1: ";
|
||||
reply += Settings.Pin_wired_in_1;
|
||||
reply +="<BR>Output 1: ";
|
||||
reply += Settings.Pin_wired_out_1;
|
||||
break;
|
||||
case 3:
|
||||
reply +="<BR>Input 1: ";
|
||||
reply += Settings.Pin_wired_in_1;
|
||||
reply +="<BR>Input 2: ";
|
||||
reply += Settings.Pin_wired_in_2;
|
||||
break;
|
||||
case 4:
|
||||
reply +="<BR>Output 1: ";
|
||||
reply += Settings.Pin_wired_out_1;
|
||||
reply +="<BR>Output 2: ";
|
||||
reply += Settings.Pin_wired_out_2;
|
||||
break;
|
||||
}
|
||||
|
||||
reply += "<BR><input type='submit' value='Submit'>";
|
||||
reply += "</form></body>";
|
||||
server.send(200, "text/html", reply);
|
||||
delay(100);
|
||||
}
|
||||
|
||||
// Nodo proof of concept. send json query as nodo event on I2C to mega
|
||||
// Compatible with Nodo 3.8 only, tested on R818
|
||||
// set used variables to global on the Mega.
|
||||
|
||||
#define NODO_VERSION_MAJOR 3
|
||||
#define TARGET_NODO 5
|
||||
|
||||
struct TransmissionStruct
|
||||
{
|
||||
byte Type;
|
||||
byte Command;
|
||||
byte Par1;
|
||||
byte Dummy;
|
||||
unsigned long Par2;
|
||||
byte P1;
|
||||
byte P2;
|
||||
byte SourceUnit;
|
||||
byte DestinationUnit;
|
||||
byte Flags;
|
||||
byte Checksum;
|
||||
};
|
||||
|
||||
void handle_json() {
|
||||
Serial.print("HTTP : Web json : idx: ");
|
||||
String idx = server.arg("idx");
|
||||
String svalue = server.arg("svalue");
|
||||
Serial.print(idx);
|
||||
Serial.print(" svalue: ");
|
||||
Serial.println(svalue);
|
||||
char c_idx[10];
|
||||
c_idx[0] = 0;
|
||||
idx.toCharArray(c_idx, 9);
|
||||
char c_svalue[40];
|
||||
c_svalue[0] = 0;
|
||||
svalue.toCharArray(c_svalue, 39);
|
||||
|
||||
struct TransmissionStruct event;
|
||||
event.Type = 1;
|
||||
event.Command = 4;
|
||||
event.Par1 = str2int(c_idx);
|
||||
event.Par2 = float2ul(atof(c_svalue));
|
||||
event.P1 = 0;
|
||||
event.P2 = 0;
|
||||
event.SourceUnit = 1;
|
||||
event.DestinationUnit = 0;
|
||||
event.Flags = 0;
|
||||
event.Checksum = 0;
|
||||
|
||||
// due to padding of structs in memory on this MCU, we need to shift some bytes
|
||||
byte data[13];
|
||||
memcpy((byte*)&data, (byte*)&event, 3);
|
||||
memcpy((byte*)&data + 3, (byte*)&event + 4, 10);
|
||||
|
||||
// calculate xor checksum
|
||||
byte NewChecksum = NODO_VERSION_MAJOR;
|
||||
for (byte x = 0; x < sizeof(data); x++)
|
||||
NewChecksum ^= data[x];
|
||||
data[12] = NewChecksum;
|
||||
|
||||
// Send data to Nodo through I2C bus
|
||||
// Currently the target Nodo nr is fixed
|
||||
// I2C implementation is still incomplete, scanning does not work, slave mode not supported yet...
|
||||
Wire.beginTransmission(TARGET_NODO);
|
||||
for (byte x = 0; x < sizeof(data); x++)
|
||||
Wire.write(data[x]);
|
||||
Wire.endTransmission();
|
||||
|
||||
server.send(200, "text/html", "OK");
|
||||
delay(100);
|
||||
|
||||
}
|
||||
|
||||
unsigned long float2ul(float f)
|
||||
{
|
||||
unsigned long ul;
|
||||
memcpy(&ul, &f, 4);
|
||||
return ul;
|
||||
}
|
||||
|
||||
|
||||
+17
-1
@@ -1,5 +1,5 @@
|
||||
// R001 01-05-2015
|
||||
// First stable edition
|
||||
// First 'stable' edition (meaning that it does not crash during boot of within one minute...)
|
||||
|
||||
// R002 02-05-2015
|
||||
// Added configuration webinterface
|
||||
@@ -12,4 +12,20 @@
|
||||
// This is convenient to control ESP with Domoticz http requests (relais, io expander, etc)
|
||||
// Support for Domoticz multiple value sensor types (temp/hum/baro)
|
||||
// Added support for pulsecounter
|
||||
|
||||
// R004 18-05-2015
|
||||
// Fixed setting ip_octet to 0 on reset
|
||||
// Fixed missing ; in domoticz send case 3:
|
||||
// Fixed: Serial Pulse settings command did not work.
|
||||
// Very experimental stuff for Nodo events on I2C (Nodo 3.8, R818)
|
||||
// Some code optimization in string/char-array handling within webserver functions
|
||||
// Replaced 'reboot function call' with ESP.reset
|
||||
// Added hardware config web page to change io pins on ESP-01 boards
|
||||
// Added basic stuff for UDP communications and syslog function
|
||||
// Listens on UDP port 65500 for commands.
|
||||
// Added connectionFailure counter
|
||||
// Sends "WD <uptime in seconds> CF <connection failures>" every 30 seconds on serial to reset external watchdog
|
||||
// Sends "WD <uptime in seconds> CF <connection failures>" to syslog if configured
|
||||
// Delayed reboot on empty IP adress (in case of DHCP issue)
|
||||
// Delayed reboot after 30 connection failures
|
||||
|
||||
|
||||
Reference in New Issue
Block a user