Fix compilation issues with espressif mqtt lib
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef MQTT_HPP
|
||||||
|
#define MQTT_HPP
|
||||||
|
|
||||||
|
void mqttTask(void *pvParameters);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef WIFI_CREDENTIALS_H
|
#ifndef WIFI_CREDENTIALS_H
|
||||||
#define WIFI_CREDENTIALS_H
|
#define WIFI_CREDENTIALS_H
|
||||||
|
|
||||||
|
// TODO: make this a config.h
|
||||||
|
|
||||||
#define SSID "your_wifi_ssid"
|
#define SSID "your_wifi_ssid"
|
||||||
#define PASSWORD "your_wifi_password"
|
#define PASSWORD "your_wifi_password"
|
||||||
#define AUTH_MODE WIFI_AUTH_WPA2_PSK
|
#define AUTH_MODE WIFI_AUTH_WPA2_PSK
|
||||||
|
|||||||
@@ -9,4 +9,4 @@ idf_component_register(SRCS "./main.cpp"
|
|||||||
esp_system
|
esp_system
|
||||||
freertos
|
freertos
|
||||||
log
|
log
|
||||||
mqtt_client)
|
mqtt)
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
dependencies:
|
||||||
|
espressif/mqtt: "*"
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "esp_pm.h"
|
#include "esp_pm.h"
|
||||||
#include "esp_task_wdt.h"
|
#include "esp_task_wdt.h"
|
||||||
#include "wifi.hpp"
|
#include "wifi.hpp"
|
||||||
|
#include "mqtt.hpp"
|
||||||
|
|
||||||
#define WATCHDOG_KEEPALIVE_MS 8000
|
#define WATCHDOG_KEEPALIVE_MS 8000
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "mqtt_client.h"
|
#include "mqtt_client.h"
|
||||||
#include "main.hpp"
|
#include "main.hpp"
|
||||||
#include "i2c.hpp"
|
//#include "i2c.hpp"
|
||||||
|
|
||||||
#define MQTT_TASK_TIMEOUT_MS 3000
|
#define MQTT_TASK_TIMEOUT_MS 3000
|
||||||
|
|
||||||
@@ -24,16 +24,18 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
|
|||||||
esp_mqtt_event_handle_t event = (esp_mqtt_event_handle_t)event_data;
|
esp_mqtt_event_handle_t event = (esp_mqtt_event_handle_t)event_data;
|
||||||
|
|
||||||
switch (event->event_id) {
|
switch (event->event_id) {
|
||||||
case MQTT_EVENT_CONNECTED:
|
case MQTT_EVENT_CONNECTED: {
|
||||||
xEventGroupSetBits(connectivity_event_group, MQTT_CONNECTED_BIT);
|
xEventGroupSetBits(connectivity_event_group, MQTT_CONNECTED_BIT);
|
||||||
mqtt_subscribe();
|
mqtt_subscribe();
|
||||||
ESP_LOGV(TAG, "Connected to broker");
|
ESP_LOGV(TAG, "Connected to broker");
|
||||||
break;
|
break;
|
||||||
case MQTT_EVENT_DISCONNECTED:
|
}
|
||||||
|
case MQTT_EVENT_DISCONNECTED: {
|
||||||
xEventGroupClearBits(connectivity_event_group, MQTT_CONNECTED_BIT);
|
xEventGroupClearBits(connectivity_event_group, MQTT_CONNECTED_BIT);
|
||||||
ESP_LOGW(TAG, "Disconnected from broker");
|
ESP_LOGW(TAG, "Disconnected from broker");
|
||||||
break;
|
break;
|
||||||
case MQTT_EVENT_DATA:
|
}
|
||||||
|
case MQTT_EVENT_DATA: {
|
||||||
ESP_LOGD(TAG, "Listening to broker");
|
ESP_LOGD(TAG, "Listening to broker");
|
||||||
ESP_LOGD(TAG, "Topic: %.*s\n", event->topic_len, event->topic);
|
ESP_LOGD(TAG, "Topic: %.*s\n", event->topic_len, event->topic);
|
||||||
ESP_LOGD(TAG, "Data: %.*s\n", event->data_len, event->data);
|
ESP_LOGD(TAG, "Data: %.*s\n", event->data_len, event->data);
|
||||||
@@ -45,23 +47,22 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
|
|||||||
|
|
||||||
if (i2c_task_handle != NULL) xTaskNotifyGive(i2c_task_handle);
|
if (i2c_task_handle != NULL) xTaskNotifyGive(i2c_task_handle);
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
|
default: {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mqtt_init(void) {
|
static void mqtt_init(void) {
|
||||||
// TODO; implement Trust only or Mutual TLS in the future (and secure boot + flash encryption)
|
// TODO; implement Trust only or Mutual TLS in the future (and secure boot + flash encryption)
|
||||||
const esp_mqtt_client_config_t mqtt_cfg = {
|
// TODO: add to config.h
|
||||||
.broker = {
|
esp_mqtt_client_config_t mqtt_cfg = {};
|
||||||
//TODO: make this a definition in config.hpp
|
mqtt_cfg.broker.address.uri = "mqtt://yourmqttserver";
|
||||||
.address.uri = "mqtt://yourmqttserver",
|
mqtt_cfg.broker.address.port = 1883;
|
||||||
.address.port = 1883
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
mqtt_client = esp_mqtt_client_init(&mqtt_cfg);
|
mqtt_client = esp_mqtt_client_init(&mqtt_cfg);
|
||||||
esp_mqtt_client_register_event(mqtt_client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL);
|
esp_mqtt_client_register_event(mqtt_client, (esp_mqtt_event_id_t)ESP_EVENT_ANY_ID, mqtt_event_handler, NULL);
|
||||||
esp_mqtt_client_start(mqtt_client);
|
esp_mqtt_client_start(mqtt_client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +82,7 @@ void mqttTask(void *pvParameters) {
|
|||||||
ESP_LOGV(TAG, "Connection established");
|
ESP_LOGV(TAG, "Connection established");
|
||||||
|
|
||||||
if (ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(MQTT_TASK_TIMEOUT_MS))) {
|
if (ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(MQTT_TASK_TIMEOUT_MS))) {
|
||||||
i2c_do(global_rx_buffer);
|
//i2c_do(global_rx_buffer); PLACEHOLDER FUNC!
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_task_wdt_reset());
|
ESP_ERROR_CHECK(esp_task_wdt_reset());
|
||||||
|
|||||||
Reference in New Issue
Block a user