mirror of
https://github.com/cesanta/mongoose.git
synced 2024-11-24 02:59:01 +08:00
Nitpick for MQTT example
PUBLISHED_FROM=a0dd26c00b41363f1cc58c28f530fbdf272ed146
This commit is contained in:
parent
4c37e49274
commit
0bb14abbdd
@ -1,4 +1,4 @@
|
||||
PROG = mqtt_broker
|
||||
MODULE_CFLAGS = -DMG_ENABLE_MQTT_BROKER -DMG_ENABLE_HTTP=0
|
||||
SSL_LIB=openssl
|
||||
#SSL_LIB=openssl
|
||||
include ../examples.mk
|
||||
|
@ -17,22 +17,31 @@
|
||||
|
||||
#include "../../mongoose.h"
|
||||
|
||||
static const char *s_listening_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;
|
||||
const char *address = "0.0.0.0:1883";
|
||||
struct mg_connection *nc;
|
||||
struct mg_connection *c;
|
||||
struct mg_mqtt_broker brk;
|
||||
|
||||
mg_mgr_init(&mgr, NULL);
|
||||
mg_mqtt_broker_init(&brk, NULL);
|
||||
|
||||
if ((nc = mg_bind(&mgr, address, mg_mqtt_broker)) == NULL) {
|
||||
fprintf(stderr, "mg_bind(%s) failed\n", address);
|
||||
if ((c = mg_bind(&mgr, s_listening_address, ev_handler)) == NULL) {
|
||||
fprintf(stderr, "mg_bind(%s) failed\n", s_listening_address);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
nc->user_data = &brk;
|
||||
mg_mqtt_broker_init(&brk, NULL);
|
||||
c->user_data = &brk;
|
||||
mg_set_protocol_mqtt(c);
|
||||
|
||||
printf("MQTT broker started on %s\n", address);
|
||||
printf("MQTT broker started on %s\n", s_listening_address);
|
||||
|
||||
/*
|
||||
* TODO: Add a HTTP status page that shows current sessions
|
||||
|
@ -27,10 +27,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) {
|
||||
struct mg_mqtt_message *msg = (struct mg_mqtt_message *) p;
|
||||
(void) nc;
|
||||
|
||||
#if 0
|
||||
if (ev != MG_EV_POLL)
|
||||
printf("USER HANDLER GOT %d\n", ev);
|
||||
#endif
|
||||
if (ev != MG_EV_POLL) printf("USER HANDLER GOT EVENT %d\n", ev);
|
||||
|
||||
switch (ev) {
|
||||
case MG_EV_CONNECT: {
|
||||
|
Loading…
Reference in New Issue
Block a user