Node-RED is a powerful tool for building IoT applications and services. Its genesis was triggered exactly by this need to rapidly prototype IoT applications and Node-RED was created as an open source project by the IBM Emerging Technologies group, in particular by two researchers, Nick O’Leary and Dave Conway-Jones. They created Node-RED initially as a tool for themselves as they were working on IoT projects and were “looking for a way to simplify the process of hooking together systems and sensors when building proof-of-concept technologies for customers.”

In this article we'll use Node-RED's native HTTP and MQTT libraries ("nodes") to read/send data to/from Ubidots.

Why use native libraries instead of Ubidots' library?

Through our experience and interaction with thousands of developers, Node-Red and Ubidots compliment each other's services well when: 

  • Grasp the concepts behind IoT protocols: Working with native HTTP and MQTT libraries will help you understand the concepts behind these protocols, enriching your IoT expertise. Using a library that wraps these protocols might save you lines of code, but will hide important concepts that might be useful for troubleshooting and scaling your project.
  • Connecting from any Node-RED device/server: Some Node-RED environments make it hard to install 3rd party libraries. For example, if you're running Node-RED from a server and you're not the admin and cannot install libraries. Using already built-in libraries can save you time, headache, and development costs. 

In the examples below we'll use an "Inject node" to simulate data, but of course in real-world applications, you need only replace this node with its actual source of data.

Node-RED + Ubidots using HTTP

Here's a simple node arrangement that sends an random "current" value, between 0 and 5, and a fixed "voltage" value to a Ubidots device called "node-red":

All the magic happens in the "function" node called "Setup Request", which prepares the request according to Ubidots API expected HTTP details:

Here's the clipboard version, so you can import it into your project:

[{"id":"9a51d38b.c2c56","type":"inject","name":"","topic":"","payload":"","payloadType":"none","repeat":"5","crontab":"","once":true,"x":129,"y":120,"z":"b40cc76f.057c28","wires":[["ce12cba7.7e25e8"]]},{"id":"ce12cba7.7e25e8","type":"function","name":"Setup Request","func":"var msg;\ndevice_label = \"Node-RED\";\nubidots_token = \"A1E-xxxxxxxxxxxxxx\";\nmsg.method = \"POST\";\nmsg.url = \"\" + device_label + \"/?token=\" + ubidots_token;\nmsg.payload = {\"current\":5*Math.round(Math.random() * 100) / 100,\"voltage\":\"110\"};\nreturn msg;","outputs":1,"valid":true,"x":294,"y":120,"z":"b40cc76f.057c28","wires":[["1f05de9a.b74411"]]},{"id":"cbae05ca.da6038","type":"debug","name":"","active":true,"console":"false","complete":"payload","x":648,"y":120,"z":"b40cc76f.057c28","wires":[]},{"id":"1f05de9a.b74411","type":"http request","name":"","method":"use","ret":"txt","url":"","x":472,"y":120,"z":"b40cc76f.057c28","wires":[["cbae05ca.da6038"]]}]

Node-RED + Ubidots using MQTT

Here's an example that publishes temperature data to Ubidots' MQTT broker and subscribes to the updated variable:

The example uses an inject node to publish the payload {"temperature":123} to an MQTT publish node configured as specified in Ubidots' MQTT documentation, that is:

For Educational users:

 port: 1883

Ubidots users:

 port: 1883

Username: Your Ubidots token 

Password: Leave blank

Publish topic:


Subscribe topic:


* Note that "lv" stands for last value. This means, this topic only returns the last value of the variable, without the JSON formatting, making it easier to parse if needed.

Entering all of this in Node-RED would look like this:

In the MQTT publish node:

When clicking in the edit button of the Broker:

In the MQTT subscribe node:

To test this function just, press the "Inject" button, and you should see the number "123" in the debug console. This number just went all the way to the cloud and came back in a few seconds:

Finally, here's the clipboard version so you can easily import it into your project:

[{"id":"ba386057.845d3","type":"mqtt-broker","broker":"","port":"1883","clientid":""},{"id":"b8b29c42.d9ecf","type":"inject","name":"","topic":"","payload":"{\"temperature\":123}","payloadType":"string","repeat":"","crontab":"","once":false,"x":285,"y":88,"z":"21dd2ded.2c3352","wires":[["b3747b5f.0fce28"]]},{"id":"b3747b5f.0fce28","type":"mqtt out","name":"","topic":"/v1.6/devices/node-red","qos":"","retain":"","broker":"ba386057.845d3","x":672,"y":89,"z":"21dd2ded.2c3352","wires":[]},{"id":"b8271085.e034c","type":"mqtt in","name":"","topic":"/v1.6/devices/node-red/temperature/lv","broker":"ba386057.845d3","x":315,"y":219,"z":"21dd2ded.2c3352","wires":[["e46bc941.41f718"]]},{"id":"e46bc941.41f718","type":"debug","name":"","active":true,"console":"false","complete":"false","x":689,"y":218,"z":"21dd2ded.2c3352","wires":[]}]

NOTE: you will need to configure the MQTT broker even after pasting the clipboard version above.

Hope this was useful! Have questions or suggestions? Want to suggest a new Node-RED capable device to our growing compatible device family? Feel free to drop us a line at support at

Did this answer your question?