Skip to content

Commit

Permalink
add debug packet count; use conditional compilation for interrupt ver…
Browse files Browse the repository at this point in the history
…sus heart beat modes
  • Loading branch information
mightymos committed Feb 4, 2023
1 parent 9da3f08 commit 7d65834
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 208 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2022 Vincent DEFERT. All rights reserved.
# Copyright (c) 2022 Jonathan Armstrong. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down
105 changes: 69 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,77 @@
### Description
This is an alternative firmware for wireless 433MHz magnetic door/window reed sensors.
This is an alternative firmware for wireless 433MHz magnetic door/window reed sensors.

This work is made possible by Vincent Defert's hardware abstraction layer for STC 8051 MCUs:
https://github.com/area-8051/uni-STC

STC15W101/104 are 8051 based processors + SYN115 radio transmitter.
'101 model has 1KB flash
'104 model has 4KB flash
(most boards but not all have a tamper detect switch installed, you could add one if yours does not)
Boards with STC15W101/104 8051 based processors + SYN115 radio transmitter are supported.
The '101 model has 1KB flash and the '104 model has 4KB flash.
Most boards but not all have a tamper detect switch installed.

As of now, adding more additional features is unlikely.
This is because it was decided to keep firmware under 1KB to support model '101 MCUs/boards.

One possibility however is to use emulated EEPROM area for code space.
Experiments with booting from other memory spaces have not worked so far:
https://github.com/mightymos/stc15bootisp/issues/1

Finally, STC MCUs do not allow read/verify of written firmware.
STC MCUs do not allow read/verify of written firmware.
Therefore an open source alternative is needed to confirm program behavior.
Also for this reason original firmware can not be reflashed once overwritten.

Boards contain a header that may be populated with pins labeled with G (ground), T (transmit), R (receive), and V (3.3 volts) for flashing with USB to UART module.
Alternatively the battery terminal maybe powered and only G, T, R pins connected for flashing.
The board needs fewer than 100 milliamps.
This work is made possible by Vincent Defert's hardware abstraction layer for STC 8051 MCUs:
https://github.com/area-8051/uni-STC

### Programming Interface
Boards contain a header that may be populated with pins labeled:
G (ground)
T (transmit)
R (receive)
V (3.3 volts)

Flashing just requires a 3.3V compatible USB to UART module.
Alternatively the battery terminal may be powered and only G, T, R pins connected for flashing.
The board needs fewer than 100 milliamps.

