|
@@ -54,12 +54,9 @@ static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event)
|
|
|
case MQTT_EVENT_CONNECTED:
|
|
|
connected = true;
|
|
|
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
|
|
|
- esp_mqtt_client_publish(client, "kitchen/fridge/available", "online", 0, 1, true);
|
|
|
- esp_mqtt_client_publish(client, "kitchen/alarm/available", "online", 0, 1, true);
|
|
|
- esp_mqtt_client_publish(client, "kitchen/alarm/state", "off", 0, 1, true);
|
|
|
- esp_mqtt_client_publish(client, "kitchen/fridge/doorState","closed", 0, 1, true);
|
|
|
- esp_mqtt_client_subscribe(client, "kitchen/alarm/set", 0);
|
|
|
- esp_mqtt_client_subscribe(client, "kitchen/alarm/notification", 0);
|
|
|
+ esp_mqtt_client_publish(client, "limedal/hottub/tempsensor/available", "offline", 0, 1, true);
|
|
|
+ //esp_mqtt_client_subscribe(client, "kitchen/alarm/set", 0);
|
|
|
+ //esp_mqtt_client_subscribe(client, "kitchen/alarm/notification", 0);
|
|
|
break;
|
|
|
case MQTT_EVENT_DISCONNECTED:
|
|
|
connected = false;
|
|
@@ -73,26 +70,6 @@ static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event)
|
|
|
ESP_LOGI(TAG, "MQTT_EVENT_DATA");
|
|
|
printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
|
|
|
printf("DATA=%.*s\r\n", event->data_len, event->data);
|
|
|
- /*if (strncmp(event->topic, "kitchen/alarm/set", event->topic_len) == 0) {
|
|
|
- if (strncmp(event->data, "off", event->data_len) == 0) {
|
|
|
- ESP_LOGI("MQTT", "Fridge alarm disabled");
|
|
|
- setAlarmState(false);
|
|
|
- esp_mqtt_client_publish(client, "kitchen/alarm/state", "off", 0, 1, true);
|
|
|
- } else if (strncmp(event->data, "on", event->data_len) == 0) {
|
|
|
- ESP_LOGI("MQTT", "Fridge alarm enabled");
|
|
|
- setAlarmState(true);
|
|
|
- esp_mqtt_client_publish(client, "kitchen/alarm/state", "on", 0, 1, true);
|
|
|
- }
|
|
|
- }
|
|
|
- else if (strncmp(event->topic, "kitchen/alarm/notification", event->topic_len) == 0) {
|
|
|
- if (strncmp(event->data, "notification", event->data_len) == 0) {
|
|
|
- ESP_LOGI("MQTT", "Fridge alarm notification enabled");
|
|
|
- triggerNotificationSound();
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- ESP_LOGI(TAG, "Unknown topic");
|
|
|
- }*/
|
|
|
|
|
|
break;
|
|
|
case MQTT_EVENT_ERROR:
|
|
@@ -106,7 +83,7 @@ static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event)
|
|
|
}
|
|
|
|
|
|
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) {
|
|
|
- ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id);
|
|
|
+ ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%ld", base, event_id);
|
|
|
mqtt_event_handler_cb(event_data);
|
|
|
}
|
|
|
|
|
@@ -119,11 +96,17 @@ void mqttTask(void *pvParameters) {
|
|
|
while( commIsUpAndRunning == false ) vTaskDelay(10000 / portTICK_PERIOD_MS);
|
|
|
#endif
|
|
|
|
|
|
- esp_mqtt_client_config_t mqtt_cfg = {
|
|
|
- .uri = "mqtt://192.168.1.110:1883",
|
|
|
- .password = CONFIG_ESP_MQTT_PASSWORD,
|
|
|
- .username = CONFIG_ESP_MQTT_UNAME
|
|
|
- };
|
|
|
+esp_mqtt_client_config_t mqtt_cfg = {
|
|
|
+ .broker = {
|
|
|
+ .address = {
|
|
|
+ .uri = "mqtt://chef.sundby.com:1883",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ .credentials = {
|
|
|
+ .username = CONFIG_ESP_MQTT_UNAME,
|
|
|
+ },
|
|
|
+ .credentials.authentication.password = CONFIG_ESP_MQTT_PASSWORD
|
|
|
+};
|
|
|
|
|
|
client = esp_mqtt_client_init(&mqtt_cfg);
|
|
|
esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, client);
|