MQTT with Boron 2G/3G

Tags: #<Tag:0x00007fe21bf5af28>


I am new to particle and was trying out the MQTT program. I set up a local mosquitto sever in my pc and was trying to connect Boron to my broker. I am using the basic MQTT library from the web ide. Mosquitto broker is working, as I checked with MQTT fx and the local client also but the boron doesn’t seem to connect to the broker. I have searched the forum but found most posts on the photon, is it any different from boron (apart from boron being a cellular module, any difference in the MQTT program?). Below is the code I have been using. would love someone’s help on this.

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

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

 * if want to use IP address,
 * byte server[] = { XXX,XXX,XXX,XXX };
 * MQTT client(server, 1883, callback);
 * want to use domain name,
 * exp) is Eclipse Open MQTT Broker:
 * MQTT client("", 1883, callback);
//MQTT client("server_name", 1883, callback);

byte server[] = { 182,108,1,144 }; 
 MQTT client(server, 1883, callback,);

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

    if (!strcmp(p, "RED"))
        RGB.color(255, 0, 0);
    else if (!strcmp(p, "GREEN"))
        RGB.color(0, 255, 0);
    else if (!strcmp(p, "BLUE"))
        RGB.color(0, 0, 255);
        RGB.color(255, 255, 255);

void setup() {
    // connect to the server

    // publish/subscribe
    if (client.isConnected()) {
        client.publish("outTopic/message","hello world");
        Serial.println("inside if");

void loop() {
    Serial.println("inside loop");
    if (client.isConnected())
    {   Serial.println("connected");

[Submission] MQTT Library and Sample

@rohan_vamshiG, the Boron is cellular, putting its communications outside your home network. In order for the Boron to “see” your MQTT server, you would need to open the ports used by MQTT on your how firewall/gateway. Have you done this?


@peekay , Yes i have put 1883 as an open port in my firewall.


You’d not only open the port but setup port forwarding too.