From 2d7db196dd056049f47cd2c4d50ba8003bc8d0a9 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 19 Dec 2019 23:15:44 +0100 Subject: [PATCH] fix digital pin and not commited changes in esp os node v3 --- .../ESP_OS_NODE_V3/ESP_OS_NODE_V3.ino | 24 ++++++++++--------- app/views/Home.php | 16 ++++++------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/_FIRMWARE/firmwares/NodeMCU Sensor/ESP_OS_NODE_V3/ESP_OS_NODE_V3.ino b/_FIRMWARE/firmwares/NodeMCU Sensor/ESP_OS_NODE_V3/ESP_OS_NODE_V3.ino index 314099b..72c765f 100644 --- a/_FIRMWARE/firmwares/NodeMCU Sensor/ESP_OS_NODE_V3/ESP_OS_NODE_V3.ino +++ b/_FIRMWARE/firmwares/NodeMCU Sensor/ESP_OS_NODE_V3/ESP_OS_NODE_V3.ino @@ -13,7 +13,7 @@ int unsuccessfulRounds = 0; //Pins #define pinDHT 4 -#define LIGHTPIN A0 +#define LIGHTPIN 13 //Inicializations DHT DHTs(pinDHT, DHT11); @@ -28,7 +28,7 @@ void setup() { Serial.print("IP address:\t"); Serial.println(WiFi.localIP()); Serial.print("MAC address:\t"); - Serial.println(WiFi.macAdress()); + Serial.println(WiFi.macAddress()); pinMode(LIGHTPIN, INPUT); } @@ -62,7 +62,7 @@ void loop() { } //Handle Photo Rezistor Values - doc["values"]["light"]["value"] = analogRead(LIGHTPIN); + doc["values"]["light"]["value"] = (String)!digitalRead(LIGHTPIN); doc["values"]["light"]["unit"] = ""; /*More Senzores to come*/ @@ -80,19 +80,21 @@ void loop() { //configuration setup int sleepTime = doc["device"]["sleepTime"]; - char *hostName = doc["device"]["hostname"].c_str(); - char *ipAddress = doc["device"]["ipAddress"].c_str(); - char *state = doc["state"].c_str(); + String hostName = doc["device"]["hostname"]; + String ipAddress = doc["device"]["ipAddress"]; + String gateway = doc["device"]["gateway"]; + String subnet = doc["device"]["subnet"]; + String state = doc["state"]; if (state != "succes") { unsuccessfulRounds++; - Serial.println("UNSUCCESSFUL ROUND NUMBER " + unsuccessfulRounds + "FROM 5"); + Serial.println("UNSUCCESSFUL ROUND NUMBER " + (String)unsuccessfulRounds + "FROM 5"); } else if (state == "succes") { unsuccessfulRounds = 0; } //Set static ip - setStaticIp(ipAddress, "192.168.0.1", "255.255.255.0") + setStaticIp(ipAddress, gateway, subnet); WiFi.hostname(hostName); //Set HostName http.end(); //Close connection @@ -101,10 +103,10 @@ void loop() { if(unsuccessfulRounds == 5) { //after 5 unsucessful request restart ESP Serial.println("RESTARTING ESP"); - ESP.restart() + ESP.restart(); } - sleep(); + sleep(sleepTime); } //checking if connection is working @@ -131,7 +133,7 @@ void setStaticIp(String IpAddress, String subnet, String gateway){ IPAddress gatewayIpAddress; if ( - staticIpAddress.fromString(ipAddress) && + staticIpAddress.fromString(IpAddress) && subnetIpAddress.fromString(subnet) && gatewayIpAddress.fromString(gateway) && WiFi.localIP() != staticIpAddress diff --git a/app/views/Home.php b/app/views/Home.php index 2231ba3..cff6783 100644 --- a/app/views/Home.php +++ b/app/views/Home.php @@ -73,14 +73,14 @@ class Home extends Template break; case 'light': - $replacementTrue = 'Light'; - $replacementFalse = 'Dark'; - $operator = '=='; - $breakValue = 1; - if ($lastValue != 1 || $lastValue != 0) { //Digital Light Senzor - $operator = '<'; - $breakValue = 810; - } + $replacementTrue = 'Light'; + $replacementFalse = 'Dark'; + $operator = '=='; + $breakValue = 1; + if ($lastValue != 1 && $lastValue != 0) { //Digital Light Senzor + $operator = '<'; + $breakValue = 810; + } break; case 'water':