EspNowSkip: Difference between revisions
(future) |
No edit summary |
||
Line 18: | Line 18: | ||
The ESP-Now protocol is connection-less, you don't need to set up a session/get an ip-address to communicate between nodes. | The ESP-Now protocol is connection-less, you don't need to set up a session/get an ip-address to communicate between nodes. | ||
This saves time and battery power, exactly what we need. | This saves time and battery power, exactly what we need. | ||
The current ESP-Now skip button prototype needs only 200 ms after wakeup to send a message and return to deep sleep again. | |||
== Hardware == | == Hardware == |
Revision as of 06:28, 7 May 2018
Project EspNowSkip | |
---|---|
350px | |
Music skip button based on ESP-Now protocol | |
Status | In progress |
Contact | bertrik, jelly |
Last Update | 2018-05-07 |
Introduction
This page is about using the ESP8266/ESP32 ESP-Now protocol in the music skip button.
A music skip button has some tricky requirements:
- you want it to react reasonably quickly, with little latency between pressing the button and skipping to the next song
- the skip button should be mobile, so it is battery powered and has to be conservative with current
The ESP-Now protocol is connection-less, you don't need to set up a session/get an ip-address to communicate between nodes. This saves time and battery power, exactly what we need.
The current ESP-Now skip button prototype needs only 200 ms after wakeup to send a message and return to deep sleep again.
Hardware
The hardware is based on ESP8266, in particular a Wemos D1 mini board, they are cheap and ubiquitous and feature the special ESP-Now mode. A Wemos D1 mini board has an onboard regulator with typically much lower quiescent current than the similar NodeMCU.
The skip button is wired such that the actual physical button just resets the ESP8266. This means the physical button connects the RST pin to GND. It also means, the SKIP only happens when you release the button.
The receiver/master is connected to a raspberry pi or similar, with the EspNowSkip receiving packets from the air and sending them over serial to the raspberry pi.
Battery life
Suppose we power the entire circuit with a 18650 battery of 2000mAh capacity.
The deep sleep current of the Wemos D1 mini has been measured at about 0.16 mA. So in deep-sleep, the battery should last > 10000 hours. Suppose a skip takes 2 seconds consuming a current of 150 mA on average. That's about 0.1 mAh per skip, so the battery should last > 10000 skips.
Software
Source code
Source code can be found here https://github.com/bertrik/EspNowSkip
EspNowSkip protocol
It works like this:
- there are two roles:
- a single central "master" node
- one or more "slave" skip-buttons
- when the skip button is pressed, the ESP8266 resets and starts running, reads the last known ESP-Now channel and MAC address from EEPROM and sends the "SKIP" message
- if the skip button doesn't receive an ACK from the central node, it starts a kind of discovery to re-establish the channel and MAC address of the central node
- the central node is configured as an AP with a specific name (e.g. "espnow-revspace")
- the discovery procedure tries to find the central node by doing an AP scan, the AP name is the only thing that needs to be agreed upon in advance between master and slave code
- in the list of the APs, the slave node finds the SSID belonging to the central node, then it also knows the wifi channel and MAC address of the central node
- the slave node stores both wifi channel and MAC address in (emulated) EEPROM and goes back to sleep
References
- Read-the-docs about the low-level IDF ESP-Now API
- WifiEspNow project on github
- Our current WiFi-based skip button
Future
Future features could be:
- get rid of the old "nrf24l01+" style messaging which used a limited 4-char convention for sending a message (just "SKIP"). We now have 250 bytes to play with, so we could just do a kind of MQTT-over-ESPnow emulation. For example, we could send a MQTT-style topic + content + flags and bridge it to the rest of our space sensor/actuator infrastructure which is completely MQTT-based.
- add more buttons besides just skipping
- send data back to the skip button, for example we could send a "now playing" message or album art back to a SHA2017 badge and have it shown on its e-ink display.
- use ESP-Now also for other kinds of hacker space infrastructure where low-power consumption is important and/or a power wire is inconvenient, e.g. temperature sensor in freezer? What about battery types that can handle sub-zero temperatures?
- make sure ESP8266 ESP-now implementation is interoperable with ESP32 ESP-now implementation