commit fccbe2247e9e658c1cff4c3ffa16f47a1df59d11 Author: Jens True Date: Sat Mar 23 15:48:17 2019 +0100 Initial import diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6c97aa4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.pioenvs +.piolibdeps +data/homie/config.json +nbproject diff --git a/README.md b/README.md new file mode 100644 index 0000000..5e80006 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# README # +edit data/homie/config.json +platformio run -t upload +platformio run -t uploadfs \ No newline at end of file diff --git a/data/homie/ui_bundle.gz b/data/homie/ui_bundle.gz new file mode 100644 index 0000000..3ef3bd5 Binary files /dev/null and b/data/homie/ui_bundle.gz differ diff --git a/lib/readme.txt b/lib/readme.txt new file mode 100644 index 0000000..b06c940 --- /dev/null +++ b/lib/readme.txt @@ -0,0 +1,38 @@ + +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 organised `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 +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +See additional options for PlatformIO Library Dependency Finder `lib_*`: + +http://docs.platformio.org/en/latest/projectconf.html#lib-install + diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..8720c4d --- /dev/null +++ b/platformio.ini @@ -0,0 +1,27 @@ +# +# Project Configuration File +# +# A detailed documentation with the EXAMPLES is located here: +# http://docs.platformio.org/en/latest/projectconf.html +# + +# A sign `#` at the beginning of the line indicates a comment +# Comment lines are ignored. + +# Simple and base environment +# [env:mybaseenv] +# platform = %INSTALLED_PLATFORM_NAME_HERE% +# framework = +# board = +# +# Automatic targets - enable auto-uploading +# targets = upload + +[env:nodemcu] +platform = espressif8266 +framework = arduino +board = nodemcu +upload_speed=921600 + +build_flags = -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY +lib_deps = https://github.com/homieiot/homie-esp8266.git#develop diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..1bdd5cb --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,42 @@ +#include + +const int PIN_RELAY = D1; +int timer = 0; +HomieNode powerNode("power", "switch"); + +bool powerOnHandler(const HomieRange& range, const String& value) { + if (value != "true" && value != "false") return false; + bool on = (value == "true"); + digitalWrite(PIN_RELAY, on ? LOW : HIGH); + powerNode.setProperty("on").send(value); + Homie.getLogger() << "Power is " << (on ? "on" : "off") << endl; + + return true; +} + +void setupHandler() { + pinMode(PIN_RELAY, OUTPUT); + digitalWrite(PIN_RELAY, HIGH); + + powerNode.setProperty("on").send("false"); +} + +void setup() { + Serial.begin(115200); + + Serial << endl << endl; + Serial << "Firmware 0.0.1" << endl; + Serial << endl << endl; + + Homie_setFirmware("deskcontrol", "1.0.0"); + Homie_setBrand("FuryFire"); + + powerNode.advertise("on").settable(powerOnHandler); + + Homie.setSetupFunction(setupHandler); + Homie.setup(); +} + +void loop() { + Homie.loop(); +} \ No newline at end of file