|
|
@@ -1,14 +1,7 @@
|
|
|
#include <WiFi.h>
|
|
|
#include <WiFiClientSecure.h>
|
|
|
|
|
|
-#define PROJECT "weather-station-58080"
|
|
|
-#define AUTH_TOKEN "aud8LdW1IeTWqcv77Ka1LJn5xSqambsJ9jYx5OEh"
|
|
|
-#define DATABASE_URL "https://weather-station-58080-default-rtdb.firebaseio.com"
|
|
|
-#define DATABASE_PATH "outdoor.json"
|
|
|
-
|
|
|
#define PORT 443
|
|
|
-#define HOST "weather-station-58080-default-rtdb.firebaseio.com"
|
|
|
-const String WRITE_URL = String("https://") + HOST + "/" + DATABASE_PATH + "?auth=" + AUTH_TOKEN;
|
|
|
|
|
|
void getSomething() {
|
|
|
showProgress(PROGRESS_GREEN);
|
|
|
@@ -19,15 +12,15 @@ void getSomething() {
|
|
|
|
|
|
WiFiClientSecure client;
|
|
|
client.setInsecure();
|
|
|
- debugln("Connectiong to: example.com");
|
|
|
+ debug("Connectiong to: example.com");
|
|
|
showProgress(PROGRESS_GREEN);
|
|
|
|
|
|
if(!client.connect("example.com", 443)) {
|
|
|
- debugln("Connection failed!");
|
|
|
+ debug("Connection failed!");
|
|
|
ERR;
|
|
|
}
|
|
|
|
|
|
- debugln("Connection established. Sending headers & body.");
|
|
|
+ debug("Connection established. Sending headers & body.");
|
|
|
showProgress(PROGRESS_GREEN);
|
|
|
client.print(content);
|
|
|
|
|
|
@@ -38,10 +31,10 @@ void getSomething() {
|
|
|
while(client.available()) {
|
|
|
showProgress(PROGRESS_GREEN);
|
|
|
String line = client.readStringUntil('\n');
|
|
|
- debuglog("Read line: ", line);
|
|
|
+ debug("Read line: %s", line);
|
|
|
}
|
|
|
hideProgress();
|
|
|
- debugln("===== Done =====");
|
|
|
+ debug("===== Done =====");
|
|
|
}
|
|
|
|
|
|
boolean uploadData(
|
|
|
@@ -58,7 +51,7 @@ boolean uploadData(
|
|
|
+ "\t\"light\": " + light + ",\n"
|
|
|
+ "\t\"time\": { \".sv\": \"timestamp\" }\n"
|
|
|
+ "}";
|
|
|
- debuglog("Content body: ", data);
|
|
|
+ debugln("Content body: ", data);
|
|
|
|
|
|
String content = String("POST ") + RTDB_URL + " HTTP/1.1\r\n"
|
|
|
+ "Host: " + RTDB_HOST + "\r\n"
|
|
|
@@ -70,20 +63,20 @@ boolean uploadData(
|
|
|
+ "\r\n"
|
|
|
+ data;
|
|
|
|
|
|
- debuglog("HTTP request: ", content);
|
|
|
+ debugln("HTTP request: ", content);
|
|
|
|
|
|
WiFiClientSecure client;
|
|
|
client.setInsecure();
|
|
|
showProgress(PROGRESS_GREEN);
|
|
|
- debuglog("Connectiong to: ", RTDB_HOST);
|
|
|
+ debugln("Connectiong to: ", RTDB_HOST);
|
|
|
|
|
|
- if(!client.connect(RTDB_HOST, PORT)) {
|
|
|
- debugln("Connection failed!");
|
|
|
+ if(!client.connect(RTDB_HOST.c_str(), PORT)) {
|
|
|
+ debug("Connection failed!");
|
|
|
showError();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- debugln("Connection established. Sending headers & body.");
|
|
|
+ debug("Connection established. Sending headers & body.");
|
|
|
showProgress(PROGRESS_GREEN);
|
|
|
client.print(content);
|
|
|
|
|
|
@@ -94,9 +87,9 @@ boolean uploadData(
|
|
|
while(client.available()) {
|
|
|
showProgress(PROGRESS_GREEN);
|
|
|
String line = client.readStringUntil('\n');
|
|
|
- debuglog("Read line: ", line);
|
|
|
+ debugln("Read line: ", line);
|
|
|
}
|
|
|
- debugln("===== Done =====");
|
|
|
+ debug("===== Done =====");
|
|
|
|
|
|
hideProgress();
|
|
|
return true;
|