Firmware impruevement #2

This commit is contained in:
JonatanRek 2019-11-27 17:27:18 +01:00
parent 79864c23fd
commit 1e7f16d3b9
2 changed files with 21 additions and 1 deletions

View File

@ -1,3 +1,4 @@
//Includes
#include <DHT.h> #include <DHT.h>
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h> #include <ESP8266HTTPClient.h>
@ -73,6 +74,7 @@ void loop() {
//configuration setup //configuration setup
String hostName = doc["device"]["hostname"]; String hostName = doc["device"]["hostname"];
int sleepTime = doc["device"]["sleepTime"]; int sleepTime = doc["device"]["sleepTime"];
String ipAddress = doc["device"]["ipAddress"];
String state = doc["state"]; String state = doc["state"];
if (state != "succes") { if (state != "succes") {
@ -82,6 +84,14 @@ void loop() {
unsuccessfulRounds = 0; unsuccessfulRounds = 0;
} }
//Set static ip
IPAddress addr;
if (addr.fromString(ipAddress)) {
IPAddress ip(addr);
Serial.print("IP address:\t");
Serial.println(WiFi.localIP());
}
WiFi.hostname(hostName); WiFi.hostname(hostName);
http.end(); //Close connection http.end(); //Close connection

View File

@ -11,7 +11,7 @@ const char* server = "http://dev.steelants.cz/vasek/home/api.php";
int unsuccessfulRounds = 0; //time to wait before restart int unsuccessfulRounds = 0; //time to wait before restart
int lastState = 0; int lastState = 0;
//Constant //Pins
#define SONOFF 12 #define SONOFF 12
#define SONOFF_LED 13 #define SONOFF_LED 13
#define SONOFF_BUT 0 #define SONOFF_BUT 0
@ -80,8 +80,10 @@ void loop() {
//configuration setup //configuration setup
String hostName = doc["device"]["hostname"]; String hostName = doc["device"]["hostname"];
String ipAddress = doc["device"]["ipAddress"];
String state = doc["state"]; 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 " + unsuccessfulRounds + "FROM 5");
@ -89,6 +91,14 @@ void loop() {
unsuccessfulRounds = 0; unsuccessfulRounds = 0;
} }
//Set static ip
IPAddress addr;
if (addr.fromString(ipAddress)) {
IPAddress ip(addr);
Serial.print("IP address:\t");
Serial.println(WiFi.localIP());
}
WiFi.hostname(hostName); WiFi.hostname(hostName);
if(unsuccessfulRounds == 5) { if(unsuccessfulRounds == 5) {