Official MQTT APIs


#1

I’ve been using the MQTT-TLS library to connect/pipeline with a local raspi. It was relatively painless to set up. But, unfortunately, has a couple drawbacks. One, is it doesn’t seem to be stable. I’m not sure exactly where the problem lies, but it’s dropping connection often enough to be frustrating. And, two, the library itself takes up a lot of FLASH space on my photon — too much for my liking.

Since MQTT is becoming quite the standard today for communication of IoT devices to local/remote servers, is Particle.io working on a built in firmware API? That would be super sweet if it’s the case. It’s certainly needed!


#2

At this point in time we do not plan to make an officially supported MQTT-TLS library. The preferred method is to use Particle.publish over the CoAP cloud connection that’s also used for device authentication and other features like functions, variables, and OTA code flash.

Of course you’re always free to use a 3rd-party MQTT library, but because it needs to bring along its own TLS library, it will always be large.


#3

Thanks rikkas for the reply. I understand the desire to keep with CoAp and the cloud systems you’ve got in place for the wider Internet connectivity (which work really well btw).

However, there’s a legitimate need for local network communication without jumping through the cloud. Do you have any links for TSL server/client examples? Seems a little daunting stepping into a lower level communication protocol like that.


#4

For local communication, one consideration may see about some sort of integration between a Xenon and your Raspberry Pi. Either something that reads the serial I/O over USB, or if you’re ambitious, some sort of Xenon Pi hat.


#5

This is something I have working reliably. I use the PubSub library https://build.particle.io/libs/PubSubClient/2.6.0/tab/PubSubClient.cpp then setup a local MQTT server (I used a raspberry pi and mosquito) - it doesn’t do TLS but if its local - is that an issue? (I used sip hash to create a hash value with the message using shared keys - not bullet proof but enough to know if someone is fiddling with the data).

I have since moved to using thingsboard.io community edition on a raspberry pi (complete prebuilt image available) and connect directly to that. I find it very reliable and painless.

I am moving to do a web hook as a trial since thingsboard supports this and then it will be more secure end to end.


#6

Thats interesting shanevanj.

I too am using a raspi as a local gateway server. Though from there, I correlate up to AWS IOT via there SDK. I’ll look into the PubSub library more and see what it can do.


#7

I use AWS IoT directly with MQTT-TLS and have not had any meaningful stability issues. How are you using it? Are you sending lots of messages, large messages, or using a QoS > 0? What is your timeout value set to?

Instability makes me think there are other problems with your application code that have sufficient blocking behavior to impact your ability to respond properly to the occasional message, causing a reconnection.

Also, are you certain that your network isn’t reconnecting in general? What are your particle cloud reconnection amounts like?

Also, you can definitely reduce flash and RAM usage of the library a bit with proper configuration. See my posts on this thread. It’s still pushing the device’s limits on the photon, but I have it working pretty well with a couple other threads and lots of other things going on too.

Also, if you are already using MQTT-TLS on the photon, why not send directly to AWS?