Ping CronMissed from an ESP32 or ESP8266
On this page
A sensor, a gateway or a greenhouse controller can ping CronMissed from the board itself, and the check alerts when the board goes quiet. The ping must use HTTPS: a plain HTTP request is answered with a redirect, and most board libraries do not follow one.
What should a board job send?
- A request to
/startbefore the work, so CronMissed can time the run and notice a job that never finishes. - A request to the plain URL when the work succeeded, or to
/failwhen it did not./<exit status>works too: 0 is a success and any other number is a failure. - The end of the output in the request body, up to 100,000 bytes, so the alert shows the error without a trip to the server.
What does the sketch look like?
ping.ino
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
const char* WIFI_SSID = "your-network";
const char* WIFI_PASS = "your-password";
const char* PING_URL = "https://ping.cronmissed.com/5f0c1b2e-7a3d-4c8e-9b61-2d4f8a7e3c10";
// The root certificate of the ping host, as PEM. Paste the one your browser shows for the ping address.
const char* ROOT_CA = "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n";
void ping(const String& suffix) {
WiFiClientSecure client;
client.setCACert(ROOT_CA); // use client.setInsecure() only for a quick test: it skips certificate checks
HTTPClient http;
http.setTimeout(10000);
if (http.begin(client, String(PING_URL) + suffix)) {
http.GET(); // the result is ignored: a lost ping must not stop the board
http.end();
}
}
void setup() {
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) delay(500);
}
void loop() {
ping("/start");
readSensorsAndStore(); // your work
ping("");
delay(10UL * 60UL * 1000UL); // ping every 10 minutes
}Keep the ping URL in an environment variable or a secret store, never in a public repository: the URL is the check's only credential.
How should the check be set?
Create a simple check whose period is the loop interval plus a little, here 10 minutes, and a grace of two or three loop times so a slow Wi-Fi reconnect is not an alert. For a board that sleeps between readings, ping on each wake-up and set the period to the sleep time.
What are the common problems?
- The request fails with a TLS error: the root certificate is wrong or the board clock is not set. Set the time with NTP before pinging.
- The ping works from a laptop and not from the board: check that the sketch uses https:// and not http://.
- Memory: TLS needs a few tens of kilobytes of free heap on an ESP8266; ping once per loop and reuse nothing between pings.
Questions and answers
- Yes, with the ESP8266 libraries (ESP8266WiFi, ESP8266HTTPClient and a BearSSL secure client). The structure of the sketch stays the same.
- If it can make an outbound HTTPS request over IPv4, yes. The ping host is reached over IPv4 or dual stack only.
Does it work on an ESP8266?
Can a board behind a mobile network ping?
Create the check these snippets report to
Make a check, copy its ping URL into the snippet, and run the job once.
Start monitoring