Deploying IoT Data Streams to Ubidots
Stream sensor data from ALPON X5 AI or ALPON X4 to Ubidots over MQTT: create a Ubidots device and token, package a paho-mqtt publisher as an arm64 container, deploy it through ALPON Cloud, and watch the values arrive in real time.
Stream IoT data to Ubidots from ALPON
Monitor your device’s data from anywhere with a few clicks. This guide connects an
ALPON X5 AI or ALPON X4 to Ubidots over
MQTT: you create a device and token in Ubidots, package a small
paho-mqtt publisher as an arm64 container, deploy it through
ALPON Cloud, and see temperature and humidity values arrive in real time.
Create a Blank Device in Ubidots, add its variables, and generate a device token. Then
build a Python container that publishes JSON to
industrial.api.ubidots.com:1883 on the topic /v1.6/devices/<DEVICE_LABEL>
using the token as the MQTT username, push it to your Sixfab Container Registry, and deploy
it from the Applications → Deploy panel on ALPON Cloud with the
API_TOKEN and DEVICE_NAME environment variables. The values appear on the device
page in Ubidots within seconds.
Overview
Ubidots is a user-friendly IoT platform for collecting, visualizing, and analyzing device data in real time. A Ubidots device represents the data your ALPON sends; its variables (for example temperature and humidity) are what you plot on dashboards. This guide walks through creating that device, then packaging an MQTT publisher as a container so it runs consistently on the ALPON and is managed from ALPON Cloud.
The steps below are identical on ALPON X4 and ALPON X5 AI.
You need an ALPON X5 AI or ALPON X4 registered on ALPON Cloud, a Ubidots account (the free plan is enough; paid plans add features), and Docker installed on your build machine to build and push the image. New to container deployment? Start with Containerize Apps for ALPON.
-
1
Log in to your Ubidots account
Open the Ubidots website and sign in with your username and password. If you don’t have an account yet, create one for free. Once logged in, you land on the Ubidots dashboard (control panel).
Signing in to Ubidots. -
2
Create a device in Ubidots
Open the Devices section
In the Ubidots dashboard, click the Devices tab in the top menu. The page lists any existing devices. To create a new one, click the Create Device button or the + icon in the top-right corner.
The Devices page in Ubidots. Select the device type
Ubidots prompts you to choose a device type. Select Blank Device — it lets the ALPON send data without a predefined template — and proceed.
Choosing Blank Device as the device type. Official device creation guideFor further details on creating a virtual device, see the Ubidots Device Creation Guide.
Enter the device details
In the form, name your device (e.g. ALPON X4). Ubidots auto-generates a unique Device Label for API use (e.g.
alpon-x4); you can edit it. Click Next to finish. Note the label — the MQTT topic in step 6 is built from it.
Naming the device and setting its Device Label. -
3
Verify the device and add variables
After creation, Ubidots redirects you to the new device’s page, where you can view its basic information (name, label, creation date, and so on).
The device page right after creation. Define one variable per value the ALPON sends. The client in this guide publishes temperature and humidity, so create two variables:
- From the Devices page, click your ALPON device to open its details.
- Click the + Add Variable button (or the + icon in the top-right corner, then + Add Variable) to add a Raw variable.
- A variable named New variable appears. Click its name to edit it: set the name (Temperature for one, Humidity for the other) and, optionally, the description, color, or API label.
- Repeat so that both Temperature and Humidity exist.
- Save your changes. The device is ready to receive data.
The device with its Temperature and Humidity variables. -
4
Obtain a device token
The ALPON authenticates to Ubidots with a device token, which the MQTT client sends as its username:
- From the top navigation bar, go to Devices → Devices.
- Click your ALPON device to select it.
- In the device options, click Manage Device Tokens.
- A drawer slides out from the right. Click + Add new token.
- Give the token a name and select one, both, or neither of the available permissions (leave blank for no permissions).
- Click the green checkmark to confirm, then copy the token.
Keep the token confidentialDo not share the token or commit it to source control. If it is compromised, generate a new one from the same drawer. For more on managing tokens, see Ubidots Security: Managing Device Tokens.
-
5
Write the Dockerfile
Packaging the publisher as a container makes it run the same way on every device. On your build machine, create a new project directory and, inside it, a file called
Dockerfilewith this content:DockerfileFROM python:3.11-slim RUN pip install --no-cache-dir paho-mqtt WORKDIR /app COPY send_to_ubidots.py . CMD ["python", "send_to_ubidots.py"]
This tells Docker to start from a lightweight Python 3.11 image, install the
paho-mqttlibrary, set up a working directory, copy the script into the container, and run it when the container starts. -
6
Write the MQTT client script
The client talks to the Ubidots MQTT broker with these settings; the token and device label are read from environment variables so the image contains no secrets:
Brokerindustrial.api.ubidots.comPort1883Topic/v1.6/devices/<DEVICE_NAME>— filled from theDEVICE_NAMEenvironment variable (your Ubidots Device Label from step 2).Client IDalpon_x4_clientUsernameThe device token from step 4, read fromAPI_TOKEN.PasswordEmpty string.In the same directory as the
Dockerfile, createsend_to_ubidots.pyand paste the following code:python · send_to_ubidots.pyimport time import os from paho.mqtt import client as mqtt_client broker = 'industrial.api.ubidots.com' port = 1883 topic = f"/v1.6/devices/{os.getenv('DEVICE_NAME', 'default_device_name')}" client_id = "alpon_x4_client" username = os.getenv('API_TOKEN', 'default_api_token') password = "" def connect_mqtt(): def on_connect(client, userdata, flags, rc): if rc == 0: print("Connected to MQTT Broker!") else: print(f"Failed to connect, return code {rc}\ ") client = mqtt_client.Client(client_id) client.username_pw_set(username, password) client.on_connect = on_connect client.connect(broker, port) return client def publish(client): while True: time.sleep(2) msg = '{"temperature": 25, "humidity": 60}' result = client.publish(topic, msg) status = result[0] if status == 0: print(f"Sent: `{msg}`") else: print(f"Failed to send message to topic {topic}") def run(): client = connect_mqtt() client.loop_start() publish(client) if __name__ == '__main__': run()The script connects to the Ubidots MQTT broker, publishes a JSON payload with temperature and humidity every 2 seconds, and prints a line each time a message is sent successfully. Replace the constant values with your own sensor readings when you adapt it.
-
7
Build the image and push it to the Sixfab Container Registry
The ALPON runs an
arm64processor, so build the image for that architecture from the project directory on your computer:bash · build the imagedocker buildx build --platform=linux/arm64 -t ubidots-mqtt-client:latest .
This creates an image named
ubidots-mqtt-clientbuilt for the ALPON’s ARM64 architecture. Then log in to ALPON Cloud, open the Sixfab Container Registry page, click + Add Container, and follow the prompts to push the image.Deploy ApplicationsVisit the Deploy Applications page for all the details on pushing your container image to the Sixfab Container Registry.
-
8
Deploy the container on ALPON
Once the image is in the registry, open your device in ALPON Cloud, go to the Applications section, and click + Deploy. In the Deploy Container window, use these settings:
Container NameThe application name, e.g.ubidots-mqtt-client.ImageTheubidots-mqtt-clientimage and tag you pushed to the Sixfab Container Registry.EnvironmentClick + Add More in the environment section and add the two variables in the table below.Key Value API_TOKEN<your-token-here>— the device token from step 4DEVICE_NAME<your-device-name-here>— the Device Label from step 2Click + Deploy to start the container on the ALPON.
The Deploy Container window in ALPON Cloud with the environment variables set. -
9
View the data on Ubidots
Now confirm that the device is publishing. Log in to your Ubidots account and go to the Devices section.
The ALPON device listed under Devices with recent activity. Select your device (e.g.
ALPON_X4) and check that temperature and humidity values are appearing in real time.
Temperature and humidity values arriving from the ALPON. If the data is flowing in, your ALPON is successfully connected to Ubidots. Build a dashboard from the variables to visualize them.
- The
ubidots-mqtt-clientcontainer shows as running in the Applications section and its logs printConnected to MQTT Broker!followed bySent:lines. - The Temperature and Humidity variables on the Ubidots device page update every few seconds.
The ALPON is now streaming data to Ubidots. Swap the constant values in send_to_ubidots.py for
real sensor readings and add dashboard widgets for the variables.
Production image policy: Replace floating
:latestreferences with a reviewed immutable tag or digest, then record the selected version for rollback.
Updated 4 days ago
