diff --git a/code-snippets/client/DRS26/Example_forte_libary/client/.gitignore b/code-snippets/client/DRS26/Example_forte_libary/client/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6dea8206d255251b692bc51b06adced35f789ce8 --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/client/.gitignore @@ -0,0 +1,6 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch +!lib/ diff --git a/code-snippets/client/DRS26/Example_forte_libary/client/.vscode/extensions.json b/code-snippets/client/DRS26/Example_forte_libary/client/.vscode/extensions.json new file mode 100644 index 0000000000000000000000000000000000000000..080e70d08b9811fa743afe5094658dba0ed6b7c2 --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/client/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/code-snippets/client/DRS26/Example_forte_libary/client/include/README b/code-snippets/client/DRS26/Example_forte_libary/client/include/README new file mode 100644 index 0000000000000000000000000000000000000000..194dcd43252dcbeb2044ee38510415041a0e7b47 --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/client/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/code-snippets/client/DRS26/Example_forte_libary/client/include/forte_sensor.hpp b/code-snippets/client/DRS26/Example_forte_libary/client/include/forte_sensor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8e030b9403653c40c5eecfca88edab96e805631d --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/client/include/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/code-snippets/client/DRS26/Example_forte_libary/client/include/pinout.hpp b/code-snippets/client/DRS26/Example_forte_libary/client/include/pinout.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7de77a4b3aab0cc8559c510091fd238db43b729d --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/client/include/pinout.hpp @@ -0,0 +1,8 @@ +#ifndef _FORTE_PINOUT +#define _FORTE_PINOUT + +// Pins for I2C +#define I2C_SDA 18 +#define I2C_SCL 19 +#define SDI_DATA 8 +#endif \ No newline at end of file diff --git a/code-snippets/client/DRS26/Example_forte_libary/client/lib/README b/code-snippets/client/DRS26/Example_forte_libary/client/lib/README new file mode 100644 index 0000000000000000000000000000000000000000..6debab1e8b4c3faa0d06f4ff44bce343ce2cdcbf --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/client/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include <Foo.h> +#include <Bar.h> + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/code-snippets/client/DRS26/Example_forte_libary/client/lib/drs26_digital/drs26.cpp b/code-snippets/client/DRS26/Example_forte_libary/client/lib/drs26_digital/drs26.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cd344e36ebfb30c96929181d4c0cf6f93c2a8e98 --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/client/lib/drs26_digital/drs26.cpp @@ -0,0 +1,42 @@ +#include <drs26.hpp> +#include <pinout.hpp> +#include "Wire.h" + +/* +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 *Forte_DRS26 ::read_data() +{ + String sdiResponse = ""; + drs26.sendCommand("1M!"); + delay(1000); + drs26.sendCommand("1D0!"); + + while (drs26.available()) + { + char c = drs26.read(); + if ((c != '\n') && (c != '\r')) + { + sdiResponse += c; + 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/code-snippets/client/DRS26/Example_forte_libary/client/lib/drs26_digital/drs26.hpp b/code-snippets/client/DRS26/Example_forte_libary/client/lib/drs26_digital/drs26.hpp new file mode 100644 index 0000000000000000000000000000000000000000..97bca378fbdc9c1c5420e5646fcc083e40e9919a --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/client/lib/drs26_digital/drs26.hpp @@ -0,0 +1,28 @@ +#ifndef _INA219 +#define _INA219 + +#include <forte_sensor.hpp> +#include <pinout.hpp> +#include <SparkFun_SCD30_Arduino_Library.h> +#include <INA219_WE.h> +#include <SDI12.h> + + +struct out_data { + int id; + float circumference; + float temperatur; + }; + + +class Forte_DRS26 : public Forte_Sensor{ + public: + void setup(); + out_data* read_data(); + + private: + SDI12 drs26; + out_data data; +}; + +#endif \ No newline at end of file diff --git a/code-snippets/client/DRS26/Example_forte_libary/client/lib/drs26_digital/forte_sensor.hpp b/code-snippets/client/DRS26/Example_forte_libary/client/lib/drs26_digital/forte_sensor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8e030b9403653c40c5eecfca88edab96e805631d --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/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/code-snippets/client/DRS26/Example_forte_libary/client/lib/drs26_digital/pinout.hpp b/code-snippets/client/DRS26/Example_forte_libary/client/lib/drs26_digital/pinout.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4c284359487510b4740a2ac4b555e4fa19b68d05 --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/client/lib/drs26_digital/pinout.hpp @@ -0,0 +1,8 @@ +#ifndef _FORTE_PINOUT +#define _FORTE_PINOUT + +// Pins for I2C +#define I2C_SDA 5 +#define I2C_SCL 4 +#define SDI_DATA 8 +#endif \ No newline at end of file diff --git a/code-snippets/client/DRS26/Example_forte_libary/client/lib/ina219/forte_sensor.hpp b/code-snippets/client/DRS26/Example_forte_libary/client/lib/ina219/forte_sensor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8e030b9403653c40c5eecfca88edab96e805631d --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/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/code-snippets/client/DRS26/Example_forte_libary/client/lib/ina219/ina219.cpp b/code-snippets/client/DRS26/Example_forte_libary/client/lib/ina219/ina219.cpp new file mode 100644 index 0000000000000000000000000000000000000000..df1fa146bc49b7e1f824bec42e7e860c260cd6b1 --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/client/lib/ina219/ina219.cpp @@ -0,0 +1,28 @@ +#include "ina219.hpp" +#include "Wire.h" +#include <SparkFun_SCD30_Arduino_Library.h> +#include <INA219_WE.h> + +void Forte_INA219 :: setup(){ + Wire.begin(I2C_SDA, I2C_SCL); + if(!ina219.init()){ + // Sensor init went wrong + return; + } +} + +out_data* 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/code-snippets/client/DRS26/Example_forte_libary/client/lib/ina219/ina219.hpp b/code-snippets/client/DRS26/Example_forte_libary/client/lib/ina219/ina219.hpp new file mode 100644 index 0000000000000000000000000000000000000000..91b8c4ba9edf1b6603737e8c0b7aa777b5e1594a --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/client/lib/ina219/ina219.hpp @@ -0,0 +1,30 @@ +#ifndef _INA219 +#define _INA219 + +#include <forte_sensor.hpp> +#include <pinout.hpp> +#include <SparkFun_SCD30_Arduino_Library.h> +#include <INA219_WE.h> + + +struct out_data { + 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* read_data(); + + private: + INA219_WE ina219; + out_data data; +}; + +#endif \ No newline at end of file diff --git a/code-snippets/client/DRS26/Example_forte_libary/client/lib/ina219/pinout.hpp b/code-snippets/client/DRS26/Example_forte_libary/client/lib/ina219/pinout.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9d336e45e266d1952527918387a8d36679bc3ae4 --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/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/code-snippets/client/DRS26/Example_forte_libary/client/lib/scd30/forte_sensor.hpp b/code-snippets/client/DRS26/Example_forte_libary/client/lib/scd30/forte_sensor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8e030b9403653c40c5eecfca88edab96e805631d --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/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/code-snippets/client/DRS26/Example_forte_libary/client/lib/scd30/pinout.hpp b/code-snippets/client/DRS26/Example_forte_libary/client/lib/scd30/pinout.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9a9ad92494f6fda373d184ef94f91d17934e01ba --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/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 diff --git a/code-snippets/client/DRS26/Example_forte_libary/client/lib/scd30/scd30.cpp b/code-snippets/client/DRS26/Example_forte_libary/client/lib/scd30/scd30.cpp new file mode 100644 index 0000000000000000000000000000000000000000..84276568291b2d87c23222bf57e286cf7f5ab03b --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/client/lib/scd30/scd30.cpp @@ -0,0 +1,24 @@ +#include "scd30.hpp" +#include "Wire.h" +#include <SparkFun_SCD30_Arduino_Library.h> + +void Forte_SCD30 :: setup(){ + Wire.begin(I2C_SDA, I2C_SCL); + if(!airSensor.begin()){ + // Sensor init went wrong + return; + } +} + +float* Forte_SCD30 :: read_data(){ + if(airSensor.dataAvailable()) + { + data1[0] = airSensor.getCO2(); + data1[1] = airSensor.getTemperature(); + data1[2] = airSensor.getHumidity(); + + return data1; + } + else + return 0; +} \ No newline at end of file diff --git a/code-snippets/client/DRS26/Example_forte_libary/client/lib/scd30/scd30.hpp b/code-snippets/client/DRS26/Example_forte_libary/client/lib/scd30/scd30.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a95ab8ea5467e932f4a2bd47b872acf1024cd87b --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/client/lib/scd30/scd30.hpp @@ -0,0 +1,18 @@ +#ifndef _SCD30 +#define _SCD30 + +#include <forte_sensor.hpp> +#include <pinout.hpp> +#include <SparkFun_SCD30_Arduino_Library.h> + +class Forte_SCD30 : public Forte_Sensor{ + public: + void setup(); + float* read_data(); + + private: + SCD30 airSensor; + float data1[3]; +}; + +#endif \ No newline at end of file diff --git a/code-snippets/client/DRS26/Example_forte_libary/client/platformio.ini b/code-snippets/client/DRS26/Example_forte_libary/client/platformio.ini new file mode 100644 index 0000000000000000000000000000000000000000..774bd23457cc773cf1c6b4adfc4cd74961e766a9 --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/client/platformio.ini @@ -0,0 +1,19 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:esp32-c3-devkitm-1] +platform = espressif32 +board = esp32-c3-devkitm-1 +framework = arduino +lib_deps = + sparkfun/SparkFun SCD30 Arduino Library@^1.0.18 + Wire + wollewald/INA219_WE@^1.3.1 + envirodiy/SDI-12@^2.1.4 diff --git a/code-snippets/client/DRS26/Example_forte_libary/client/src/main.cpp b/code-snippets/client/DRS26/Example_forte_libary/client/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..61deff619b1c3a50354903552ce593953ddc0c92 --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/client/src/main.cpp @@ -0,0 +1,34 @@ + +#include <Arduino.h> + +#include <drs26.hpp> + +Forte_DRS26 sensor1; + +void setup() { + + Serial.begin(9600); + sensor1.setup(); +} + +void loop() { + + out_data* data; + sensor1.read_data(); + + data = sensor1.read_data(); + + if(data==0) + { + Serial.println("Waiting for data"); + } + else{ + Serial.print("Sensor ID "); Serial.println(data->id); + Serial.print("Cicumfence "); Serial.println(data->circumference); + Serial.print("Temperature "); Serial.println(data->temperatur); + Serial.println(); + } + delay(5000); + +} + diff --git a/code-snippets/client/DRS26/Example_forte_libary/client/test/README b/code-snippets/client/DRS26/Example_forte_libary/client/test/README new file mode 100644 index 0000000000000000000000000000000000000000..9b1e87bc67c90e7f09a92a3e855444b085c655a6 --- /dev/null +++ b/code-snippets/client/DRS26/Example_forte_libary/client/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html diff --git a/code-snippets/client/DRS26/Example_forte_libary/drs26_breadboard.png b/code-snippets/client/DRS26/Example_forte_libary/drs26_breadboard.png new file mode 100644 index 0000000000000000000000000000000000000000..f92d811bc6abc726a47edf07774ada8e1c4f4a09 Binary files /dev/null and b/code-snippets/client/DRS26/Example_forte_libary/drs26_breadboard.png differ