From 3b72bf85fd3328b67d9ca00efd6ab261f1bd13fc Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Wed, 27 Nov 2019 19:11:43 +0100 Subject: [PATCH] Merge Local Fixes NTB2 --- ...OS_NODE_V3.ino~HEAD => ESP_OS_NODE_V3.ino} | 0 .../ESP_OS_NODE_V3.ino/ESP_OS_NODE_V3.ino.ino | 136 ------------------ 2 files changed, 136 deletions(-) rename _FIRMWARE/firmwares/NodeMCU Sensor/{ESP_OS_NODE_V3.ino~HEAD => ESP_OS_NODE_V3.ino} (100%) delete mode 100644 _FIRMWARE/firmwares/NodeMCU Sensor/ESP_OS_NODE_V3.ino/ESP_OS_NODE_V3.ino.ino diff --git a/_FIRMWARE/firmwares/NodeMCU Sensor/ESP_OS_NODE_V3.ino~HEAD b/_FIRMWARE/firmwares/NodeMCU Sensor/ESP_OS_NODE_V3.ino similarity index 100% rename from _FIRMWARE/firmwares/NodeMCU Sensor/ESP_OS_NODE_V3.ino~HEAD rename to _FIRMWARE/firmwares/NodeMCU Sensor/ESP_OS_NODE_V3.ino diff --git a/_FIRMWARE/firmwares/NodeMCU Sensor/ESP_OS_NODE_V3.ino/ESP_OS_NODE_V3.ino.ino b/_FIRMWARE/firmwares/NodeMCU Sensor/ESP_OS_NODE_V3.ino/ESP_OS_NODE_V3.ino.ino deleted file mode 100644 index 02e6968..0000000 --- a/_FIRMWARE/firmwares/NodeMCU Sensor/ESP_OS_NODE_V3.ino/ESP_OS_NODE_V3.ino.ino +++ /dev/null @@ -1,136 +0,0 @@ -//Includes -#include -#include -#include -#include - -//Variables -const char* ssid = "SteelAntsNET"; -const char* pasw = "tgr786hgtp3CZ"; -const char* hwId = "JOK3R"; -const char* url = "http://dev.steelants.cz/vasek/home/api.php"; -int unsuccessfulRounds = 0; - -//Pins -#define pinDHT 4 -#define LIGHTPIN A0 - -//Inicializations -DHT DHTs(pinDHT, DHT11); - -void setup() { - Serial.begin(9600); - while (!Serial) continue; - delay(10); - Serial.println('\n'); - Serial.println("HW: " + String(hwId)); - - pinMode(LIGHTPIN, INPUT); -} - -void loop() { - WiFi.begin(ssid, pasw); - checkConnection(); - Serial.print("IP address:\t"); - Serial.println(WiFi.localIP()); - Serial.print("MAC address:\t"); - Serial.println(WiFi.macAddress()); - - //HTTP CLIENT - HTTPClient http; - http.begin(url); - http.addHeader("Content-Type", "text/plain"); //Specify content-type header - - DHTs.begin(); - - //JsonDocsDefinition - StaticJsonDocument<265> doc; - doc["token"] = hwId; - - float tem = DHTs.readTemperature(); - float hum = DHTs.readHumidity(); - Serial.println("TEMP" + String(tem) + ";HUMI" + String(hum)); - if (isnan(tem) || isnan(hum)) { - Serial.println("Unable to read DHT"); - } else { - doc["values"]["temp"]["value"] = tem; - doc["values"]["temp"]["unit"] = "C"; - doc["values"]["humi"]["value"] = hum; - doc["values"]["humi"]["unit"] = "%"; - } - - doc["values"]["light"]["value"] = analogRead(LIGHTPIN); - doc["values"]["light"]["unit"] = ""; - - /*More Senzores to come*/ - String jsonPayload = ""; - serializeJson(doc, jsonPayload); - Serial.print("JSON: "); - Serial.println(jsonPayload); - - int httpCode = http.POST(jsonPayload); - String httpPayload = http.getString(); //Get the response payload - Serial.println("HTTP CODE: " + String(httpCode) + ""); //Print HTTP return code - Serial.println("HTTP BODY: " + String(httpPayload) + ""); //Print request response payload - - DeserializationError error = deserializeJson(doc, httpPayload); - - //configuration setup - String hostName = doc["device"]["hostname"]; - int sleepTime = doc["device"]["sleepTime"]; - String ipAddress = doc["device"]["ipAddress"]; - String state = doc["state"]; - - if (state != "succes") { - unsuccessfulRounds++; - Serial.println("UNSUCCESSFUL ROUND NUMBER " + String(unsuccessfulRounds) + "FROM 5"); - } else if (state == "succes") { - unsuccessfulRounds = 0; - } - - //Set static ip - IPAddress staticIpAddress; -IPAddress subnetIpAddress(192,168,0,1); -IPAddress gatewayIpAddress(255, 255, 255, 0); - - if (staticIpAddress.fromString(ipAddress)) { - WiFi.config(staticIpAddress, subnetIpAddress, gatewayIpAddress); - Serial.print("IP address:\t"); - Serial.println(WiFi.localIP()); - } - - WiFi.hostname(hostName); - - http.end(); //Close connection - Serial.println("DISCONECTED FROM WIFI"); - WiFi.disconnect(); - - if(unsuccessfulRounds == 5) { - Serial.println("RESTARTING ESP"); - ESP.restart(); - } - - Serial.println("GOING TO SLEEP FOR " + String(sleepTime)); - if (sleepTime > 0) { - ESP.deepSleep((sleepTime * 60) * 1000000, RF_DEFAULT); - } else { - delay(5000); - } -} - -bool checkConnection() { - int count = 0; - Serial.print("Waiting for Wi-Fi connection"); - while ( count < 30 ) { - if (WiFi.status() == WL_CONNECTED) { - Serial.println(); - Serial.println("Connected!"); - return (true); - } - delay(500); - Serial.print("."); - count++; - } - Serial.println("Timed out."); - return false; -}