Why i cant connect to my own build mqtt broker in esp8266?

#1

If you are asking a question, please follow this template:

  1. I want to make my esp8266 act as a mqtt broker, but i cant connect to it. i dont know why i cant connect it, i already change the port in mqttbox to ip that provided by my mqtt broker(esp8266).
  2. here is my code :
#include "mongoose.h"

#if MG_ENABLE_MQTT_BROKER
#define MG_ENABLE_MQTT_BROKER 1

static const char *address = "0.0.0.0:1883";


static void ev_handler(struct mg_connection *c, int ev, void *ev_data) {
  if (ev != MG_EV_POLL) printf("USER HANDLER GOT EVENT %d\n", ev);
  /* Do your custom event processing here */
  mg_mqtt_broker(c, ev, ev_data);
}

int main(void) {
  struct mg_mgr mgr;
  struct mg_connection *c;
  struct mg_mqtt_broker brk;

  mg_mgr_init(&mgr, NULL);


  if ((c = mg_bind(&mgr, address, ev_handler)) == NULL) {
    fprintf(stderr, "mg_bind(%s) failed\n", address);
    exit(EXIT_FAILURE);
  }
  mg_mqtt_broker_init(&brk, NULL);
  c->priv_2 = &brk;
  mg_set_protocol_mqtt(c);

  printf("MQTT broker started on %s\n", address);

  /*
   * TODO: Add a HTTP status page that shows current sessions
   * and subscriptions
   */

  for (;;) {
    mg_mgr_poll(&mgr, 1000);
  }
}
#endif /* MG_ENABLE_MQTT_BROKER */

src : https://github.com/cesanta/mongoose/blob/master/examples/mqtt_broker/mqtt_broker.c
3.


4. can someone help me to solve this? thanks

0 Likes

#2

The mqtt-broker is not included in the Mongoose OS build.

It is only available for applications which use the “standalone” Mongoose - Embedded Web Server / Embedded Networking Library

The version used by Mongoose OS does not enable the mqtt-broker.

0 Likes

#3

hello again nliviu and thanks for helping me again :smiley:

what is that mean with “standalone” , can u give me some example?
i didnt understand because i still newbie with mongoose haha

0 Likes

#4

By “standalone” I mean a program compiled for Windows, Linux, or other platforms like the ones from the examples.

0 Likes

#5

oh ok, so mqtt broker is only available in https://github.com/cesanta/mongoose and if i want to use mqtt broker i need to copy mongoose.c and mongoose.h to my build trees then what?

0 Likes

#6

No, it won’t work.
The library mongoose is pulled in by default and it does not enable the mqtt-broker.

0 Likes

#7

yeah , i already try that
so is there any another way to use mqtt broker in mongoose? or its hopeless to use mqtt broker on mongoose? , i mean like if by default mongoose os does not have a mqtt broker libs , how can i even enable the mqtt broker haha.

0 Likes

#8

You have to use a mqtt-broker installed somewhere else in your LAN.
mosquitto is a very good choice.

0 Likes

#9

how do we apply that? does you have any examples?

0 Likes