As you can tell if you've been reading my blog lately, I've been spending some time playing with Ring Central. One of the use cases that I've mentioned in the past is using it for SMS notifications in an IoT environment. Maybe you have a temperature sensor or a motion sensor and you want an SMS notification each time a certain reading or event is detected - these are very common use cases. Since I've also spent some time playing around with Node-RED in the past, I thought an integration with these two tools would be a perfect idea, so I built one! If you don't have Node-RED installed, see my other post on this blog - or, install it locally. You may also be working on a Raspberry Pi - and some versions of Raspbian come with Node-RED pre-installed. When your Node-RED server is up and running, you'll want to install the Ring Central module that I built.
Go to Manage Pallete -> Install, search for 'ring central' and click 'Install':
You'll now have a new group and set of nodes in your sidebar to interact with the Ring Central SMS APIs:
So how might you use these nodes? Well, let's say you have a temperature sensor somewhere in your network that is publishing temperature data to an MQTT topic. Here's an example flow (that uses a random number to simulate a temp value):
In another flow, we'll read from the MQTT topic and check the incoming temperature value - if the value is less than "40" we will send an SMS message:
To use the Ring Central nodes, first create an app in the Ring Central Developer portal - here's a quick start guide if you're new to Ring Central. It's pretty easy, just click 'Create App' on the quick start guide and it'll bring you to a screen like so (after you're logged in):
Click 'Create' and on the next screen we'll need some values - the API Server URL, the client id and client secret, your account phone number and your password:
Now, back in Node-RED - configure your Ring Central credentials by clicking on the '
sms send' node and then editing your credentials:
Populate the credentials from your Ring Central App in to the Node-RED credentials dialog - these will be persistent in your Node-RED application and you can use them in other flows - even add additional credentials if you have multiple accounts.
Go ahead and edit the recipient number while you're in the sms send node - be sure to include the country code in the recipient phone number. Now deploy the flows and test it out by triggering the random temperature flow a few times until you get a reading below 40 which will result in an SMS message:
So that's what it takes to send an SMS - but what about receiving SMS? It's just as easy. Set up another flow - this time with an inject node that injects the current timestamp. The '
sms receive' node expects
msg.dateFrom to be a ISO formatted date from which to retrieve the messages from. In this example, I repeat the inject node every X seconds and use the moment node to set msg.dateFrom to be the current date minus X seconds - so everything that has been received since the last time the flow ran will be retrieved. The
sms receive node will retrieve the messages and set them into the msg and we're free to do whatever we need with them. In this case, I split the array of messages and check each of them for the existence of a specific substring and debug the msg if it exists - but you can do whatever you need - publish a message to MQTT, make an HTTP request - whatever you need.
There's one other bit to talk about - if the message was an MMS message then it will contain a URL that can be used to download the attachment. You'll need to use a signed URL to download the attachment, so you'll need the
sign url node in your flow. So now, we can send an MMS to our Ring Central number:
Retrieve the message, then create a new flow to generate a signed URL:
And then view the attachment in our browser:
I have some plans to enhance this module even further in the future, but for now please try it out and let me know what you think. I hope you find it helpful and an easy way to send and receive SMS from your Node-RED flows!
I have blogged quite a bit about serverless Oracle Functions here on this blog, including several various examples about function invocation. But, I've...
I have blogged quite a bit about our OCI Java SDK in the past. It's easy to use and a very intuitive and consistent SDK that can perform just about any...