This article was sent to us by one of our early adopters who develops a DIY hydroponics system at home and uses our service for it. We are happy to publish it here.

Recently I got the UniPi board and decided to test the Cloud4RPi service on a real-world task.

UniPi is a Raspberry Pi single-board PC combined with the controls and sensors board connected via I2C. The board has the following hardware:

  • Relays (250V/5A) x8
  • Analog Output (0–10V) x1
  • Analog Inputs (0–10V) x2
  • Digital Inputs (5–24V) x14
  • 1 Wire bus
  • I2C bus
  • UART port

t’s more than sufficient for control automation and data collection. The desktop-class operating system on Raspberry Pi is also a big advantage.

The official control software is Node-RED, which allows you to create algorithms for IoT devices in graphical mode. The Node-RED setup is described well in this manual, I had no difficulties with it.

Cloud4RPi is a control panel that enables you to control all your devices via the Internet and log history. The Cloud4RPi-enabled device can communicate with the Cloud in two different ways: via the MQTT message queue and via the HTTP Web-API. In Node-RED, we can implement both ways, but MQTT seems to be the better option.

Node-RED has a set of tools for this: mqtt-broker to setup broker connection, and a node to send and receive messages. Cloud4RPi has two types of messages:

  • Messages that the device sends to the cloud. Used for initial configuration, status reports and sensor data.
  • Messages sent from Cloud4RPi to the device. Used to deliver commands sent from the Control Panel.

First thing you need to do is to configure the device, i.e., send the variables list to the devices/{token}/config MQTT topic. The message should be in JSON format and look as follows:

  "ts": /* Date & Time in ISO 8601 format */,
  "payload": [
    {"name": "Boolean Variable", "type": "bool" },
    {"name": "Numerical Variable", "type": "numeric" },
    {"name": "String Variable", "type": "string" }

Messages with data are sent to the devices/{token}/data channel in the following format:

  "ts": /* Date & Time in ISO 8601 format */,
  payload: {
    "Variable Name": "Variable Value",
    "One more variable": 42,
    /* etc... */
    "Yet another variable": false

You can also send the diagnostic data that is not logged to the devices/{token}/diagnostics channel:

  "ts": /* Date & Time in ISO 8601 format */,
  payload: {
      "Diagnostic Variable": "Variable Value",
      "Another Diagnostic Variable": 12

To configure the MQTT connection in Node-RED, add the flow node that will subscribe to topics and send messages to them:

Double click it to open the configuration menu:

In the Server field, you can choose the existing server or add a new one:

The Cloud4RPi Connection settings are the following:

  • Server: <a target="_blank" rel="noopener noreferrer" href=""></a>
  • Port: 1883
  • Client ID: (Your Device Token)
  • Use legacy MQTT 3.1 support: Unchecked

You can find more info in the documentation and Python client library.

After the server creation, it will become available for selection in any subscription or broadcasting node. You can create as many nodes as you need to make the scheme more readable.

In the node configuration, you should also specify the channel to communicate with. The channel list is presented below:

devices/{token}/config        - variables configuration
devices/{token}/data        - sending variable values
devices/{token}/diagnostics    - sending diagnostic data
devices/{token}/commands    - receiving commands from UI (subscribe to this one)

The first thing we need to do is to send the variables configuration to Cloud4RPi. I need to do it on device startup, for which I added the inject node

and checked the following checkbox in its settings:

Now it will trigger at the system startup. Additionally, you can trigger it by clicking here:

This node should trigger the variables...

Read more »