Ubidots not working with MQTT

This is directed mostly at @RWB but anyone else who can help please chime in.

I have been spending the better part of a week trying to get MQTT to work with my Photon because I was interested in the subscription feature. I had no success with that so I found myself going with nothing but the example. No joy.

Thank you @RWB for introducing me to Ubidots back in March of this year, I have been and am currently using the HTTP method to publish to Ubidots on several projects since then without any difficulty, so when I recently read that you were using MQTT to publish data to Ubidots from an Electron I had to try it too since saving power is important to me also.

At the most basic level I am using the published code with my TOKEN without success. I read somewhere else on the forum that Serial was interfering with MQTT so I commented that out, but still no success.

The code below is taken straight from the example on Ubidots and the only difference is that it only publishes every 15 seconds instead of hundreds of times a second, the code as posted loops infinitely fast and I thought Ubidots wouldn’t appreciate that much data in such a short period of time. :grimacing:

The example states “After running this function, you should see a new data source in your account with the name “my-device” and two variables “temperature” and “humidity”, with the corresponding analog readings inside each variable.” This implies that it is pretty much automatic or automagic. I have even created this data source and the variables and it still doesn’t update. Yes, I replaced “my-device” with “nudibranch” as in the code below.

If you or anybody else sees anything missing and/or bungled in the code below please let me know. I’d really like to get this working and then move on to using MQTTs Subscribe feature.

// This #include statement was automatically added by the Particle IDE.
#include "UbidotsMQTT/UbidotsMQTT.h"

// This #include statement was automatically added by the Particle IDE.
#include "MQTT/MQTT.h"

#define TOKEN "xxxxxxxxxx"  // Add here your Ubidots TOKEN
#define VARIABLE_IDENTIFIER_ONE "humidity" // Add a variable identifier, it must be in lowercase
#define VARIABLE_IDENTIFIER_TWO "temperature" // Add a variable identifier, it must be in lowercase
#define DATA_SOURCE_NAME "nudibranch"

void callback(char* topic, byte* payload, unsigned int length);

Ubidots client(TOKEN, callback);

void callback(char* topic, byte* payload, unsigned int length) {
    char p[length + 1];
    memcpy(p, payload, length);
    p[length] = NULL;
    String message(p);
    //Serial.write(payload, length);

void setup() {
    while (client.connect());

void loop() {
    int hum = random(100);
    int temp = random(1000, 5000);
    client.add(VARIABLE_IDENTIFIER_ONE, hum);
    client.add(VARIABLE_IDENTIFIER_TWO, temp);

Thanks in advance for any assistance,
Joerg Seiler

Hey! Glad your enjoying Ubidots. I’m using it daily also for testing various projects.

I think the problem your seeing is because the Ubidots MQTT library is an old library and is not working or up to date:

I had some trouble getting Ubidots to work awhile ago but got it working after updating to their latest library they have uploaded to the Online Build IDE Libraries.

Based on my last email communication with Ubidots it sounds like you are currently using the MQTT messaging functions if your using their latest library examples.

If you are using the Electron and want to cut the data consumption down then they have a library that uses UDP data transfer which uses less data than the MQTT messaging that is built into their latest library.

See the copy of this email string between Ubidots Support and Me not long ago:

I would hit up Maria @ Ubidots for help if you have questions or want clarifications on how to get something going. Her email is: maria@ubidots.com

Let me know what you figure out and if you have any other questions I can try to answer.

@aguspg Maybe around also to shed some light on your questions.

1 Like

Thanks for the reply @RWB. It’s good to know the library may be at fault, I can stop pulling my hair out.

I am specifically looking to push data back to my device. The project I want to enhance is a small environmental chamber that both logs data to Ubidots and uses some of the slider and button controls as a user interface for the chamber. Of course without being able to push their state if it changes, the only other option is polling which isn’t a real good use of processor time. Therefore the need for MQTT functionality.

I’ll give Maria a shout and see what we can work out. I’ll post back my findings.

1 Like

They have a solution for that I’m pretty sure since we have talked about needing it for one of my projects in the past. Let me know what ya figure out.