diff --git a/Devices.ino b/Devices.ino index 98d32dfa7..b2c61cc3a 100644 --- a/Devices.ino +++ b/Devices.ino @@ -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 { diff --git a/ESPEasy.ino b/ESPEasy.ino index c6d728a61..1280c5439 100644 --- a/ESPEasy.ino +++ b/ESPEasy.ino @@ -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 #include #include @@ -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); } - diff --git a/Hardware.ino b/Hardware.ino index 3ff462f35..a9c5a46d0 100644 --- a/Hardware.ino +++ b/Hardware.ino @@ -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); - } diff --git a/Serial.ino b/Serial.ino index c47e423ed..953295823 100644 --- a/Serial.ino +++ b/Serial.ino @@ -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 += "
"; + } + } + } + + 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 += "
"; + } + } + } + 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(); diff --git a/WebServer.ino b/WebServer.ino index ca7cc7457..ac9f7f6d7 100644 --- a/WebServer.ino +++ b/WebServer.ino @@ -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(""); @@ -40,8 +41,8 @@ void addMenu(String& str) str += Settings.Name; str += F("Main"); str += F("Config"); - str += F("Devices"); str += F("Hardware"); + str += F("Devices"); #ifdef ESP_CONNEXIO str += F("Eventlist"); #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("'>Sensor Delay:Message Delay (ms):Optional SettingsFixed IP Octet:
Device SettingsIDX/VariableConnect to
"); - reply += F("
Delay:
Message Delay (ms):
Dallas:Output 1
DHT:Output 2
DHT Type:
BMP:I2C
LUX:I2C
RFID:Input 1+2
Analog:ADC
Pulse:Input 1
Switch:Input 1
"); - reply += F("
"); + + reply += F("
TaskDeviceIDX/Variable1st GPIO2nd GPIOValue 1Value2"); + for (byte x=0; x < TASKS_MAX; x++) + { + reply += F("
"); + reply += F("Edit"); + reply += F(""); + reply += x+1; + reply += F(""); + reply += Device[Settings.TaskDeviceNumber[x]].Name; + reply += F(""); + reply += Settings.TaskDeviceID[x]; + reply += F(""); + + if (Settings.TaskDevicePin1[x] != -1) + { + reply += F("GPIO-"); + reply += Settings.TaskDevicePin1[x]; + } + reply += F(""); + + if (Settings.TaskDevicePin2[x] != -1) + { + reply += F("GPIO-"); + reply += Settings.TaskDevicePin2[x]; + } + + if (Device[Settings.TaskDeviceNumber[x]].Number == DEVICE_PULSE) + { + reply += F(""); + reply += pulseCounter[x]; + reply += F(""); + reply += pulseTotalCounter[x]; + } + else + { + reply += F(""); + reply += UserVar[2*x]; + reply += F(""); + reply += UserVar[2*x+1]; + } + } + reply += F("
"); + + if (index != 0) + { + reply += F("

Task SettingsValue"); + + reply += "
Device:"; + byte choice = Settings.TaskDeviceNumber[index-1];; + reply += F("
IDX / Var:"); + + if (Device[Settings.TaskDeviceNumber[index-1]].Type == DEVICE_TYPE_SINGLE || Device[Settings.TaskDeviceNumber[index-1]].Type == DEVICE_TYPE_DUAL) + { + reply += F("
1st GPIO:"); + addPinSelect(false, reply,"taskdevicepin1",Settings.TaskDevicePin1[index-1]); + } + if (Device[Settings.TaskDeviceNumber[index-1]].Type == DEVICE_TYPE_DUAL) + { + reply += F("
2nd GPIO:"); + addPinSelect(false, reply,"taskdevicepin2",Settings.TaskDevicePin2[index-1]); + } + reply += F("
"); + reply += F(""); + reply += F("
"); + } + 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("
Hardware Settings
"); - - reply += "
Board Type:"; - 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("
SDA:"); - addSelect(reply,"pini2csda",Settings.Pin_i2c_sda); - reply += F("
SCL:"); - addSelect(reply,"pini2cscl",Settings.Pin_i2c_scl); - reply += F("
Input 1:"); - addSelect(reply,"pinwiredin1",Settings.Pin_wired_in_1); - reply += F("
Input 2:"); - addSelect(reply,"pinwiredin2",Settings.Pin_wired_in_2); - reply += F("
Output 1:"); - addSelect(reply,"pinwiredout1",Settings.Pin_wired_out_1); - reply += F("
Output 2:"); - addSelect(reply,"pinwiredout2",Settings.Pin_wired_out_2); - } + reply += F("
SDA:"); + addPinSelect(true, reply,"pini2csda",Settings.Pin_i2c_sda); + reply += F("
SCL:"); + addPinSelect(true, reply,"pini2cscl",Settings.Pin_i2c_scl); reply += F("
"); - switch (Settings.BoardType) - { - case 0: - case 5: - reply += F("
SDA:"); - reply += Settings.Pin_i2c_sda; - reply += F("
SCL:"); - reply += Settings.Pin_i2c_scl; - reply += F("
Input 1:"); - reply += Settings.Pin_wired_in_1; - reply += F("
Input 2:"); - reply += Settings.Pin_wired_in_2; - reply += F("
Output 1:"); - reply += Settings.Pin_wired_out_1; - reply += F("
Output 2:"); - reply += Settings.Pin_wired_out_2; - break; - case 1: - reply += F("
SDA:"); - reply += Settings.Pin_i2c_sda; - reply += F("
SCL:"); - reply += Settings.Pin_i2c_scl; - break; - case 2: - reply += F("
Input 1:"); - reply += Settings.Pin_wired_in_1; - reply += F("
Output 1:"); - reply += Settings.Pin_wired_out_1; - break; - case 3: - reply += F("
Input 1:"); - reply += Settings.Pin_wired_in_1; - reply += F("
Input 2:"); - reply += Settings.Pin_wired_in_2; - break; - case 4: - reply += F("
Output 1:"); - reply += Settings.Pin_wired_out_1; - reply += F("
Output 2:"); - reply += Settings.Pin_wired_out_2; - break; - } - reply += F("
"); 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("