Ubidots

Integrate IoT data with Ubidots

Ubidots is an IoT platform, allowing IoT developers to rapidly assemble and launch applications without having to write complicated code. It supports multiple protocols to integrate data, including UDP, TCP, HTTP(S) and MQTT.

Quick Navigation

Prerequisites

  • Monogoto SIM

  • Access to an IoT modem

  • Account on Ubidots

Set up your Ubidots account

You can get started with Ubidots free of charge by signing up for a account.

In order to send data to Ubidots, you need the following parameters to create the data string:

  • Ubidots Token starting with BBFF e.g. BBFF-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123 You can find your token when selecting your profile in the top-right corner and select API Credentials.

  • User agent You can think of name that will help you identify the IoT application you are working on, e.g. iotfleet1

  • Device Label e.g. iot-sensor The device label is the name of your device as registered in Ubidots. Visit your Devices page in the Ubidots console, and select the + sign at the top right corner to add a new device and provide its name.

Send data using UDP

Detailed information about using UDP to integrate data, see the Ubidots API documentation.

In order to send data using UDP, 4 AT Commands needs to be sent:

  1. Create UDP socket

  2. Activate socket

  3. Send UDP data

  4. Close UDP Socket

1. Create UDP socket

AT%SOCKETCMD="ALLOCATE",1,"UDP","OPEN","3.19.87.203",9012 

Ubidots IP address: 3.19.87.203 UDP port:9012

Example response: %SOCKETCMD:1

2. Activate Socket

AT%SOCKETCMD="ACTIVATE",1

Example response: %SOCKETCMD:1

3. Send UDP data

In order to send data to Ubidots, you need the following parameters to create the data string:

  • User agent, e.g. iotfleet1

  • Ubidots Token e.g. BBFF-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123

  • Device Label e.g. iotsensor

  • Variable Label e.g. temperature

  • Value e.g. 21

To send data to Ubidots, a data string needs to be created with all the parameters mentioned above:

USER_AGENT|POST|TOKEN|DEV_LABEL=>[VAR_LABEL:VALUE|end

For example:

iotfleet1|POST|BBFF-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123|iotsensor=>temperature:21|end

The same data, but converted to hexademical number:

696F74666C656574317C504F53547C424246462D4142434445464748494A4B4C4D4E4F505152535455565758595A303132337C696F7473656E736F723D3E74656D70657261747572653A32317C656E64

AT Command

AT%SOCKETDATA="SEND",1,<length>,"<data>"

length need to be replaced with the amount of bytes you're sending, data is replaced by the actual message.

Example AT Command:

AT%SOCKETDATA="SEND",1,80,"696F74666C656574317C504F53547C424246462D4142434445464748494A4B4C4D4E4F505152535455565758595A303132337C696F7473656E736F723D3E74656D70657261747572653A32317C656E64"

Expected response: +SOCKETDATA: 1,80

It may take up to 10 seconds for the message to be fully processed.

4. Close UDP socket

End your UDP session by closing the UDP socket.

AT%SOCKETCMD="DELETE",1

Expected response: OK

If all went well, the Ubidots platform will visualize and store your data:

Send data using HTTP

Detailed information about using HTTP(S) to integrate data, see the Ubidots API documentation.

In order to send data using HTTP, 4 AT Commands needs to be sent:

  1. Set the HTTP base url AT+UHTTP

  2. Set custom headers AT+UHTTP

  3. Create a JSON file containing the data you want to send AT+UDWNFILE

  4. Send data AT+UHTTPC

1. Set the HTTP base url

AT Command:

AT+UHTTP=<profile_id>,1,"<param_val>"
  • Replace <profile_id> with an identifier, e.g. 0

  • Replace <param_val> with Ubidots' IP address or domain name: industrial.api.ubidots.com

The AT Command becomes:

AT+UHTTP=0,1,"industrial.api.ubidots.com"

To test if the base url was set correctly, enter: AT+UHTTP=0,1. Expected response:

+UHTTP: 0,1,"industrial.api.ubidots.com"
OK

2. Set custom headers

AT Command:

AT+UHTTP=<profile_id>,0,"<param_val>"
  • Replace <profile_id> with the same identifier you used before, e.g. 0

  • Replace <param_val> with a counter, going up for each new header you set, followed by the custom header, e.g. "0:X-Auth-Token:BBFF-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123"

Set the first header, containing the Ubidots authentication token:

AT+UHTTP=0,9,"0:X-Auth-Token:BBFF-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123"

The second header, contains the content type JSON:

AT+UHTTP=0,9,"1:Content-Type:application/json"

3. Create a JSON file containing the data you want to send

AT Command:

AT+UDWNFILE="<file_name>",<size>
  • Replace <file_name> with any name, e.g. sensordata.json

  • Replace <size> with the exact number of characters in the file.

To create a new file with 49 characters, called sensordata.json and add the sensordata, for example: {"temperature": 19,"humidity": 90,"pressure": 78}

AT+UDWNFILE="sensordata.json",49
> {"temperature": 19,"humidity": 90,"pressure": 78}

Read the contents of the file you just created:

AT+URDFILE="sensordata.json"

4. Send data

AT Command:

AT+UHTTPC=<profile_id>,4,"<url path>","<responseFilename>","<filesystemName>",4
  • Replace <profile_id> with the same identifier you used before, e.g. 0

  • Replace <url path> starting with /, e.g. /api/v1.6/devices/{Device Label}

  • Replace <responseFilename> with any name to store the server response, e.g. data.txt

  • Replace <filesystemName> with the file containing the data you want to send, e.g. sensordata.json

For example:

AT+UHTTPC=0,4,"/api/v1.6/devices/iotsensor","data.txt","sensordata.json",4

Expected response: +UUHTTPCR: 0,4,1

If the message was sent correctly, the Ubidots platform will visualize and store your data.

Optionally, delete the created file so you can recreate it when collecting new sensordata:

AT+UDELFILE="sensordata.json"

Last updated

Was this helpful?