fix digital pin and not commited changes in esp os node v3

This commit is contained in:
unknown 2019-12-19 23:15:44 +01:00
parent ded59cc24a
commit 2d7db196dd
2 changed files with 21 additions and 19 deletions

View File

@ -13,7 +13,7 @@ int unsuccessfulRounds = 0;
//Pins //Pins
#define pinDHT 4 #define pinDHT 4
#define LIGHTPIN A0 #define LIGHTPIN 13
//Inicializations //Inicializations
DHT DHTs(pinDHT, DHT11); DHT DHTs(pinDHT, DHT11);
@ -28,7 +28,7 @@ void setup() {
Serial.print("IP address:\t"); Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
Serial.print("MAC address:\t"); Serial.print("MAC address:\t");
Serial.println(WiFi.macAdress()); Serial.println(WiFi.macAddress());
pinMode(LIGHTPIN, INPUT); pinMode(LIGHTPIN, INPUT);
} }
@ -62,7 +62,7 @@ void loop() {
} }
//Handle Photo Rezistor Values //Handle Photo Rezistor Values
doc["values"]["light"]["value"] = analogRead(LIGHTPIN); doc["values"]["light"]["value"] = (String)!digitalRead(LIGHTPIN);
doc["values"]["light"]["unit"] = ""; doc["values"]["light"]["unit"] = "";
/*More Senzores to come*/ /*More Senzores to come*/
@ -80,19 +80,21 @@ void loop() {
//configuration setup //configuration setup
int sleepTime = doc["device"]["sleepTime"]; int sleepTime = doc["device"]["sleepTime"];
char *hostName = doc["device"]["hostname"].c_str(); String hostName = doc["device"]["hostname"];
char *ipAddress = doc["device"]["ipAddress"].c_str(); String ipAddress = doc["device"]["ipAddress"];
char *state = doc["state"].c_str(); String gateway = doc["device"]["gateway"];
String subnet = doc["device"]["subnet"];
String state = doc["state"];
if (state != "succes") { if (state != "succes") {
unsuccessfulRounds++; unsuccessfulRounds++;
Serial.println("UNSUCCESSFUL ROUND NUMBER " + unsuccessfulRounds + "FROM 5"); Serial.println("UNSUCCESSFUL ROUND NUMBER " + (String)unsuccessfulRounds + "FROM 5");
} else if (state == "succes") { } else if (state == "succes") {
unsuccessfulRounds = 0; unsuccessfulRounds = 0;
} }
//Set static ip //Set static ip
setStaticIp(ipAddress, "192.168.0.1", "255.255.255.0") setStaticIp(ipAddress, gateway, subnet);
WiFi.hostname(hostName); //Set HostName WiFi.hostname(hostName); //Set HostName
http.end(); //Close connection http.end(); //Close connection
@ -101,10 +103,10 @@ void loop() {
if(unsuccessfulRounds == 5) { //after 5 unsucessful request restart ESP if(unsuccessfulRounds == 5) { //after 5 unsucessful request restart ESP
Serial.println("RESTARTING ESP"); Serial.println("RESTARTING ESP");
ESP.restart() ESP.restart();
} }
sleep(); sleep(sleepTime);
} }
//checking if connection is working //checking if connection is working
@ -131,7 +133,7 @@ void setStaticIp(String IpAddress, String subnet, String gateway){
IPAddress gatewayIpAddress; IPAddress gatewayIpAddress;
if ( if (
staticIpAddress.fromString(ipAddress) && staticIpAddress.fromString(IpAddress) &&
subnetIpAddress.fromString(subnet) && subnetIpAddress.fromString(subnet) &&
gatewayIpAddress.fromString(gateway) && gatewayIpAddress.fromString(gateway) &&
WiFi.localIP() != staticIpAddress WiFi.localIP() != staticIpAddress

View File

@ -73,14 +73,14 @@ class Home extends Template
break; break;
case 'light': case 'light':
$replacementTrue = 'Light'; $replacementTrue = 'Light';
$replacementFalse = 'Dark'; $replacementFalse = 'Dark';
$operator = '=='; $operator = '==';
$breakValue = 1; $breakValue = 1;
if ($lastValue != 1 || $lastValue != 0) { //Digital Light Senzor if ($lastValue != 1 && $lastValue != 0) { //Digital Light Senzor
$operator = '<'; $operator = '<';
$breakValue = 810; $breakValue = 810;
} }
break; break;
case 'water': case 'water':