#include #include #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); String content = String("GET / HTTP/1.1\r\n") + "Host: example.com\r\n" + "User-Agent: ESP32/FunHouse/tarka-outdoor-weather-station" + "\r\n" + "Connection: close" + "\r\n"; WiFiClientSecure client; client.setInsecure(); debugln("Connectiong to: example.com"); showProgress(PROGRESS_GREEN); if(!client.connect("example.com", 443)) { debugln("Connection failed!"); ERR; } debugln("Connection established. Sending headers & body."); showProgress(PROGRESS_GREEN); client.print(content); // Wait for things to happen showProgress(PROGRESS_GREEN); delay(500); while(client.available()) { showProgress(PROGRESS_GREEN); String line = client.readStringUntil('\n'); debuglog("Read line: ", line); } hideProgress(); debugln("===== Done ====="); } boolean uploadData( float temperature, float pressure, float humidity, float light ) { showProgress(PROGRESS_GREEN); String data = String("{") + "\t\"temperature\": " + temperature + ",\n" + "\t\"pressure\": " + pressure + ",\n" + "\t\"humidity\": " + humidity + ",\n" + "\t\"light\": " + light + ",\n" + "\t\"time\": { \".sv\": \"timestamp\" }\n" + "}"; debuglog("Content body: ", data); String content = String("POST ") + RTDB_URL + " HTTP/1.1\r\n" + "Host: " + RTDB_HOST + "\r\n" + "User-Agent: ESP32/FunHouse/tarka-outdoor-weather-station" + "\r\n" + "Content-Type: application/x-www-form-urlencoded" + "\r\n" + "Accept: */*" + "\r\n" + "Content-Length: " + data.length() + "\r\n" + "Connection: close" + "\r\n" + "\r\n" + data; debuglog("HTTP request: ", content); WiFiClientSecure client; client.setInsecure(); showProgress(PROGRESS_GREEN); debuglog("Connectiong to: ", RTDB_HOST); if(!client.connect(RTDB_HOST, PORT)) { debugln("Connection failed!"); showError(); return false; } debugln("Connection established. Sending headers & body."); showProgress(PROGRESS_GREEN); client.print(content); // Wait for things to happen showProgress(PROGRESS_GREEN); delay(500); while(client.available()) { showProgress(PROGRESS_GREEN); String line = client.readStringUntil('\n'); debuglog("Read line: ", line); } debugln("===== Done ====="); hideProgress(); return true; }