|
|
|
@ -12,11 +12,6 @@ |
|
|
|
|
|
|
|
|
|
MQTT_Client mqttClient; // main mqtt client used by esp-link
|
|
|
|
|
|
|
|
|
|
#ifdef BRUNNELS |
|
|
|
|
char* statusTopicStr; |
|
|
|
|
static char* onlineMsgStr; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
static MqttCallback connected_cb; |
|
|
|
|
static MqttCallback disconnected_cb; |
|
|
|
|
static MqttCallback published_cb; |
|
|
|
@ -27,9 +22,6 @@ mqttConnectedCb(uint32_t *args) { |
|
|
|
|
DBG_MQTTCLIENT("MQTT Client: Connected\n"); |
|
|
|
|
//MQTT_Client* client = (MQTT_Client*)args;
|
|
|
|
|
//MQTT_Subscribe(client, "system/time", 0); // handy for testing
|
|
|
|
|
#ifdef BRUNNELS |
|
|
|
|
MQTT_Publish(client, "announce/all", onlineMsgStr, 0, 0); |
|
|
|
|
#endif |
|
|
|
|
if (connected_cb) |
|
|
|
|
connected_cb(args); |
|
|
|
|
} |
|
|
|
@ -93,29 +85,6 @@ mqtt_client_init() |
|
|
|
|
flashConfig.mqtt_clientid, flashConfig.mqtt_username, flashConfig.mqtt_password, |
|
|
|
|
flashConfig.mqtt_keepalive); |
|
|
|
|
|
|
|
|
|
// removed client_id concat for now until a better solution is devised
|
|
|
|
|
// statusTopicStr = (char*)os_zalloc(strlen(flashConfig.mqtt_clientid) + strlen(flashConfig.mqtt_status_topic) + 2);
|
|
|
|
|
// os_strcpy(statusTopicStr, flashConfig.mqtt_clientid);
|
|
|
|
|
// os_strcat(statusTopicStr, "/");
|
|
|
|
|
|
|
|
|
|
#ifdef BRUNNELS |
|
|
|
|
char* onlineMsg = " is online"; |
|
|
|
|
onlineMsgStr = (char*)os_zalloc(strlen(flashConfig.mqtt_clientid) + strlen(onlineMsg) + 1); |
|
|
|
|
os_strcpy(onlineMsgStr, flashConfig.mqtt_clientid); |
|
|
|
|
os_strcat(onlineMsgStr, onlineMsg); |
|
|
|
|
|
|
|
|
|
char* offlineMsg = " is offline"; |
|
|
|
|
char* offlineMsgStr = (char*)os_zalloc(strlen(flashConfig.mqtt_clientid) + strlen(offlineMsg) + 1); |
|
|
|
|
os_strcpy(offlineMsgStr, flashConfig.mqtt_clientid); |
|
|
|
|
os_strcat(offlineMsgStr, offlineMsg); |
|
|
|
|
|
|
|
|
|
char* lwt = "/lwt"; |
|
|
|
|
char *lwtMsgStr = (char*)os_zalloc(strlen(flashConfig.mqtt_clientid) + strlen(lwt) + 1); |
|
|
|
|
os_strcpy(lwtMsgStr, flashConfig.mqtt_clientid); |
|
|
|
|
os_strcat(lwtMsgStr, lwt); |
|
|
|
|
MQTT_InitLWT(&mqttClient, lwtMsgStr, offlineMsg, 0, 0); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
MQTT_OnConnected(&mqttClient, mqttConnectedCb); |
|
|
|
|
MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); |
|
|
|
|
MQTT_OnPublished(&mqttClient, mqttPublishedCb); |
|
|
|
|