Sensor setup
Point your ESP32 at the endpoint below and include the device key from the Devices tab.
Endpoint
Method: POST · Content-Type: application/json
https://project--670037ee-58ed-4aa3-9988-56cec5e1267e.lovable.app/api/public/readingsThe key may be sent in the JSON body as device_key or as the header x-device-key. A successful post returns {"ok":true}.
JSON payload
{
"device_key": "YOUR_DEVICE_KEY",
"moisture": 6.4,
"temperature": 22.5,
"battery": 3.9,
"raw": 2310
}- moisture — required, 0–100 percent
- temperature, battery, raw — optional extras
- recorded_at — optional ISO timestamp; defaults to the time it arrives
Example ESP32 firmware (Arduino)
#include <WiFi.h>
#include <HTTPClient.h>
const char* WIFI_SSID = "your-wifi";
const char* WIFI_PASS = "your-password";
const char* ENDPOINT = "https://project--670037ee-58ed-4aa3-9988-56cec5e1267e.lovable.app/api/public/readings";
const char* DEVICE_KEY = "YOUR_DEVICE_KEY"; // copy from the Devices tab
const int SENSOR_PIN = 34; // ADC pin
const int RAW_DRY = 3200; // reading in air / fully dry
const int RAW_WET = 1300; // reading in water / saturated
void setup() {
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }
Serial.println("\nWiFi connected");
}
void postReading(int raw, float moisture) {
HTTPClient http;
http.begin(ENDPOINT); // HTTPS
http.addHeader("Content-Type", "application/json");
String body = String("{\"device_key\":\"") + DEVICE_KEY +
"\",\"moisture\":" + String(moisture, 2) +
",\"raw\":" + String(raw) + "}";
int code = http.POST(body);
Serial.printf("POST %d: %s\n", code, http.getString().c_str());
http.end();
}
void loop() {
int raw = analogRead(SENSOR_PIN);
float moisture = (float)(RAW_DRY - raw) * 100.0 / (float)(RAW_DRY - RAW_WET);
if (moisture < 0) moisture = 0;
if (moisture > 100) moisture = 100;
postReading(raw, moisture);
delay(15UL * 60UL * 1000UL); // every 15 minutes
}Test it from a computer
curl -X POST https://project--670037ee-58ed-4aa3-9988-56cec5e1267e.lovable.app/api/public/readings \
-H "Content-Type: application/json" \
-d '{"device_key":"YOUR_DEVICE_KEY","moisture":6.4}'