mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-27 19:57:38 +00:00
Redesigned device configuration mechanism
Changed password timeout to 5 minutes Added direct GPIO output control without password request
This commit is contained in:
+134
-14
@@ -1,16 +1,139 @@
|
||||
void Device_Init()
|
||||
{
|
||||
Device[1].Number = DEVICE_DS18B20;
|
||||
strcpy(Device[1].Name,"Temperature DS18b20");
|
||||
Device[1].Type = DEVICE_TYPE_SINGLE;
|
||||
Device[2].Number = DEVICE_DHT11;
|
||||
strcpy(Device[2].Name,"Temp + Hum DHT 11");
|
||||
Device[2].Type = DEVICE_TYPE_SINGLE;
|
||||
Device[3].Number = DEVICE_DHT22;
|
||||
strcpy(Device[3].Name,"Temp + Hum DHT 22");
|
||||
Device[3].Type = DEVICE_TYPE_SINGLE;
|
||||
Device[4].Number = DEVICE_BMP085;
|
||||
strcpy(Device[4].Name,"Temp + Baro BMP085");
|
||||
Device[4].Type = DEVICE_TYPE_I2C;
|
||||
Device[5].Number = DEVICE_BH1750;
|
||||
strcpy(Device[5].Name,"LUX BH1750");
|
||||
Device[5].Type = DEVICE_TYPE_I2C;
|
||||
Device[6].Number = DEVICE_ANALOG;
|
||||
strcpy(Device[6].Name,"Analog input");
|
||||
Device[6].Type = DEVICE_TYPE_ANALOG;
|
||||
Device[7].Number = DEVICE_RFID;
|
||||
strcpy(Device[7].Name,"RFID Reader");
|
||||
Device[7].Type = DEVICE_TYPE_DUAL;
|
||||
Device[8].Number = DEVICE_PULSE;
|
||||
strcpy(Device[8].Name,"Pulse Counter");
|
||||
Device[8].Type = DEVICE_TYPE_SINGLE;
|
||||
Device[9].Number = DEVICE_SWITCH;
|
||||
strcpy(Device[9].Name,"Switch input");
|
||||
Device[9].Type = DEVICE_TYPE_SINGLE;
|
||||
|
||||
for (byte x=0; x < TASKS_MAX; x++)
|
||||
{
|
||||
if (Settings.TaskDeviceID[x] != 0)
|
||||
{
|
||||
switch(Settings.TaskDeviceNumber[x])
|
||||
{
|
||||
case DEVICE_RFID:
|
||||
Serial.print(F("INIT : RFID "));
|
||||
Serial.print(Settings.TaskDevicePin1[x]);
|
||||
Serial.print(" & ");
|
||||
Serial.println(Settings.TaskDevicePin2[x]);
|
||||
pinMode(Settings.TaskDevicePin1[x], INPUT_PULLUP);
|
||||
pinMode(Settings.TaskDevicePin2[x], INPUT_PULLUP);
|
||||
rfidinit(Settings.TaskDevicePin1[x], Settings.TaskDevicePin2[x]);
|
||||
break;
|
||||
case DEVICE_PULSE:
|
||||
Serial.print(F("INIT : Pulse "));
|
||||
Serial.println(Settings.TaskDevicePin1[x]);
|
||||
pinMode(Settings.TaskDevicePin1[x], INPUT_PULLUP);
|
||||
pulseinit(Settings.TaskDevicePin1[x], x);
|
||||
break;
|
||||
case DEVICE_SWITCH:
|
||||
Serial.print(F("INIT : InputPullup "));
|
||||
Serial.println(Settings.TaskDevicePin1[x]);
|
||||
pinMode(Settings.TaskDevicePin1[x], INPUT_PULLUP);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Pulse Counter
|
||||
* Pulse Counters
|
||||
\*********************************************************************************************/
|
||||
void pulse_interrupt1()
|
||||
{
|
||||
pulseCounter1++;
|
||||
pulseCounter[0]++;
|
||||
pulseTotalCounter[0]++;
|
||||
}
|
||||
void pulse_interrupt2()
|
||||
{
|
||||
pulseCounter[1]++;
|
||||
pulseTotalCounter[1]++;
|
||||
}
|
||||
void pulse_interrupt3()
|
||||
{
|
||||
pulseCounter[2]++;
|
||||
pulseTotalCounter[2]++;
|
||||
}
|
||||
void pulse_interrupt4()
|
||||
{
|
||||
pulseCounter[3]++;
|
||||
pulseTotalCounter[3]++;
|
||||
}
|
||||
void pulse_interrupt5()
|
||||
{
|
||||
pulseCounter[4]++;
|
||||
pulseTotalCounter[4]++;
|
||||
}
|
||||
void pulse_interrupt6()
|
||||
{
|
||||
pulseCounter[5]++;
|
||||
pulseTotalCounter[5]++;
|
||||
}
|
||||
void pulse_interrupt7()
|
||||
{
|
||||
pulseCounter[6]++;
|
||||
pulseTotalCounter[6]++;
|
||||
}
|
||||
void pulse_interrupt8()
|
||||
{
|
||||
pulseCounter[7]++;
|
||||
pulseTotalCounter[7]++;
|
||||
}
|
||||
|
||||
void pulseinit(byte Par1)
|
||||
void pulseinit(byte Par1, byte Index)
|
||||
{
|
||||
// Init IO pins
|
||||
Serial.println("PULSE: Init");
|
||||
attachInterrupt(Par1, pulse_interrupt1, FALLING);
|
||||
switch(Index)
|
||||
{
|
||||
case 0:
|
||||
attachInterrupt(Par1, pulse_interrupt1, FALLING);
|
||||
break;
|
||||
case 1:
|
||||
attachInterrupt(Par1, pulse_interrupt2, FALLING);
|
||||
break;
|
||||
case 2:
|
||||
attachInterrupt(Par1, pulse_interrupt3, FALLING);
|
||||
break;
|
||||
case 3:
|
||||
attachInterrupt(Par1, pulse_interrupt4, FALLING);
|
||||
break;
|
||||
case 4:
|
||||
attachInterrupt(Par1, pulse_interrupt5, FALLING);
|
||||
break;
|
||||
case 5:
|
||||
attachInterrupt(Par1, pulse_interrupt6, FALLING);
|
||||
break;
|
||||
case 6:
|
||||
attachInterrupt(Par1, pulse_interrupt7, FALLING);
|
||||
break;
|
||||
case 7:
|
||||
attachInterrupt(Par1, pulse_interrupt8, FALLING);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
@@ -271,17 +394,17 @@ uint8_t DS_reset()
|
||||
|
||||
boolean dallas(byte Par1, byte Par2)
|
||||
{
|
||||
static byte Call_Status = 0x00; // Each bit represents one relative port. 0=not called before, 1=already called before.
|
||||
static unsigned int Call_Status = 0x00; // Each bit represents one relative port. 0=not called before, 1=already called before.
|
||||
boolean success = false;
|
||||
int DSTemp; // Temperature in 16-bit Dallas format.
|
||||
byte ScratchPad[12]; // Scratchpad buffer Dallas sensor.
|
||||
byte var = Par2; // Variable to be set.
|
||||
byte RelativePort = Par1 - 1;
|
||||
byte RelativePort = Par1;
|
||||
|
||||
if (Par1 == 1)
|
||||
DallasPin = Settings.Pin_wired_out_1;
|
||||
else
|
||||
DallasPin = Settings.Pin_wired_out_2;
|
||||
DallasPin = Par1;
|
||||
|
||||
pinMode(DallasPin, OUTPUT);
|
||||
digitalWrite(DallasPin, LOW);
|
||||
|
||||
noInterrupts();
|
||||
while (!(bitRead(Call_Status, RelativePort)))
|
||||
@@ -345,10 +468,7 @@ boolean dht(byte type, byte Par1, byte Par2)
|
||||
byte i;
|
||||
byte Retry = 0;
|
||||
|
||||
if (Par1 == 1)
|
||||
DHT_Pin = Settings.Pin_wired_out_1;
|
||||
else
|
||||
DHT_Pin = Settings.Pin_wired_out_2;
|
||||
DHT_Pin = Par1;
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
+136
-106
@@ -7,9 +7,12 @@
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
* You received a copy of the GNU General Public License along with this program in file 'License.txt'.
|
||||
*
|
||||
* Source Code : https://sourceforge.net/projects/espeasy/
|
||||
* Support : http://www.esp8266.nu
|
||||
* Discussion : http://www.esp8266.nu/forum/
|
||||
* IDE download : https://www.arduino.cc/en/Main/Software
|
||||
* ESP8266 Package : https://github.com/esp8266/Arduino
|
||||
*
|
||||
* Source Code : https://sourceforge.net/projects/espeasy/
|
||||
* Support : http://www.esp8266.nu
|
||||
* Discussion : http://www.esp8266.nu/forum/
|
||||
*
|
||||
* Additional information about licensing can be found at : http://www.gnu.org/licenses
|
||||
\*************************************************************************************************************************/
|
||||
@@ -27,22 +30,21 @@
|
||||
*
|
||||
* Voor toelichting op de licentievoorwaarden zie : http://www.gnu.org/licenses
|
||||
* Uitgebreide documentatie is te vinden op : http://www.nodo-domotica.nl
|
||||
* bugs kunnen worden gelogd op : https://code.google.com/p/arduino-nodo/
|
||||
* Compiler voor deze programmacode te downloaden op : http://arduino.cc
|
||||
* Voor vragen of suggesties, mail naar : p.k.tonkes@gmail.com
|
||||
\*************************************************************************************************************************/
|
||||
|
||||
// Simple Arduino sketch for ESP module, supporting:
|
||||
// Dallas OneWire DS18b20 temperature sensor
|
||||
// DHT11/22 humidity sensor
|
||||
// Dallas OneWire DS18b20 temperature sensors
|
||||
// DHT11/22 humidity sensors
|
||||
// BH1750 I2C Lux sensor
|
||||
// BMP085 I2C Barometric Pressure sensor
|
||||
// RFID Wiegand-26 reader
|
||||
// MCP23017 I2C IO Expander
|
||||
// MCP23017 I2C IO Expanders
|
||||
// Analog input (ESP-7/12 only)
|
||||
// LCD I2C display 4x20 chars
|
||||
// Pulse counter
|
||||
// Simple switch input
|
||||
// Pulse counters
|
||||
// Simple switch inputs
|
||||
// Direct GPIO output control to drive relais, mosfets, etc
|
||||
|
||||
// ********************************************************************************
|
||||
// User specific configuration
|
||||
@@ -78,17 +80,6 @@
|
||||
// DO NOT CHANGE ANYTHING BELOW THIS LINE
|
||||
// ********************************************************************************
|
||||
|
||||
// variables used
|
||||
// 1 Dallas
|
||||
// 2-3 DHT
|
||||
// 4-5 BMP085
|
||||
// 6 Lux
|
||||
// 7 Analog
|
||||
// 8 RFID
|
||||
// 9 Pulsecounter
|
||||
// 10 DomoticzSend Serial in
|
||||
// 11 Switch
|
||||
|
||||
// sensor types
|
||||
// 1 = single value, general purpose (Dallas, LUX, counters, etc)
|
||||
// 2 = temp + hum (DHT)
|
||||
@@ -97,8 +88,8 @@
|
||||
|
||||
#define ESP_PROJECT_PID 2015050101L
|
||||
#define ESP_EASY
|
||||
#define VERSION 3
|
||||
#define BUILD 13
|
||||
#define VERSION 4
|
||||
#define BUILD 14
|
||||
#define REBOOT_ON_MAX_CONNECTION_FAILURES 30
|
||||
|
||||
#define LOG_LEVEL_ERROR 1
|
||||
@@ -109,6 +100,24 @@
|
||||
#define CMD_REBOOT 89
|
||||
#define CMD_WIFI_DISCONNECT 135
|
||||
|
||||
#define DEVICE_DS18B20 1
|
||||
#define DEVICE_DHT11 2
|
||||
#define DEVICE_DHT22 3
|
||||
#define DEVICE_BMP085 4
|
||||
#define DEVICE_BH1750 5
|
||||
#define DEVICE_ANALOG 6
|
||||
#define DEVICE_RFID 7
|
||||
#define DEVICE_PULSE 8
|
||||
#define DEVICE_SWITCH 9
|
||||
|
||||
#define DEVICES_MAX 10
|
||||
#define TASKS_MAX 8
|
||||
|
||||
#define DEVICE_TYPE_SINGLE 1 // connected through 1 datapin
|
||||
#define DEVICE_TYPE_I2C 2 // connected through I2C
|
||||
#define DEVICE_TYPE_ANALOG 3 // tout pin
|
||||
#define DEVICE_TYPE_DUAL 4 // connected through 2 datapins
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
@@ -143,21 +152,21 @@ struct SettingsStruct
|
||||
byte IP_Octet;
|
||||
char WifiAPKey[26];
|
||||
unsigned long Delay;
|
||||
unsigned int Dallas;
|
||||
unsigned int DHT;
|
||||
byte DHTType;
|
||||
unsigned int BMP;
|
||||
unsigned int LUX;
|
||||
unsigned int RFID;
|
||||
unsigned int Analog;
|
||||
unsigned int Pulse1;
|
||||
byte BoardType;
|
||||
unsigned int _Dallas;
|
||||
unsigned int _DHT;
|
||||
byte _DHTType;
|
||||
unsigned int _BMP;
|
||||
unsigned int _LUX;
|
||||
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;
|
||||
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];
|
||||
unsigned int UDPPort;
|
||||
unsigned int Switch1;
|
||||
@@ -175,6 +184,10 @@ struct SettingsStruct
|
||||
char ControllerPassword[26];
|
||||
char Password[26];
|
||||
unsigned long MessageDelay;
|
||||
byte TaskDeviceNumber[TASKS_MAX];
|
||||
unsigned int TaskDeviceID[TASKS_MAX];
|
||||
int8_t TaskDevicePin1[TASKS_MAX];
|
||||
int8_t TaskDevicePin2[TASKS_MAX];
|
||||
} Settings;
|
||||
|
||||
struct LogStruct
|
||||
@@ -184,10 +197,21 @@ struct LogStruct
|
||||
} Logging[10];
|
||||
int logcount = -1;
|
||||
|
||||
struct DeviceStruct
|
||||
{
|
||||
byte Number;
|
||||
char Name[26];
|
||||
byte Type;
|
||||
} Device[DEVICES_MAX];
|
||||
|
||||
boolean printToWeb = false;
|
||||
String printWebString = "";
|
||||
|
||||
float UserVar[15];
|
||||
float UserVar[2 * TASKS_MAX];
|
||||
unsigned long pulseCounter[TASKS_MAX];
|
||||
unsigned long pulseTotalCounter[TASKS_MAX];
|
||||
byte switchstate[TASKS_MAX];
|
||||
|
||||
unsigned long timer;
|
||||
unsigned long timer100ms;
|
||||
unsigned long timer1s;
|
||||
@@ -203,12 +227,12 @@ unsigned long pulseCounter1 = 0;
|
||||
byte switch1state = 0;
|
||||
|
||||
boolean WebLoggedIn = false;
|
||||
int WebLoggedInTimer = 60;
|
||||
int WebLoggedInTimer = 300;
|
||||
|
||||
void setup()
|
||||
{
|
||||
EEPROM.begin(1024);
|
||||
|
||||
|
||||
LoadSettings();
|
||||
|
||||
// if different version, eeprom settings structure has changed. Full Reset needed
|
||||
@@ -230,6 +254,7 @@ void setup()
|
||||
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG_MORE)
|
||||
Serial.setDebugOutput(true);
|
||||
|
||||
Device_Init();
|
||||
hardwareInit();
|
||||
|
||||
WifiAPconfig();
|
||||
@@ -320,7 +345,7 @@ void loop()
|
||||
{
|
||||
if (WebLoggedIn)
|
||||
WebLoggedInTimer++;
|
||||
if (WebLoggedInTimer > 60)
|
||||
if (WebLoggedInTimer > 300)
|
||||
WebLoggedIn = false;
|
||||
}
|
||||
}
|
||||
@@ -338,89 +363,95 @@ void loop()
|
||||
delayedReboot(60);
|
||||
}
|
||||
|
||||
if (Settings.Switch1 != 0)
|
||||
{
|
||||
byte state1 = digitalRead(Settings.Pin_wired_in_1);
|
||||
if (state1 != switch1state)
|
||||
{
|
||||
switch1state = state1;
|
||||
UserVar[11 - 1] = state1;
|
||||
sendData(10, Settings.Switch1, 11);
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
backgroundtasks();
|
||||
|
||||
}
|
||||
|
||||
void inputCheck()
|
||||
{
|
||||
if (Settings.RFID > 0)
|
||||
// Handle switches
|
||||
for (byte x=0; x < TASKS_MAX; x++)
|
||||
{
|
||||
unsigned long rfid_id = rfid();
|
||||
if (rfid_id > 0)
|
||||
if(Settings.TaskDeviceNumber[x] == DEVICE_SWITCH && Settings.TaskDeviceID[x] != 0)
|
||||
{
|
||||
Serial.print("RFID : Tag : ");
|
||||
Serial.println(rfid_id);
|
||||
UserVar[8 - 1] = rfid_id;
|
||||
sendData(1, Settings.RFID, 8);
|
||||
byte state = digitalRead(Settings.TaskDevicePin1[x]);
|
||||
if (state != switchstate[x])
|
||||
{
|
||||
switchstate[x] = state;
|
||||
UserVar[(x*2+1) - 1] = state;
|
||||
sendData(10, Settings.TaskDeviceID[x], x*2+1);
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle rfid
|
||||
for (byte x=0; x < TASKS_MAX; x++)
|
||||
{
|
||||
if(Settings.TaskDeviceNumber[x] == DEVICE_RFID && Settings.TaskDeviceID[x] != 0)
|
||||
{
|
||||
unsigned long rfid_id = rfid();
|
||||
if (rfid_id > 0)
|
||||
{
|
||||
Serial.print("RFID : Tag : ");
|
||||
Serial.println(rfid_id);
|
||||
UserVar[(x*2+1) - 1] = rfid_id;
|
||||
sendData(1, Settings.TaskDeviceID[x], x*2+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SensorSend()
|
||||
{
|
||||
if (Settings.Dallas > 0)
|
||||
for (byte x=0; x < TASKS_MAX; x++)
|
||||
{
|
||||
dallas(1, 1); // read ds18b20 on wiredout 1, store to var 1
|
||||
sendData(1, Settings.Dallas, 1);
|
||||
}
|
||||
|
||||
if (Settings.DHT > 0)
|
||||
{
|
||||
dht(Settings.DHTType, 2, 2); // read dht on wiredout 2, store to var 2 (and 3)
|
||||
if (!isnan(UserVar[2 - 1]) && (UserVar[3 - 1] > 0))
|
||||
sendData(2, Settings.DHT, 2);
|
||||
}
|
||||
|
||||
if (Settings.BMP > 0)
|
||||
{
|
||||
bmp085(4); // read bmp085 (i2c) and store to vars 4 and 5
|
||||
if ((UserVar[5-1] >= 300) && (UserVar[5-1] <= 1100))
|
||||
sendData(3, Settings.BMP, 4);
|
||||
}
|
||||
|
||||
if (Settings.LUX > 0)
|
||||
{
|
||||
lux(6); // read BH1750 LUX sensor and store to var 6
|
||||
sendData(1, Settings.LUX, 6);
|
||||
}
|
||||
|
||||
if (Settings.Analog > 0)
|
||||
{
|
||||
analog(7); // read ADC and store to var 7
|
||||
sendData(1, Settings.Analog, 7);
|
||||
}
|
||||
|
||||
if (Settings.Pulse1 > 0)
|
||||
{
|
||||
float value = 0;
|
||||
if (Domoticz_getData(Settings.Pulse1, &value))
|
||||
if (Settings.TaskDeviceID[x] != 0)
|
||||
{
|
||||
Serial.print(F("Current Value:"));
|
||||
Serial.println(value);
|
||||
Serial.print(F("Delta Value:"));
|
||||
Serial.println(pulseCounter1);
|
||||
value = (value + pulseCounter1) * 100;
|
||||
pulseCounter1 = 0;
|
||||
Serial.print(F("New Value:"));
|
||||
Serial.println(value);
|
||||
UserVar[9 - 1] = value; // store pulsecount to var 9
|
||||
sendData(1, Settings.Pulse1, 9);
|
||||
switch(Settings.TaskDeviceNumber[x])
|
||||
{
|
||||
case DEVICE_DS18B20:
|
||||
dallas(Settings.TaskDevicePin1[x], x*2+1);
|
||||
sendData(1, Settings.TaskDeviceID[x], x*2+1);
|
||||
break;
|
||||
|
||||
case DEVICE_DHT11:
|
||||
dht(11, Settings.TaskDevicePin1[x], x*2+1);
|
||||
if (!isnan(UserVar[(x*2+1) - 1]) && (UserVar[(x*2+2) - 1] > 0))
|
||||
sendData(2,Settings.TaskDeviceID[x], x*2+1);
|
||||
break;
|
||||
|
||||
case DEVICE_DHT22:
|
||||
dht(22, Settings.TaskDevicePin1[x], 2);
|
||||
if (!isnan(UserVar[(x*2+1) - 1]) && (UserVar[(x*2+2) - 1] > 0))
|
||||
sendData(2, Settings.TaskDeviceID[x], x*2+1);
|
||||
break;
|
||||
|
||||
case DEVICE_BMP085:
|
||||
bmp085(x*2+1);
|
||||
if ((UserVar[(x*2+2) - 1] >= 300) && (UserVar[(x*2+2) - 1] <= 1100))
|
||||
sendData(3, Settings.TaskDeviceID[x], x*2+1);
|
||||
break;
|
||||
|
||||
case DEVICE_BH1750:
|
||||
lux(x*2+1); // read BH1750 LUX sensor and store to var 6
|
||||
sendData(1, Settings.TaskDeviceID[x], x*2+1);
|
||||
break;
|
||||
|
||||
case DEVICE_ANALOG:
|
||||
analog(x*2+1); // read ADC and store to var 7
|
||||
sendData(1, Settings.TaskDeviceID[x], x*2+1);
|
||||
break;
|
||||
|
||||
case DEVICE_PULSE:
|
||||
UserVar[(x*2+1) - 1] = pulseCounter[x];
|
||||
sendData(1, Settings.TaskDeviceID[x], x*2+1);
|
||||
pulseCounter[x] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void backgroundtasks()
|
||||
@@ -429,5 +460,4 @@ void backgroundtasks()
|
||||
MQTTclient.loop();
|
||||
delay(10);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,36 +6,5 @@ void hardwareInit()
|
||||
Serial.println(F("INIT : I2C"));
|
||||
Wire.begin(Settings.Pin_i2c_sda, Settings.Pin_i2c_scl);
|
||||
}
|
||||
|
||||
if (Settings.Pin_wired_in_1 != -1)
|
||||
{
|
||||
Serial.println(F("INIT : Input 1"));
|
||||
pinMode(Settings.Pin_wired_in_1, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
if (Settings.Pin_wired_in_2 != -1)
|
||||
{
|
||||
Serial.println(F("INIT : Input 2"));
|
||||
pinMode(Settings.Pin_wired_in_2, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
if (Settings.Pin_wired_out_1 != -1)
|
||||
{
|
||||
Serial.println(F("INIT : Output 1"));
|
||||
pinMode(Settings.Pin_wired_out_1, OUTPUT);
|
||||
}
|
||||
|
||||
if (Settings.Pin_wired_out_2 != -1)
|
||||
{
|
||||
Serial.println(F("INIT : Output 2"));
|
||||
pinMode(Settings.Pin_wired_out_2, OUTPUT);
|
||||
}
|
||||
|
||||
if (Settings.RFID > 0)
|
||||
rfidinit(Settings.Pin_wired_in_1, Settings.Pin_wired_in_2);
|
||||
|
||||
if (Settings.Pulse1 > 0)
|
||||
pulseinit(Settings.Pin_wired_in_1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+60
-64
@@ -20,6 +20,40 @@ void ExecuteCommand(char *Line)
|
||||
// commands to execute io tasks
|
||||
// ****************************************
|
||||
|
||||
if (strcasecmp(Command, "GPIO") == 0)
|
||||
{
|
||||
if (Par1 >= 0 && Par1 <= 16)
|
||||
{
|
||||
pinMode(Par1, OUTPUT);
|
||||
digitalWrite(Par1, Par2);
|
||||
if (printToWeb)
|
||||
{
|
||||
printWebString += "GPIO ";
|
||||
printWebString += Par1;
|
||||
printWebString += " Set to ";
|
||||
printWebString += Par2;
|
||||
printWebString += "<BR>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strcasecmp(Command, "PWM") == 0)
|
||||
{
|
||||
if (Par1 >= 0 && Par1 <= 1023)
|
||||
{
|
||||
pinMode(Par1, OUTPUT);
|
||||
analogWrite(Par1, Par2);
|
||||
if (printToWeb)
|
||||
{
|
||||
printWebString += "GPIO ";
|
||||
printWebString += Par1;
|
||||
printWebString += " Set PWM to ";
|
||||
printWebString += Par2;
|
||||
printWebString += "<BR>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strcasecmp(Command, "DomoticzSend") == 0)
|
||||
{
|
||||
if (GetArgv(Line, TmpStr1, 4))
|
||||
@@ -101,39 +135,12 @@ void ExecuteCommand(char *Line)
|
||||
// ****************************************
|
||||
// configure settings commands:
|
||||
// ****************************************
|
||||
if (strcasecmp(Command, "Analog") == 0)
|
||||
Settings.Analog = Par1;
|
||||
|
||||
if (strcasecmp(Command, "Dallas") == 0)
|
||||
Settings.Dallas = Par1;
|
||||
|
||||
if (strcasecmp(Command, "DHT") == 0)
|
||||
Settings.DHT = Par1;
|
||||
|
||||
if (strcasecmp(Command, "DHTType") == 0)
|
||||
Settings.DHTType = Par1;
|
||||
|
||||
if (strcasecmp(Command, "BMP") == 0)
|
||||
Settings.BMP = Par1;
|
||||
|
||||
if (strcasecmp(Command, "LUX") == 0)
|
||||
Settings.LUX = Par1;
|
||||
|
||||
if (strcasecmp(Command, "RFID") == 0)
|
||||
Settings.RFID = Par1;
|
||||
|
||||
if (strcasecmp(Command, "Unit") == 0)
|
||||
Settings.Unit = Par1;
|
||||
|
||||
if (strcasecmp(Command, "Delay") == 0)
|
||||
Settings.Delay = Par1;
|
||||
|
||||
if (strcasecmp(Command, "Pulse") == 0)
|
||||
Settings.Pulse1 = Par1;
|
||||
|
||||
if (strcasecmp(Command, "Switch") == 0)
|
||||
Settings.Switch1 = Par1;
|
||||
|
||||
if (strcasecmp(Command, "Debug") == 0)
|
||||
Settings.Debug = Par1;
|
||||
|
||||
@@ -210,13 +217,8 @@ void ExecuteCommand(char *Line)
|
||||
IPAddress ip = WiFi.localIP();
|
||||
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);
|
||||
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");
|
||||
@@ -230,18 +232,6 @@ void ExecuteCommand(char *Line)
|
||||
Serial.print(" Fixed IP octet : "); Serial.println(Settings.IP_Octet);
|
||||
Serial.print(" WifiKey (APmode) : "); Serial.println(Settings.WifiAPKey);
|
||||
|
||||
Serial.println();
|
||||
Serial.println("Device settings");
|
||||
Serial.print(" Delay : "); Serial.println(Settings.Delay);
|
||||
Serial.print(" Dallas : "); Serial.println(Settings.Dallas);
|
||||
Serial.print(" DHT : "); Serial.println(Settings.DHT);
|
||||
Serial.print(" DHTType : "); Serial.println(Settings.DHTType);
|
||||
Serial.print(" BMP : "); Serial.println(Settings.BMP);
|
||||
Serial.print(" LUX : "); Serial.println(Settings.LUX);
|
||||
Serial.print(" RFID : "); Serial.println(Settings.RFID);
|
||||
Serial.print(" Analog : "); Serial.println(Settings.Analog);
|
||||
Serial.print(" Pulse : "); Serial.println(Settings.Pulse1);
|
||||
Serial.print(" Switch : "); Serial.println(Settings.Switch1);
|
||||
}
|
||||
|
||||
if (strcasecmp(Command, "Freemem") == 0)
|
||||
@@ -405,22 +395,22 @@ void ResetFactory(void)
|
||||
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;
|
||||
Settings.DHTType = DEFAULT_DHT_TYPE;
|
||||
Settings.BMP = DEFAULT_BMP_IDX;
|
||||
Settings.LUX = DEFAULT_LUX_IDX;
|
||||
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.Delay = DEFAULT_DELAY;
|
||||
//Settings.Dallas = DEFAULT_DALLAS_IDX;
|
||||
//Settings.DHT = DEFAULT_DHT_IDX;
|
||||
//Settings.DHTType = DEFAULT_DHT_TYPE;
|
||||
//Settings.BMP = DEFAULT_BMP_IDX;
|
||||
//Settings.LUX = DEFAULT_LUX_IDX;
|
||||
//Settings.RFID = DEFAULT_RFID_IDX;
|
||||
//Settings.Analog = DEFAULT_ANALOG_IDX;
|
||||
//Settings.Pulse1 = DEFAULT_PULSE1_IDX;
|
||||
//Settings.BoardType = 0;
|
||||
Settings.Pin_i2c_sda = 4;
|
||||
Settings.Pin_i2c_scl = 5;
|
||||
//Settings.Pin_wired_in_1 = 0;
|
||||
//Settings.Pin_wired_in_2 = 2;
|
||||
//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;
|
||||
@@ -443,14 +433,20 @@ void ResetFactory(void)
|
||||
Settings.Debug = 0;
|
||||
strcpy(Settings.Name, DEFAULT_NAME);
|
||||
Settings.SyslogLevel = 0;
|
||||
Settings.SerialLogLevel = 4;
|
||||
Settings.WebLogLevel = 0;
|
||||
Settings.SerialLogLevel = 3;
|
||||
Settings.WebLogLevel = 3;
|
||||
Settings.BaudRate = 115200;
|
||||
Settings.ControllerUser[0] = 0;
|
||||
Settings.ControllerPassword[0] = 0;
|
||||
Settings.Password[0] = 0;
|
||||
Settings.MessageDelay=2000;
|
||||
|
||||
Settings.MessageDelay=1000;
|
||||
for (byte x=0; x < TASKS_MAX; x++)
|
||||
{
|
||||
Settings.TaskDeviceNumber[x]=0;
|
||||
Settings.TaskDeviceID[x]=0;
|
||||
Settings.TaskDevicePin1[x]=-1;
|
||||
Settings.TaskDevicePin2[x]=-1;
|
||||
}
|
||||
Save_Settings();
|
||||
WifiDisconnect();
|
||||
ESP.reset();
|
||||
|
||||
+181
-246
@@ -17,6 +17,7 @@ void WebServerInit()
|
||||
WebServer.on("/i2cscanner", handle_i2cscanner);
|
||||
WebServer.on("/wifiscanner", handle_wifiscanner);
|
||||
WebServer.on("/login", handle_login);
|
||||
WebServer.on("/control", handle_control);
|
||||
WebServer.begin();
|
||||
}
|
||||
|
||||
@@ -26,7 +27,7 @@ void addMenu(String& str)
|
||||
str += F("<style>");
|
||||
str += F("* {font-family:sans-serif; font-size:12pt;}");
|
||||
str += F("h1 {font-size:16pt; border:1px solid #333; color:#ffffff; background:#27f;}");
|
||||
str += F(".button-link {padding:5px 10px; background:#5bf; color:#fff; border-radius:4px; border:solid 1px #258; text-decoration:none}");
|
||||
str += F(".button-link {padding:2px 10px; background:#5bf; color:#fff; border-radius:4px; border:solid 1px #258; text-decoration:none}");
|
||||
str += F(".button-link:hover {background:#369;}");
|
||||
str += F("</style>");
|
||||
|
||||
@@ -40,8 +41,8 @@ void addMenu(String& str)
|
||||
str += Settings.Name;
|
||||
str += F("</h1><a class=\"button-link\" href=\".\">Main</a>");
|
||||
str += F("<a class=\"button-link\" href=\"config\">Config</a>");
|
||||
str += F("<a class=\"button-link\" href=\"devices\">Devices</a>");
|
||||
str += F("<a class=\"button-link\" href=\"hardware\">Hardware</a>");
|
||||
str += F("<a class=\"button-link\" href=\"devices\">Devices</a>");
|
||||
#ifdef ESP_CONNEXIO
|
||||
str += F("<a class=\"button-link\" href=\"eventlist\">Eventlist</a>");
|
||||
#endif
|
||||
@@ -199,6 +200,8 @@ void handle_config() {
|
||||
String protocol = WebServer.arg("protocol");
|
||||
String controlleruser = WebServer.arg("controlleruser");
|
||||
String controllerpassword = WebServer.arg("controllerpassword");
|
||||
String sensordelay = WebServer.arg("delay");
|
||||
String messagedelay = WebServer.arg("messagedelay");
|
||||
String ip = WebServer.arg("ip");
|
||||
String espip = WebServer.arg("espip");
|
||||
String espgateway = WebServer.arg("espgateway");
|
||||
@@ -231,6 +234,8 @@ void handle_config() {
|
||||
controllerpassword.toCharArray(tmpstring, 25);
|
||||
strcpy(Settings.ControllerPassword, tmpstring);
|
||||
Settings.Protocol = protocol.toInt();
|
||||
Settings.Delay = sensordelay.toInt();
|
||||
Settings.MessageDelay = messagedelay.toInt();
|
||||
Settings.IP_Octet = ip.toInt();
|
||||
espip.toCharArray(tmpstring, 25);
|
||||
str2ip(tmpstring, Settings.IP);
|
||||
@@ -315,6 +320,11 @@ void handle_config() {
|
||||
reply += Settings.ControllerPassword;
|
||||
}
|
||||
|
||||
reply += F("'><TR><TD>Sensor Delay:<TD><input type='text' name='delay' value='");
|
||||
reply += Settings.Delay;
|
||||
reply += F("'><TR><TD>Message Delay (ms):<TD><input type='text' name='messagedelay' value='");
|
||||
reply += Settings.MessageDelay;
|
||||
|
||||
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;
|
||||
|
||||
@@ -363,110 +373,117 @@ void handle_devices() {
|
||||
if (!isLoggedIn()) return;
|
||||
|
||||
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG)
|
||||
Serial.println(F("HTTP : Webdevices"));
|
||||
Serial.println(F("HTTP : Webtasks"));
|
||||
|
||||
String boardtype = WebServer.arg("boardtype");
|
||||
String sensordelay = WebServer.arg("delay");
|
||||
String messagedelay = WebServer.arg("messagedelay");
|
||||
String dallas = WebServer.arg("dallas");
|
||||
String dht = WebServer.arg("dht");
|
||||
String dhttype = WebServer.arg("dhttype");
|
||||
String bmp = WebServer.arg("bmp");
|
||||
String lux = WebServer.arg("lux");
|
||||
String rfid = WebServer.arg("rfid");
|
||||
String analog = WebServer.arg("analog");
|
||||
String pulse1 = WebServer.arg("pulse1");
|
||||
String switch1 = WebServer.arg("switch1");
|
||||
String taskindex = WebServer.arg("index");
|
||||
String taskdevicenumber = WebServer.arg("taskdevicenumber");
|
||||
String taskdeviceid = WebServer.arg("taskdeviceid");
|
||||
String taskdevicepin1 = WebServer.arg("taskdevicepin1");
|
||||
String taskdevicepin2 = WebServer.arg("taskdevicepin2");
|
||||
String edit = WebServer.arg("edit");
|
||||
byte index = taskindex.toInt();
|
||||
|
||||
if (sensordelay.toInt() != 0)
|
||||
if (edit.toInt() != 0)
|
||||
{
|
||||
Settings.Delay = sensordelay.toInt();
|
||||
Settings.MessageDelay = messagedelay.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();
|
||||
Settings.Switch1 = switch1.toInt();
|
||||
#ifdef ESP_CONNEXIO
|
||||
|
||||
struct NodoEventStruct TempEvent;
|
||||
ClearEvent(&TempEvent);
|
||||
byte x = 1;
|
||||
while (Eventlist_Write(x++, &TempEvent, &TempEvent)) delay(1);
|
||||
|
||||
char cmd[80];
|
||||
sprintf_P(cmd, PSTR("eventlistwrite; boot %u; TimerSet 1,%u"), Settings.Unit, Settings.Delay);
|
||||
ExecuteLine(cmd, VALUE_SOURCE_SERIAL);
|
||||
sprintf_P(cmd, PSTR("eventlistwrite; Timer 1; TimerSet 1,%u"), Settings.Delay);
|
||||
ExecuteLine(cmd, VALUE_SOURCE_SERIAL);
|
||||
if (Settings.Dallas != 0)
|
||||
{
|
||||
eventAddTimer((char*)"DallasRead 1,1");
|
||||
eventAddVarSend(1, 1, Settings.Dallas);
|
||||
if (Settings.MessageDelay != 0)
|
||||
eventAddDelay();
|
||||
}
|
||||
if (Settings.DHT != 0)
|
||||
{
|
||||
eventAddTimer((char*)"DHTRead 2,2");
|
||||
eventAddVarSend(2, 2, Settings.DHT);
|
||||
if (Settings.MessageDelay != 0)
|
||||
eventAddDelay();
|
||||
}
|
||||
if (Settings.BMP != 0)
|
||||
{
|
||||
eventAddTimer((char*)"BMP085Read 4");
|
||||
eventAddVarSend(4, 3, Settings.BMP);
|
||||
if (Settings.MessageDelay != 0)
|
||||
eventAddDelay();
|
||||
}
|
||||
if (Settings.LUX != 0)
|
||||
{
|
||||
eventAddTimer((char*)"LuxRead 6");
|
||||
eventAddVarSend(6, 1, Settings.LUX);
|
||||
if (Settings.MessageDelay != 0)
|
||||
eventAddDelay();
|
||||
}
|
||||
if (Settings.Analog != 0)
|
||||
{
|
||||
eventAddTimer((char*)"VariableWiredAnalog 7");
|
||||
eventAddVarSend(7, 1, Settings.Analog);
|
||||
}
|
||||
#endif
|
||||
Settings.TaskDeviceNumber[index-1] = taskdevicenumber.toInt();
|
||||
Settings.TaskDeviceID[index-1] = taskdeviceid.toInt();
|
||||
Settings.TaskDevicePin1[index-1] = taskdevicepin1.toInt();
|
||||
Settings.TaskDevicePin2[index-1] = taskdevicepin2.toInt();
|
||||
if (Device[Settings.TaskDeviceNumber[index-1]].Type != DEVICE_TYPE_SINGLE && Device[Settings.TaskDeviceNumber[index-1]].Type != DEVICE_TYPE_DUAL)
|
||||
Settings.TaskDevicePin1[index-1] = -1;
|
||||
if (Device[Settings.TaskDeviceNumber[index-1]].Type != DEVICE_TYPE_DUAL)
|
||||
Settings.TaskDevicePin2[index-1] = -1;
|
||||
|
||||
Save_Settings();
|
||||
}
|
||||
|
||||
String reply = "";
|
||||
addMenu(reply);
|
||||
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>Message Delay (ms):<TD><input type='text' name='messagedelay' value='");
|
||||
reply += Settings.MessageDelay;
|
||||
reply += F("'><TR><TD>Dallas:<TD><input type='text' name='dallas' value='");
|
||||
reply += Settings.Dallas;
|
||||
reply += F("'><TD>Output 1<TR><TD>DHT:<TD><input type='text' name='dht' value='");
|
||||
reply += Settings.DHT;
|
||||
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("'><TD>I2C<TR><TD>LUX:<TD><input type='text' name='lux' value='");
|
||||
reply += Settings.LUX;
|
||||
reply += F("'><TD>I2C<TR><TD>RFID:<TD><input type='text' name='rfid' value='");
|
||||
reply += Settings.RFID;
|
||||
reply += F("'><TD>Input 1+2<TR><TD>Analog:<TD><input type='text' name='analog' value='");
|
||||
reply += Settings.Analog;
|
||||
reply += F("'><TD>ADC<TR><TD>Pulse:<TD><input type='text' name='pulse1' value='");
|
||||
reply += Settings.Pulse1;
|
||||
reply += F("'><TD>Input 1<TR><TD>Switch:<TD><input type='text' name='switch1' value='");
|
||||
reply += Settings.Switch1;
|
||||
reply += F("'><TD>Input 1<TR><TD><TD><input class=\"button-link\" type='submit' value='Submit'>");
|
||||
reply += F("</table></form>");
|
||||
|
||||
reply += F("<table border='1' bgcolor='#ddeeff'><tr bgcolor='#55bbff'><td><TD>Task<TD>Device<td>IDX/Variable<TD>1st GPIO<TD>2nd GPIO<TD>Value 1<TD>Value2");
|
||||
for (byte x=0; x < TASKS_MAX; x++)
|
||||
{
|
||||
reply += F("<TR><TD>");
|
||||
reply += F("<a class=\"button-link\" href=\"devices?index=");
|
||||
reply += x+1;
|
||||
reply += F("\">Edit</a>");
|
||||
reply += F("<TD>");
|
||||
reply += x+1;
|
||||
reply += F("<TD>");
|
||||
reply += Device[Settings.TaskDeviceNumber[x]].Name;
|
||||
reply += F("<TD>");
|
||||
reply += Settings.TaskDeviceID[x];
|
||||
reply += F("<TD>");
|
||||
|
||||
if (Settings.TaskDevicePin1[x] != -1)
|
||||
{
|
||||
reply += F("GPIO-");
|
||||
reply += Settings.TaskDevicePin1[x];
|
||||
}
|
||||
reply += F("<TD>");
|
||||
|
||||
if (Settings.TaskDevicePin2[x] != -1)
|
||||
{
|
||||
reply += F("GPIO-");
|
||||
reply += Settings.TaskDevicePin2[x];
|
||||
}
|
||||
|
||||
if (Device[Settings.TaskDeviceNumber[x]].Number == DEVICE_PULSE)
|
||||
{
|
||||
reply += F("<TD>");
|
||||
reply += pulseCounter[x];
|
||||
reply += F("<TD>");
|
||||
reply += pulseTotalCounter[x];
|
||||
}
|
||||
else
|
||||
{
|
||||
reply += F("<TD>");
|
||||
reply += UserVar[2*x];
|
||||
reply += F("<TD>");
|
||||
reply += UserVar[2*x+1];
|
||||
}
|
||||
}
|
||||
reply += F("</table>");
|
||||
|
||||
if (index != 0)
|
||||
{
|
||||
reply += F("<BR><BR><form method='post'><table bgcolor='#ddeeff'><tr bgcolor='#55bbff'><td>Task Settings<td>Value");
|
||||
|
||||
reply += "<TR><TD>Device:<TD>";
|
||||
byte choice = Settings.TaskDeviceNumber[index-1];;
|
||||
reply += F("<select name='taskdevicenumber'>");
|
||||
for (byte x = 0; x < DEVICES_MAX; x++)
|
||||
{
|
||||
reply += F("<option value='");
|
||||
reply += Device[x].Number;
|
||||
reply += "'";
|
||||
if (choice == Device[x].Number)
|
||||
reply += " selected";
|
||||
reply += ">";
|
||||
reply += Device[x].Name;
|
||||
reply += "</option>";
|
||||
}
|
||||
reply += F("</select>");
|
||||
|
||||
reply += F("<TR><TD>IDX / Var:<TD><input type='text' name='taskdeviceid' value='");
|
||||
reply += Settings.TaskDeviceID[index-1];
|
||||
reply += F("'>");
|
||||
|
||||
if (Device[Settings.TaskDeviceNumber[index-1]].Type == DEVICE_TYPE_SINGLE || Device[Settings.TaskDeviceNumber[index-1]].Type == DEVICE_TYPE_DUAL)
|
||||
{
|
||||
reply += F("<TR><TD>1st GPIO:<TD>");
|
||||
addPinSelect(false, reply,"taskdevicepin1",Settings.TaskDevicePin1[index-1]);
|
||||
}
|
||||
if (Device[Settings.TaskDeviceNumber[index-1]].Type == DEVICE_TYPE_DUAL)
|
||||
{
|
||||
reply += F("<TR><TD>2nd GPIO:<TD>");
|
||||
addPinSelect(false, reply,"taskdevicepin2",Settings.TaskDevicePin2[index-1]);
|
||||
}
|
||||
reply += F("<TR><TD><TD><input class=\"button-link\" type='submit' value='Submit'><TR><TD>");
|
||||
reply += F("<input type='hidden' name='edit' value='1'>");
|
||||
reply += F("</table></form>");
|
||||
}
|
||||
|
||||
addFooter(reply);
|
||||
WebServer.send(200, "text/html", reply);
|
||||
}
|
||||
@@ -513,71 +530,13 @@ void handle_hardware() {
|
||||
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)
|
||||
if (pin_i2c_sda.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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
Settings.Pin_i2c_sda = pin_i2c_sda.toInt();
|
||||
Settings.Pin_i2c_scl = pin_i2c_scl.toInt();
|
||||
Save_Settings();
|
||||
}
|
||||
|
||||
@@ -585,99 +544,21 @@ void handle_hardware() {
|
||||
addMenu(reply);
|
||||
|
||||
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[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 < 6; x++)
|
||||
{
|
||||
reply += F("<option value='");
|
||||
reply += x;
|
||||
reply += "'";
|
||||
if (choice == x)
|
||||
reply += " selected";
|
||||
reply += ">";
|
||||
reply += options[x];
|
||||
reply += "</option>";
|
||||
}
|
||||
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>SDA:<TD>");
|
||||
addPinSelect(true, reply,"pini2csda",Settings.Pin_i2c_sda);
|
||||
reply += F("<TR><TD>SCL:<TD>");
|
||||
addPinSelect(true, reply,"pini2cscl",Settings.Pin_i2c_scl);
|
||||
|
||||
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>");
|
||||
reply += Settings.Pin_i2c_scl;
|
||||
reply += F("<TR><TD>Input 1:<TD>");
|
||||
reply += Settings.Pin_wired_in_1;
|
||||
reply += F("<TR><TD>Input 2:<TD>");
|
||||
reply += Settings.Pin_wired_in_2;
|
||||
reply += F("<TR><TD>Output 1:<TD>");
|
||||
reply += Settings.Pin_wired_out_1;
|
||||
reply += F("<TR><TD>Output 2:<TD>");
|
||||
reply += Settings.Pin_wired_out_2;
|
||||
break;
|
||||
case 1:
|
||||
reply += F("<TR><TD>SDA:<TD>");
|
||||
reply += Settings.Pin_i2c_sda;
|
||||
reply += F("<TR><TD>SCL:<TD>");
|
||||
reply += Settings.Pin_i2c_scl;
|
||||
break;
|
||||
case 2:
|
||||
reply += F("<TR><TD>Input 1:<TD>");
|
||||
reply += Settings.Pin_wired_in_1;
|
||||
reply += F("<TR><TD>Output 1:<TD>");
|
||||
reply += Settings.Pin_wired_out_1;
|
||||
break;
|
||||
case 3:
|
||||
reply += F("<TR><TD>Input 1:<TD>");
|
||||
reply += Settings.Pin_wired_in_1;
|
||||
reply += F("<TR><TD>Input 2:<TD>");
|
||||
reply += Settings.Pin_wired_in_2;
|
||||
break;
|
||||
case 4:
|
||||
reply += F("<TR><TD>Output 1:<TD>");
|
||||
reply += Settings.Pin_wired_out_1;
|
||||
reply += F("<TR><TD>Output 2:<TD>");
|
||||
reply += Settings.Pin_wired_out_2;
|
||||
break;
|
||||
}
|
||||
|
||||
reply += F("</table></form>");
|
||||
addFooter(reply);
|
||||
WebServer.send(200, "text/html", reply);
|
||||
}
|
||||
|
||||
void addSelect(String& str, String name, int choice)
|
||||
void addPinSelect(boolean forI2C, String& str, String name, int choice)
|
||||
{
|
||||
String options[7];
|
||||
String options[10];
|
||||
options[0] = F(" ");
|
||||
options[1] = F("GPIO-0");
|
||||
options[2] = F("GPIO-2");
|
||||
@@ -685,7 +566,10 @@ void addSelect(String& str, String name, int choice)
|
||||
options[4] = F("GPIO-5");
|
||||
options[5] = F("GPIO-12");
|
||||
options[6] = F("GPIO-13");
|
||||
int optionValues[7];
|
||||
options[7] = F("GPIO-14");
|
||||
options[8] = F("GPIO-15");
|
||||
options[9] = F("GPIO-16");
|
||||
int optionValues[10];
|
||||
optionValues[0] = -1;
|
||||
optionValues[1] = 0;
|
||||
optionValues[2] = 2;
|
||||
@@ -693,15 +577,19 @@ void addSelect(String& str, String name, int choice)
|
||||
optionValues[4] = 5;
|
||||
optionValues[5] = 12;
|
||||
optionValues[6] = 13;
|
||||
|
||||
optionValues[7] = 14;
|
||||
optionValues[8] = 15;
|
||||
optionValues[9] = 16;
|
||||
str += F("<select name='");
|
||||
str += name;
|
||||
str += "'>";
|
||||
for (byte x = 0; x < 7; x++)
|
||||
for (byte x = 0; x < 10; x++)
|
||||
{
|
||||
str += F("<option value='");
|
||||
str += optionValues[x];
|
||||
str += "'";
|
||||
if (!forI2C && ((optionValues[x] == Settings.Pin_i2c_sda) || (optionValues[x] == Settings.Pin_i2c_scl)))
|
||||
str += " disabled";
|
||||
if (choice == optionValues[x])
|
||||
str += " selected";
|
||||
str += ">";
|
||||
@@ -1073,6 +961,53 @@ void handle_login() {
|
||||
printToWeb = false;
|
||||
}
|
||||
|
||||
//********************************************************************************
|
||||
// Web Interface control page (no password!)
|
||||
//********************************************************************************
|
||||
void handle_control() {
|
||||
|
||||
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG)
|
||||
Serial.print(F("HTTP : Webrequest : "));
|
||||
String webrequest = WebServer.arg("cmd");
|
||||
webrequest.replace("%20", " ");
|
||||
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG)
|
||||
Serial.println(webrequest);
|
||||
char command[80];
|
||||
command[0] = 0;
|
||||
webrequest.toCharArray(command, 79);
|
||||
boolean validCmd = false;
|
||||
|
||||
char Cmd[40];
|
||||
Cmd[0] = 0;
|
||||
GetArgv(command, Cmd, 1);
|
||||
|
||||
if ((strcasecmp(Cmd, "gpio") == 0) || (strcasecmp(Cmd, "pwm") == 0))
|
||||
validCmd = true;
|
||||
|
||||
String reply = "";
|
||||
|
||||
printToWeb = true;
|
||||
printWebString = "";
|
||||
|
||||
if (validCmd)
|
||||
{
|
||||
#ifdef ESP_CONNEXIO
|
||||
ExecuteLine(command, VALUE_SOURCE_SERIAL);
|
||||
#endif
|
||||
#ifdef ESP_EASY
|
||||
ExecuteCommand(command);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
reply += F("Unknown or restricted command!");
|
||||
|
||||
reply += printWebString;
|
||||
reply += F("</table></form>");
|
||||
WebServer.send(200, "text/html", reply);
|
||||
printWebString = "";
|
||||
printToWeb = false;
|
||||
}
|
||||
|
||||
boolean isLoggedIn()
|
||||
{
|
||||
if (Settings.Password[0] == 0)
|
||||
|
||||
@@ -94,4 +94,8 @@
|
||||
// Fixed io pin settings for Dallas/DHT for inconsecutive pin configuration (ESP-01)
|
||||
// Support for ThingsSpeak "controller" (webservice)
|
||||
|
||||
// R014 20-08-2015
|
||||
// Redesigned device configuration mechanisme
|
||||
// Changed password timeout to 5 minutes
|
||||
// Added direct GPIO output control without password request
|
||||
|
||||
|
||||
Reference in New Issue
Block a user