diff --git a/.gitignore b/.gitignore index 968a41b..2cb2faa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .pio/ .vscode/ +credentials.h diff --git a/README.md b/README.md index 810d518..be137bd 100644 --- a/README.md +++ b/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 -Each sensor has a dedicated branch. E.g.: -* temp_sensor -* oil_sensor +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` -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" + } +} +``` diff --git a/devices/README.md b/devices/README.md new file mode 100644 index 0000000..810d518 --- /dev/null +++ b/devices/README.md @@ -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 diff --git a/lamp_switch/lamp_switch.ino b/devices/lamp_switch/lamp_switch.ino similarity index 100% rename from lamp_switch/lamp_switch.ino rename to devices/lamp_switch/lamp_switch.ino diff --git a/light_sensor/light_sensor.ino b/devices/light_sensor/light_sensor.ino similarity index 100% rename from light_sensor/light_sensor.ino rename to devices/light_sensor/light_sensor.ino diff --git a/movement_sensor/movement_sensor.ino b/devices/movement_sensor/movement_sensor.ino similarity index 100% rename from movement_sensor/movement_sensor.ino rename to devices/movement_sensor/movement_sensor.ino diff --git a/oil_sensor/.gitignore b/devices/oil_sensor/.gitignore similarity index 100% rename from oil_sensor/.gitignore rename to devices/oil_sensor/.gitignore diff --git a/oil_sensor/README.md b/devices/oil_sensor/README.md similarity index 100% rename from oil_sensor/README.md rename to devices/oil_sensor/README.md diff --git a/oil_sensor/docs/oil_sensor.fzz b/devices/oil_sensor/docs/oil_sensor.fzz similarity index 100% rename from oil_sensor/docs/oil_sensor.fzz rename to devices/oil_sensor/docs/oil_sensor.fzz diff --git a/oil_sensor/docs/oil_sensor_bb.png b/devices/oil_sensor/docs/oil_sensor_bb.png similarity index 100% rename from oil_sensor/docs/oil_sensor_bb.png rename to devices/oil_sensor/docs/oil_sensor_bb.png diff --git a/gateway/include/README b/devices/oil_sensor/include/README similarity index 100% rename from gateway/include/README rename to devices/oil_sensor/include/README diff --git a/oil_sensor/include/SonarSensor.h b/devices/oil_sensor/include/SonarSensor.h similarity index 100% rename from oil_sensor/include/SonarSensor.h rename to devices/oil_sensor/include/SonarSensor.h diff --git a/gateway/lib/README b/devices/oil_sensor/lib/README similarity index 100% rename from gateway/lib/README rename to devices/oil_sensor/lib/README diff --git a/oil_sensor/platformio.ini b/devices/oil_sensor/platformio.ini similarity index 95% rename from oil_sensor/platformio.ini rename to devices/oil_sensor/platformio.ini index a6e74fd..4c52322 100644 --- a/oil_sensor/platformio.ini +++ b/devices/oil_sensor/platformio.ini @@ -14,7 +14,7 @@ board = attiny85 framework = arduino build_src_filter = + lib_extra_dirs = - ../libraries + ../../libraries upload_protocol = stk500v1 upload_flags = -P$UPLOAD_PORT @@ -31,4 +31,4 @@ lib_deps = teckel12/NewPing@^1.9.4 sui77/rc-switch @ ^2.6.4 lib_extra_dirs = - ../libraries + ../../libraries diff --git a/oil_sensor/src/oil_sensor.cpp b/devices/oil_sensor/src/oil_sensor.cpp similarity index 100% rename from oil_sensor/src/oil_sensor.cpp rename to devices/oil_sensor/src/oil_sensor.cpp diff --git a/oil_sensor/src/switch.cpp b/devices/oil_sensor/src/switch.cpp similarity index 100% rename from oil_sensor/src/switch.cpp rename to devices/oil_sensor/src/switch.cpp diff --git a/gateway/test/README b/devices/oil_sensor/test/README similarity index 100% rename from gateway/test/README rename to devices/oil_sensor/test/README diff --git a/pre_filter/pre_filter.ino b/devices/pre_filter/pre_filter.ino similarity index 100% rename from pre_filter/pre_filter.ino rename to devices/pre_filter/pre_filter.ino diff --git a/temp_sensor/.gitignore b/devices/temp_sensor/.gitignore similarity index 100% rename from temp_sensor/.gitignore rename to devices/temp_sensor/.gitignore diff --git a/temp_sensor/README.md b/devices/temp_sensor/README.md similarity index 100% rename from temp_sensor/README.md rename to devices/temp_sensor/README.md diff --git a/temp_sensor/docs/temp_sensor.fzz b/devices/temp_sensor/docs/temp_sensor.fzz similarity index 100% rename from temp_sensor/docs/temp_sensor.fzz rename to devices/temp_sensor/docs/temp_sensor.fzz diff --git a/temp_sensor/docs/temp_sensor_bb.png b/devices/temp_sensor/docs/temp_sensor_bb.png similarity index 100% rename from temp_sensor/docs/temp_sensor_bb.png rename to devices/temp_sensor/docs/temp_sensor_bb.png diff --git a/temp_sensor/include/Dht22Sensor.h b/devices/temp_sensor/include/Dht22Sensor.h similarity index 100% rename from temp_sensor/include/Dht22Sensor.h rename to devices/temp_sensor/include/Dht22Sensor.h diff --git a/oil_sensor/include/README b/devices/temp_sensor/include/README similarity index 100% rename from oil_sensor/include/README rename to devices/temp_sensor/include/README diff --git a/temp_sensor/include/TempSensor.h b/devices/temp_sensor/include/TempSensor.h similarity index 100% rename from temp_sensor/include/TempSensor.h rename to devices/temp_sensor/include/TempSensor.h diff --git a/temp_sensor/include/Tmp36Sensor.h b/devices/temp_sensor/include/Tmp36Sensor.h similarity index 100% rename from temp_sensor/include/Tmp36Sensor.h rename to devices/temp_sensor/include/Tmp36Sensor.h diff --git a/oil_sensor/lib/README b/devices/temp_sensor/lib/README similarity index 100% rename from oil_sensor/lib/README rename to devices/temp_sensor/lib/README diff --git a/temp_sensor/platformio.ini b/devices/temp_sensor/platformio.ini similarity index 97% rename from temp_sensor/platformio.ini rename to devices/temp_sensor/platformio.ini index 64c02f2..5b3028a 100644 --- a/temp_sensor/platformio.ini +++ b/devices/temp_sensor/platformio.ini @@ -17,7 +17,7 @@ lib_deps = adafruit/DHT sensor library@^1.4.3 sui77/rc-switch @ ^2.6.4 lib_extra_dirs = - ../libraries + ../../libraries build_flags = -D DHT_SENSOR=0 upload_protocol = stk500v1 upload_flags = diff --git a/temp_sensor/src/temp_sensor.cpp b/devices/temp_sensor/src/temp_sensor.cpp similarity index 100% rename from temp_sensor/src/temp_sensor.cpp rename to devices/temp_sensor/src/temp_sensor.cpp diff --git a/oil_sensor/test/README b/devices/temp_sensor/test/README similarity index 100% rename from oil_sensor/test/README rename to devices/temp_sensor/test/README diff --git a/water_sensor/water_sensor.ino b/devices/water_sensor/water_sensor.ino similarity index 100% rename from water_sensor/water_sensor.ino rename to devices/water_sensor/water_sensor.ino diff --git a/window1/README.md b/devices/window1/README.md similarity index 100% rename from window1/README.md rename to devices/window1/README.md diff --git a/window1/examples/rf24-sender.ino b/devices/window1/examples/rf24-sender.ino similarity index 100% rename from window1/examples/rf24-sender.ino rename to devices/window1/examples/rf24-sender.ino diff --git a/window1/wiki/breadboard.png b/devices/window1/wiki/breadboard.png similarity index 100% rename from window1/wiki/breadboard.png rename to devices/window1/wiki/breadboard.png diff --git a/window1/wiki/schema.png b/devices/window1/wiki/schema.png similarity index 100% rename from window1/wiki/schema.png rename to devices/window1/wiki/schema.png diff --git a/window1/wiki/window1.fzz b/devices/window1/wiki/window1.fzz similarity index 100% rename from window1/wiki/window1.fzz rename to devices/window1/wiki/window1.fzz diff --git a/window1/window1.ino b/devices/window1/window1.ino similarity index 100% rename from window1/window1.ino rename to devices/window1/window1.ino diff --git a/window2/README.md b/devices/window2/README.md similarity index 100% rename from window2/README.md rename to devices/window2/README.md diff --git a/window2/wiki/breadboard.png b/devices/window2/wiki/breadboard.png similarity index 100% rename from window2/wiki/breadboard.png rename to devices/window2/wiki/breadboard.png diff --git a/window2/wiki/schema.png b/devices/window2/wiki/schema.png similarity index 100% rename from window2/wiki/schema.png rename to devices/window2/wiki/schema.png diff --git a/window2/wiki/window2.fzz b/devices/window2/wiki/window2.fzz similarity index 100% rename from window2/wiki/window2.fzz rename to devices/window2/wiki/window2.fzz diff --git a/window2/window2.ino b/devices/window2/window2.ino similarity index 100% rename from window2/window2.ino rename to devices/window2/window2.ino diff --git a/gateway/.gitignore b/gateway/.gitignore deleted file mode 100644 index 20133f8..0000000 --- a/gateway/.gitignore +++ /dev/null @@ -1 +0,0 @@ -include/credentials.h diff --git a/gateway/README.md b/gateway/README.md deleted file mode 100644 index be137bd..0000000 --- a/gateway/README.md +++ /dev/null @@ -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" - } -} -``` diff --git a/gateway/include/Dht.h b/include/Dht.h similarity index 100% rename from gateway/include/Dht.h rename to include/Dht.h diff --git a/gateway/include/Protocol.h b/include/Protocol.h similarity index 100% rename from gateway/include/Protocol.h rename to include/Protocol.h diff --git a/gateway/include/Protocol_1.h b/include/Protocol_1.h similarity index 100% rename from gateway/include/Protocol_1.h rename to include/Protocol_1.h diff --git a/gateway/include/Protocol_2.h b/include/Protocol_2.h similarity index 100% rename from gateway/include/Protocol_2.h rename to include/Protocol_2.h diff --git a/gateway/include/Protocol_Doorbell.h b/include/Protocol_Doorbell.h similarity index 100% rename from gateway/include/Protocol_Doorbell.h rename to include/Protocol_Doorbell.h diff --git a/temp_sensor/include/README b/include/README similarity index 100% rename from temp_sensor/include/README rename to include/README diff --git a/gateway/include/RcDecoder.h b/include/RcDecoder.h similarity index 100% rename from gateway/include/RcDecoder.h rename to include/RcDecoder.h diff --git a/gateway/include/TinyComponent.h b/include/TinyComponent.h similarity index 100% rename from gateway/include/TinyComponent.h rename to include/TinyComponent.h diff --git a/gateway/include/devices.h b/include/devices.h similarity index 100% rename from gateway/include/devices.h rename to include/devices.h diff --git a/gateway/include/huzzah.h b/include/huzzah.h similarity index 100% rename from gateway/include/huzzah.h rename to include/huzzah.h diff --git a/gateway/include/output.h b/include/output.h similarity index 100% rename from gateway/include/output.h rename to include/output.h diff --git a/gateway/include/pins.h b/include/pins.h similarity index 100% rename from gateway/include/pins.h rename to include/pins.h diff --git a/gateway/include/pro-mini.h b/include/pro-mini.h similarity index 100% rename from gateway/include/pro-mini.h rename to include/pro-mini.h diff --git a/temp_sensor/lib/README b/lib/README similarity index 100% rename from temp_sensor/lib/README rename to lib/README diff --git a/gateway/platformio.ini b/platformio.ini similarity index 98% rename from gateway/platformio.ini rename to platformio.ini index cea1959..271178c 100644 --- a/gateway/platformio.ini +++ b/platformio.ini @@ -13,7 +13,7 @@ default_envs = huzzah [env] lib_extra_dirs = - ../libraries + ./libraries lib_deps = sui77/rc-switch@^2.6.4 bblanchon/ArduinoJson@6.21.5 diff --git a/rc-gateway.code-workspace b/rc-gateway.code-workspace index 53d97a2..5e605b8 100644 --- a/rc-gateway.code-workspace +++ b/rc-gateway.code-workspace @@ -1,22 +1,17 @@ { "folders": [ { - "path": "gateway" + "path": "." }, { - "name": "temp_sensor", - "path": "temp_sensor" + "path": "devices/temp_sensor" }, { - "path": "libraries" - }, - { - "path": "oil_sensor" + "path": "devices/oil_sensor" } ], "settings": { "files.associations": { - "*.yaml": "esphome", "functional": "cpp", "queue": "cpp", "array": "cpp", diff --git a/gateway/src/gateway.cpp b/src/gateway.cpp similarity index 100% rename from gateway/src/gateway.cpp rename to src/gateway.cpp diff --git a/temp_sensor/test/README b/test/README similarity index 100% rename from temp_sensor/test/README rename to test/README diff --git a/gateway/test/native/test_decoder/decoder.cpp b/test/native/test_decoder/decoder.cpp similarity index 100% rename from gateway/test/native/test_decoder/decoder.cpp rename to test/native/test_decoder/decoder.cpp diff --git a/gateway/test/native/test_sensor_builder/sensor_builder.cpp b/test/native/test_sensor_builder/sensor_builder.cpp similarity index 100% rename from gateway/test/native/test_sensor_builder/sensor_builder.cpp rename to test/native/test_sensor_builder/sensor_builder.cpp