Code Monkey home page Code Monkey logo

mqtt's Introduction

MQTT for Photon, Spark Core

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

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.

mqtt's People

Contributors

hirotakaster avatar nitej avatar ganehag avatar imaustink avatar dguerizec avatar khaledosman avatar jenesaisdiq avatar technobly avatar kalkov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.