add: mongoose for connections and mqtt
This commit is contained in:
parent
f5f9be803c
commit
1d1ae61310
14 changed files with 22620 additions and 233 deletions
src/handlers
37
src/handlers/mqtt.c
Normal file
37
src/handlers/mqtt.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
#include <logger.h>
|
||||
#include <handlers.h>
|
||||
#include <models/controller.h>
|
||||
|
||||
void
|
||||
handler_mqtt(struct mg_connection *nc, int ev, void *p) {
|
||||
struct mg_mqtt_message *msg = (struct mg_mqtt_message *) p;
|
||||
(void) nc;
|
||||
|
||||
if (ev != MG_EV_POLL) LOG_DEBUG("USER HANDLER GOT EVENT %d\n", ev);
|
||||
|
||||
switch (ev) {
|
||||
case MG_EV_CONNECT: {
|
||||
struct mg_send_mqtt_handshake_opts opts;
|
||||
memset(&opts, 0, sizeof(opts));
|
||||
// TODO add password
|
||||
|
||||
mg_set_protocol_mqtt(nc);
|
||||
mg_send_mqtt_handshake_opt(nc, global_controller->name, opts);
|
||||
break;
|
||||
}
|
||||
case MG_EV_MQTT_CONNACK:
|
||||
if (msg->connack_ret_code != MG_EV_MQTT_CONNACK_ACCEPTED) {
|
||||
LOG_DEBUG("Got mqtt connection error: %d\n", msg->connack_ret_code);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case MG_EV_MQTT_PUBACK:
|
||||
LOG_DEBUG("Message publishing acknowledged (msg_id: %d)\n", msg->message_id);
|
||||
break;
|
||||
case MG_EV_MQTT_SUBACK:
|
||||
LOG_DEBUG("Subscription acknowledged, forwarding to '/test'\n");
|
||||
break;
|
||||
case MG_EV_CLOSE:
|
||||
LOG_DEBUG("Connection closed\n");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue