Box IO

Self-hosted IoT for Arduino and ESP32.

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.

Sample pin: GPIO 2

Set it up on the server

  1. Sign in to the Box IO dashboard and open the project that uses this device key.
  2. Turn on Edit.
  3. Wire the device you want to pulse to an Arduino digital pin. This sample uses GPIO 2.
  4. In Edit, add Ping watchdog.
  5. Set Arduino pin to 2. That number is the pin on the board. It is not virtual pin V2, and the sketch does not need BOX_WRITE for it.
  6. Set Site or IP to an address such as x.x.x.x or https://example.com. The board opens a short TCP connection: port 80 for a host or IP, port 443 for https. You can also write example.com:443.
  7. Set Ping interval in seconds. The shortest interval is 5 seconds. The sample is 30.
  8. Set Missed pings before failure. Three misses means three intervals in a row with no connection.
  9. Set On failure to High, then low, or Low, then high.
  10. Set Transition in seconds. That is the wait on the board between the first GPIO level and the second. The sample waits 5 seconds.
  11. Save the layout. BoxIO.run() in loop() 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, or fail 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.
  12. Flash the sketch below with the same device key, host, and port 5923. Keep BoxIO.run() in loop().

Properties

Sketch values are always strings, including numbers: BoxIO.setProperty(V2, "max", "200").

PropertyWhere to set itFormatExampleEffect
pinDashboardArduino GPIO, 0 to 1272The physical pin the board toggles. This is not a virtual pin.
targetDashboard or sketchHost, IP, or http(s) URLx.x.x.xWhat the Arduino tries to reach. A host or IP uses port 80. https uses port 443.
intervalSecDashboard or sketchSeconds, 5 to 8640030How often the board checks.
missesDashboard or sketchWhole number, 1 to 503Missed checks in a row before the GPIO runs.
directionDashboard or sketchhigh-to-low or low-to-highhigh-to-lowhigh-to-low drives the GPIO HIGH, waits, then LOW. low-to-high drives LOW, waits, then HIGH.
transitionSecDashboard or sketchSeconds, 1 to 36005Time between the two GPIO levels.
labelDashboard or sketchPlain textPumpCaption above the widget. On a round or oval button this is the caption, not the word on the button face.
hideLabelDashboardOn or offcheckedHides the caption. Button face text, meter numbers, and label text stay visible.
fontSizeDashboardWhole number 8 to 160, or blank for automatic size28Text size in pixels inside the widget.
opacityDashboard10% to 100%70%Lets an overlapping widget show through. 100% is solid.

Formatting

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.