Bluetooth remote
In the Bluetooth remote role, the board pairs with Bluetooth remotes and
sends each button press to a controller over the network, as a key name such
as volume_up. It turns any Bluetooth LE remote into an IP remote for GEM:
the remote that came with a streaming box, a media remote, a small Bluetooth
keyboard.
Nothing plugs into the USB port. The role needs a board with Bluetooth: the Waveshare ESP32-P4-WIFI6-POE-ETH, with an antenna on its antenna connector (see remotes).
Set up the board
- Choose Bluetooth remote under Settings and Save & reboot. The Bluetooth remote panel shows Bluetooth ready. The first time, the board may update its Wi-Fi chip's firmware and restart once more (see Wi-Fi chip firmware).
- Under Controller, choose how keys are sent and where to (see use it from GEM), then Save. Changes apply at once.
- Pair a remote.
The panel shows where keys go under Controller, how many went under Keys, the last button pressed under Last button, and anything wrong under Problems.
Use it from GEM
The board has two ways to send a key. Either way, GEM knows a remote by the address its keys come from, so give the board a static IP address or a DHCP reservation.
TCP socket
The board keeps a connection open to one of GEM's remote ports and sends each key name as a line.
- In GEM, open Remotes and add a remote. Set IP Address to the
board's address and Port to one of
6333to6339. Choose its AV Zone and save. - On the board, choose TCP socket, set Controller address to GEM's address and TCP port to the port chosen in GEM, and Save.
Controller reads connected once GEM accepts the connection. GEM closes a connection from an address that isn't one of its remotes: the board then shows closed the connection at once.
REST URL
The board makes one HTTP request per key, to GEM's Remote Proxy driver.
- In GEM, add a device with the Remote Proxy driver. Its port is
8060unless you change it. Add a remote under Remotes with IP Address set to the board's address. - On the board, choose REST URL, set URL to
http://<GEM address>:8060/keypress/{key}, leave Method at POST, and Save.
{key} is replaced by the key name. A URL without {key} gets the key name
added as its last path segment. Any controller that takes an HTTP request per
key works the same way; http:// only.
In GEM
Bind the remote's keys on its Keys tab, or turn Pass Through on to send unbound keys to the zone's active source. GEM's live key log shows each key as it arrives. To check the path without a remote, enter a key name under Test a key on the board and choose Send.
When the connection drops
The board looks after the connection by itself. If the controller restarts or the network drops, it reconnects as soon as the network is back, trying at most 8 seconds apart; a button press makes it try at once. A controller that goes silent without closing the connection is noticed within about 10 seconds. A remote that drops out of range or loses power reconnects on its next press. Keys pressed while the controller can't be reached are not saved up: they count under Keys as not sent.
Pair a remote
- Choose Pair a remote. The board lists remotes in pairing mode for two minutes.
- Put the remote in pairing mode. How depends on the remote: often two buttons held together until a light blinks. Hold it within a metre or two of the board.
- When the remote appears in the list, choose Pair next to it.
The remote moves to Remotes once it is paired. Up to 4 remotes can be paired, and all send to the same controller. Forget removes one.
Remotes sleep between presses to save their battery, so a paired remote usually reads asleep. A press wakes it, it reconnects in a moment, and the press is sent: the first press after a long pause can take up to a second longer than the rest.
A remote pairs with one host at a time. Pairing it with the board takes it away from the device it came with, and pairing it with that device again takes it away from the board.
Program a Sofabaton U3
A Sofabaton U3 is a universal remote that is set up from a phone app: which code each button sends is stored on the remote. The board can write that setup itself, so the remote needs no app and no key naming:
- Choose Pair a remote on the board.
- Put the U3 in pairing mode. It appears in the list as
SOFA_U3and four characters, with Program next to it in place of Pair. - Choose Program and enter a name of up to 30 characters. It is the name the remote shows for the board, among its devices.
- Enter a list of activities, separated by commas, or leave it blank. Up to
eight, for example
Roku, DirecTV, AppleTV.
The board adds a device with that name to the remote, sets every button it can
to the key the board names for it, reads it all back to check, makes a macro on
the remote for each activity, and pairs with the remote. It takes about 45
seconds; the page shows how far it is. Keep the remote within a metre or two
until it reads Programmed. When it is done, the remote is under Remotes
as BLE-SOFA_U3 and its four characters.
Each activity becomes a macro on the remote, in the order given: the first
sends activity_1, the second activity_2, and so on up to activity_8. Map
those names in GEM to the source or scene each should start.
| Buttons | Key names |
|---|---|
| Power | power |
| Menu, Home, Info, Back, Exit, Guide | menu, home, info, back, exit, guide |
| Arrows and OK | up, down, left, right, select |
| Volume, mute, channel | volume_up, volume_down, mute, channel_up, channel_down |
| Playback | play, pause, rewind, fast_forward |
| DVR | record |
| Colour buttons | red, green, yellow, blue |
| Number pad | 0 to 9, dash, enter |
| Input | input |
Holding a button sends a second key, its name with _hold added: menu_hold,
play_hold, 1_hold, and for OK and DVR select_hold and record_hold.
The buttons that repeat while held (arrows, volume, channel) and power have
no long press. input, dash and the _hold names aren't in GEM's standard
list: bind them in GEM as custom key names.
The device also carries activity_1 to activity_8 as keys on no button, so
besides the activities the board makes you can put them on macros of your own on
the remote. A tap then sends that name to GEM, where it can run a source or
scene.
Programming again replaces the device the board added before, and the board forgets its pairing with it. Devices added with Sofabaton's app are left as they are. The remote sends the board's keys while the board's device is the one selected on it.
- The power button at the top of the remote sends
power, the same as the keypad's power button. - The remote leaves pairing mode after a few minutes. If programming stops with Not programmed, put it in pairing mode and choose Program again: nothing is left half done.
- If it reads it was programmed, but not paired, the device is on the remote: program it again to pair.
- The way a U3 is programmed isn't published by its maker. The board was tried with a U3 on firmware 1.0.0, and checks what it wrote before it pairs.
Key names
Each button on a remote has a number, its HID usage, written as a page and an
ID: 0c:00e9 is volume up. The board sends GEM's standard key name for the
buttons it knows:
| Buttons | Key names |
|---|---|
| Power | power |
| Navigation | up, down, left, right, select, back, home, menu, guide, info, exit |
| Playback | play, pause, play_pause, stop, record, fast_forward, rewind, skip_forward, skip_back, previous |
| Volume and channel | volume_up, volume_down, mute, channel_up, channel_down |
| Number pad | 0 to 9, asterisk, enter |
| Colour buttons | red, green, yellow, blue |
| Letters | a, b, c, d |
| F1 to F8 | activity_1 to activity_8 |
| Input, and the dash of a number pad | input, dash (not in GEM's standard list: bind them as custom key names) |
A button with no standard name sends nothing until you name it. Press it,
and Last button shows its usage with no key name; the usage is also
filled in under Key names. Enter a Key name and choose Set key
name. The same form renames a button that has a standard name, for example
to make a remote's home button send activity_1. A key name of - makes a
button send nothing. Remove gives a button its standard name back. Up to
24 buttons can be named this way, and the names apply to every paired remote.
A key name can be any text GEM takes from a remote, up to 47 characters:
a custom key name bound in GEM, or a JSON command such as
{"macro":"good_night"}.
With Repeat volume, channel and arrow keys while held on, holding one of those keys sends it again after half a second and then every 200 ms, for at most 8 seconds. Repeat every (ms) sets that interval, from 50 to 1000 ms: lower is faster. Other keys are sent once per press.
Voice
Remotes for Google TV and Android TV have a microphone, which they carry over Bluetooth LE with the Android TV Voice service. The board finds it when the remote connects, and the remote's row then reads microphone.
Tick Send voice (TCP socket only) and the microphone button sends what is said to the controller as JSON lines on the same connection:
{"command":"voice_start","rate":8000,"format":"s16le","remote":"Living Room Remote"}
{"command":"voice_audio","seq":0,"data":"<base64>"}
{"command":"voice_end","ms":3120}
voice_audio lines carry up to a quarter of a second each of mono 16-bit
little-endian PCM at the rate given (8000 or 16000, as the remote sends),
as it is spoken. voice_end follows 0.8 seconds of quiet after speech, 4
seconds with nothing said, the button's release on a remote that sends while
it is held, or 15 seconds at most, with the length sent in ms. Buttons pressed meanwhile are sent
between the lines as usual.
The controller has to understand these lines: leave Send voice off for a version of GEM that doesn't, which would take them for key names. With it off, the microphone button does nothing.
Remotes
Bluetooth LE remotes that are HID devices, which covers most remotes sold since about 2015. The remote has to be within Bluetooth range of the board, about 10 m in a room.
- Bluetooth Classic remotes and keyboards don't work: the board's radio is Bluetooth LE only.
- A remote's microphone, touchpad and pointer aren't sent, only its buttons.
- Some remotes send a few buttons in their maker's own format, which the board can't read: those buttons don't show under Last button.
- Remotes that ask for a passkey to pair don't work.
The board's Bluetooth uses the same antenna connector as its Wi-Fi. Without an antenna, remotes show up in the pairing list with a weak signal and then fail to pair.
Limits
- Up to 4 paired remotes, 24 named buttons.
- Programming: the Sofabaton U3 only, one remote at a time.
- One controller: every remote's keys go to the same place.
http://URLs only, no HTTPS.- A key that can't be sent within 2 seconds is dropped, not sent late.
- Bluetooth LE only, HID remotes only: buttons, and the microphone of remotes with the Android TV Voice service.
- Voice is 8 or 16 kHz, as the remote offers, on the TCP socket only, one utterance at a time.