Implementing WiFi push button, battery powered

Edit: Thanks to @eduperez getting me thinking in a great direction, later in this thread are ideas on how to minimize the delay between device activation and getting a "signal" to take action.

Not sure quite where this fits, but I'm looking for a battery-powered button that can connect to a nearby OpenWRT box and be used as a light switch "toggler" -- push the button, the lights turn on; push it again and they turn off.

I haven't had much luck with my Google or eBay searches, coming up with either $30-100 items, things to let you use two BT devices with a single phone, or the reverse of what I'm looking for -- a relay controlled by WiFi/BT.

I've thought about an ESP8266 (and am staring at a couple right now), but it would have to deep sleep to run off a battery and the wake-associate-send time is likely to be too long. Batteries are definitely preferred so I can just stick the thing on the wall and be done with it for a year or so.

Suggestions welcome!

(As well as BLE adapters that have driver support in OpenWRT)

A strange game. The only winning move is not to play. How about a nice game of chess?

Ah, the flip-flop action is the easy part. I just need a battery-operated device that communicates wirelessly to a receiver with a well-supported protocol stack (preferably on OpenWRT) that either has a momentary-contact push button already, or an accessible input pin.

I think that any WiFi device is going to have roughly the same wake-associate-send time as the ESP8266, unless you are willing to have it always powered on, and that is going to drain the batteries pretty fast. If you want to go that route, there is a simple circuit that you can build with a ESP8266 so the device only draws battery when a button is pushed; see https://www.hackster.io/iboboc/smartbutton-pro-06ce5d for an example.

May people has been using Amazon Dash buttons for this purpose (google for "amazon dash hack" for some pointers): the idea is that you configure it to join your network but not to buy any product, then run a script on the router to fire an action when the device contacts the DHCP server. Amazon also has a programmable version of the device, but it is far more expensive.

1 Like

Solid idea, especially at the $2-5 price point! Knowing that I can get it associated with a "secure" WiFi AP without ordering a product makes it even more attractive. OK, so not so visually attractive, but I can accept what I'm guessing is a 2-5 second delay (some users report them being "slow") at that price point.

The "unbranded" Amazon IOT Button at $20 right now is interesting as one can build the "take action" code with AWS. However, I don't need the TLS set-up time and what I'm guessing it a four-packet MQTT transaction adding to the wake-up/associate time. The "look for the MAC address" trick still works. If I didn't already have fixed-IP hosting, I'd probably be ordering one of those instead of the Clorox Disinfecting Wipes buttons that were "on special" at $1.99 each today. For $18 I can paint over the logo!

(Yes, these will go on their own "non-routed" AP once configured)

As the coffee hits this morning, I'm glad @eduperez got me thinking. I'll look at it later, but I think that if you're willing to monitor at the WiFi media layer, you should be able to catch the probe request when the device starts to try to associate, and not even need to go any further than that.

Good news is that at least with the 2.4 GHz radio in my Archer C7, I can "see" the initial probe and save significant time triggering off that, rather than the DHCP lease.

In the setup I'm testing, there is an ESP8266 on my desk, an Archer C7 ~3 meters away, and DHCP is supplied by a wired server running kea. <CLIENT_MAC> is the colon-notation form of the ESP8266's MAC address. <SSID> is shown as a string in the tcpdump output.

The authentication appears to take around 1.5 seconds, so catching the packets at the media layer should improve responsiveness significantly.

Now to figure out
How to configure a monitor interface with UCI...

In /etc/config/wireless

config wifi-iface
	option device 'radio0'
	option mode 'monitor'
	option ifname 'mon24'

(no changes in /etc/config/network needed)

Capture of ESP8266 connection