### Receiver Hardware
Receiving radio packets requires a receiver.
We have chosen "protocol 1" from the rc-switch library.
You can use a generic 433 MHz receiver and controller using [rc-switch](https://github.com/sui77/rc-switch).
There is also an rc-switch fork that appears more recently updated [rc-switch by 1technophile] (https://github.com/1technophile/rc-switch).
We support both "stock" timings captured from the factory sensor and "protocol 1" supported by the rc-switch library.
You can of course modify constants in the firmware to support any timings desired.
Number of missed events or missed packets at various receivers is being evaluated currently.


Another option is the Sonoff RF Bridge 433 MHz.
| Hardware | modifications | stock protocol | protocol 1 | missed packets? |
| ------------- | ------------- | ------------- | ------------- |
| Sonoff R1 | original | untested | untested | |
| Sonoff R2 v1.0 | original | yes | yes | |
| Sonoff R2 v1.0 | RF-Bridge-EFM8BB1 | yes | yes | |
| Sonoff R2 v1.0 | bypass EFM8BB1 | untested | untested | |
| Sonoff R2 v2.0 | original | untested | untested | |
| Sonoff R2 v2.0 | RF-Bridge-EFM8BB1 | untested | untested | |
| sonoff R2 v2.0 | bypass | untested | untested | |
| sonoff R2 v2.2 | original | yes | yes | |
| sonoff R2 v2.2 | bypass | untested | yes | |
| SIGNALDuino | original | yes | yes | |

For Sonoff R2 V1.0 one of the two methods is required so that "protocol 1" is available [see Modifications section in link below].
https://github.com/xoseperez/espurna/wiki/Hardware-Itead-Sonoff-RF-Bridge

Flashing Portisch is described here:
https://tasmota.github.io/docs/devices/Sonoff-RF-Bridge-433/#rf-firmware-upgrade
### Receiver Modifications (optional)

Generic controller with 433 MHz receiver:
https://github.com/sui77/rc-switch
Fork that appears more recently updated:
https://github.com/1technophile/rc-switch


For Sonoff RF Bridge R1/R2 v1.0 and v2.0 modifications are available but are not explicitly required if stock timings are used:
https://github.com/xoseperez/espurna/wiki/Hardware-Itead-Sonoff-RF-Bridge
https://tasmota.github.io/docs/devices/Sonoff-RF-Bridge-433/#rf-firmware-upgrade

Portisch is not supported on Sonoff R2 V2.2 hardware:

RF-Bridge-EFM8BB1 is not supported on Sonoff R2 v2.2 hardware:
https://github.com/Portisch/RF-Bridge-EFM8BB1/issues/217

However apparently there is a hardware modification for R2 V2.2 which bypasses rf chip so Tasmota directly decodes:
However a similar hardware modification for R2 v2.2 which bypasses the radio chip so that Tasmota directly decodes is available:
https://community.home-assistant.io/t/new-sonoff-rf-bridge-board-need-flashing-help/344326/17

### Home automation support (optional)

[ESPurna](https://github.com/xoseperez/espurna "ESPurna") is nice because it treats wireless sensors as "virtual" sensors.
Virtual sensors show up as permanent switch entities in Home Assistant.
Also ESPurna can learn/remember unique sensor codes.


[Tasmota](https://tasmota.github.io/docs/devices/Sonoff-RF-Bridge-433/ "Tasmota") firmware can also be flashed.

ESPHome is also an option (link?).

### Features

Expand All @@ -67,15 +85,16 @@ Also ESPurna can learn/remember unique sensor codes.
| "Heart beat" mode for periodic transmission | added | DONE |
| Add tamper closed key | added | DONE |
| Add tamper "trip" mode | added | DONE |
| Send code if pin goes low indicating low battery | original | DONE |
| Send information over radio (e.g., battery?) | added | DONE |
| Support stock transmission protocols | added | todo |
| Add packet count to upper bits of transmitted rf code | added | todo |
| Interrupt and heart beat mode for low battery | original | DONE |
| Add battery OK code | added | DONE |
| Support stock transmission protocols | added | DONE |
| Add packet count to upper bits of transmitted rf code | added | DONE |
| User configuration/input with tamper switch press(es) | added | todo |
| Store settings in EEPROM | added | todo |
| Compare power usage to original firmware | added | todo |
| Adjustable LED blink behavior | added | todo |
| Adjustable sleep behavior | added | todo |
| Adjustable heart beat time period | added | todo |
| Store settings in EEPROM | added | todo |


![alt text](/photos/water_leak_store_hookup_example.jpg "Wireless 433 MHz Door Sensor")

Expand Down Expand Up @@ -119,3 +138,17 @@ make upload
| Source | Link | Price (USD) |
| ------------- | ------------- | ------------- |
| aliexpress | https://www.aliexpress.com/item/3256803337417240.html | $4.09 (12/05/2022) |
| aliexpress | https://www.aliexpress.com/item/2255800593881608.html | $4.38 (1/31/2023) |
| amazon(de) | https://www.amazon.de/-/en/Aiggend-Magnetic-433M-H-Z-Wireless-Detector/dp/B07Z93Q7NL/ | €11.99 (2/2/2023) |
| amazon(de) | https://www.amazon.de/-/en/Nikou-Magnetic-Sensor-Switch-Wireless/dp/B07PTYD171/ | €11.49 (2/2/2023) |


### Future plans

As of now, adding more additional features is unlikely.
This is because it was decided to keep firmware under 1KB to support model '101 MCUs/boards.
It would be possible to add features to the 4KB model '104 MCUs of course.

One additional possibility is to use emulated EEPROM area on either MCU as code space.
Experiments with booting from other memory spaces have not worked so far:
https://github.com/mightymos/stc15bootisp/issues/1
Loading

0 comments on commit 7d65834

Please sign in to comment.