mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-28 04:07:47 +00:00
IMPORTANT NOTICE: this release needs ESP Package version 1.6.5-947-g39819f0, built on Jul 23, 2015)
If udp port = 0 no actions! Used sprintf_P to save more RAM Added login page and admin password Added hardware custom gpio pin selection Added sanity check on BMP085 pressure values
This commit is contained in:
+20
-13
@@ -5,7 +5,7 @@ boolean Domoticz_getData(int idx, float *data)
|
||||
{
|
||||
boolean success = false;
|
||||
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]);
|
||||
sprintf_P(host, PSTR("%u.%u.%u.%u"), Settings.Controller_IP[0], Settings.Controller_IP[1], Settings.Controller_IP[2], Settings.Controller_IP[3]);
|
||||
|
||||
Serial.print(F("connecting to "));
|
||||
Serial.println(host);
|
||||
@@ -86,9 +86,9 @@ boolean Domoticz_sendData(byte sensorType, int idx, byte varIndex)
|
||||
char log[80];
|
||||
boolean success = false;
|
||||
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]);
|
||||
sprintf_P(host, PSTR("%u.%u.%u.%u"), Settings.Controller_IP[0], Settings.Controller_IP[1], Settings.Controller_IP[2], Settings.Controller_IP[3]);
|
||||
|
||||
sprintf(log, "%s%s", "HTTP : connecting to ", host);
|
||||
sprintf_P(log, PSTR("%s%s"), "HTTP : connecting to ", host);
|
||||
addLog(LOG_LEVEL_DEBUG,log);
|
||||
if (printToWeb)
|
||||
{
|
||||
@@ -164,13 +164,13 @@ boolean Domoticz_sendData(byte sensorType, int idx, byte varIndex)
|
||||
while (client.available()) {
|
||||
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG_MORE)
|
||||
{
|
||||
sprintf(log,"C1 WS %u FM %u",WiFi.status(),FreeMem());
|
||||
sprintf_P(log,PSTR("C1 WS %u FM %u"),WiFi.status(),FreeMem());
|
||||
Serial.println(log);
|
||||
}
|
||||
String line = client.readStringUntil('\n');
|
||||
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG_MORE)
|
||||
{
|
||||
sprintf(log,"C2 WS %u FM %u",WiFi.status(),FreeMem());
|
||||
sprintf_P(log,PSTR("C2 WS %u FM %u"),WiFi.status(),FreeMem());
|
||||
Serial.println(log);
|
||||
}
|
||||
line.toCharArray(log,79);
|
||||
@@ -202,9 +202,9 @@ boolean NodoTelnet_sendData(byte sensorType, int var, byte varIndex)
|
||||
char log[80];
|
||||
boolean success = false;
|
||||
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]);
|
||||
sprintf_P(host, PSTR("%u.%u.%u.%u"), Settings.Controller_IP[0], Settings.Controller_IP[1], Settings.Controller_IP[2], Settings.Controller_IP[3]);
|
||||
|
||||
sprintf(log, "%s%s", "TELNT: connecting to ", host);
|
||||
sprintf_P(log, PSTR("%s%s"), "TELNT: connecting to ", host);
|
||||
addLog(LOG_LEVEL_DEBUG,log);
|
||||
if (printToWeb)
|
||||
{
|
||||
@@ -283,7 +283,7 @@ void syslog(char *message)
|
||||
portTX.beginPacket(broadcastIP, 514);
|
||||
char str[80];
|
||||
str[0] = 0;
|
||||
sprintf(str, "<7>ESP Unit: %u : %s", Settings.Unit, message);
|
||||
sprintf_P(str, PSTR("<7>ESP Unit: %u : %s"), Settings.Unit, message);
|
||||
addLog(LOG_LEVEL_DEBUG,str);
|
||||
portTX.write(str);
|
||||
portTX.endPacket();
|
||||
@@ -488,9 +488,9 @@ boolean nodeVariableCopy(byte var, byte unit)
|
||||
return false;
|
||||
}
|
||||
|
||||
sprintf(host, "%u.%u.%u.%u", Nodes[unit].ip[0], Nodes[unit].ip[1], Nodes[unit].ip[2], Nodes[unit].ip[3]);
|
||||
sprintf_P(host, PSTR("%u.%u.%u.%u"), Nodes[unit].ip[0], Nodes[unit].ip[1], Nodes[unit].ip[2], Nodes[unit].ip[3]);
|
||||
|
||||
sprintf(log, "%s%s", "connecting to ", host);
|
||||
sprintf_P(log, PSTR("%s%s"), "connecting to ", host);
|
||||
addLog(LOG_LEVEL_DEBUG,log);
|
||||
if (printToWeb)
|
||||
{
|
||||
@@ -557,6 +557,9 @@ boolean nodeVariableCopy(byte var, byte unit)
|
||||
\*********************************************************************************************/
|
||||
void checkUDP()
|
||||
{
|
||||
if (Settings.UDPPort == 0)
|
||||
return;
|
||||
|
||||
// UDP events
|
||||
int packetSize = portRX.parsePacket();
|
||||
if (packetSize)
|
||||
@@ -600,11 +603,11 @@ void checkUDP()
|
||||
}
|
||||
|
||||
char macaddress[20];
|
||||
sprintf(macaddress, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
sprintf_P(macaddress, PSTR("%02x:%02x:%02x:%02x:%02x:%02x"), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
char ipaddress[16];
|
||||
sprintf(ipaddress, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]);
|
||||
sprintf_P(ipaddress, PSTR("%u.%u.%u.%u"), ip[0], ip[1], ip[2], ip[3]);
|
||||
char log[80];
|
||||
sprintf(log, "UDP : %s,%s,%u", macaddress,ipaddress,unit);
|
||||
sprintf_P(log, PSTR("UDP : %s,%s,%u"), macaddress,ipaddress,unit);
|
||||
addLog(LOG_LEVEL_DEBUG,log);
|
||||
}
|
||||
}
|
||||
@@ -628,6 +631,9 @@ void refreshNodeList()
|
||||
|
||||
void sendSysInfoUDP(byte repeats)
|
||||
{
|
||||
if (Settings.UDPPort == 0)
|
||||
return;
|
||||
|
||||
// 1 byte 'binary token 255'
|
||||
// 1 byte id
|
||||
// 6 byte mac
|
||||
@@ -636,6 +642,7 @@ void sendSysInfoUDP(byte repeats)
|
||||
// ??? build
|
||||
// ??
|
||||
// send my info to the world...
|
||||
addLog(LOG_LEVEL_DEBUG,(char*)"UDP : Send Sysinfo message");
|
||||
for (byte counter = 0; counter < repeats; counter++)
|
||||
{
|
||||
uint8_t mac[] = {0, 0, 0, 0, 0, 0};
|
||||
|
||||
+17
-4
@@ -97,8 +97,8 @@
|
||||
|
||||
#define ESP_PROJECT_PID 2015050101L
|
||||
#define ESP_EASY
|
||||
#define VERSION 2
|
||||
#define BUILD 11
|
||||
#define VERSION 3
|
||||
#define BUILD 12
|
||||
#define REBOOT_ON_MAX_CONNECTION_FAILURES 30
|
||||
|
||||
#define LOG_LEVEL_ERROR 1
|
||||
@@ -173,6 +173,7 @@ struct SettingsStruct
|
||||
unsigned long BaudRate;
|
||||
char ControllerUser[26];
|
||||
char ControllerPassword[26];
|
||||
char Password[26];
|
||||
} Settings;
|
||||
|
||||
struct LogStruct
|
||||
@@ -200,6 +201,9 @@ unsigned long wdcounter = 0;
|
||||
unsigned long pulseCounter1 = 0;
|
||||
byte switch1state = 0;
|
||||
|
||||
boolean WebLoggedIn = false;
|
||||
int WebLoggedInTimer = 60;
|
||||
|
||||
void setup()
|
||||
{
|
||||
EEPROM.begin(1024);
|
||||
@@ -295,7 +299,7 @@ void loop()
|
||||
char str[40];
|
||||
str[0] = 0;
|
||||
Serial.print("WD : ");
|
||||
sprintf(str, "Uptime %u ConnectFailures %u FreeMem %u", wdcounter / 2, connectionFailures, FreeMem());
|
||||
sprintf_P(str, PSTR("Uptime %u ConnectFailures %u FreeMem %u"), wdcounter / 2, connectionFailures, FreeMem());
|
||||
Serial.println(str);
|
||||
syslog(str);
|
||||
sendSysInfoUDP(1);
|
||||
@@ -314,6 +318,14 @@ void loop()
|
||||
{
|
||||
timer1s = millis() + 1000;
|
||||
WifiCheck();
|
||||
|
||||
if (Settings.Password[0] != 0)
|
||||
{
|
||||
if (WebLoggedIn)
|
||||
WebLoggedInTimer++;
|
||||
if (WebLoggedInTimer > 60)
|
||||
WebLoggedIn = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check sensors and send data to controller when sensor timer has elapsed
|
||||
@@ -376,7 +388,8 @@ void SensorSend()
|
||||
if (Settings.BMP > 0)
|
||||
{
|
||||
bmp085(4); // read bmp085 (i2c) and store to vars 4 and 5
|
||||
sendData(3, Settings.BMP, 4);
|
||||
if ((UserVar[5-1] >= 300) && (UserVar[5-1] <= 1100))
|
||||
sendData(3, Settings.BMP, 4);
|
||||
}
|
||||
|
||||
if (Settings.LUX > 0)
|
||||
|
||||
+3
-2
@@ -208,7 +208,7 @@ 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]);
|
||||
sprintf_P(str, PSTR("%u.%u.%u.%u"), ip[0], ip[1], ip[2], ip[3]);
|
||||
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);
|
||||
@@ -224,7 +224,7 @@ void ExecuteCommand(char *Line)
|
||||
Serial.print(" Unit : "); Serial.println((int)Settings.Unit);
|
||||
Serial.print(" WifiSSID : "); Serial.println(Settings.WifiSSID);
|
||||
Serial.print(" WifiKey : "); Serial.println(Settings.WifiKey);
|
||||
sprintf(str, "%u.%u.%u.%u", Settings.Controller_IP[0], Settings.Controller_IP[1], Settings.Controller_IP[2], Settings.Controller_IP[3]);
|
||||
sprintf_P(str, PSTR("%u.%u.%u.%u"), Settings.Controller_IP[0], Settings.Controller_IP[1], Settings.Controller_IP[2], Settings.Controller_IP[3]);
|
||||
Serial.print(" ControllerIP : "); Serial.println(str);
|
||||
Serial.print(" ControllerPort : "); Serial.println(Settings.ControllerPort);
|
||||
Serial.print(" Fixed IP octet : "); Serial.println(Settings.IP_Octet);
|
||||
@@ -448,6 +448,7 @@ void ResetFactory(void)
|
||||
Settings.BaudRate = 115200;
|
||||
Settings.ControllerUser[0] = 0;
|
||||
Settings.ControllerPassword[0] = 0;
|
||||
Settings.Password[0] = 0;
|
||||
|
||||
Save_Settings();
|
||||
WifiDisconnect();
|
||||
|
||||
+181
-29
@@ -16,6 +16,7 @@ void WebServerInit()
|
||||
WebServer.on("/tools", handle_tools);
|
||||
WebServer.on("/i2cscanner", handle_i2cscanner);
|
||||
WebServer.on("/wifiscanner", handle_wifiscanner);
|
||||
WebServer.on("/login", handle_login);
|
||||
WebServer.begin();
|
||||
}
|
||||
|
||||
@@ -57,6 +58,8 @@ void addFooter(String& str)
|
||||
// Web Interface root page
|
||||
//********************************************************************************
|
||||
void handle_root() {
|
||||
if (!isLoggedIn()) return;
|
||||
|
||||
int freeMem = ESP.getFreeHeap();
|
||||
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG)
|
||||
Serial.print(F("HTTP : Webrequest : "));
|
||||
@@ -94,11 +97,11 @@ void handle_root() {
|
||||
reply += F(" minutes");
|
||||
|
||||
char str[20];
|
||||
sprintf(str, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]);
|
||||
sprintf_P(str, PSTR("%u.%u.%u.%u"), ip[0], ip[1], ip[2], ip[3]);
|
||||
reply += F("<TR><TD>IP:<TD>");
|
||||
reply += str;
|
||||
|
||||
sprintf(str, "%u.%u.%u.%u", gw[0], gw[1], gw[2], gw[3]);
|
||||
sprintf_P(str, PSTR("%u.%u.%u.%u"), gw[0], gw[1], gw[2], gw[3]);
|
||||
reply += F("<TR><TD>GW:<TD>");
|
||||
reply += str;
|
||||
|
||||
@@ -112,12 +115,12 @@ void handle_root() {
|
||||
uint8_t mac[] = {0, 0, 0, 0, 0, 0};
|
||||
uint8_t* macread = WiFi.macAddress(mac);
|
||||
char macaddress[20];
|
||||
sprintf(macaddress, "%02x:%02x:%02x:%02x:%02x:%02x", macread[0], macread[1], macread[2], macread[3], macread[4], macread[5]);
|
||||
sprintf_P(macaddress, PSTR("%02x:%02x:%02x:%02x:%02x:%02x"), macread[0], macread[1], macread[2], macread[3], macread[4], macread[5]);
|
||||
reply += macaddress;
|
||||
|
||||
reply += F("<TR><TD>AP MAC:<TD>");
|
||||
macread = WiFi.softAPmacAddress(mac);
|
||||
sprintf(macaddress, "%02x:%02x:%02x:%02x:%02x:%02x", macread[0], macread[1], macread[2], macread[3], macread[4], macread[5]);
|
||||
sprintf_P(macaddress, PSTR("%02x:%02x:%02x:%02x:%02x:%02x"), macread[0], macread[1], macread[2], macread[3], macread[4], macread[5]);
|
||||
reply += macaddress;
|
||||
|
||||
reply += F("<TR><TD>ESP Chip ID:<TD>");
|
||||
@@ -137,7 +140,7 @@ void handle_root() {
|
||||
if (x == Settings.Unit)
|
||||
reply += "<font color='blue'>";
|
||||
char url[80];
|
||||
sprintf(url, "<a href='http://%u.%u.%u.%u'>%u.%u.%u.%u</a>", Nodes[x].ip[0], Nodes[x].ip[1], Nodes[x].ip[2], Nodes[x].ip[3], Nodes[x].ip[0], Nodes[x].ip[1], Nodes[x].ip[2], Nodes[x].ip[3]);
|
||||
sprintf_P(url, PSTR("<a href='http://%u.%u.%u.%u'>%u.%u.%u.%u</a>"), Nodes[x].ip[0], Nodes[x].ip[1], Nodes[x].ip[2], Nodes[x].ip[3], Nodes[x].ip[0], Nodes[x].ip[1], Nodes[x].ip[2], Nodes[x].ip[3]);
|
||||
reply += "<TR><TD>Unit ";
|
||||
reply += x;
|
||||
reply += ":<TD>";
|
||||
@@ -180,12 +183,15 @@ void handle_root() {
|
||||
// Web Interface config page
|
||||
//********************************************************************************
|
||||
void handle_config() {
|
||||
if (!isLoggedIn()) return;
|
||||
|
||||
char tmpstring[26];
|
||||
|
||||
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG)
|
||||
Serial.println(F("HTTP : Webconfig"));
|
||||
|
||||
String name = WebServer.arg("name");
|
||||
String password = WebServer.arg("password");
|
||||
String ssid = WebServer.arg("ssid");
|
||||
String key = WebServer.arg("key");
|
||||
String controllerip = WebServer.arg("controllerip");
|
||||
@@ -211,6 +217,8 @@ void handle_config() {
|
||||
name.replace("+", " ");
|
||||
name.toCharArray(tmpstring, 25);
|
||||
strcpy(Settings.Name, tmpstring);
|
||||
password.toCharArray(tmpstring, 25);
|
||||
strcpy(Settings.Password, tmpstring);
|
||||
ssid.toCharArray(tmpstring, 25);
|
||||
strcpy(Settings.WifiSSID, tmpstring);
|
||||
key.toCharArray(tmpstring, 25);
|
||||
@@ -247,10 +255,13 @@ void handle_config() {
|
||||
String reply = "";
|
||||
addMenu(reply);
|
||||
|
||||
reply += F("<form><table bgcolor='#ddeeff'>");
|
||||
reply += F("<form method='post'><table bgcolor='#ddeeff'>");
|
||||
reply += F("<tr bgcolor='#55bbff'><td>Main Settings<td><TR><TD>Name:<TD><input type='text' name='name' value='");
|
||||
Settings.Name[25] = 0;
|
||||
reply += Settings.Name;
|
||||
reply += F("'><TR><TD>Admin Password:<TD><input type='text' name='password' value='");
|
||||
Settings.Password[25] = 0;
|
||||
reply += Settings.Password;
|
||||
reply += F("'><TR><TD>SSID:<TD><input type='text' name='ssid' value='");
|
||||
reply += Settings.WifiSSID;
|
||||
reply += F("'><TR><TD>WPA Key:<TD><input type='text' name='key' value='");
|
||||
@@ -285,7 +296,7 @@ void handle_config() {
|
||||
|
||||
reply += F("<TR><TD>Controller IP:<TD><input type='text' name='controllerip' value='");
|
||||
char str[20];
|
||||
sprintf(str, "%u.%u.%u.%u", Settings.Controller_IP[0], Settings.Controller_IP[1], Settings.Controller_IP[2], Settings.Controller_IP[3]);
|
||||
sprintf_P(str, PSTR("%u.%u.%u.%u"), Settings.Controller_IP[0], Settings.Controller_IP[1], Settings.Controller_IP[2], Settings.Controller_IP[3]);
|
||||
reply += str;
|
||||
|
||||
reply += F("'><TR><TD>Controller Port:<TD><input type='text' name='controllerport' value='");
|
||||
@@ -307,20 +318,20 @@ void handle_config() {
|
||||
reply += Settings.IP_Octet;
|
||||
|
||||
reply += F("'><TR><TD>ESP IP:<TD><input type='text' name='espip' value='");
|
||||
sprintf(str, "%u.%u.%u.%u", Settings.IP[0], Settings.IP[1], Settings.IP[2], Settings.IP[3]);
|
||||
sprintf_P(str, PSTR("%u.%u.%u.%u"), Settings.IP[0], Settings.IP[1], Settings.IP[2], Settings.IP[3]);
|
||||
reply += str;
|
||||
|
||||
reply += F("'><TR><TD>ESP GW:<TD><input type='text' name='espgateway' value='");
|
||||
sprintf(str, "%u.%u.%u.%u", Settings.Gateway[0], Settings.Gateway[1], Settings.Gateway[2], Settings.Gateway[3]);
|
||||
sprintf_P(str, PSTR("%u.%u.%u.%u"), Settings.Gateway[0], Settings.Gateway[1], Settings.Gateway[2], Settings.Gateway[3]);
|
||||
reply += str;
|
||||
|
||||
reply += F("'><TR><TD>ESP Subnet:<TD><input type='text' name='espsubnet' value='");
|
||||
sprintf(str, "%u.%u.%u.%u", Settings.Subnet[0], Settings.Subnet[1], Settings.Subnet[2], Settings.Subnet[3]);
|
||||
sprintf_P(str, PSTR("%u.%u.%u.%u"), Settings.Subnet[0], Settings.Subnet[1], Settings.Subnet[2], Settings.Subnet[3]);
|
||||
reply += str;
|
||||
|
||||
reply += F("'><TR><TD>Syslog IP:<TD><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]);
|
||||
sprintf_P(str, PSTR("%u.%u.%u.%u"), Settings.Syslog_IP[0], Settings.Syslog_IP[1], Settings.Syslog_IP[2], Settings.Syslog_IP[3]);
|
||||
reply += str;
|
||||
|
||||
reply += F("'><TR><TD>Syslog Level:<TD><input type='text' name='sysloglevel' value='");
|
||||
@@ -348,6 +359,7 @@ void handle_config() {
|
||||
// Web Interface device page
|
||||
//********************************************************************************
|
||||
void handle_devices() {
|
||||
if (!isLoggedIn()) return;
|
||||
|
||||
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG)
|
||||
Serial.println(F("HTTP : Webdevices"));
|
||||
@@ -384,9 +396,9 @@ void handle_devices() {
|
||||
while (Eventlist_Write(x++, &TempEvent, &TempEvent)) delay(1);
|
||||
|
||||
char cmd[80];
|
||||
sprintf(cmd, "eventlistwrite; boot %u; TimerSet 1,%u", Settings.Unit, Settings.Delay);
|
||||
sprintf_P(cmd, PSTR("eventlistwrite; boot %u; TimerSet 1,%u"), Settings.Unit, Settings.Delay);
|
||||
ExecuteLine(cmd, VALUE_SOURCE_SERIAL);
|
||||
sprintf(cmd, "eventlistwrite; Timer 1; TimerSet 1,%u", Settings.Delay);
|
||||
sprintf_P(cmd, PSTR("eventlistwrite; Timer 1; TimerSet 1,%u"), Settings.Delay);
|
||||
ExecuteLine(cmd, VALUE_SOURCE_SERIAL);
|
||||
if (Settings.Dallas != 0)
|
||||
{
|
||||
@@ -419,29 +431,28 @@ void handle_devices() {
|
||||
|
||||
String reply = "";
|
||||
addMenu(reply);
|
||||
reply += F("<form><table bgcolor='#ddeeff'><tr bgcolor='#55bbff'><td>Device Settings<td><TR><TD>");
|
||||
reply += F("<form method='post'><table bgcolor='#ddeeff'><tr bgcolor='#55bbff'><td>Device Settings<td>IDX/Variable<TD>Connect to<TR><TD>");
|
||||
reply += F("<TR><TD>Delay:<TD><input type='text' name='delay' value='");
|
||||
reply += Settings.Delay;
|
||||
reply += F("'><TR><TD>Dallas:<TD><input type='text' name='dallas' value='");
|
||||
reply += Settings.Dallas;
|
||||
reply += F("'><TR><TD>DHT:<TD><input type='text' name='dht' value='");
|
||||
reply += F("'><TD>Output 1<TR><TD>DHT:<TD><input type='text' name='dht' value='");
|
||||
reply += Settings.DHT;
|
||||
reply += F("'><TR><TD>DHT Type:<TD><input type='text' name='dhttype' value='");
|
||||
reply += F("'><TD>Output 2<TR><TD>DHT Type:<TD><input type='text' name='dhttype' value='");
|
||||
reply += Settings.DHTType;
|
||||
reply += F("'><TR><TD>BMP:<TD><input type='text' name='bmp' value='");
|
||||
reply += Settings.BMP;
|
||||
reply += F("'><TR><TD>LUX:<TD><input type='text' name='lux' value='");
|
||||
reply += F("'><TD>I2C<TR><TD>LUX:<TD><input type='text' name='lux' value='");
|
||||
reply += Settings.LUX;
|
||||
reply += F("'><TR><TD>RFID:<TD><input type='text' name='rfid' value='");
|
||||
reply += F("'><TD>I2C<TR><TD>RFID:<TD><input type='text' name='rfid' value='");
|
||||
reply += Settings.RFID;
|
||||
reply += F("'><TR><TD>Analog:<TD><input type='text' name='analog' value='");
|
||||
reply += F("'><TD>Input 1+2<TR><TD>Analog:<TD><input type='text' name='analog' value='");
|
||||
reply += Settings.Analog;
|
||||
reply += F("'><TR><TD>Pulse:<TD><input type='text' name='pulse1' value='");
|
||||
reply += F("'><TD>ADC<TR><TD>Pulse:<TD><input type='text' name='pulse1' value='");
|
||||
reply += Settings.Pulse1;
|
||||
reply += F("'><TR><TD>Switch:<TD><input type='text' name='switch1' value='");
|
||||
reply += F("'><TD>Input 1<TR><TD>Switch:<TD><input type='text' name='switch1' value='");
|
||||
reply += Settings.Switch1;
|
||||
|
||||
reply += F("'><TR><TD><TD><input class=\"button-link\" type='submit' value='Submit'>");
|
||||
reply += F("'><TD>Input 1<TR><TD><TD><input class=\"button-link\" type='submit' value='Submit'>");
|
||||
reply += F("</table></form>");
|
||||
addFooter(reply);
|
||||
WebServer.send(200, "text/html", reply);
|
||||
@@ -458,14 +469,14 @@ void eventAddVarSend(byte var, byte sensortype, int idx)
|
||||
strcpy(strProtocol, "MQTT");
|
||||
if (Settings.Protocol == 3)
|
||||
strcpy(strProtocol, "TELNET");
|
||||
sprintf(cmd, "eventlistwrite; Timer 1; VariableSend %u,%s,%u,%u", var, strProtocol, sensortype, idx);
|
||||
sprintf_P(cmd, PSTR("eventlistwrite; Timer 1; VariableSend %u,%s,%u,%u"), var, strProtocol, sensortype, idx);
|
||||
ExecuteLine(cmd, VALUE_SOURCE_SERIAL);
|
||||
}
|
||||
|
||||
void eventAddTimer(char* event)
|
||||
{
|
||||
char cmd[80];
|
||||
sprintf(cmd, "eventlistwrite; Timer 1; %s", event);
|
||||
sprintf_P(cmd, PSTR("eventlistwrite; Timer 1; %s"), event);
|
||||
ExecuteLine(cmd, VALUE_SOURCE_SERIAL);
|
||||
}
|
||||
#endif
|
||||
@@ -475,11 +486,18 @@ void eventAddTimer(char* event)
|
||||
// Web Interface hardware page
|
||||
//********************************************************************************
|
||||
void handle_hardware() {
|
||||
if (!isLoggedIn()) return;
|
||||
|
||||
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG)
|
||||
Serial.println(F("HTTP : Hardware"));
|
||||
|
||||
String boardtype = WebServer.arg("boardtype");
|
||||
String pin_i2c_sda = WebServer.arg("pini2csda");
|
||||
String pin_i2c_scl = WebServer.arg("pini2cscl");
|
||||
String pin_wired_in_1 = WebServer.arg("pinwiredin1");
|
||||
String pin_wired_in_2 = WebServer.arg("pinwiredin2");
|
||||
String pin_wired_out_1 = WebServer.arg("pinwiredout1");
|
||||
String pin_wired_out_2 = WebServer.arg("pinwiredout2");
|
||||
|
||||
if (boardtype.length() != 0)
|
||||
{
|
||||
@@ -526,7 +544,17 @@ void handle_hardware() {
|
||||
Settings.Pin_wired_out_1 = 0;
|
||||
Settings.Pin_wired_out_2 = 2;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
if (pin_i2c_sda.length() != 0)
|
||||
{
|
||||
Settings.Pin_i2c_sda = pin_i2c_sda.toInt();
|
||||
Settings.Pin_i2c_scl = pin_i2c_scl.toInt();
|
||||
Settings.Pin_wired_in_1 = pin_wired_in_1.toInt();
|
||||
Settings.Pin_wired_in_2 = pin_wired_in_2.toInt();
|
||||
Settings.Pin_wired_out_1 = pin_wired_out_1.toInt();
|
||||
Settings.Pin_wired_out_2 = pin_wired_out_2.toInt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
Save_Settings();
|
||||
}
|
||||
@@ -534,18 +562,19 @@ void handle_hardware() {
|
||||
String reply = "";
|
||||
addMenu(reply);
|
||||
|
||||
reply += F("<form><table bgcolor='#ddeeff'><tr bgcolor='#55bbff'><td>Hardware Settings<td><TR><TD>");
|
||||
reply += F("<form method='post'><table bgcolor='#ddeeff'><tr bgcolor='#55bbff'><td>Hardware Settings<td><TR><TD>");
|
||||
|
||||
reply += "<TR><TD>Board Type:<TD>";
|
||||
byte choice = Settings.BoardType;
|
||||
String options[5];
|
||||
String options[6];
|
||||
options[0] = F("ESP-07/12");
|
||||
options[1] = F("ESP-01 I2C");
|
||||
options[2] = F("ESP-01 In/Out");
|
||||
options[3] = F("ESP-01 2 x In");
|
||||
options[4] = F("ESP-01 2 x Out");
|
||||
options[5] = F("Custom");
|
||||
reply += F("<select name='boardtype'>");
|
||||
for (byte x = 0; x < 5; x++)
|
||||
for (byte x = 0; x < 6; x++)
|
||||
{
|
||||
reply += F("<option value='");
|
||||
reply += x;
|
||||
@@ -558,11 +587,28 @@ void handle_hardware() {
|
||||
}
|
||||
reply += F("</select>");
|
||||
|
||||
if (choice == 5) // custom config
|
||||
{
|
||||
reply += F("<TR><TD>SDA:<TD>");
|
||||
addSelect(reply,"pini2csda",Settings.Pin_i2c_sda);
|
||||
reply += F("<TR><TD>SCL:<TD>");
|
||||
addSelect(reply,"pini2cscl",Settings.Pin_i2c_scl);
|
||||
reply += F("<TR><TD>Input 1:<TD>");
|
||||
addSelect(reply,"pinwiredin1",Settings.Pin_wired_in_1);
|
||||
reply += F("<TR><TD>Input 2:<TD>");
|
||||
addSelect(reply,"pinwiredin2",Settings.Pin_wired_in_2);
|
||||
reply += F("<TR><TD>Output 1:<TD>");
|
||||
addSelect(reply,"pinwiredout1",Settings.Pin_wired_out_1);
|
||||
reply += F("<TR><TD>Output 2:<TD>");
|
||||
addSelect(reply,"pinwiredout2",Settings.Pin_wired_out_2);
|
||||
}
|
||||
|
||||
reply += F("<TR><TD><TD><input class=\"button-link\" type='submit' value='Submit'><TR><TD>");
|
||||
|
||||
switch (Settings.BoardType)
|
||||
{
|
||||
case 0:
|
||||
case 5:
|
||||
reply += F("<TR><TD>SDA:<TD>");
|
||||
reply += Settings.Pin_i2c_sda;
|
||||
reply += F("<TR><TD>SCL:<TD>");
|
||||
@@ -607,6 +653,42 @@ void handle_hardware() {
|
||||
WebServer.send(200, "text/html", reply);
|
||||
}
|
||||
|
||||
void addSelect(String& str, String name, int choice)
|
||||
{
|
||||
String options[7];
|
||||
options[0] = F(" ");
|
||||
options[1] = F("GPIO-0");
|
||||
options[2] = F("GPIO-2");
|
||||
options[3] = F("GPIO-4");
|
||||
options[4] = F("GPIO-5");
|
||||
options[5] = F("GPIO-12");
|
||||
options[6] = F("GPIO-13");
|
||||
int optionValues[7];
|
||||
optionValues[0] = -1;
|
||||
optionValues[1] = 0;
|
||||
optionValues[2] = 2;
|
||||
optionValues[3] = 4;
|
||||
optionValues[4] = 5;
|
||||
optionValues[5] = 12;
|
||||
optionValues[6] = 13;
|
||||
|
||||
str += F("<select name='");
|
||||
str += name;
|
||||
str += "'>";
|
||||
for (byte x = 0; x < 7; x++)
|
||||
{
|
||||
str += F("<option value='");
|
||||
str += optionValues[x];
|
||||
str += "'";
|
||||
if (choice == optionValues[x])
|
||||
str += " selected";
|
||||
str += ">";
|
||||
str += options[x];
|
||||
str += "</option>";
|
||||
}
|
||||
str += F("</select>");
|
||||
}
|
||||
|
||||
//********************************************************************************
|
||||
// Nodo proof of concept. send json query as nodo event on I2C to mega
|
||||
// Compatible with Nodo 3.8 only, tested on R818
|
||||
@@ -684,6 +766,8 @@ void handle_json() {
|
||||
// Web Interface eventlist page
|
||||
//********************************************************************************
|
||||
void handle_eventlist() {
|
||||
if (!isLoggedIn()) return;
|
||||
|
||||
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG)
|
||||
Serial.println(F("HTTP : Eventlist request"));
|
||||
|
||||
@@ -758,6 +842,8 @@ void handle_eventlist() {
|
||||
// Web Interface log page
|
||||
//********************************************************************************
|
||||
void handle_log() {
|
||||
if (!isLoggedIn()) return;
|
||||
|
||||
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG)
|
||||
Serial.println(F("HTTP : Log request"));
|
||||
|
||||
@@ -795,6 +881,8 @@ void handle_log() {
|
||||
// Web Interface debug page
|
||||
//********************************************************************************
|
||||
void handle_tools() {
|
||||
if (!isLoggedIn()) return;
|
||||
|
||||
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG)
|
||||
Serial.print(F("HTTP : Tools request : "));
|
||||
|
||||
@@ -844,6 +932,8 @@ void handle_tools() {
|
||||
// Web Interface I2C scanner
|
||||
//********************************************************************************
|
||||
void handle_i2cscanner() {
|
||||
if (!isLoggedIn()) return;
|
||||
|
||||
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG)
|
||||
Serial.println(F("HTTP : I2C Scanner"));
|
||||
|
||||
@@ -887,6 +977,8 @@ void handle_i2cscanner() {
|
||||
// Web Interface I2C scanner
|
||||
//********************************************************************************
|
||||
void handle_wifiscanner() {
|
||||
if (!isLoggedIn()) return;
|
||||
|
||||
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG)
|
||||
Serial.println(F("HTTP : Wifi Scanner"));
|
||||
|
||||
@@ -916,4 +1008,64 @@ void handle_wifiscanner() {
|
||||
WebServer.send(200, "text/html", reply);
|
||||
free(TempString);
|
||||
}
|
||||
|
||||
//********************************************************************************
|
||||
// Web Interface login page
|
||||
//********************************************************************************
|
||||
void handle_login() {
|
||||
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG)
|
||||
Serial.print(F("HTTP : Login request : "));
|
||||
|
||||
String webrequest = WebServer.arg("password");
|
||||
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG)
|
||||
Serial.println(webrequest);
|
||||
char command[80];
|
||||
command[0] = 0;
|
||||
webrequest.toCharArray(command, 79);
|
||||
|
||||
String reply = "";
|
||||
reply += F("<form>");
|
||||
reply += F("<table bgcolor='#ddeeff'><tr bgcolor='#55bbff'><td>Password<TD>");
|
||||
reply += F("<input type='text' name='password' value='");
|
||||
reply += webrequest;
|
||||
reply += F("'><TR><TD><TD><input class=\"button-link\" type='submit' value='Submit'><TR><TD>");
|
||||
reply += F("</table></form>");
|
||||
|
||||
if (webrequest.length() != 0)
|
||||
{
|
||||
// compare with stored password and set timer if there's a match
|
||||
if ((strcasecmp(command, Settings.Password) == 0) || (Settings.Password[0] == 0))
|
||||
{
|
||||
WebLoggedIn = true;
|
||||
WebLoggedInTimer=0;
|
||||
reply = F("<script language='JavaScript'>window.location = '.'</script>");
|
||||
}
|
||||
else
|
||||
{
|
||||
reply += F("Invalid password!");
|
||||
}
|
||||
}
|
||||
|
||||
WebServer.send(200, "text/html", reply);
|
||||
printWebString = "";
|
||||
printToWeb = false;
|
||||
}
|
||||
|
||||
boolean isLoggedIn()
|
||||
{
|
||||
if (Settings.Password[0] == 0)
|
||||
WebLoggedIn = true;
|
||||
|
||||
if (!WebLoggedIn)
|
||||
{
|
||||
String reply = F("<a class=\"button-link\" href=\"login\">Login</a>");
|
||||
WebServer.send(200, "text/html", reply);
|
||||
}
|
||||
else
|
||||
{
|
||||
WebLoggedInTimer=0;
|
||||
}
|
||||
|
||||
return WebLoggedIn;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ void WifiAPconfig()
|
||||
char ap_ssid[20];
|
||||
ap_ssid[0] = 0;
|
||||
strcpy(ap_ssid, "ESP_");
|
||||
sprintf(ap_ssid, "%s%u", ap_ssid, Settings.Unit);
|
||||
sprintf_P(ap_ssid, PSTR("%s%u"), ap_ssid, Settings.Unit);
|
||||
// setup ssid for AP Mode when needed
|
||||
WiFi.softAP(ap_ssid, Settings.WifiAPKey);
|
||||
// We start in STA mode
|
||||
@@ -26,7 +26,7 @@ void WifiAPMode(boolean state)
|
||||
char ap_ssid[20];
|
||||
ap_ssid[0] = 0;
|
||||
strcpy(ap_ssid, "ESP_");
|
||||
sprintf(ap_ssid, "%s%u", ap_ssid, Settings.Unit);
|
||||
sprintf_P(ap_ssid, PSTR("%s%u"), ap_ssid, Settings.Unit);
|
||||
Serial.println(F("WIFI : Starting AP Mode"));
|
||||
WiFi.softAP(ap_ssid, Settings.WifiAPKey);
|
||||
WiFi.mode(WIFI_AP_STA);
|
||||
@@ -78,7 +78,7 @@ boolean WifiConnect()
|
||||
{
|
||||
Serial.print(F("IP : Static IP :"));
|
||||
char str[20];
|
||||
sprintf(str, "%u.%u.%u.%u", Settings.IP[0], Settings.IP[1], Settings.IP[2], Settings.IP[3]);
|
||||
sprintf_P(str, PSTR("%u.%u.%u.%u"), Settings.IP[0], Settings.IP[1], Settings.IP[2], Settings.IP[3]);
|
||||
Serial.println(str);
|
||||
IPAddress ip = Settings.IP;
|
||||
IPAddress gw = Settings.Gateway;
|
||||
|
||||
@@ -79,4 +79,13 @@
|
||||
// Added webgui Wifi scanner
|
||||
// Fixed bug in settingssave on devices
|
||||
// Added delay(1) in Domoticz_sendData, while available loop
|
||||
|
||||
// R012 07-08-2015
|
||||
// IMPORTANT NOTICE: this release needs ESP Package version 1.6.5-947-g39819f0, built on Jul 23, 2015)
|
||||
// If udp port = 0 no actions!
|
||||
// Used sprintf_P to save more RAM
|
||||
// Added login page and admin password
|
||||
// Added hardware custom gpio pin selection
|
||||
// Added sanity check on BMP085 pressure values
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user