commit b40e8a87665e69eec351d8e874bea478c2594927 Author: smallsolar Date: Mon Dec 29 12:55:05 2025 +0000 Add monitor/greenhouse1.ino diff --git a/monitor/greenhouse1.ino b/monitor/greenhouse1.ino new file mode 100644 index 0000000..9a6ff7e --- /dev/null +++ b/monitor/greenhouse1.ino @@ -0,0 +1,123 @@ + + +/** + * Coded for ESP32-C6 https://www.dfrobot.com/product-2778.html + * Remember to put your wifi credentials into wifiMulti.addAP("", ""); + */ + +#include + +#include +#include + +#include + +#define USE_SERIAL Serial + +WiFiMulti wifiMulti; + +#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */ +#define TIME_TO_SLEEP 60 /* Time ESP32 will go to sleep (in seconds) */ + +RTC_DATA_ATTR int bootCount = 0; + +void setup() { + + USE_SERIAL.begin(115200); + //sensors.begin(); + + delay(1000); + + USE_SERIAL.println(); + USE_SERIAL.println(); + USE_SERIAL.println(); + + for (uint8_t t = 4; t > 0; t--) { + USE_SERIAL.printf("[SETUP] WAIT %d...\n", t); + USE_SERIAL.flush(); + delay(1000); + } + + wifiMulti.addAP("", ""); + delay(3000); + + // wait for WiFi connection + if ((wifiMulti.run() == WL_CONNECTED)) { + + HTTPClient http; + + float temp_celsius = temperatureRead(); + + String url="http://192.168.1.221:8086/write?db=garagedb"; + + String value_data="green_temp,host=greenhouse value="; + value_data.concat(temp_celsius); + USE_SERIAL.print("[SENSOR] Temp: "); + USE_SERIAL.println(temp_celsius); + + USE_SERIAL.print("[HTTP] begin...\n"); + // configure traged server and url + http.begin(url); //HTTP + + int httpResponseCode = http.POST(value_data); + + if(httpResponseCode>0){ + USE_SERIAL.print("Success: "); + USE_SERIAL.println(httpResponseCode); //Print return code + } else { + USE_SERIAL.print("Error on sending POST: "); + USE_SERIAL.println(httpResponseCode); + } + + http.end(); + USE_SERIAL.print("[HTTP] complete\n"); + +/******************************/ + + uint32_t Vbatt = 0; + for(int i = 0; i < 4; i++) { + Vbatt += analogReadMilliVolts(0); // Read and accumulate ADC voltage + } + float Vbattf = 2 * Vbatt / 4 / 1000.0; // Adjust for 1:2 divider and convert to volts + + USE_SERIAL.print("[SENSOR] Voltage: "); + USE_SERIAL.println(Vbattf, 3); // Output voltage to 3 decimal places + value_data="battery_v,host=greenhouse value="; + value_data.concat(Vbattf); + + USE_SERIAL.print("[HTTP] begin...\n"); + // configure traged server and url + http.begin(url); //HTTP + + httpResponseCode = http.POST(value_data); + + if(httpResponseCode>0){ + USE_SERIAL.print("Success: "); + USE_SERIAL.println(httpResponseCode); //Print return code + } else { + USE_SERIAL.print("Error on sending POST: "); + USE_SERIAL.println(httpResponseCode); + httpResponseCode = http.POST(value_data); + USE_SERIAL.print("Error on sending POST: "); + USE_SERIAL.println(httpResponseCode); + } + + http.end(); + USE_SERIAL.print("[HTTP] complete\n"); + +/******************************/ + } + + USE_SERIAL.println("Sleep"); + esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); + USE_SERIAL.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) + " Seconds"); + + USE_SERIAL.println("Going to sleep now"); + USE_SERIAL.flush(); + esp_deep_sleep_start(); + USE_SERIAL.println("This will never be printed"); + +} + +void loop() { +} \ No newline at end of file