From 41fe669374c7d8a03be58b8d94ac766fb660b165 Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Thu, 14 Nov 2024 23:05:49 +0100 Subject: [PATCH] extended TempSender to work with two sensors Signed-off-by: Stephan Richter --- Software/TempSender/TempSender.ino | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/Software/TempSender/TempSender.ino b/Software/TempSender/TempSender.ino index a3e3f22..c67f443 100644 --- a/Software/TempSender/TempSender.ino +++ b/Software/TempSender/TempSender.ino @@ -23,7 +23,7 @@ #define ID 0 #define HW_VERSION "2.0" #define PROGRAM "TempSender" -#define SW_VERSION "1.5" +#define SW_VERSION "1.6" #define BTN_INT 2 // button interrupt pin #define Max485_RO 3 // read-output of Max485 @@ -34,7 +34,8 @@ #define TRESHOLD 1024 #define TRIGGER_LEVEL 200 -#define DHT_PIN 4 +#define DHT1_PIN 4 +#define DHT2_PIN 5 #define PERIOD 100000000 // 100s //#define DEBUG @@ -47,7 +48,10 @@ unsigned long capacitor[8]; unsigned long times[8]; unsigned long sensor_time = 0; -SimpleDHT22 sensor(DHT_PIN); +SimpleDHT22 sensor1(DHT1_PIN); +#ifdef DHT2_PIN +SimpleDHT22 sensor2(DHT2_PIN); +#endif float temperature = 0; float humidity = 0; int err = SimpleDHTErrSuccess; @@ -59,7 +63,7 @@ void setup(){ states[i] = LOW; } Serial.begin(115200); - init485(Max485_RO,Max485_RE,Max485_DE,Max485_DI); // library initialization: + init485(Max485_RO,Max485_RE,Max485_DE,Max485_DI,4000); // library initialization: pinMode(BTN_INT,INPUT_PULLUP); pinMode(14,INPUT_PULLUP); pinMode(15,INPUT_PULLUP); @@ -134,8 +138,17 @@ void loop(){ if (now - sensor_time > PERIOD){ sensor_time = now; - if ((err = sensor.read2(&temperature, &humidity, NULL)) == SimpleDHTErrSuccess) { - String s = "{nano:"+String(ID)+",temp:"+String(temperature,1)+",humi:"+String(humidity,1)+"}"; + String s = "{nano:"+String(ID); + if ((err = sensor1.read2(&temperature, &humidity, NULL)) == SimpleDHTErrSuccess) { + s += ",temp:"+String(temperature,1)+",humi:"+String(humidity,1); + } +#ifdef DHT2_PIN + if ((err = sensor2.read2(&temperature, &humidity, NULL)) == SimpleDHTErrSuccess) { + s += ",temp2:"+String(temperature,1)+",humi2:"+String(humidity,1); + } +#endif + if (s.length()>10){ + s += "}"; send485(s.c_str()); } }