upload with drone pipeline, add json examples
This commit is contained in:
parent
66854190df
commit
8a554a75f0
26
gateway/.drone.yml
Normal file
26
gateway/.drone.yml
Normal file
@ -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
|
||||||
@ -7,3 +7,51 @@ It acts as a serial gateway and it is connected to a Raspberry Pi running Home a
|
|||||||
|
|
||||||
It uses an Arduino Pro Mini 5v 16 Mhz.
|
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/
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
@ -8,10 +8,9 @@
|
|||||||
; Please visit documentation for the other options and examples
|
; Please visit documentation for the other options and examples
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[env:uno]
|
[env:pro-mini]
|
||||||
platform = atmelavr
|
platform = atmelavr
|
||||||
board = uno
|
board = pro16MHzatmega328
|
||||||
board_build.mcu = atmega328p
|
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps =
|
lib_deps =
|
||||||
sui77/rc-switch@^2.6.3
|
sui77/rc-switch@^2.6.3
|
||||||
|
|||||||
@ -11,8 +11,7 @@
|
|||||||
|
|
||||||
#define READ_INTERVAL(c) (c*60*1000UL) // read interval in minutes
|
#define READ_INTERVAL(c) (c*60*1000UL) // read interval in minutes
|
||||||
|
|
||||||
const unsigned long readInterval = READ_INTERVAL(5);
|
unsigned long currentTime = 0;
|
||||||
unsigned long lastReadTime = -READ_INTERVAL(10);
|
|
||||||
|
|
||||||
RCSwitch mySwitch = RCSwitch();
|
RCSwitch mySwitch = RCSwitch();
|
||||||
DHT dht = DHT(DHT11_PIN, DHT11);
|
DHT dht = DHT(DHT11_PIN, DHT11);
|
||||||
@ -38,6 +37,7 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
currentTime = millis();
|
||||||
StaticJsonDocument<200> jsonDoc;
|
StaticJsonDocument<200> jsonDoc;
|
||||||
readCommand();
|
readCommand();
|
||||||
readRcSwitch(jsonDoc);
|
readRcSwitch(jsonDoc);
|
||||||
@ -126,9 +126,9 @@ void readCommand() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void readDht(JsonDocument& jsonDoc) {
|
void readDht(JsonDocument& jsonDoc) {
|
||||||
unsigned long currentTime = millis();
|
static unsigned long lastReadTime = 0;
|
||||||
if ((currentTime - lastReadTime) > readInterval) {
|
if (currentTime > lastReadTime) {
|
||||||
lastReadTime = currentTime;
|
lastReadTime = currentTime + READ_INTERVAL(5);
|
||||||
JsonObject dht11 = jsonDoc.createNestedObject("dht11");
|
JsonObject dht11 = jsonDoc.createNestedObject("dht11");
|
||||||
dht11["temperature"] = dht.readTemperature();
|
dht11["temperature"] = dht.readTemperature();
|
||||||
dht11["humidity"] = dht.readHumidity();
|
dht11["humidity"] = dht.readHumidity();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user