Command
A text box for sending arbitrary commands to your device. Where a Button sends one fixed command, this sends whatever you type.
Useful while developing firmware, and for occasional commands that don’t deserve a permanent button.
Settings
| Field | What it does |
|---|---|
| Input label | Wording shown above the box |
| Color | The colour of the box and its send button |
| Admin only | Hide it from everyone who isn’t an admin of the device — see Sharing a device |
Handling commands
Whatever you type arrives in receivedCommand, exactly as a button’s command would:
.receivedCommand = [](JsonDoc doc) {
String cmd = doc["data"];
if (cmd == "led on") {
digitalWrite(LED_BUILTIN, HIGH);
} else if (cmd.startsWith("interval ")) {
int seconds = cmd.substring(9).toInt();
// apply it
}
},Because the text is free-form, this is where commands with a value are convenient —
interval 30, setpoint 21.5 — without needing an element per option.
Who sent it
A device can be shared between several accounts, and each of them has a number on it: 1 for whoever added the device, 2 for the first person it was shared with, and so on. The number is shown next to each person in the device’s Access tab. It never changes and is never given to anyone else, even after that person loses access.
Every command says who sent it, in user: idx is the sender’s number and role is what
they are on this device, "admin" or "user". sensordata.space sets it from that
person’s sign-in, so it can’t be faked from the browser:
.receivedCommand = [](JsonDoc doc) {
String cmd = doc["data"];
int idx = doc["user"]["idx"] | 0; // 0 if unknown
String role = doc["user"]["role"] | "";
Serial.printf("%s from user #%d\n", cmd.c_str(), idx);
if (cmd == "unlock" && role != "admin") return; // only the device's admins may unlock
// ...
},Switches and sliders send it the same way, to entityChanged.
Command history
The last ten commands you sent from an element are remembered and offered as suggestions the next time you use it, so repeating one is a couple of keystrokes. Each suggestion has an × to remove it from the list.
History is stored in your browser, per element. It isn’t shared with other people who have access to the device, and it won’t follow you to another browser or machine.
A note on unknown commands
Your device only acts on the commands your firmware recognises. Anything else is simply
ignored, with no error shown on the dashboard — so if a typed command appears to do
nothing, check the spelling against your receivedCommand code first.