Webhook
When the sketch virtualWrites this pin, the Box IO server calls a URL. Dashboard edits do not fire it. Comma-separated fields fill the data template.
Set it up on the server
- Sign in to the Box IO dashboard and open the project that uses this device key.
- Turn on Edit.
- In Edit, add Webhook.
- Set Virtual pin to
11. The device on the widget, or the project device, must be the device key in the sketch. - Set URL to an http or https address. The server must be able to reach it.
- Set Method to GET, POST, or PUT.
- Set Content type to one of
application/json,text/plain, orapplication/x-www-form-urlencoded. - Set Data using
{1},{2}, and{value}. - Save the layout. The call happens only after a device virtualWrite. The widget shows the pin value and a status such as
204 POST. - Flash the sketch below with the same device key, host, and port
5923. KeepBoxIO.run()inloop().
Properties
Sketch values are always strings, including numbers: BoxIO.setProperty(V2, "max", "200").
| Property | Where to set it | Format | Example | Effect |
|---|---|---|---|---|
url | Dashboard | http or https URL, 2000 characters max | https://example.com/hook | Placeholders in the URL are URL-encoded. <code>{1}</code> in the URL is the first field. |
method | Dashboard | GET, POST, or PUT | POST | GET puts Data on the URL and sends no body. POST and PUT send Data as the body. |
contentType | Dashboard | One of the three types below | application/json | Chooses how inserted values are escaped and which Content-Type header is sent. |
data | Dashboard | Template, 8000 characters max | {"temp":"{1}","room":"{2}"} | <code>{1}</code> is the first comma field, <code>{2}</code> the second, and <code>{value}</code> is the whole virtualWrite string. Fields are trimmed. |
label | Dashboard or sketch | Plain text | Pump | Caption above the widget. On a round or oval button this is the caption, not the word on the button face. |
hideLabel | Dashboard | On or off | checked | Hides the caption. Button face text, meter numbers, and label text stay visible. |
fontSize | Dashboard | Whole number 8 to 160, or blank for automatic size | 28 | Text size in pixels inside the widget. |
opacity | Dashboard | 10% to 100% | 70% | Lets an overlapping widget show through. 100% is solid. |
Formatting
BoxIO.virtualWrite(V11, "72,north room")makes{1}=72and{2}=north room.- application/json escapes quotes, backslashes, and newlines inside each inserted value. Template
{"temp":"{1}","room":"{2}"}is sent as{"temp":"72","room":"north room"}. A room namednorth "hall"does not break the JSON. - application/x-www-form-urlencoded encodes each inserted value. Spaces become
+.&and=become%26and%3D. Templatetemp={1}&room={2}is sent astemp=72&room=north+room. - text/plain inserts the values unchanged. The header is
text/plain;charset=utf-8. - GET appends Data with
?or&. A form content type still uses+for spaces on that query. POST and PUT send the body with the Content-Type you picked. - If Content type is left empty, a template that starts with
{or[is JSON, a template that contains=is form data, and anything else is plain text. - Only http and https are called. The request times out after 8 seconds. The status line is stored on the pin as
webhookStatus.
Sketch
Paste the device key over bx_paste_your_device_key_here. Wi-Fi boards include BoxIOEsp32.h. Ethernet boards use the same calls with an EthernetClient.
#define BOXIO_AUTH "bx_paste_your_device_key_here"
#define WIFI_SSID "your-ssid"
#define WIFI_PASS "your-password"
#define BOXIO_HOST "boxio.krmsproducts.net"
#define BOXIO_PORT 5923
#include <BoxIOEsp32.h>
void setup() {
BoxIO.begin(BOXIO_AUTH, WIFI_SSID, WIFI_PASS, BOXIO_HOST, BOXIO_PORT);
// Dashboard data for JSON:
// {"temp":"{1}","room":"{2}"}
// Form data instead:
// temp={1}&room={2}
}
void loop() {
BoxIO.run();
static uint32_t last = 0;
if (millis() - last < 5000) return;
last = millis();
BoxIO.virtualWrite(V11, "72,north room");
}
What you should see
After the virtualWrite, the widget leaves “Waiting for virtualWrite” and shows 72,north room plus the HTTP status. A button click on a different widget does not call this URL. The call is only from virtualWrite on V11.