Project Gem – Panic button with ESP8266 & OpenWrt Linux

Gem is an ESP8266 based panic button pendant that triggers sending of notifications (e-mail,SMS) over a base station device. I will post updates, this project is still work in progress, and it’s
only a segment of a bigger project
, but here’s a picture of the first working version:

How does it work:
Gem has implemented MQTT client that sends its state to a base station(access point running Linux and MQTT) when it detects a button press and periodically(every hour) to make sure everything is in working order.
In short steps:
1. Connect to wifi base station
2. Ping base station over MQTT
3. Check panic pin input
4. Set panicPin to OUTPUT && LOW to discharge button circuit and set panicPin to LOW
5. Set panicPin back to INPUT
6. Go to deep sleep for an hour

7. On panic button press (interrupt deep sleep)
-Put logic level HIGH on panicButton gpio via hardware
-Ground the reset pin and trigger step 1
When active ESP will consume around 80 mA, and in deepsleep around 80uA.

Parts needed:
2x 1n4007 Diodes
1x 35V 330uF Capacitor, can try different values
1x 68kOhm resistor for panicPin PULLDOWN, can try different values
1x DPDT DIP 2 pole pushbutton momentary , I hacked together mine for the first version
1x ESP8266
1x 3.3V power source

4x 10k resistors (not indicated in the scheme) are also needed for stable work of bare minimum ESP setup: 3 for pullup on CH_PD, RESET and GPIO0 and one pulldown on gpio15


Deep sleep delay switch:
The circuit is designed to hold voltage level for digitalRead HIGH on panicPin after button press and is needed to distinguish between waking up on timer and button press.

ESP Code:

Base code:

In the current state of the project i use TP-link tlwr703n with OpenWrt, but I’ll describe what needs to be done in order for this project to work in next post, here’s a few details upfront:

1. Flash OpenWrt on the device and enable extroot.
2. install mosquito:

opkg update
opkg install mosquitto mosquitto-client libmosquitto nano

You can now subscribe to a topic with command from terminal with command:

mosquitto_sub -d -t /sensors/panicbutton -h

3. The simplest way to send mail from OpenWrt is mailsend so install it and try it:

opkg install mailsend
echo “Panic button presed” > /tmp/body
mailsend -f -t -smtp -port 587 -starttls -auth -user -pass password -sub “It works!!” -msg-body /tmp/body

4. ignore last two steps and make it all work with python. I’ll keep you posted!

4 thoughts on “Project Gem – Panic button with ESP8266 & OpenWrt Linux

  1. i think the current is not quite correct. when active the power consumption is around 80mA. when in deep sleep, it’s around 15uA.

  2. Hi, Thanks for putting this online, I’m hooking up a remote rain gauge and your code will work for that too. I’ll replace the dpdt switch and RC network with a simple flip flop to achieve the same functionality with spst reed switch in the gauge. Additionally the same setup could monitor a door switch etc where a realtime response isn’t always needed. It may be worth reporting the battery level via mqtt as well as a nice feature.
    -Thanks again, Max.

    • Well, yes, im also planning to use it on a wide array of sensors. The ping metod is an easy way to check the battery, if there’s no ping the battery is out, but power level readout would be cool. Thanx for the feedback!

Leave a Reply

Your email address will not be published. Required fields are marked *