From 97528622db85b49e72e1ac997aebc70d2637ff10 Mon Sep 17 00:00:00 2001 From: 033zhek <033zhek@gmail.com> Date: Sun, 8 Oct 2023 05:36:42 +0300 Subject: [PATCH 1/2] no temp, others work --- cybergarden-sensor/lib/Sensors/Sensors.cpp | 31 +++++++++++++++++ cybergarden-sensor/lib/Sensors/Sensors.h | 39 ++++++++++++++++++++++ cybergarden-sensor/platformio.ini | 4 +++ cybergarden-sensor/src/main.cpp | 11 +++++- 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 cybergarden-sensor/lib/Sensors/Sensors.cpp create mode 100644 cybergarden-sensor/lib/Sensors/Sensors.h diff --git a/cybergarden-sensor/lib/Sensors/Sensors.cpp b/cybergarden-sensor/lib/Sensors/Sensors.cpp new file mode 100644 index 0000000..904a4b1 --- /dev/null +++ b/cybergarden-sensor/lib/Sensors/Sensors.cpp @@ -0,0 +1,31 @@ +#include + + +float Sensor::temperatureSensor(){ + tempSens->requestTemperatures(); + while (!tempSens->isConversionComplete()); + float temp = tempSens->getTempCByIndex(1); + return temp; +} + +float Sensor::humiditySensor(){ + float h = dht->readHumidity(); + if (isnan(h)) { + return -1; + } + else{ + return h; + } +} + +int Sensor::photoSensor(){ + int value = analogRead(PHOTO_SENS); + return value; +} + +int Sensor::vibroSensor(){ + int value = analogRead(VIBRO_SENS); + return value; +} + + diff --git a/cybergarden-sensor/lib/Sensors/Sensors.h b/cybergarden-sensor/lib/Sensors/Sensors.h new file mode 100644 index 0000000..6faeec6 --- /dev/null +++ b/cybergarden-sensor/lib/Sensors/Sensors.h @@ -0,0 +1,39 @@ +#pragma once +#include "Arduino.h" +#include "DallasTemperature.h" +#include "DHT.h" + +/////////////////////////////////////////////////////// +// Pins Definitions +/////////////////////////////////////////////////////// + +#define HUM_SENS 33 +#define TEMP_SENS 32 +#define PHOTO_SENS 25 +#define VIBRO_SENS 26 +class Sensor{ + + private: + // KY-001 + OneWire *oneWire; + DallasTemperature *tempSens; + //KY-015 + DHT *dht; + + public: + float temperatureSensor(); + float humiditySensor(); + int photoSensor(); + int vibroSensor(); + +Sensor() + { + oneWire = new OneWire(TEMP_SENS); + tempSens = new DallasTemperature(oneWire); + dht = new DHT(HUM_SENS, DHT11); + tempSens->begin(); + dht->begin(); + } + + +}; diff --git a/cybergarden-sensor/platformio.ini b/cybergarden-sensor/platformio.ini index 203b30b..1084f9e 100644 --- a/cybergarden-sensor/platformio.ini +++ b/cybergarden-sensor/platformio.ini @@ -16,3 +16,7 @@ monitor_speed = 115200 lib_deps = mikem/RadioHead@^1.120 rweather/Crypto@^0.4.0 + paulstoffregen/OneWire@^2.3.7 + milesburton/DallasTemperature@^3.11.0 + adafruit/DHT sensor library@^1.4.4 + adafruit/Adafruit Unified Sensor@^1.1.13 diff --git a/cybergarden-sensor/src/main.cpp b/cybergarden-sensor/src/main.cpp index d2c64f8..e23b2c1 100644 --- a/cybergarden-sensor/src/main.cpp +++ b/cybergarden-sensor/src/main.cpp @@ -2,10 +2,12 @@ #include "TransmitterModule.h" #include "TransmissionModule.h" #include "ReedSolomonModule.h" +#include "Sensors.h" TransmitterModule transmitterModule; ReedSolomonModule reedSolomonModule; TransmissionModule transmissionModule(transmitterModule, reedSolomonModule); +Sensor sensors; void setup() { Serial.begin(115200); @@ -21,6 +23,13 @@ void loop() { measureData.sensor_id = 0xA5; measureData.sensor_type = 0x01; measureData.payload = getMockSensorData(); + Serial.print(sensors.humiditySensor(), DEC); + Serial.print(" "); + Serial.print(sensors.temperatureSensor(), DEC); + Serial.print(" "); + Serial.print(sensors.photoSensor(), DEC); + Serial.print(" "); + Serial.println(sensors.vibroSensor(), DEC); transmissionModule.transmit(measureData); - delay(1000); + delay(100); } \ No newline at end of file From 8624f652f23f2b9975eed7a6b1ae43b7e2304fee Mon Sep 17 00:00:00 2001 From: 033zhek <033zhek@gmail.com> Date: Sun, 8 Oct 2023 08:55:50 +0300 Subject: [PATCH 2/2] changed temperature sensor --- cybergarden-sensor/lib/Sensors/Sensors.cpp | 9 ++--- cybergarden-sensor/lib/Sensors/Sensors.h | 10 +----- cybergarden-sensor/src/main.cpp | 38 +++++++++++++++++++--- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/cybergarden-sensor/lib/Sensors/Sensors.cpp b/cybergarden-sensor/lib/Sensors/Sensors.cpp index 904a4b1..9fd7591 100644 --- a/cybergarden-sensor/lib/Sensors/Sensors.cpp +++ b/cybergarden-sensor/lib/Sensors/Sensors.cpp @@ -1,15 +1,12 @@ #include -float Sensor::temperatureSensor(){ - tempSens->requestTemperatures(); - while (!tempSens->isConversionComplete()); - float temp = tempSens->getTempCByIndex(1); - return temp; +float Sensor::temperatureSensor(){ + return analogRead(TEMP_SENS); } float Sensor::humiditySensor(){ - float h = dht->readHumidity(); + float h = dht->readHumidity(); if (isnan(h)) { return -1; } diff --git a/cybergarden-sensor/lib/Sensors/Sensors.h b/cybergarden-sensor/lib/Sensors/Sensors.h index 6faeec6..446d320 100644 --- a/cybergarden-sensor/lib/Sensors/Sensors.h +++ b/cybergarden-sensor/lib/Sensors/Sensors.h @@ -1,7 +1,7 @@ #pragma once #include "Arduino.h" -#include "DallasTemperature.h" #include "DHT.h" +#include "math.h" /////////////////////////////////////////////////////// // Pins Definitions @@ -14,9 +14,6 @@ class Sensor{ private: - // KY-001 - OneWire *oneWire; - DallasTemperature *tempSens; //KY-015 DHT *dht; @@ -28,12 +25,7 @@ class Sensor{ Sensor() { - oneWire = new OneWire(TEMP_SENS); - tempSens = new DallasTemperature(oneWire); dht = new DHT(HUM_SENS, DHT11); - tempSens->begin(); dht->begin(); } - - }; diff --git a/cybergarden-sensor/src/main.cpp b/cybergarden-sensor/src/main.cpp index e23b2c1..d3d579f 100644 --- a/cybergarden-sensor/src/main.cpp +++ b/cybergarden-sensor/src/main.cpp @@ -19,10 +19,38 @@ uint16_t getMockSensorData() { } void loop() { - MeasureData measureData; - measureData.sensor_id = 0xA5; - measureData.sensor_type = 0x01; - measureData.payload = getMockSensorData(); + MeasureData measureData_temp; + measureData_temp.sensor_id = 0xA5; + measureData_temp.sensor_type = 0x01; + measureData_temp.payload = sensors.temperatureSensor(); + transmissionModule.transmit(measureData_temp); + + delay(100); + + MeasureData measureData_hum; + measureData_hum.sensor_id = 0xA5; + measureData_hum.sensor_type = 0x02; + measureData_hum.payload = sensors.humiditySensor(); + transmissionModule.transmit(measureData_hum); + + delay(100); + + MeasureData measureData_photo; + measureData_photo.sensor_id = 0xA5; + measureData_photo.sensor_type = 0x03; + measureData_photo.payload = sensors.photoSensor(); + transmissionModule.transmit(measureData_photo); + + delay(100); + + MeasureData measureData_vibro; + measureData_vibro.sensor_id = 0xA5; + measureData_vibro.sensor_type = 0x04; + measureData_vibro.payload = sensors.photoSensor(); + transmissionModule.transmit(measureData_vibro); + + delay(100); + Serial.print(sensors.humiditySensor(), DEC); Serial.print(" "); Serial.print(sensors.temperatureSensor(), DEC); @@ -30,6 +58,6 @@ void loop() { Serial.print(sensors.photoSensor(), DEC); Serial.print(" "); Serial.println(sensors.vibroSensor(), DEC); - transmissionModule.transmit(measureData); + delay(100); } \ No newline at end of file