From 0045d00abc871b888b49b4e66d653cd107e4ef5e Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Wed, 27 Nov 2019 19:48:41 +0100 Subject: [PATCH] Comments, Comments Everywhere --- .../NodeMCU Sensor/ESP_OS_NODE_V3.ino | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/_FIRMWARE/firmwares/NodeMCU Sensor/ESP_OS_NODE_V3.ino b/_FIRMWARE/firmwares/NodeMCU Sensor/ESP_OS_NODE_V3.ino index d98669c..c7fd49d 100644 --- a/_FIRMWARE/firmwares/NodeMCU Sensor/ESP_OS_NODE_V3.ino +++ b/_FIRMWARE/firmwares/NodeMCU Sensor/ESP_OS_NODE_V3.ino @@ -23,6 +23,7 @@ void setup() { while (!Serial) continue; delay(10); Serial.println('\n'); + //Show start up Configuration Serial.println("HW: " + String(hwId)); Serial.print("IP address:\t"); Serial.println(WiFi.localIP()); @@ -32,12 +33,13 @@ void setup() { } void loop() { + //Start Conection to wifi WiFi.begin(ssid, pasw); checkConnection(); //HTTP CLIENT HTTPClient http; - http.begin(url); + http.begin(url); //Begun HTTP Request http.addHeader("Content-Type", "text/plain"); //Specify content-type header DHTs.begin(); @@ -46,6 +48,7 @@ void loop() { StaticJsonDocument<265> doc; doc["token"] = hwId; + //Read and Handle DHT values float tem = DHTs.readTemperature(); float hum = DHTs.readHumidity(); Serial.println("TEMP" + String(tem) + ";HUMI" + String(hum)); @@ -58,6 +61,7 @@ void loop() { doc["values"]["humi"]["unit"] = "%"; } + //Handle Photo Rezistor Values doc["values"]["light"]["value"] = analogRead(LIGHTPIN); doc["values"]["light"]["unit"] = ""; @@ -67,12 +71,12 @@ void loop() { Serial.print("JSON: "); Serial.println(jsonPayload); - int httpCode = http.POST(jsonPayload); + int httpCode = http.POST(jsonPayload); //Get Http response code 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); + DeserializationError error = deserializeJson(doc, httpPayload); //Get deserialization Error if exists //configuration setup String hostName = doc["device"]["hostname"]; @@ -98,25 +102,26 @@ void loop() { Serial.println(WiFi.localIP()); } - WiFi.hostname(hostName); + WiFi.hostname(hostName); //Set HostName http.end(); //Close connection + WiFi.disconnect(); //Disconect from WIFI Serial.println("DISCONECTED FROM WIFI"); - WiFi.disconnect(); - if(unsuccessfulRounds == 5) { + if(unsuccessfulRounds == 5) { //after 5 unsucessful request restart ESP Serial.println("RESTARTING ESP"); ESP.restart() } - Serial.println("GOING TO SLEEP FOR " + String(sleepTime)); - if (sleepTime > 0) { + if (sleepTime > 0) { //if deep sleepTime > 0 use deep sleep + Serial.println("GOING TO SLEEP FOR " + String(sleepTime)); ESP.deepSleep((sleepTime * 60) * 1000000, RF_DEFAULT); } else { delay(5000); } } +//checking if connection is working bool checkConnection() { int count = 0; Serial.print("Waiting for Wi-Fi connection");