diff --git a/.gitignore b/.gitignore index 88fc45a5d3e6393ec741bdcde9b09edfd146f48e..23b4089d3cc1f51224abf31302d6e238d622ddf4 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,7 @@ dist/ downloads/ eggs/ .eggs/ -lib/ +#lib/ // commented this out as to not always force add /lib in platformio project lib64/ parts/ sdist/ diff --git a/client/client/lib/I2C/I2C.cpp b/client/client/lib/I2C/I2C.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e293d48fd0fd44c55b4c07d1dedce2bf9f1fe2af --- /dev/null +++ b/client/client/lib/I2C/I2C.cpp @@ -0,0 +1,26 @@ +#include <Wire.h> +#include <SparkFun_SCD30_Arduino_Library.h> +#include "pinout.hpp" +#include "I2C.hpp" + +SCD30 airSensor; + +int i2c_setup(){ + Wire.begin(I2C_SDA, I2C_SCL); + if(!airSensor.begin()){ + return 1; + } + return 0; +} + +i2c_readout get_i2c_data(){ + if(airSensor.dataAvailable()){ + i2c_readout result; + result.co2 = airSensor.getCO2(); + result.temp = airSensor.getTemperature(); + result.humidity = airSensor.getHumidity(); + return result; + } + i2c_readout empty; // bad, remove this + return empty; +} \ No newline at end of file diff --git a/client/client/lib/I2C/I2C.hpp b/client/client/lib/I2C/I2C.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1c767d1f4f2c32043c02a0a8f2b0983b24b7e003 --- /dev/null +++ b/client/client/lib/I2C/I2C.hpp @@ -0,0 +1,8 @@ +typedef struct i2c_readout{ + float co2; + float temp; + float humidity; +} i2c_readout; + +int i2c_setup(); +i2c_readout get_i2c_data(); diff --git a/client/client/lib/I2C/pinout.hpp b/client/client/lib/I2C/pinout.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7385cac569f85223e14ccb084bfea970419e2e69 --- /dev/null +++ b/client/client/lib/I2C/pinout.hpp @@ -0,0 +1,2 @@ +#define I2C_SDA 18 +#define I2C_SCL 19 diff --git a/client/client/lib/espnow/src/espnow.hpp b/client/client/lib/espnow/src/espnow.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a32e7c9d5041a31c9ac2647030252f682828e60e --- /dev/null +++ b/client/client/lib/espnow/src/espnow.hpp @@ -0,0 +1,13 @@ +#include <string> +#define NUM_SENSORS 10 + +// I originally wanted to define the mac addresses here, but i got a "multiple definition" error? +typedef struct dataMessage{ + std::string identifiers[NUM_SENSORS]; + float values[NUM_SENSORS]; +}dataMessage; + +int send_data(dataMessage data); + +int espnow_setup(); + diff --git a/client/client/platformio.ini b/client/client/platformio.ini index ee508333132cfda864e7904a4bce39848398781c..aeb9e53bf932227a4e13d3252f4da94147a547dd 100644 --- a/client/client/platformio.ini +++ b/client/client/platformio.ini @@ -12,4 +12,5 @@ platform = espressif32 board = esp32-c3-devkitm-1 framework = arduino -monitor_speed = 115200 \ No newline at end of file +monitor_speed = 115200 +lib_deps = sparkfun/SparkFun SCD30 Arduino Library@^1.0.18 diff --git a/client/client/src/main.cpp b/client/client/src/main.cpp index 91da067ae710afa516736eee9e828bacd5627a23..e0d73dac7d692854cdf05435e356f5cfad56c520 100644 --- a/client/client/src/main.cpp +++ b/client/client/src/main.cpp @@ -1,5 +1,6 @@ #include <Arduino.h> #include "espnow.hpp" +#include "I2C.hpp" void setup() { @@ -7,9 +8,24 @@ void setup() { Serial.begin(115200); while(!Serial); - int result = espnow_setup(); + espnow_setup(); + i2c_setup(); } void loop() { // put your main code here, to run repeatedly: + i2c_readout data = get_i2c_data(); + dataMessage message; + message.identifiers[0] = "co2"; + message.identifiers[1] = "temp"; + message.identifiers[2] = "humid"; + + message.values[0] = data.co2; + message.values[1] = data.co2; + message.values[2] = data.humidity; + + send_data(message); + Serial.println("Message sent"); + + delay(3000); } \ No newline at end of file diff --git a/code-snippets/espnow/espNowTest/lib/README b/code-snippets/espnow/espNowTest/lib/README new file mode 100644 index 0000000000000000000000000000000000000000..6debab1e8b4c3faa0d06f4ff44bce343ce2cdcbf --- /dev/null +++ b/code-snippets/espnow/espNowTest/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