MQTT publish/subscribe library for Photon, Spark Core version 0.4.14.
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.
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.
This library is Arduino compatible. Arduino version is here.
some applications use MQTT with Photon. here are developer's reference examples.
- Spark Core / Photon and CloudMQTT
- MQTT Publish-Subscribe Using Rpi, ESP and Photon
- Particle Photon on Watson IoT
- Connecting IoT devices to the Watson Conversation Car-Dashboard app
- ThingSpeak MQTT API
- HOW TO CONNECT A PARTICLE PHOTON TO THE LOSANT IOT PLATFORM
- How I Hacked my Humidor with Losant and a Particle Photon
- ARTIK as MQTT Message Broker
- Particle and Ubidots using MQTT
- 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");
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.
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
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.
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.