Heartbeat Monitoring

This example uses Twilio's SMS API plus Webscript's built-in storage to monitor the heartbeats sent from a device. If a heartbeat hasn't been received for too long, the system sends a text message.

The Twilio part of this example is similar to the Twilio SMS example. We recommend that you read that first.

This example borrows heavily from Charalampos Doukas's post (with permission).

Script Code

The system is comprised of two scripts: one to accept the heartbeat "pings", and another to monitor if the last heartbeat was more than N minutes ago.

Heartbeat Script

The heartbeat script records the current time in persistent storage.

Monitor Script

The monitor script checks if the last heartbeat was more than N minutes ago. If so, it sends a text message to that effect. It returns a JSON object that may be useful during debugging.

The monitor script is run as a cron job to periodically check the heartbeat status.