A two-way radio between two boards
Hold a button on one board, and the other plays what it hears. Nothing in between.
What it is
A walkie-talkie. Two boards talk to each other over ESP-NOW, the ESP32's own radio-to-radio link: no router, no phone, no internet, and it works on every ESP32 with Wi-Fi - the original, the S2, S3, C3, C5 and C6. While a button is held, what the board's microphone hears is sent; the other board plays it through its audio output. One talks and one listens, as on any handheld radio: a board does not play while it is talking, or its speaker would be in its own microphone.
It is written for the Arduino export and is part of Pro: free to design and preview with, and generating code for it needs Pro.
The widget is an icon
Drop a Two-way radio from the palette's Ready-made group. It is a small mark - a handset - in the colour of what the link is doing, and it is where the radio's settings are. Talking and pairing are actions, so a button on the screen, a physical switch or a rotary encoder's press can do either.
| The link is | The icon | Colour to start with |
|---|---|---|
| Not paired | Lit. Nobody to talk to yet. | Grey |
| Pairing | Flashes: looking for another board that is pairing too. | Blue |
| Ready | Lit. Paired, or on its channel, and quiet. | Blue |
| Talking | Lit. This board is sending its microphone. | Red |
| Hearing | Lit. The other board is talking, and this one is playing it. | Green |
| No answer | Lit. What it sends is not being received: the other board is off or out of range. A paired board knows this while nobody is talking too - it checks once a second. | Amber |
Dropped on a board that is wired for sound, it switches the audio output and the microphone on. Its inspector then says which halves the board has and offers two buttons, each added in one step: Add a push-to-talk button and Add a Pair button. They are ordinary buttons with ordinary events, yours to restyle or replace.
What a board needs
| The board has | It can |
|---|---|
| A microphone and an audio output | Talk and hear. A codec with both, such as the ES8311 on the LCDWIKI ES3C35P or the Waveshare 3.5B, is a handset by itself. |
| An audio output only | Hear. A CYD or an E32R28T, with its speaker, is a receiver. |
| A microphone only | Talk. |
| Neither | Nothing: the export is refused, and says to switch one on under Hardware > Audio. |
The two boards need not be the same kind. Flash each its own design - or the same design to both, if they are the same board.
Pairing two boards
ESP-NOW has no pairing of its own: a board sends to an address, or to everybody. So the radio does it. Run the Pair action on both boards within half a minute - press each one's Pair button. Each announces itself, hears the other, and the icon stops flashing. From then on:
- each board has the other's address and a key saved in flash, so the pairing survives a restart;
- they talk only to each other, and what they send is encrypted by ESP-NOW's own AES;
- each knows the other's name - the widget's This board is called - which is a value a label can show.
Forget, the same action's other setting, undoes it. Pairing again with a different board replaces the old one. If a board's flash is erased it has forgotten its partner: pair the two again.
What the pairing is worth: the two halves of the key cross the air while the boards pair, so it keeps out anybody who was not listening at that moment, and nobody who was. It is what Bluetooth calls "just works", and it is a walkie-talkie, not a secure line.
Or a channel for many
Set It talks to to Every board on the same channel name, and give every board the same words under Channel name. Any number of them then hear each other, with no pairing at all - a handset for everybody in the workshop. Nothing is encrypted, because a broadcast cannot be, and a board cannot know whether anybody heard it, so the icon never says "no answer".
The Wi-Fi channel
ESP-NOW uses Wi-Fi's radio, on whichever channel that is on, and two boards hear each other only on the same one.
- In a design with no Wi-Fi of its own, the radio is on the widget's Wi-Fi channel, 1 to start with. Give both boards the same number.
- In a design that joins a network - a WiFi Setup widget - it is on that network's channel, whatever the widget says. Two boards on the same network are on the same channel; two boards on two networks will not hear each other.
Actions
| Action | What it does |
|---|---|
| Two-way radio: talk | Start talking, Stop talking, or start if it is not and stop if it is. Start on a button's Pressed and Stop on its Released is push-to-talk. The toggle is for a latching "talk" key. |
| Two-way radio: pair or forget | Pair with another board, for half a minute, or Forget the board it is paired with. On a channel name it does nothing: there is nobody to pair with. |
What a design can read
On the Data tab, in the Two-way radio group, for a variable to read:
| Value | Type | Notes |
|---|---|---|
| What it is doing | Text | A sentence: not paired, pairing, paired with whom, talking, hearing - or that nobody answered. Worth a label of its own. |
| What it is doing, as a number | Number | 0 not paired, 1 pairing, 2 ready, 3 talking, 4 hearing, 5 no answer. What the icon shows. |
| There is a board to talk to | Boolean | Bind a Talk button's Disabled to its opposite and it cannot be pressed with nobody there. |
| This board is talking, The other board is talking | Boolean | For a lamp, or to hide something while a voice is playing. |
| The other board's name | Text | Empty until it is paired. |
| Link quality, 0 to 100 | Number | How good the link is, now: whether what is sent is arriving. 0 when the other board does not answer, and while there is nobody to talk to. |
| Link quality bars | Number | The same as 0 to 4, for an indicator. |
| The other board's signal strength, and the same 0 to 100 | Number | How strongly the other board was last heard, in dBm (about -50 is excellent, -85 barely usable) and as a share. 0 until it has been heard. Strength is not quality: a strong signal can still be losing packets. |
| Packets sent, sent and not acknowledged, heard, never arrived | Number | Counted since the board started. A packet is 24 ms of sound, the end of a transmission, or the once-a-second check. On a channel name nothing is acknowledged, so the second stays 0. |
| Packets lost, per cent | Number | Those counts as one figure, both ways together, since the board started. |
The other board's voice goes through the same audio output as everything else, so the board's volume is its volume, and Audio > Level moves with it: a level meter built for the radio is one for the handset. If a station is playing when the other board talks, the station stops, as it would for a call.
How it sounds, and how far it reaches
The microphone is sampled 16,000 times a second, which is speech quality - a telephone and a little better - and sent as ADPCM, four bits a sample, in packets of 24 milliseconds. A packet that is lost is 24 ms of silence and nothing after it. The delay from mouth to speaker is about a tenth of a second.
Range is Wi-Fi's: a house, a workshop, a garden; tens of metres through walls and more in the open, depending on the boards' aerials.
How good the link is
Link quality is not signal strength. Strength says how loudly the other board is heard; quality says whether what is sent is arriving, which is the thing a handset's bars are for. It is the share of the last eight seconds' packets that got through - what this board sent and had acknowledged, and what the other sent and arrived - marked down as the other board's signal weakens: by nothing at -50 dBm, by three quarters at -90. So the bars are full when everything gets through with signal to spare, they fall as the other board gets further away, they fall faster once packets are being lost, and they are empty when it does not answer.
A link is only known to be up while something crosses it, so while nobody is talking a paired board sends the other a very short packet once a second. Whether it is acknowledged is what the quality, and No answer, go by between transmissions; hearing the other board's is how its signal stays known. A board that has not been switched on for the other to find shows No answer within a few seconds, without anybody pressing a key.
| Bars | Quality | Roughly |
|---|---|---|
| 4 | 75 and above | Everything arrives, the other board is near. |
| 3 | 50 to 74 | Everything arrives at a distance, or a little is lost close by. |
| 2 | 25 to 49 | At the edge of range, or losing a good part of what is sent. |
| 1 | 1 to 24 | Most of it is lost. |
| 0 | 0 | No answer, or nobody to talk to. |
To draw the bars, put four panels of rising height side by side and bind each one's
Hidden to a variable that reads Link quality bars, with the formula x < 1
on the first, x < 2 on the second and so on. A dim panel under each is the unlit
step.
Two things to know. On a channel name nothing is acknowledged, so quality there goes by what is heard: the signal of whoever was heard in the last ten seconds, and what was missing from their voice. And a board running an older export acknowledges the check without sending one of its own, so between transmissions its partner goes by the acknowledgements alone.
One loudness, whichever board is talking
Two boards rarely have the same microphone, and a board plays what it is sent: without help, one end of a pair is loud and the other faint. So the widget's Even out the voice is on to start with. What a board sends is brought towards one loudness first - quickly down when a word would be too loud, more slowly up when a voice is quiet, and never past full scale. While nobody is speaking it leaves the level where the last words put it, so the room is not turned up in the pauses.
Raise it by at most is how far a quiet voice may be brought up: 12, 18, 24 or 30 dB, 24 to start with. More reaches a quieter microphone, and makes whatever else it hears louder with the voice. Switched off, a board sends its microphone as it is - the setting for a design that sets the microphone's sensitivity itself. How loud a board plays is still its own volume.
In preview
No other board is on the air in a browser. The drawer has a Two-way radio section to choose what the link is doing, and the icon and the values follow; the Talk button turns the icon its talking colour while it is held, and Pair is taken to have found a board.