Node-RED : IBM developerWorks Open Tech Talk

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.

node-redIBM developerWorks Open Tech Talk
Node-RED
Categories: Cloud, Internet of Things

Wed June 22nd, 11 AM ET

Web Meeting link.

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.

Advertisements

Allowing CORS from a Node-Red Bluemix application

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:

Image (1) rate-flow-680x422.png for post 5391

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 Image (2) cors.png for post 5391 node I added the following to the response:

Image (3) cors2.png for post 5391

And that did not work. Then, I stumbled upon this in my Cloudant dashboard in the Account Section under CORS:

 

Image (4) cloudant_admin-680x212.png for post 5391

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.

Update:

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:

httpNodeCors: { origin: “*”, methods: [‘GET’,’PUT’,’POST’,’DELETE’] },

So this is clearly the issue as I saw a similar question on developerworks but saw no example of the syntax.

Searching a Cloudant DB search index with Node-Red

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:

review-doc

So lets start by looking at my index definition:

cloudant_index

Now you will notice I have three references to “namesearch”:

  1. The design document name is “_design/namesearch”
  2. The Index name is “nameSearch”
  3. 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:

flow

The selector node is pretty basic, after following many different instructions I finally resolved the problems with this function:

selector

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:

cloudantin

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:

designdoc

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:

node-red cloudant in

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:

cloudantin

Needless to say this actually took me hours to figure out because I thought it was something with the query being passed in!

If you are not familiar with Node-Red then click this link.

URL Rating application on BlueMix – Part 2 – the user interface

starsThe 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

For now, I will use the index.html to test the user interface. I want to make it dead simple for someone to use this in the end so the only need is to include the javascript file and define a div with an id of “urlRate”, like so:

[codesyntax lang=”html4strict”]

</div> </div>

[/codesyntax]

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.

Continue reading

Creating a URL Rating Application in Node-RED on BlueMix – Part 1

starsThis 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.

Continue reading

Node-RED boilerplate on #BlueMix now uses Cloudant NoSQL DB

Not sure if anyone noticed this but the Node-RED boilerplate application on BlueMix now uses the Cloudant NoSQL database service for storage. The beta version used Mongo:

CLOUDANT

Adding a new node type to your Node-Red flow application on BlueMix

Screen Shot 2014-07-09 at 12.02.32 PMIn 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.

26 Node-Red nodes for your arsenal!

GitHub-MarkCheck out this project on GitHub, it has 26 new nodes for your Node-Red application. Everything from Analysis to Hardware:

https://github.com/node-red/node-red-nodes

Analysis

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.

Hardware

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

IO

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.

Social

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.

Storage

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.

Time

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,

Misc

99-sample – A sample node with more comments than most to try to help you get started without any other docs…

Final Re-Tweet Code for my Node-RED application on BlueMix (updated)

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:

 

Continue reading

Debugging A Node-RED Application on BlueMix

debug-nodeRED

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.

 

Continue reading