Saturday, January 9, 2016

A Xively trigger PHP script to send email and SMS notifications

Xively is a platform devoted to simplifying the interconnection of devices and data with applications on the Internet of Things.


It uses feed and channels to collect user data. Any Xively channel can have one or more triggers. A trigger is a notification sent when a condition occurs on that channel.
For example if a channel is related to temperature. One can add a notification triggered when the temperature goes below a ceratin threshold.
Xively trigger does an HTTP POST request to an URL.
This is a PHP script one can use to send email and/or SMS alert for a Xively feed trigger action.

To use this script you have to upload it to any website running a PHP server.
Email are sent using the PHP mail function.
SMS are sent through a Betamax/Dellmont Voip provider. So, in order to be able to send SMS you must have some Dellmont voip account, and fill your credetils in the configuration zone of this script.
To prevent the notification of many SMS, a limiter functionality is implemented.
Also a sign it is used as a token to allow only the ones who know the token to use the script.

To use this script, point the Xively channel trigger post url to this script, and set the url parameter for your message.
As example, suppose you have installed the script at this address:
http://example.com/xivelytrig/xivelytrig.php
To send both mail and sms, use this url:
http://example.com/xivelytrig/xivelytrig.php?sign=example.com/xivelytrig/xivelytrig.php?sign=123456&feed=your_feed_name&channel=your_channel_name&alarm=your_alarm_text&address=address@example.com&mobile=000000000000
To send just email use this:
http://example.com/xivelytrig/xivelytrig.php?sign=example.com/xivelytrig/xivelytrig.php?sign=123456&feed=your_feed_name&channel=your_channel_name&alarm=your_alarm_text&address=address@example.com
Replace
 - 123456 with the $sign you set in your script
 - your_feed_name with then feed name you want to get for the notification
 - your_channel_name with then channel name you want to get for the notification
 - your_alarm_text with then message you want to get for the notification
 - address=address@example.com with the mail where to send the notification
 - 000000000000 with the mobile number where to send the notification


Code

Notes
  • read risk disclaimer
  • excuse my bad english