Readers of my blog know I am a huge fan of Node-RED so now you can learn about it in the upcoming tech talk by IBM developerWorks. I most recently used Node-RED in an Eclipse application where I provide an automatic translation service for a tool called PET.
IBM developerWorks Open Tech Talk Node-RED
Categories: Cloud, Internet of Things
Node-RED is a tool for wiring together the Internet of Things in new and interesting ways, including hardware devices, APIs, and online services. Node-RED makes it easy to wire together real-world events, add in some intelligence, and access simple nodes to integrate them with existing messaging systems and social platforms such as Twitter, MongoDB, and Redis to create apps that can react to the world around them.. Learn more.
I wrote a rating application some time ago in Node-Red and have since needed another similar application but with slightly different behavior. So I went ahead and created a new Node-Red application on Bluemix and decided to start from scratch since it was so simple to set up. This application has three requests – Get Rating, Post Rating, and Post Comment. Here is the current flow:
The problem I had was the requests actually respond with JSON and I could not figure out how to enable CORS!
The first thing I did was in the node I added the following to the response:
And that did not work. Then, I stumbled upon this in my Cloudant dashboard in the Account Section under CORS:
Once I checked all domains it worked fine! I am sure I can restrict the domains appropriately but I guess I don’t understand why the CORS options are under the Cloudant section and not the base application somewhere. I would think this is a specific thing to hitting the Cloudant service directly, not through a Node-Red Node. I am very interested in hearing others opinions on this.
After using the Cloudant UI to update my profile I went back and checked the bluemix-settings.js saw it indeed added the httpNodeCors line to the profile:
After much searching the internet and seeing multiple posts about this subject I can only think that many others are greatly confused with the use of the Cloudant In node in Node-Red. I think my problem was terminology and not being familiar enough with the Cloudant nomenclature more than anything and the user interface in Node needs a little more work.
I basically want to return all documents where name=XXXXX. My document is pretty simple, here is an example:
So lets start by looking at my index definition:
Now you will notice I have three references to “namesearch”:
The design document name is “_design/namesearch”
The Index name is “nameSearch”
The index in the search index function is also named “nameSearch”
My flow takes in an HTTP request, formats it with the Selector node, and passes the query on to the Cloudant In node:
The selector node is pretty basic, after following many different instructions I finally resolved the problems with this function:
This results in a payload that looks like this:
nameSearch:Create a category layout
The Cloudant In node now has the following configuration (which seemed to be the primary problem, I will explain later:
The problem I had was I could not future out the search index fields. Mainly because this is the form when no fields are filled in:
Notice it specifically says “design document“. Now, anyone that is not familiar with this, based on my configuration, would most likely fill it out like this:
But after scouring many documents on the internet a suggestion was to just remove the “_design/” from the first field. Which resulted in the correct version I have above:
Needless to say this actually took me hours to figure out because I thought it was something with the query being passed in!
The next step in my Node-RED application on BlueMix is to create some user interface that calls the services I defined in my Node-RED flow sheet. If you recall from the last post, I created two services:
/postrating – which will post a rating for a given url
/rating – which retrieves the average rating for the url
In this next video I create a basic jQuery user interface that allows the user to click on a star and register their rating for the given page. There are no checks and balances in the application as of yet – ie. I can click as many times as I want so I can test my services.
This is the first part of a new application I am creating using Node-RED on BlueMix. With very little programming, I show how you can get a basic URL rating application up and running very quickly using Node-RED. In this first part I focus on the two primary web services, posting a rating and getting a rating for a URL.
In my last post I introduced a project on GitHub that provided 26 new Node-Red nodes you can use in your Node-Red flow. Today I am going to show how you can bundle up one of those nodes and deploy it to your application on BlueMix.
I have had problems with my blog service provider in that the database server goes off-line at random times. While it only happens maybe once or twice every other month it is very annoying and most of the time I get notified by some of my avid readers that my ‘blog is down”. If anyone knows WordPress, if your database server is down the blog is pretty much dead.
In this video I show how you can bundle up a node and deploy that new node to your Node-Red application flow to be used in your flows.
72-wordpos – Analyses the payload and classifies the part-of-speech of each word. The resulting message has msg.pos added with the results. A word may appear in multiple categories (eg, ‘great’ is both a noun and an adjective).
74-swearfilter – Analyses the payload and tries to filter out any messages containing bad swear words. This only operates on payloads of type string. Everything else is blocked.
37-rpi-piface – Adds support for the PiFace interface module for Raspberry Pi.
78-ledborg – A simple driver for the LEDborg plug on module for Raspberry Pi.
60-wemo – Basic node to drive a WeMo socket and switch. Does not use discovery.
76-blinkstick – Provides support for the BlinkStick USB LED device.
77-blink1 – Provides support for the Blink1 USB LED from ThingM.
78-digiRGB – Provides support for the DigiSpark RGB USB LED.
79-sensorTag – Reads data from the Ti BLE SensorTag device.
100-heatmiser-in – Writes settings for temperature and frost protection to Heatmiser thermostats.
101-heatmiser-out – Reads settings from Heatmiser thermostats at a polling interval.
101-scanBLE – Scans for a particular Bluetooth Low Energy (BLE) device.
145-BBB-hardware – A collection of analogue & digital input & output nodes for the Beaglebone Black
26-rawserial – Only really needed for Windows boxes without serialport npm module installed. Uses a simple read of the serial port as a file to input data. You must set the baud rate etc externally before starting Node-RED. This node does not implement pooling of connections so only one instance of each port may be used – so in orout but not both.
39-wol – Sends a Wake-On-LAN magic packet to the mac address specified. You may instead set msg.mac to dynamically set the target device mac to wake up.
88-ping – Pings a machine and returns the trip time in mS. Returns false if no response received within 3 seconds, or if the host is unresolveable. Default ping is every 20 seconds but can be configured.
69-mpd – MPD music control nodes. Output node expects payload to be a valid mpc command. Currently only simple commands that expect no reply are supported. Input node creates a payload object with Artist, Album, Title, Genre and Date.
57-notify – Uses Growl to provide a desktop popup containing the payload. Only useful on the local machine.
57-prowl – Uses Prowl to push the payload to an Apple device that has the Prowl app installed.
57-pushbullet – Uses PushBullet to push the payload to an Android device that has the PushBullet app installed.
92-xmpp – Connects to an XMPP server to send and receive messages.
67-leveldb – Uses LevelDB for a simple key value pair database.
68-mysql – Allows basic access to a MySQL database. This node uses the query operation against the configured database. This does allow both INSERTS and DELETES. By it’s very nature it allows SQL injection…so be careful out there…
69-ddbout – Support output to Amazon DynamoDB.
79-suncalc – Uses the suncalc module to generate an output at sunrise and sunset based on a specified location. Several choices of definition of sunrise and sunset are available,
99-sample – A sample node with more comments than most to try to help you get started without any other docs…
If you have been following my blog and more specifically my Twitter account in the past week you probably noticed an awful lot of re-tweets in the past week. Well, if you just happen to have missed my original video where I created a simple Node-RED application to automatically retweet and promote “bluemix” on Twitter feel free to get some context here and watch the video.
This is the final flow after some debugging and watching the different retweets happening:
In this video I show how easy it is to debug a Node-RED application flow using the debug output element. A few things I realized when writing this application was you have to be very careful when automating a retweet. You have to take some things into consideration like:
Maybe only retweeting people you trust
Retweet only tweets in your native language
Filter out tweets with foul language
Don’t retweet your own retweets!
Make sure the end retweet is under the 140 character limit
Limit your retweet activity as so not to spam yours and others feeds.