From c82e3a894d1716cf99f5500a50ca0ff3bb1658df Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer <reinhold@kainhofer.com> Date: Sat, 22 Jul 2017 01:28:49 +0200 Subject: [PATCH] Update for PlatformIO --- .gitignore | 4 ++ NodeManager_GasSensor.ino | 91 +++++++++++++++++++++++++++++++++++++++ lib/readme.txt | 36 ++++++++++++++++ platformio.ini | 19 ++++++++ 4 files changed, 150 insertions(+) create mode 100644 NodeManager_GasSensor.ino create mode 100644 lib/readme.txt create mode 100644 platformio.ini diff --git a/.gitignore b/.gitignore index 126fc83..918d2c7 100755 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ *~ *.tmp *.part +.pioenvs +.piolibdeps +.clang_complete +.gcc-flags.json diff --git a/NodeManager_GasSensor.ino b/NodeManager_GasSensor.ino new file mode 100644 index 0000000..1301d1f --- /dev/null +++ b/NodeManager_GasSensor.ino @@ -0,0 +1,91 @@ +/* +NodeManager is intended to take care on your behalf of all those common tasks a MySensors node has to accomplish, speeding up the development cycle of your projects. + +NodeManager includes the following main components: +- Sleep manager: allows managing automatically the complexity behind battery-powered sensors spending most of their time sleeping +- Power manager: allows powering on your sensors only while the node is awake +- Battery manager: provides common functionalities to read and report the battery level +- Remote configuration: allows configuring remotely the node without the need to have physical access to it +- Built-in personalities: for the most common sensors, provide embedded code so to allow their configuration with a single line + +Documentation available on: https://github.com/mysensors/NodeManager + */ + + +// load user settings +#include "config.h" +// include supporting libraries +#ifdef MY_GATEWAY_ESP8266 + #include <ESP8266WiFi.h> +#endif +// load MySensors library +#include <MySensors.h> +// load NodeManager library +#include "NodeManager.h" + +// create a NodeManager instance +NodeManager nodeManager; + +// before +void before() { + // setup the serial port baud rate + Serial.println(F("BEFORE")); + printFM(); + Serial.begin(MY_BAUD_RATE); + /* + * Register below your sensors + */ + nodeManager.setSleep(SLEEP, 2, MINUTES); + Serial.print(F("BEFORE registerSensor0: ")); printFM(); + nodeManager.registerSensor(SENSOR_MQ, A0, 0); + Serial.print(F("BEFORE registerSensor1: ")); printFM(); + nodeManager.registerSensor(SENSOR_MQ, A1, 1); + Serial.print(F("BEFORE registerSensor2: ")); printFM(); + nodeManager.registerSensor(SENSOR_MQ, A2, 2); + Serial.print(F("BEFORE registerSensor3: ")); printFM(); + nodeManager.registerSensor(SENSOR_MQ, A3, 3); + Serial.print(F("BEFORE reg.Sens. MHZ19: ")); printFM(); + + int co2 = nodeManager.registerSensor(SENSOR_MHZ19, 6, 4); + SensorMHZ19* co2Sensor = ((SensorMHZ19*)nodeManager.getSensor(co2)); + co2Sensor->setRxTx(6, 7); + Serial.print(F("AFTER reg. sensors: "));printFM(); + + /* + * Register above your sensors + */ + nodeManager.before(); +} + +// presentation +void presentation() { + // call NodeManager presentation routine + nodeManager.presentation(); +} + +// setup +void setup() { + // call NodeManager setup routine + nodeManager.setup(); +} + +// loop +void loop() { + // call NodeManager loop routine + nodeManager.loop(); + +} + +// receive +void receive(const MyMessage &message) { + // call NodeManager receive routine + nodeManager.receive(message); +} + +// receiveTime +void receiveTime(unsigned long ts) { + // call NodeManager receiveTime routine + nodeManager.receiveTime(ts); +} + + diff --git a/lib/readme.txt b/lib/readme.txt new file mode 100644 index 0000000..dbadc3d --- /dev/null +++ b/lib/readme.txt @@ -0,0 +1,36 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include <Foo.h> +#include <Bar.h> + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +More information about PlatformIO Library Dependency Finder +- http://docs.platformio.org/page/librarymanager/ldf.html diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..3c97f47 --- /dev/null +++ b/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 +; http://docs.platformio.org/page/projectconf.html + +[platformio] +src_dir = . + +[env:nanoatmega328] +platform = atmelavr +board = nanoatmega328 +framework = arduino +lib_deps = MySensors +upload_port = /dev/ttyUSB1 -- GitLab