From 8aa4487fb991a0d0547e381c2949a3dc965dd106 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 30 Sep 2021 17:44:06 -0400 Subject: network support --- src/main/Makefile | 4 ++-- src/main/main.ino | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/Makefile b/src/main/Makefile index 023ef7b..d27d024 100644 --- a/src/main/Makefile +++ b/src/main/Makefile @@ -118,7 +118,7 @@ all: $(ELF) compile: $(ELF) .PHONY: compile -$(ELF): $(SRC) $(HDRS) +$(BIN) $(ELF): $(SRC) $(HDRS) arduino-cli compile -b $(FQBN) $(VFLAG) @if which arduino-manifest.pl; \ then echo "---> Generating manifest.txt"; \ @@ -138,7 +138,7 @@ PLAT_PATH != arduino-cli compile -b "$(FQBN)" --show-properties | grep '^runtime PY_PATH != arduino-cli compile -b "$(FQBN)" --show-properties | grep '^runtime.tools.python3.path' | awk -F= '{print $$2}' IOT_IP != getent ahostsv4 mush.local | (read ip _; echo $$ip) -ota: +ota: $(BIN) "$(PY_PATH)/python3" "$(PLAT_PATH)/tools/espota.py" -i "$(IOT_IP)" -p "$(OTA_PORT)" --auth="$(OTA_PASS)" -f "$(BIN)" clean: diff --git a/src/main/main.ino b/src/main/main.ino index 8f9dbd1..1027bed 100644 --- a/src/main/main.ino +++ b/src/main/main.ino @@ -18,6 +18,8 @@ #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); +WiFiClient *wific = 0; + void setup () { setupWifi((char *) hostname); setupOTA((char *) hostname); @@ -26,14 +28,31 @@ void setup () { Serial.println(F("Mushing...")); dht.begin(); // temp+humidity sensor + wific = new WiFiClient(); } void log_reading ( float temp_c, float humidity, float heat_index_c ) { - Serial.printf("T: %.2f H: %.2f HI: %.2f\r\n", temp_c, humidity, heat_index_c); + auto fmt = "T: %.2f H: %.2f HI: %.2f\r\n"; + char buf[500]; + snprintf(buf, sizeof(buf), fmt, temp_c, humidity, heat_index_c); + //Serial.printf(fmt, temp_c, humidity, heat_index_c); + Serial.print(buf); + if (wific->connected()) { + wific->write(buf); + } } void loop() { ArduinoOTA.handle(); + + + auto ip = IPAddress(192,168,1,2); + auto port = 3141; + if (!wific->connected()) { + Serial.println("Attempting to connect"); + wific->connect(ip, port); + } + // Wait a few seconds between measurements. delay(2000); -- cgit v1.2.3