# iw phy phy1 interface add mon1 type monitor
# ip link set mon1 up
# tcpdump -ni mon1 wlan host <CLIENT_MAC>
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on mon1, link-type IEEE802_11_RADIO (802.11 plus radiotap header), capture size 262144 bytes
07:17:48.017592 50799940183us tsft 1.0 Mb/s 2437 MHz 11b -42dBm signal -43dBm signal antenna 0 -53dBm signal antenna 1 -49dBm signal antenna 2 Probe Request (<SSID>) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit]
07:17:48.021090 1.0 Mb/s [bit 15] Probe Response (<SSID>) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit] CH: 6, PRIVACY
07:17:49.439918 50801362618us tsft 1.0 Mb/s 2437 MHz 11b -44dBm signal -44dBm signal antenna 0 -55dBm signal antenna 1 -51dBm signal antenna 2 Authentication (Open System)-1: Successful
07:17:49.443378 1.0 Mb/s [bit 15] Authentication (Open System)-2: 
07:17:49.444610 50801366736us tsft 1.0 Mb/s 2437 MHz 11b -42dBm signal -44dBm signal antenna 0 -53dBm signal antenna 1 -51dBm signal antenna 2 Assoc Request (<SSID>) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit]
07:17:49.449734 1.0 Mb/s [bit 15] Assoc Response AID(1) : PRIVACY : Successful
07:17:49.453714 1.0 Mb/s [bit 15] EAPOL key (3) v2, len 95
07:17:49.468222 50801389933us tsft 1.0 Mb/s 2437 MHz 11b -41dBm signal -42dBm signal antenna 0 -53dBm signal antenna 1 -49dBm signal antenna 2 EAPOL key (3) v1, len 117
07:17:49.471817 1.0 Mb/s [bit 15] EAPOL key (3) v2, len 151
07:17:49.476641 50801398511us tsft 1.0 Mb/s 2437 MHz 11b -41dBm signal -41dBm signal antenna 0 -54dBm signal antenna 1 -50dBm signal antenna 2 EAPOL key (3) v1, len 95
07:17:49.492670 50801412526us tsft 1.0 Mb/s 2437 MHz 11b -40dBm signal -41dBm signal antenna 0 -52dBm signal antenna 1 -50dBm signal antenna 2 Data IV:  1 Pad 20 KeyID 0
07:17:49.513276 50801433144us tsft 1.0 Mb/s 2437 MHz 11b -43dBm signal -44dBm signal antenna 0 -53dBm signal antenna 1 -52dBm signal antenna 2 Data IV:  2 Pad 20 KeyID 0
07:17:49.536982 50801459319us tsft 1.0 Mb/s 2437 MHz 11b -42dBm signal -42dBm signal antenna 0 -56dBm signal antenna 1 -54dBm signal antenna 2 Data IV:  3 Pad 20 KeyID 0
07:17:50.006659 50801929306us tsft short preamble 2.0 Mb/s 2437 MHz 11b -41dBm signal -42dBm signal antenna 0 -52dBm signal antenna 1 -49dBm signal antenna 2 Data IV:  4 Pad 20 KeyID 0
07:17:50.007434 50801929999us tsft short preamble 2.0 Mb/s 2437 MHz 11b -42dBm signal -43dBm signal antenna 0 -52dBm signal antenna 1 -49dBm signal antenna 2 Data IV:  5 Pad 20 KeyID 0
07:17:50.495802 50802418414us tsft short preamble 2.0 Mb/s 2437 MHz 11b -40dBm signal -41dBm signal antenna 0 -52dBm signal antenna 1 -50dBm signal antenna 2 Data IV:  6 Pad 20 KeyID 0
07:17:50.508544 50802431155us tsft short preamble 2.0 Mb/s 2437 MHz 11b -42dBm signal -43dBm signal antenna 0 -52dBm signal antenna 1 -50dBm signal antenna 2 Data IV:  6 Pad 20 KeyID 0
07:17:51.006775 50802929419us tsft short preamble 2.0 Mb/s 2437 MHz 11b -40dBm signal -41dBm signal antenna 0 -52dBm signal antenna 1 -49dBm signal antenna 2 Data IV:  7 Pad 20 KeyID 0
07:17:51.995837 50803918688us tsft short preamble 5.5 Mb/s 2437 MHz 11b -42dBm signal -42dBm signal antenna 0 -53dBm signal antenna 1 -51dBm signal antenna 2 Data IV:  8 Pad 20 KeyID 0
07:17:52.995535 50804918347us tsft short preamble 5.5 Mb/s 2437 MHz 11b -41dBm signal -42dBm signal antenna 0 -52dBm signal antenna 1 -50dBm signal antenna 2 Data IV:  9 Pad 20 KeyID 0
# iw dev mon1 del