First, we will set the serial number (name) of your notecard and the ProductUID. The ProductUID is the one corresponding to the project you created in Cloud Setup. Replace the sn and product values with your own and paste the resulting command into the in-browser terminal.
This instructs the Notecard to assume LiPo battery characteristics, monitor USB power and send an alert immediately when a power outage occurs and when power is restored. For more details, see the Notecard API reference and the Enable USB Power Alerting example.
If you want to issue all of the above requests in one shot, you can do so with the Notecard CLI and the config.json configuration script. You will need to change the ProductUID in the hub.set command to match your ProductUID. Once you've done that, you can configure the Notecard with:
Notehub supports forwarding data to a wide range of API endpoints by using the Route feature. This can be used to forward your power monitoring events to external dashboards and alerts to a realtime notification service. Here, we will use Twilio SMS API to send a notification of an alert to a phone number.
Fill out the required fields for the Twilio SMS route, including "from" and "to" phone numbers, where "from" is your virtual Twilio number, and "to" is the number of the phone that receives the power outage alerts. We will not be using placeholders for these numbers, but will use a placeholder for the message, so set the message field to [.body.customMessage].
Under the "Filters" section, set "Notefiles" to "Selected Notefiles" and type _health.qo in the text input area below the list of notefiles.
Under "Data", select "JSONata Expression" and copy and paste the contents of jsonata/route.jsonata into the text field "Insert your JSONata expression here".
With the Notecard connected to USB power, and the LiPo connected, simulate a power outage by unplugging the USB power supply. Within a few seconds, an SMS will be sent to the to number you configured in the route above.
The message looks like this:
ALERT! Power has failed to device Refrigerator.
This indicates a mains power failure on the Notecard with serial number "Refrigerator".