Skip to content

cstapels/MQTT

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MQTT for Photon, Spark Core

MQTT publish/subscribe library for Photon, Spark Core version 0.4.21.

Source Code

This lightweight library source code are only 2 files. firmware -> MQTT.cpp, MQTT.h.

Application can use QOS0,1,2 and retain flag when send a publish message.

Example

Some sample sketches for Spark Core and Photon included(firmware/examples/).

  • mqtttest.ino : simple pub/sub sample.
  • mqttqostest.ino : QoS1, QoS2 publish and callback sample.

Arduino compatible

This library is Arduino compatible. Arduino version is here.

developer examples

some applications use MQTT with Photon. here are developer's reference examples.

FAQ

Can't connect/publish/subscribe to the MQTT server?

  • Check your MQTT server and port(default 1883) is really working with the mosquitto_pub/sub command. And maybe your MQTT server can't connect from Internet because of firewall. Check your network environments.
  • Check your subscribe/publish topic name is really matched.
  • Perhaps device firmware network stack is failed. check your firmware version and bugs.
  • If you use MQTT-TLS, check your RooT CA pem file, client key, certifications is okay or not.
  • Several MQTT server will disconnect to the 1st connection when you use the same user_id. When the application call the connect method, use different user_id in every devices in connect method's 2nd argument. Use MAC address as a user_id will be better.
   // device.1
   client.connect("spark-client", "user_1", "password1");
   // other devices...
   client.connect("spark-client", "user_others", "password1");

I want to change MQTT keep alive timeout.

MQTT keepalive timeout is defined "MQTT_DEFAULT_KEEPALIVE 15"(15 sec) in header file. You can change the keepalive timeout in constructor.

    MQTT client("server_name", 1883, callback); // default: send keepalive packet to MQTT server in every 15sec.
    MQTT client("server_name", 1883, 30, callback); // keepliave timeout is 30sec.

Want to use over the 255 message size.

In this library, max MQTT message size is defined "MQTT_MAX_PACKET_SIZE 255" in header file. But If you want to use over 255bytes, use the constructor 4th argument.

    MQTT client("server_name", 1883, callback); // default 255bytes
    MQTT client("server_name", 1883, MQTT_DEFAULT_KEEPALIVE, callback, 512); // max 512bytes

Can I use on old firmware?

No, use default latest firmware. I test this library on default latest firmware or latest pre-release version. If you really want to use old firmware(I think don't need that case), maybe it can't work well and it is out of my assumption.

Bug or Problem?

First of all, check the Particle community site. But still problem will not solve, please send a bug-fixed diff and Pull request or problem details to issue.

About

MQTT for Photon, Spark Core

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • C++ 100.0%