re-organize:
- move code for all devices in dedicated folder - move code for gateway in the root folder
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
.pio/
|
.pio/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
credentials.h
|
||||||
|
|||||||
187
README.md
@ -1,10 +1,183 @@
|
|||||||
# Gateway & sensors
|
# A gateway for 433 MHz devices
|
||||||
|
It uses [rc_switch](https://github.com/sui77/rc-switch) library for controlling wall sockets.
|
||||||
|
|
||||||
## Branches
|
It supports receiving:
|
||||||
Each sensor has a dedicated branch. E.g.:
|
- serial commands for controlling wall switches - all protocols
|
||||||
* temp_sensor
|
- RC commands from wall switches remotes - protocols 1 and 2
|
||||||
* oil_sensor
|
- sensors states over `Protocol 2`
|
||||||
|
|
||||||
The gateway uses `master` as the main branch. Other sensors' branches get merged once they are ready for production.
|
It acts as a serial gateway, communicating in JSON format, and it is connected to a Raspberry Pi running Home Assistant.
|
||||||
|
|
||||||
## Release flow
|
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/
|
||||||
|
|
||||||
|
## Receive RC
|
||||||
|
### Sensors
|
||||||
|
Sensors transmit state using `Protocol 2` and the gateway translates them into JSON over serial.
|
||||||
|
##### Protocol structure
|
||||||
|
```
|
||||||
|
STATE
|
||||||
|
|
|
||||||
|
1010|1|101010101|1010101010101|10101
|
||||||
|
----|-----------|-------------|-----
|
||||||
|
TYPE| VALUE | VCC | ID
|
||||||
|
```
|
||||||
|
##### Sensors types
|
||||||
|
```C++
|
||||||
|
enum SensorType : unsigned short {
|
||||||
|
GENERIC = 4,
|
||||||
|
HUMIDITY = 5,
|
||||||
|
TEMPERATURE = 6,
|
||||||
|
CONTACT = 7
|
||||||
|
};
|
||||||
|
```
|
||||||
|
##### Sensors IDs
|
||||||
|
```C++
|
||||||
|
enum SensorId : unsigned short {
|
||||||
|
WINDOW1 = 1,
|
||||||
|
WINDOW2 = 2,
|
||||||
|
WATER_SENSOR = 3,
|
||||||
|
TEMP_SENSOR = 4,
|
||||||
|
LIGHT_SENSOR = 5,
|
||||||
|
MOVEMENT_SENSOR = 6,
|
||||||
|
OIL_SENSOR = 7
|
||||||
|
};
|
||||||
|
```
|
||||||
|
#### Stairs temperature
|
||||||
|
##### Value and voltage
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"sensor": {
|
||||||
|
"id": 4,
|
||||||
|
"diagnostic": {
|
||||||
|
"voltage": 2.239
|
||||||
|
},
|
||||||
|
"temperature": 16.2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
##### Value only
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"sensor": {
|
||||||
|
"id": 4,
|
||||||
|
"temperature": 16.2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
#### Oil sensor
|
||||||
|
##### Value and voltage
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"sensor": {
|
||||||
|
"id": 7,
|
||||||
|
"diagnostic": {
|
||||||
|
"voltage": 4.282
|
||||||
|
},
|
||||||
|
"value": 13
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
### Switches
|
||||||
|
Gateway receives remote commands over RC Switch and translates them into JSON over serial
|
||||||
|
#### Protocol 1
|
||||||
|
##### on
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"rcSwitch": {
|
||||||
|
"protocol": 1,
|
||||||
|
"state": true,
|
||||||
|
"group": "1",
|
||||||
|
"channel": 1,
|
||||||
|
"raw_value": 5571921
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
##### off
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"rcSwitch": {
|
||||||
|
"protocol": 1,
|
||||||
|
"state": false,
|
||||||
|
"group": "1",
|
||||||
|
"channel": 1,
|
||||||
|
"raw_value": 5571921
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Protocol 2
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"rcSwitch": {
|
||||||
|
"protocol": 2,
|
||||||
|
"value": 2650807673
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Other protocols
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"rcSwitch": {
|
||||||
|
"protocol": 4,
|
||||||
|
"value": 1234567890
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
### DHT
|
||||||
|
Reads local DHT11 sensor and outputs JSON over serial
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"dht11": {
|
||||||
|
"temperature": 31.9,
|
||||||
|
"humidity": 45
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
---
|
||||||
|
## Receive commands
|
||||||
|
It receives commands over serial, in JSON format, and executes them.
|
||||||
|
#### Protocol 1
|
||||||
|
##### on
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"rcSwitch": {
|
||||||
|
"protocol": 1,
|
||||||
|
"group": "00001",
|
||||||
|
"channel": 1,
|
||||||
|
"state": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
##### off
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"rcSwitch": {
|
||||||
|
"protocol": 1,
|
||||||
|
"group": "00001",
|
||||||
|
"channel": 1,
|
||||||
|
"state": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Protocol 2
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"rcSwitch": {
|
||||||
|
"protocol": 2,
|
||||||
|
"value": "10010110000000000001110101111001"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Other protocols
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"rcSwitch": {
|
||||||
|
"protocol": 4,
|
||||||
|
"value": "010001101001100101110100"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
10
devices/README.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Gateway & sensors
|
||||||
|
|
||||||
|
## Branches
|
||||||
|
Each sensor has a dedicated branch. E.g.:
|
||||||
|
* temp_sensor
|
||||||
|
* oil_sensor
|
||||||
|
|
||||||
|
The gateway uses `master` as the main branch. Other sensors' branches get merged once they are ready for production.
|
||||||
|
|
||||||
|
## Release flow
|
||||||
|
Before Width: | Height: | Size: 211 KiB After Width: | Height: | Size: 211 KiB |
@ -14,7 +14,7 @@ board = attiny85
|
|||||||
framework = arduino
|
framework = arduino
|
||||||
build_src_filter = +<switch.cpp>
|
build_src_filter = +<switch.cpp>
|
||||||
lib_extra_dirs =
|
lib_extra_dirs =
|
||||||
../libraries
|
../../libraries
|
||||||
upload_protocol = stk500v1
|
upload_protocol = stk500v1
|
||||||
upload_flags =
|
upload_flags =
|
||||||
-P$UPLOAD_PORT
|
-P$UPLOAD_PORT
|
||||||
@ -31,4 +31,4 @@ lib_deps =
|
|||||||
teckel12/NewPing@^1.9.4
|
teckel12/NewPing@^1.9.4
|
||||||
sui77/rc-switch @ ^2.6.4
|
sui77/rc-switch @ ^2.6.4
|
||||||
lib_extra_dirs =
|
lib_extra_dirs =
|
||||||
../libraries
|
../../libraries
|
||||||
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
@ -17,7 +17,7 @@ lib_deps =
|
|||||||
adafruit/DHT sensor library@^1.4.3
|
adafruit/DHT sensor library@^1.4.3
|
||||||
sui77/rc-switch @ ^2.6.4
|
sui77/rc-switch @ ^2.6.4
|
||||||
lib_extra_dirs =
|
lib_extra_dirs =
|
||||||
../libraries
|
../../libraries
|
||||||
build_flags = -D DHT_SENSOR=0
|
build_flags = -D DHT_SENSOR=0
|
||||||
upload_protocol = stk500v1
|
upload_protocol = stk500v1
|
||||||
upload_flags =
|
upload_flags =
|
||||||
|
Before Width: | Height: | Size: 255 KiB After Width: | Height: | Size: 255 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 255 KiB After Width: | Height: | Size: 255 KiB |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
1
gateway/.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
include/credentials.h
|
|
||||||
@ -1,183 +0,0 @@
|
|||||||
# A gateway for 433 MHz devices
|
|
||||||
It uses [rc_switch](https://github.com/sui77/rc-switch) library for controlling wall sockets.
|
|
||||||
|
|
||||||
It supports receiving:
|
|
||||||
- serial commands for controlling wall switches - all protocols
|
|
||||||
- RC commands from wall switches remotes - protocols 1 and 2
|
|
||||||
- sensors states over `Protocol 2`
|
|
||||||
|
|
||||||
It acts as a serial gateway, communicating in JSON format, 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/
|
|
||||||
|
|
||||||
## Receive RC
|
|
||||||
### Sensors
|
|
||||||
Sensors transmit state using `Protocol 2` and the gateway translates them into JSON over serial.
|
|
||||||
##### Protocol structure
|
|
||||||
```
|
|
||||||
STATE
|
|
||||||
|
|
|
||||||
1010|1|101010101|1010101010101|10101
|
|
||||||
----|-----------|-------------|-----
|
|
||||||
TYPE| VALUE | VCC | ID
|
|
||||||
```
|
|
||||||
##### Sensors types
|
|
||||||
```C++
|
|
||||||
enum SensorType : unsigned short {
|
|
||||||
GENERIC = 4,
|
|
||||||
HUMIDITY = 5,
|
|
||||||
TEMPERATURE = 6,
|
|
||||||
CONTACT = 7
|
|
||||||
};
|
|
||||||
```
|
|
||||||
##### Sensors IDs
|
|
||||||
```C++
|
|
||||||
enum SensorId : unsigned short {
|
|
||||||
WINDOW1 = 1,
|
|
||||||
WINDOW2 = 2,
|
|
||||||
WATER_SENSOR = 3,
|
|
||||||
TEMP_SENSOR = 4,
|
|
||||||
LIGHT_SENSOR = 5,
|
|
||||||
MOVEMENT_SENSOR = 6,
|
|
||||||
OIL_SENSOR = 7
|
|
||||||
};
|
|
||||||
```
|
|
||||||
#### Stairs temperature
|
|
||||||
##### Value and voltage
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"sensor": {
|
|
||||||
"id": 4,
|
|
||||||
"diagnostic": {
|
|
||||||
"voltage": 2.239
|
|
||||||
},
|
|
||||||
"temperature": 16.2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
##### Value only
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"sensor": {
|
|
||||||
"id": 4,
|
|
||||||
"temperature": 16.2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
#### Oil sensor
|
|
||||||
##### Value and voltage
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"sensor": {
|
|
||||||
"id": 7,
|
|
||||||
"diagnostic": {
|
|
||||||
"voltage": 4.282
|
|
||||||
},
|
|
||||||
"value": 13
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
### Switches
|
|
||||||
Gateway receives remote commands over RC Switch and translates them into JSON over serial
|
|
||||||
#### Protocol 1
|
|
||||||
##### on
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"rcSwitch": {
|
|
||||||
"protocol": 1,
|
|
||||||
"state": true,
|
|
||||||
"group": "1",
|
|
||||||
"channel": 1,
|
|
||||||
"raw_value": 5571921
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
##### off
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"rcSwitch": {
|
|
||||||
"protocol": 1,
|
|
||||||
"state": false,
|
|
||||||
"group": "1",
|
|
||||||
"channel": 1,
|
|
||||||
"raw_value": 5571921
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Protocol 2
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"rcSwitch": {
|
|
||||||
"protocol": 2,
|
|
||||||
"value": 2650807673
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Other protocols
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"rcSwitch": {
|
|
||||||
"protocol": 4,
|
|
||||||
"value": 1234567890
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
### DHT
|
|
||||||
Reads local DHT11 sensor and outputs JSON over serial
|
|
||||||
```
|
|
||||||
{
|
|
||||||
"dht11": {
|
|
||||||
"temperature": 31.9,
|
|
||||||
"humidity": 45
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
---
|
|
||||||
## Receive commands
|
|
||||||
It receives commands over serial, in JSON format, and executes them.
|
|
||||||
#### Protocol 1
|
|
||||||
##### on
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"rcSwitch": {
|
|
||||||
"protocol": 1,
|
|
||||||
"group": "00001",
|
|
||||||
"channel": 1,
|
|
||||||
"state": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
##### off
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"rcSwitch": {
|
|
||||||
"protocol": 1,
|
|
||||||
"group": "00001",
|
|
||||||
"channel": 1,
|
|
||||||
"state": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Protocol 2
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"rcSwitch": {
|
|
||||||
"protocol": 2,
|
|
||||||
"value": "10010110000000000001110101111001"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Other protocols
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"rcSwitch": {
|
|
||||||
"protocol": 4,
|
|
||||||
"value": "010001101001100101110100"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
@ -13,7 +13,7 @@ default_envs = huzzah
|
|||||||
|
|
||||||
[env]
|
[env]
|
||||||
lib_extra_dirs =
|
lib_extra_dirs =
|
||||||
../libraries
|
./libraries
|
||||||
lib_deps =
|
lib_deps =
|
||||||
sui77/rc-switch@^2.6.4
|
sui77/rc-switch@^2.6.4
|
||||||
bblanchon/ArduinoJson@6.21.5
|
bblanchon/ArduinoJson@6.21.5
|
||||||
@ -1,22 +1,17 @@
|
|||||||
{
|
{
|
||||||
"folders": [
|
"folders": [
|
||||||
{
|
{
|
||||||
"path": "gateway"
|
"path": "."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "temp_sensor",
|
"path": "devices/temp_sensor"
|
||||||
"path": "temp_sensor"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "libraries"
|
"path": "devices/oil_sensor"
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "oil_sensor"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"*.yaml": "esphome",
|
|
||||||
"functional": "cpp",
|
"functional": "cpp",
|
||||||
"queue": "cpp",
|
"queue": "cpp",
|
||||||
"array": "cpp",
|
"array": "cpp",
|
||||||
|
|||||||