summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven <steven.vasilogianis@gmail.com>2021-09-30 17:44:06 -0400
committerSteven <steven.vasilogianis@gmail.com>2021-09-30 17:44:06 -0400
commit8aa4487fb991a0d0547e381c2949a3dc965dd106 (patch)
tree25c42618ae9e2aa0739ae35b849c147af51fedd9
parent55c2e51976c9612752b186112cc5e96d9569b516 (diff)
network support
-rw-r--r--src/main/Makefile4
-rw-r--r--src/main/main.ino21
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)
118compile: $(ELF) 118compile: $(ELF)
119.PHONY: compile 119.PHONY: compile
120 120
121$(ELF): $(SRC) $(HDRS) 121$(BIN) $(ELF): $(SRC) $(HDRS)
122 arduino-cli compile -b $(FQBN) $(VFLAG) 122 arduino-cli compile -b $(FQBN) $(VFLAG)
123 @if which arduino-manifest.pl; \ 123 @if which arduino-manifest.pl; \
124 then echo "---> Generating manifest.txt"; \ 124 then echo "---> Generating manifest.txt"; \
@@ -138,7 +138,7 @@ PLAT_PATH != arduino-cli compile -b "$(FQBN)" --show-properties | grep '^runtime
138PY_PATH != arduino-cli compile -b "$(FQBN)" --show-properties | grep '^runtime.tools.python3.path' | awk -F= '{print $$2}' 138PY_PATH != arduino-cli compile -b "$(FQBN)" --show-properties | grep '^runtime.tools.python3.path' | awk -F= '{print $$2}'
139IOT_IP != getent ahostsv4 mush.local | (read ip _; echo $$ip) 139IOT_IP != getent ahostsv4 mush.local | (read ip _; echo $$ip)
140 140
141ota: 141ota: $(BIN)
142 "$(PY_PATH)/python3" "$(PLAT_PATH)/tools/espota.py" -i "$(IOT_IP)" -p "$(OTA_PORT)" --auth="$(OTA_PASS)" -f "$(BIN)" 142 "$(PY_PATH)/python3" "$(PLAT_PATH)/tools/espota.py" -i "$(IOT_IP)" -p "$(OTA_PORT)" --auth="$(OTA_PASS)" -f "$(BIN)"
143 143
144clean: 144clean:
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 @@
18#define DHTTYPE DHT11 18#define DHTTYPE DHT11
19DHT dht(DHTPIN, DHTTYPE); 19DHT dht(DHTPIN, DHTTYPE);
20 20
21WiFiClient *wific = 0;
22
21void setup () { 23void setup () {
22 setupWifi((char *) hostname); 24 setupWifi((char *) hostname);
23 setupOTA((char *) hostname); 25 setupOTA((char *) hostname);
@@ -26,14 +28,31 @@ void setup () {
26 Serial.println(F("Mushing...")); 28 Serial.println(F("Mushing..."));
27 29
28 dht.begin(); // temp+humidity sensor 30 dht.begin(); // temp+humidity sensor
31 wific = new WiFiClient();
29} 32}
30 33
31void log_reading ( float temp_c, float humidity, float heat_index_c ) { 34void log_reading ( float temp_c, float humidity, float heat_index_c ) {
32 Serial.printf("T: %.2f H: %.2f HI: %.2f\r\n", temp_c, humidity, heat_index_c); 35 auto fmt = "T: %.2f H: %.2f HI: %.2f\r\n";
36 char buf[500];
37 snprintf(buf, sizeof(buf), fmt, temp_c, humidity, heat_index_c);
38 //Serial.printf(fmt, temp_c, humidity, heat_index_c);
39 Serial.print(buf);
40 if (wific->connected()) {
41 wific->write(buf);
42 }
33} 43}
34 44
35void loop() { 45void loop() {
36 ArduinoOTA.handle(); 46 ArduinoOTA.handle();
47
48
49 auto ip = IPAddress(192,168,1,2);
50 auto port = 3141;
51 if (!wific->connected()) {
52 Serial.println("Attempting to connect");
53 wific->connect(ip, port);
54 }
55
37 // Wait a few seconds between measurements. 56 // Wait a few seconds between measurements.
38 delay(2000); 57 delay(2000);
39 58