From 8a554a75f0220b7c701a41fd28f2b9a262254a90 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Sun, 20 Jun 2021 21:29:45 +0200 Subject: [PATCH] upload with drone pipeline, add json examples --- gateway/.drone.yml | 26 +++++++++++++++++++++ gateway/README.md | 50 ++++++++++++++++++++++++++++++++++++++++- gateway/platformio.ini | 5 ++--- gateway/src/gateway.cpp | 10 ++++----- 4 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 gateway/.drone.yml diff --git a/gateway/.drone.yml b/gateway/.drone.yml new file mode 100644 index 0000000..6d052a4 --- /dev/null +++ b/gateway/.drone.yml @@ -0,0 +1,26 @@ +--- +kind: pipeline +type: exec +name: upload gateway firmare + +platform: + os: linux + arch: arm + +steps: +- name: build + commands: + - pio run -e pro-mini + +- name: upload + commands: + - pio run -e pro-mini -t upload + +trigger: + branch: + - gateway + target: + - production + +node: + host: homebox diff --git a/gateway/README.md b/gateway/README.md index e8e94c9..216a099 100644 --- a/gateway/README.md +++ b/gateway/README.md @@ -6,4 +6,52 @@ It also supports receiving commands from the same protocol. It acts as a serial gateway and it is connected to a Raspberry Pi running Home assistant. It uses an Arduino Pro Mini 5v 16 Mhz. -The original bootloader has been replaced with Optiboot using this tutorial: https://andreasrohner.at/posts/Electronics/How-to-make-the-Watchdog-Timer-work-on-an-Arduino-Pro-Mini-by-replacing-the-bootloader/ \ No newline at end of file +The original bootloader has been replaced with Optiboot using this tutorial: https://andreasrohner.at/posts/Electronics/How-to-make-the-Watchdog-Timer-work-on-an-Arduino-Pro-Mini-by-replacing-the-bootloader/ + +## Read sensors +### DHT +``` +{ + "dht11": { + "temperature": 31.9, + "humidity": 45 + } +} +``` +### RC Switch +#### on +``` +[ + { + "rcSwitch": { + "protocol": 1, + "group": "00001", + "channel": 1, + "state": true + } + } +] +``` +#### off +``` +[ + { + "rcSwitch": { + "protocol": 1, + "group": "00001", + "channel": 1, + "state": false + } + } +] +``` +``` +[ + { + "rcSwitch": { + "protocol": 2, + "value": "10011110000000000001110101111001" + } + } +] +``` \ No newline at end of file diff --git a/gateway/platformio.ini b/gateway/platformio.ini index 39885e5..79ac733 100644 --- a/gateway/platformio.ini +++ b/gateway/platformio.ini @@ -8,10 +8,9 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -[env:uno] +[env:pro-mini] platform = atmelavr -board = uno -board_build.mcu = atmega328p +board = pro16MHzatmega328 framework = arduino lib_deps = sui77/rc-switch@^2.6.3 diff --git a/gateway/src/gateway.cpp b/gateway/src/gateway.cpp index 74cdc73..3eb7f5a 100644 --- a/gateway/src/gateway.cpp +++ b/gateway/src/gateway.cpp @@ -11,8 +11,7 @@ #define READ_INTERVAL(c) (c*60*1000UL) // read interval in minutes -const unsigned long readInterval = READ_INTERVAL(5); -unsigned long lastReadTime = -READ_INTERVAL(10); +unsigned long currentTime = 0; RCSwitch mySwitch = RCSwitch(); DHT dht = DHT(DHT11_PIN, DHT11); @@ -38,6 +37,7 @@ void setup() { } void loop() { + currentTime = millis(); StaticJsonDocument<200> jsonDoc; readCommand(); readRcSwitch(jsonDoc); @@ -126,9 +126,9 @@ void readCommand() { } void readDht(JsonDocument& jsonDoc) { - unsigned long currentTime = millis(); - if ((currentTime - lastReadTime) > readInterval) { - lastReadTime = currentTime; + static unsigned long lastReadTime = 0; + if (currentTime > lastReadTime) { + lastReadTime = currentTime + READ_INTERVAL(5); JsonObject dht11 = jsonDoc.createNestedObject("dht11"); dht11["temperature"] = dht.readTemperature(); dht11["humidity"] = dht.readHumidity();