]> git.tnoah.ca Git - garden.git/commitdiff
IOT JSON for BME280
authorNoah Tomkins <noah@tnoah.ca>
Wed, 19 Aug 2026 04:13:52 +0000 (00:13 -0400)
committerNoah Tomkins <noah@tnoah.ca>
Wed, 19 Aug 2026 04:13:52 +0000 (00:13 -0400)
.gitignore
platformio.ini
src/garden.c [deleted file]
src/main.cpp
src/main.h [new file with mode: 0644]
src/secrets.h.example [new file with mode: 0644]

index 89cc49cbd652508924b868ea609fa8f6b758ec56..4117624b64ba21a2ffe3153f108044dd803baa2c 100644 (file)
@@ -3,3 +3,4 @@
 .vscode/c_cpp_properties.json
 .vscode/launch.json
 .vscode/ipch
+src/secrets.h
\ No newline at end of file
index 68698433d1deb956bda95a120dceb92ce0b4af71..2049f4b9d8597db7c31f213ea763ff81bedd9aae 100644 (file)
@@ -8,7 +8,14 @@
 ; Please visit documentation for the other options and examples
 ; https://docs.platformio.org/page/projectconf.html
 
-[env:wemos_d1_mini32]
-platform = espressif32
-board = wemos_d1_mini32
+[env:d1_mini_lite]
+platform = espressif8266
+board = d1_mini_lite
 framework = arduino
+monitor_speed = 115200
+lib_deps = 
+       bblanchon/ArduinoJson@^7.2.2
+       esp32async/ESPAsyncWebServer@^3.12.0
+       esp32async/ESPAsyncTCP@^2.0.0
+       adafruit/Adafruit BME280 Library@^2.3.0
+       adafruit/Adafruit Unified Sensor@^1.1.15
diff --git a/src/garden.c b/src/garden.c
deleted file mode 100644 (file)
index e20cfc7..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-void setup() {
-  // put your setup code here, to run once:
-
-}
-
-void loop() {
-  // put your main code here, to run repeatedly:
-
-}
\ No newline at end of file
index cb9fbba46e2fddd293e9056f65b63f69ce859b83..37f2a2e17b3b624a735e3da25fa04aed09094a02 100644 (file)
@@ -1,18 +1,88 @@
 #include <Arduino.h>
 
-// put function declarations here:
-int myFunction(int, int);
+#include <ESP8266WiFi.h>
+#include <ESPAsyncTCP.h>
+#include <ESPAsyncWebServer.h>
+
+#include <Wire.h>
+#include <Adafruit_Sensor.h>
+#include <Adafruit_BME280.h>
+
+#include "AsyncJson.h"
+#include "ArduinoJson.h"
+
+#include "main.h"
+#include "secrets.h"
+
+void connectToWiFi();
+void setupWebServer();
+void setupBME280();
+
+WiFiClient wifiClient;
+AsyncWebServer server(80);
+
+Adafruit_BME280 bme;
+
+void connectToWiFi() {
+               WiFi.begin(ssid, pass);
+
+       Serial.print("Connecting");
+       while (WiFi.status() != WL_CONNECTED)
+       {
+               delay(500);
+               Serial.print(".");
+       }
+       Serial.println();
+
+       Serial.print("Connected, IP address: ");
+       Serial.println(WiFi.localIP());
+}
+
+void setupWebServer() {
+       server.on("/api/sensors", HTTP_GET, [] (AsyncWebServerRequest *request) {
+               
+               AsyncResponseStream *response = request->beginResponseStream("application/json");
+               JsonDocument doc;
+
+               doc["temperature"] = bme.readTemperature();
+               doc["pressure"] = bme.readPressure() / 1000;
+               doc["humidity"] = bme.readHumidity();
+               doc["altitude"] = bme.readAltitude(SEALEVELPRESSURE_HPA);
+
+               serializeJson(doc, *response);
+               request->send(response);
+
+       });
+
+       server.begin();
+}
+
+void setupBME280() {
+       bool status;
+
+       status = bme.begin(0x76);
+       for (int i = 10; i < 10; i++) {
+               if (status) continue;
+               delay(100);
+               Serial.print("Could not connect to BME, retrying");
+       }
+
+       Serial.print("Connected to BME280!");
+}
 
 void setup() {
-  // put your setup code here, to run once:
-  int result = myFunction(2, 3);
+       Serial.begin(115200);
+       Serial.println();
+
+       connectToWiFi();
+       setupWebServer();
+       setupBME280();
+
+       pinMode(SOAKER, OUTPUT);
 }
 
 void loop() {
-  // put your main code here, to run repeatedly:
+       
+       delay(1000);
 }
 
-// put function definitions here:
-int myFunction(int x, int y) {
-  return x + y;
-}
\ No newline at end of file
diff --git a/src/main.h b/src/main.h
new file mode 100644 (file)
index 0000000..84b49c5
--- /dev/null
@@ -0,0 +1,8 @@
+// Soaker Hose Solenoid
+#define SOAKER         D8
+
+// BME280 I2C
+#define BME_SCL        D1
+#define BME_SDA D2
+
+#define SEALEVELPRESSURE_HPA (1013.25)
\ No newline at end of file
diff --git a/src/secrets.h.example b/src/secrets.h.example
new file mode 100644 (file)
index 0000000..90a1225
--- /dev/null
@@ -0,0 +1,3 @@
+// WiFi settings
+const char *ssid = "ssid";
+const char *pass = "password";
\ No newline at end of file