diff options
Diffstat (limited to 'src/main/main.ino')
-rw-r--r-- | src/main/main.ino | 21 |
1 files changed, 20 insertions, 1 deletions
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 |
19 | DHT dht(DHTPIN, DHTTYPE); | 19 | DHT dht(DHTPIN, DHTTYPE); |
20 | 20 | ||
21 | WiFiClient *wific = 0; | ||
22 | |||
21 | void setup () { | 23 | void 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 | ||
31 | void log_reading ( float temp_c, float humidity, float heat_index_c ) { | 34 | void 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 | ||
35 | void loop() { | 45 | void 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 | ||