Improvement to the ESP8266 Arduino code
This commit is contained in:
parent
67c9fb1dee
commit
1c13707b39
1 changed files with 9 additions and 9 deletions
|
@ -51,8 +51,8 @@ void setup() {
|
||||||
|
|
||||||
if (c > 100) {
|
if (c > 100) {
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println("Unable to connect. Sleeping for 30 seconds before trying again.");
|
Serial.println("Unable to connect. Sleeping for 60 seconds before trying again.");
|
||||||
int sleepTime = 30 * 1e6;
|
int sleepTime = 60 * 1e6;
|
||||||
ESP.deepSleep(sleepTime);
|
ESP.deepSleep(sleepTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,11 +70,11 @@ void loop() {
|
||||||
t = bmp.readTemperature();
|
t = bmp.readTemperature();
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("Got t=" + String(t) + " and h=" + String(h) + "...");
|
Serial.println("Got t=" + String(t) + " and h=" + String(h) + ".");
|
||||||
|
|
||||||
|
|
||||||
String content = "{\n";
|
String content = "{\n";
|
||||||
//content += "\"id\": \"" + String(getNodeId()) + "\",\n";
|
content += "\"id\": \"" + WiFi.macAddress() + "\",\n";
|
||||||
|
content += "\"name\": \"" + String(getNodeId()) + "\",\n";
|
||||||
content += "\"temp\": " + String(t) + ",\n";
|
content += "\"temp\": " + String(t) + ",\n";
|
||||||
content += "\"pressure\": " + String(h) + "\n";
|
content += "\"pressure\": " + String(h) + "\n";
|
||||||
content += "}\n";
|
content += "}\n";
|
||||||
|
@ -84,7 +84,7 @@ void loop() {
|
||||||
String response = "";
|
String response = "";
|
||||||
int statusCode = 0;
|
int statusCode = 0;
|
||||||
|
|
||||||
while (statusCode < 100) {
|
while (statusCode < 100 || statusCode >= 500) {
|
||||||
RestClient client = RestClient(host, httpsPort, 1);
|
RestClient client = RestClient(host, httpsPort, 1);
|
||||||
const char * contentArr = content.c_str();
|
const char * contentArr = content.c_str();
|
||||||
statusCode = client.post(path, contentArr, &response);
|
statusCode = client.post(path, contentArr, &response);
|
||||||
|
@ -92,8 +92,8 @@ void loop() {
|
||||||
Serial.println("Got response code: " + String(statusCode));
|
Serial.println("Got response code: " + String(statusCode));
|
||||||
Serial.println("Got response: " + response);
|
Serial.println("Got response: " + response);
|
||||||
|
|
||||||
if (statusCode < 100) {
|
if (statusCode < 100 || statusCode >= 500) {
|
||||||
delay(2500);
|
delay(5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ void loop() {
|
||||||
|
|
||||||
Serial.print("Going to sleep for ");
|
Serial.print("Going to sleep for ");
|
||||||
Serial.print(sleepTime);
|
Serial.print(sleepTime);
|
||||||
Serial.print(" nanoseconds");
|
Serial.println(" nanoseconds");
|
||||||
|
|
||||||
ESP.deepSleep(sleepTime);
|
ESP.deepSleep(sleepTime);
|
||||||
/*
|
/*
|
||||||
|
|
Reference in a new issue