Ping watchdog
The Arduino itself checks a site or IP. If the board loses that connection, it drives one of its own GPIO pins high then low, or low then high, and waits the transition time between those two levels.
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.
- Wire the device you want to pulse to an Arduino digital pin. This sample uses GPIO
2. - In Edit, add Ping watchdog.
- Set Arduino pin to
2. That number is the pin on the board. It is not virtual pin V2, and the sketch does not needBOX_WRITEfor it. - Set Site or IP to an address such as
x.x.x.xorhttps://example.com. The board opens a short TCP connection: port 80 for a host or IP, port 443 for https. You can also writeexample.com:443. - Set Ping interval in seconds. The shortest interval is 5 seconds. The sample is 30.
- Set Missed pings before failure. Three misses means three intervals in a row with no connection.
- Set On failure to High, then low, or Low, then high.
- Set Transition in seconds. That is the wait on the board between the first GPIO level and the second. The sample waits 5 seconds.
- Save the layout.
BoxIO.run()inloop()loads these settings about every 15 seconds and does the check on the board. The status line includes the host:ok x.x.x.x,miss 1/3 x.x.x.x, orfail high-to-low x.x.x.x. A successful check after a failure arms it again. It does not pulse again while the target is still down. - 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 |
|---|---|---|---|---|
pin | Dashboard | Arduino GPIO, 0 to 127 | 2 | The physical pin the board toggles. This is not a virtual pin. |
target | Dashboard or sketch | Host, IP, or http(s) URL | x.x.x.x | What the Arduino tries to reach. A host or IP uses port 80. https uses port 443. |
intervalSec | Dashboard or sketch | Seconds, 5 to 86400 | 30 | How often the board checks. |
misses | Dashboard or sketch | Whole number, 1 to 50 | 3 | Missed checks in a row before the GPIO runs. |
direction | Dashboard or sketch | high-to-low or low-to-high | high-to-low | high-to-low drives the GPIO HIGH, waits, then LOW. low-to-high drives LOW, waits, then HIGH. |
transitionSec | Dashboard or sketch | Seconds, 1 to 3600 | 5 | Time between the two GPIO levels. |
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
- The check runs on the Arduino, not on the Box IO server. Losing Wi-Fi on an ESP board counts as a miss. A connected radio that still cannot open the target also counts as a miss.
- High, then low: the GPIO goes HIGH immediately, stays there for the transition, then goes LOW.
- Low, then high: the GPIO goes LOW immediately, stays there for the transition, then goes HIGH.
- One outage runs that pair once. Further misses while the target is still down do not start another pair. The next success clears the miss count so a later outage can run the pin again.
- The status line on the widget is the pin property
watchdogStatus, reported by the board. A healthy check looks likeok x.x.x.x. A miss looks likemiss 1/3 x.x.x.x. A trip looks likefail high-to-low x.x.x.xorfail low-to-high x.x.x.x. An empty target showsSet a site or IP. Before the first check the widget saysWaiting for the first ping. - Call
BoxIO.setPingWatchdogfrom the sketch when you want the same behavior without the widget. A saved widget replaces that sketch setting the next timeBoxIO.run()syncs. BOX_HIGH_TO_LOWandBOX_LOW_TO_HIGHare the direction values in the sketch.
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 "localhost"
#define BOXIO_PORT 5923
#include <BoxIOEsp32.h>
void setup() {
BoxIO.begin(BOXIO_AUTH, WIFI_SSID, WIFI_PASS, BOXIO_HOST, BOXIO_PORT);
// Optional. A saved Ping watchdog widget replaces this.
// Check x.x.x.x every 30s. After 3 misses, GPIO 2 goes HIGH, then LOW 5s later.
BoxIO.setPingWatchdog("x.x.x.x", 30, 3, 2, BOX_HIGH_TO_LOW, 5);
}
void loop() {
BoxIO.run();
}
What you should see
While the board can reach the target, the widget says ok and the host. After the missed-check count it says fail, the direction, and the host, and GPIO 2 on the Arduino follows that direction, with the transition time between the two levels. The board does the check. The server only stores the settings and shows the status.