diff --git a/client/client/lib/drs26_digital/drs26.cpp b/client/client/lib/drs26_digital/drs26.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4c3378ae05042fcd0bdc89bc905060be97dcd99e --- /dev/null +++ b/client/client/lib/drs26_digital/drs26.cpp @@ -0,0 +1,42 @@ +#include <drs26.hpp> +/* +It happens for some reason that the sensor cant get reached every 2 time +Because the sensor use sdi12 protocoll we have to wait aproxemettly 1 secound between the commands +It is not known how lond the response takes so we use a while loop which can be a risk wehre the programm can get stuck +*/ + +void Forte_DRS26 ::setup() +{ + drs26.begin(SDI_DATA); +} + +out_data_drs26 *Forte_DRS26 ::read_data() +{ + String sdiResponse = ""; + String measurement_command="1M!"; //The drs26 sensor uses the sdi12 protocoll , in the sdi12 protocoll is the measurement command is specified as 1M!=Sebsir measurement request at adress 1 + String data_command="1D0!"; //and the followed data command 1D0! = Sensor data request at adress 1 + + drs26.sendCommand(measurement_command); + delay(1000); + drs26.sendCommand(data_command); + + while (drs26.available()) + { + char next_character = drs26.read(); + if ((next_character != '\n') && (next_character != '\r')) + { + sdiResponse += next_character; + delay(10); // 1 character ~ 7.5ms + } + } + + if (sdiResponse.length() > 1) + { + data.id = sdiResponse.substring(0, 8).toInt(); + data.circumference = sdiResponse.substring(9, 15).toFloat(); + data.temperatur = sdiResponse.substring(16, 22).toFloat(); + return &data; + } + + return 0; +} \ No newline at end of file diff --git a/client/client/lib/drs26_digital/drs26.hpp b/client/client/lib/drs26_digital/drs26.hpp new file mode 100644 index 0000000000000000000000000000000000000000..83d02ae0a5a5f88e556e1f4a811dc6510b122f98 --- /dev/null +++ b/client/client/lib/drs26_digital/drs26.hpp @@ -0,0 +1,27 @@ +#ifndef _DRS26 +#define _DRS26 + +#include <forte_sensor.hpp> +#include <SDI12.h> +#include <pinout.hpp> +#include "Wire.h" + + +struct out_data_drs26 { + int id; + float circumference; + float temperatur; + }; + + +class Forte_DRS26 : public Forte_Sensor{ + public: + void setup(); + out_data_drs26* read_data(); + + private: + SDI12 drs26; + out_data_drs26 data; +}; + +#endif \ No newline at end of file diff --git a/client/client/lib/drs26_digital/forte_sensor.hpp b/client/client/lib/drs26_digital/forte_sensor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8e030b9403653c40c5eecfca88edab96e805631d --- /dev/null +++ b/client/client/lib/drs26_digital/forte_sensor.hpp @@ -0,0 +1,13 @@ +#ifndef _FORTE_SENSOR +#define _FORTE_SENSOR + +class Forte_Sensor { + public: + virtual void* read_data() = 0; + virtual void setup() = 0; + + private: + +}; + +#endif \ No newline at end of file diff --git a/client/client/lib/drs26_digital/pinout.hpp b/client/client/lib/drs26_digital/pinout.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5ac8641a53a8d0718bfba0cdb1aedd53cf543b82 --- /dev/null +++ b/client/client/lib/drs26_digital/pinout.hpp @@ -0,0 +1,6 @@ +#ifndef _FORTE_PINOUT +#define _FORTE_PINOUT + +// Pins for SDI12 +#define SDI_DATA 8 +#endif \ No newline at end of file diff --git a/client/client/lib/ina219/forte_sensor.hpp b/client/client/lib/ina219/forte_sensor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8e030b9403653c40c5eecfca88edab96e805631d --- /dev/null +++ b/client/client/lib/ina219/forte_sensor.hpp @@ -0,0 +1,13 @@ +#ifndef _FORTE_SENSOR +#define _FORTE_SENSOR + +class Forte_Sensor { + public: + virtual void* read_data() = 0; + virtual void setup() = 0; + + private: + +}; + +#endif \ No newline at end of file diff --git a/client/client/lib/ina219/ina219.cpp b/client/client/lib/ina219/ina219.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7f4beb3527965f301f0f9c50679189958275220c --- /dev/null +++ b/client/client/lib/ina219/ina219.cpp @@ -0,0 +1,26 @@ +#include "ina219.hpp" + + +void Forte_INA219 :: setup(){ + Wire.begin(I2C_SDA, I2C_SCL); + if(!ina219.init()){ + // Sensor init went wrong + return; + } +} + +out_data_ina219* Forte_INA219 :: read_data(){ + if(!ina219.getOverflow()) + { + data.shuntVoltage_mV = ina219.getShuntVoltage_mV(); + data.busVoltage_V= ina219.getBusVoltage_V(); + data.current_mA= ina219.getCurrent_mA(); + data.power_mW= ina219.getBusPower(); + data.loadVoltage_V = data.busVoltage_V + (data.shuntVoltage_mV/1000); + data.ina219_overflow=ina219.getOverflow(); + + return &data; + } + else + return 0; +} \ No newline at end of file diff --git a/client/client/lib/ina219/ina219.hpp b/client/client/lib/ina219/ina219.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a975ba51978c825f33740d6a84aeb7bf4f96bcd6 --- /dev/null +++ b/client/client/lib/ina219/ina219.hpp @@ -0,0 +1,31 @@ +#ifndef _INA219 +#define _INA219 + +#include <forte_sensor.hpp> +#include <pinout.hpp> +#include <INA219_WE.h> +#include "Wire.h" + + + +struct out_data_ina219 { + float shuntVoltage_mV = 0.0; + float loadVoltage_V = 0.0; + float busVoltage_V = 0.0; + float current_mA = 0.0; + float power_mW = 0.0; + bool ina219_overflow = false; + }; + + +class Forte_INA219 : public Forte_Sensor{ + public: + void setup(); + out_data_ina219* read_data(); + + private: + INA219_WE ina219; + out_data_ina219 data; +}; + +#endif \ No newline at end of file diff --git a/client/client/lib/ina219/pinout.hpp b/client/client/lib/ina219/pinout.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9d336e45e266d1952527918387a8d36679bc3ae4 --- /dev/null +++ b/client/client/lib/ina219/pinout.hpp @@ -0,0 +1,8 @@ +#ifndef _FORTE_PINOUT +#define _FORTE_PINOUT + +// Pins for I2C +#define I2C_SDA 5 +#define I2C_SCL 4 + +#endif \ No newline at end of file diff --git a/client/client/lib/scd30/forte_sensor.hpp b/client/client/lib/scd30/forte_sensor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8e030b9403653c40c5eecfca88edab96e805631d --- /dev/null +++ b/client/client/lib/scd30/forte_sensor.hpp @@ -0,0 +1,13 @@ +#ifndef _FORTE_SENSOR +#define _FORTE_SENSOR + +class Forte_Sensor { + public: + virtual void* read_data() = 0; + virtual void setup() = 0; + + private: + +}; + +#endif \ No newline at end of file diff --git a/client/client/lib/scd30/pinout.hpp b/client/client/lib/scd30/pinout.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9a9ad92494f6fda373d184ef94f91d17934e01ba --- /dev/null +++ b/client/client/lib/scd30/pinout.hpp @@ -0,0 +1,8 @@ +#ifndef _FORTE_PINOUT +#define _FORTE_PINOUT + +// Pins for I2C +#define I2C_SDA 18 +#define I2C_SCL 19 + +#endif \ No newline at end of file