Clearly I am missing something. I have set up a twilio message route to handle power out messages. I went through the process of setting up a message for the _health using twilio, I used a transformation similar to the power out example documented by Rob, but have not had success. I am not clear what is going on as the format of my transformation seem correct?
error building route request: error validating twilio body: no twilioBody provided
The transformation is set up as below:
“&Body=” & ($contains(body.text, “USB” )? “Your power is out! ” : “Your power is back on! ”) & “&From=+1234567&To=+1234567&”
Hi @rksteeves,
Since that Hackster tutorial was published, the process to use Twilio in Notehub has been updated. Assuming your “from” and “to” phone numbers are static, you’ll enter those in the route creation screen.
Assuming (again from your code above) that you want the body to be dynamic, try this expression (not fully tested, but should at least get you most of the way there):
{
"body":{
"twilioBody": $contains(body.text, "USB" )? "Your power is out!" : "Your power is back on!"
}
}
Hope that helps,
Rob
Thanks. I finally resorted to using the generic http request method. I came up with the following which seems to work:
$contains(body.text, “USB”) ? (“&Body=” & ($contains(body.text, “usb-disabled” )? “Your power is out! ” : “Your power is back on! ”) & “&From=+12345678&To=+187654321&”) : $doNotRoute()
The only thing I dont know if there are any other _health.qo events that contain USB? I am assuming if “USB” is contained in the _health.qo event, it is a power out event and apply the above.
I’m not sure if you noticed this, but (also since the Hackster article was published) the card.voltage
API can automatically send health.qo notes whenever there is a change in USB power state:
{
"req": "card.voltage",
"usb": true,
"alert": true,
"sync": true
}
1 Like
Yes, that is the functionality that I am using.
My only question was if there were any other health.qo notes/events that contained USB. I am assuming “USB” is in the _health.qo note, it is an alert about USB power. ie in my above script, if “USB” is in the health.qo note, I check if it is usb-disabled (power out) and send a message accordingly. If the health.qo note does not contain “USB”, I dont route it.
Can I assume that “USB” in the health.qo message is for a usb power issue, or are there other health.qo notes that havee “USB” in the text?
Got it. I would recommend keying on the {usb-disabled}
and {usb-enabled}
strings in the text of the _health.qo
Note. The reason for this is the error/status codes in curly braces will persist across firmware versions, whereas other strings in text
may change:
"body": {
"text": "USB power OFF {usb-disabled}"
},
and
"body": {
"text": "USB power ON {usb-enabled}"
},
1 Like
Thanks for that, I have switched to usb-enabled/disabled and it seems to work fine.
One final question, is there a simple method to generate a _health.qo note that is not associated with usb power?
You should always get a _health.qo
Note generated upon a cold boot of the Notecard. We certainly don’t recommend this as the Notecard was built to be powered-on all the time, and it adds wear to the flash (not to mention takes longer to connect to the cellular network). But in a pinch, it’ll work!
Rob
FYI - a better way to do this is to use the hub.log API. This will generate a custom _health.qo
Notefile:
{
"req": "hub.log",
"text": "something is wrong!",
"alert": true,
"sync": true
}
1 Like