Button
A Button sends a command when you press it. Use Push for things that act only while held, like a buzzer or a motor jog. Use Switch mode when each tap should flip the state.
1 / 05 looks · 8 iconsTry it
Press and hold the button. In Push (Momentary) mode the buzzer sounds only while you hold it. Change Button Action to Switch (Latching) and each tap flips it instead. Then try the shapes, looks and icons — they are the same settings as in the widget's settings window.
1 when you press and 0 when you let go. If the connection drops while you hold it, your code should treat a missing 0 safely, for example with a timeout.How to add and set up
- Open the dashboard in edit modeOpen the device and turn on editing.
- Add a ButtonPress + on the right edge of the canvas and pick Button. Drag it into place.
- Open its settingsClick the gear icon on the widget. The window title shows the widget's name.
- Link a Telemetry PointUnder Linked Telemetry Points, pick the point your code reads, for example
TP0. - Choose the action and lookSet Button Action to Push (Momentary) or Switch (Latching), pick a Button Shape, Button Style and Icon, then save and press DONE.
Settings
| Setting | What it does |
|---|---|
| Widget Name | The title shown on the widget. |
| Label Color | Colour of the title. |
| Linked Telemetry Points | The Telemetry Point (TP0, TP1…) the widget uses. Your device code uses the same point. |
| Button Action | Push (Momentary): sends 1 while pressed, 0 when released. Switch (Latching): each tap flips between 1 and 0. |
| Button Shape | Round / Circle or Square / Rectangular. |
| Button Style | Flat (default), 3D (sinks when on), Outline, Label (text inside) (icon and text in a pill) or Glass (frosted). 3D and Label need Starter or above. |
| Icon | Auto (hand in Push mode, power in Switch mode), Power, Bulb, Fan, Pump / Water, Lock, Bell or Play / Pause. Fan, Pump / Water, Lock, Bell and Play / Pause need Starter or above. |
| ON / OFF label | Text shown in each state. Defaults: ON and OFF. |
| ON / OFF text colour | Colour of that text in each state. |
| Widget Color | Colour of the button when it is on, and of the tile's border. |
| Hide widget Name / Telemetry Point / Widget Border | Hide the title, the TP badge or the outline around the tile. |
Push or Switch?
| Use | Mode |
|---|---|
| Buzzer, horn, motor jog, garage door pulse | Push (Momentary) |
| Light, fan, pump that should stay on | Switch (Latching) |
Receive commands on your device
Your board picks the value up with SME_LISTEN on the linked point. The examples use TP0.
SME_LISTEN(TP0)
{
digitalWrite(BUZZER_PIN, data.toInt()); // 1 while held, 0 when released
}// React to the press and ignore the release. Use Push mode.
SME_LISTEN(TP0)
{
if (data.toInt() == 1) {
digitalWrite(DOOR_PIN, HIGH);
delay(300); // short pulse
digitalWrite(DOOR_PIN, LOW);
}
}#define DASHBOARD_ID "PROJ-XXXXXXXX"
#define DEVICE_TOKEN "SME-XXXX-XXXX-XXXX"
#define FIRMWARE_VERSION "1.0.0"
#define WIFI_SSID "your_wifi"
#define WIFI_PASS "your_pass"
#include <SMEIoT.h>
#define BUZZER_PIN 5
// Button on TP0 (Push mode): 1 while held, 0 when released
SME_LISTEN(TP0)
{
digitalWrite(BUZZER_PIN, data.toInt());
}
void setup()
{
Serial.begin(115200);
pinMode(BUZZER_PIN, OUTPUT);
SME.begin(DASHBOARD_ID, DEVICE_TOKEN, FIRMWARE_VERSION,
WIFI_SSID, WIFI_PASS);
}
void loop()
{
SME.run(); // keeps the link alive
}SME_LISTEN(TP0) runs every time the dashboard writes TP0. data holds the value it sent, as text: use data.toInt() for whole numbers or data.toFloat() for decimals.
delay() calls inside SME_LISTEN hold up the connection.These are snippets. Your sketch also needs #include <SMEIoT.h>, SME.begin(...) in setup() and SME.run() in loop(). The full sketch tab shows a complete example; see the SDK quick start for more.
Docs