EspNowSkip: Difference between revisions

From RevSpace
Jump to navigation Jump to search
No edit summary
No edit summary
Line 19: Line 19:


== Hardware ==
== Hardware ==
The hardware is based on ESP8266, they are cheap and ubiquitous and feature the special ESP-Now mode.
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.
A Wemos D1 mini board has an onboard regulator with typically much lower quiescent current than the similar NodeMCU.
I've measured the Wemos D1 mini deep sleep current before at about 0.16 mA.


If we power the entire circuit with a cheap 18650 battery of 2000mAh, it should last > 10000 hours in standby.
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.


Suppose a skip takes 5 seconds of run-time at 100 mA.
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.
That's about 0.14 mAh per skip, so the button should last > 10000 skips.  


The skip button is wired such that the actual physical button just wakes up the ESP8266.
=== Battery life ===
Suppose we power the entire circuit with a 18650 battery of 2000mAh capacity.


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.
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 5 seconds consuming a current of 100 mA on average.
That's about 0.14 mAh per skip, so the battery should last > 10000 skips.  


== Software ==
== Software ==
Line 42: Line 45:
** a single central "master" node
** a single central "master" node
** one or more "slave" skip-buttons
** one or more "slave" skip-buttons
* when the skip button is pressed, it wakes up from deep sleep and sends an ESP-Now "SKIP" message to the last known channel and MAC address of the central node
* 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 ESP-Now "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
** 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 sets up an AP by name (e.g. "espnow-revspace")
* the central node sets up an AP by name (e.g. "espnow-revspace")
* the discovery procedure tries to find the central node by name, this AP name is the only thing that needs to be agreed upon in advance between master and slave code
* the discovery procedure tries to find the central node by name, this AP name is the only thing that needs to be agreed upon in advance between master and slave code
** from the AP name, the slave node can do a scan to determine the wifi channel and MAC address to use
** with the AP name, the slave node can do an SSID scan to determine the wifi channel and MAC address of the central node
** the slave node keeps both wifi channel and MAC address in (emulated) EEPROM and goes back to sleep
** the slave node keeps both wifi channel and MAC address in (emulated) EEPROM and goes back to sleep


Line 52: Line 55:
* [https://esp-idf.readthedocs.io/en/latest/api-reference/wifi/esp_now.html Read-the-docs] about the low-level IDF ESP-Now API
* [https://esp-idf.readthedocs.io/en/latest/api-reference/wifi/esp_now.html Read-the-docs] about the low-level IDF ESP-Now API
* [https://github.com/yoursunny/WifiEspNow WifiEspNow project on github]
* [https://github.com/yoursunny/WifiEspNow WifiEspNow project on github]
* Our current [https://revspace.nl/Wifiskip WiFi-based skip button]

Revision as of 07:44, 6 May 2018

Project EspNowSkip
350px
Music skip button based on ESP-Now protocol
Status Initializing
Contact bertrik, jelly
Last Update 2018-05-06


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 conserve power

The ESP-Now protocol is connectionless, you don't need to set up a session/get an ip-address to communicate between nodes.

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.

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 5 seconds consuming a current of 100 mA on average. That's about 0.14 mAh per skip, so the battery should last > 10000 skips.

Software

Source code

Source code can be found here https://github.com/bertrik/EspNowSkip

Proposed EspNowSkip protocol

It could work something 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 ESP-Now "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 sets up an AP by name (e.g. "espnow-revspace")
  • the discovery procedure tries to find the central node by name, this AP name is the only thing that needs to be agreed upon in advance between master and slave code
    • with the AP name, the slave node can do an SSID scan to determine the wifi channel and MAC address of the central node
    • the slave node keeps both wifi channel and MAC address in (emulated) EEPROM and goes back to sleep

References