mirror of
https://github.com/alexandrebobkov/ESP-Nodes.git
synced 2025-08-19 15:29:05 +00:00
mqtt
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
#include "mqtt_client.h"
|
||||||
|
|
||||||
|
#include "mqtt.h"
|
||||||
|
|
||||||
|
WIFI_ID = "IoT_bots";
|
||||||
|
WIFI_PASSWORD = "208208208";
|
||||||
|
MQTT_BROKER_URI = "mqtt://techquadbit.net";
|
||||||
|
|
||||||
|
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) {
|
||||||
|
|
||||||
|
|
||||||
|
esp_mqtt_event_handle_t event = event_data;
|
||||||
|
esp_mqtt_client_handle_t client = event->client;
|
||||||
|
|
||||||
|
switch ((esp_mqtt_event_id_t)event_id) {
|
||||||
|
case MQTT_EVENT_CONNECTED:
|
||||||
|
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
|
||||||
|
esp_mqtt_client_publish(client, "/esp/test", "Hello from ESP32!", 0, 1, 0);
|
||||||
|
break;
|
||||||
|
case MQTT_EVENT_DISCONNECTED:
|
||||||
|
ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,4 +1,14 @@
|
|||||||
#ifndef __MQTT_H__
|
#ifndef __MQTT_H__
|
||||||
#define __MQTT_H__
|
#define __MQTT_H__
|
||||||
|
|
||||||
|
#include "mqtt_client.h"
|
||||||
|
#include "esp_wifi.h"
|
||||||
|
|
||||||
|
static const char* WIFI_SSID;
|
||||||
|
static const char* WIFI_PASSWORD;
|
||||||
|
static const char* MQTT_BROKER_URI;
|
||||||
|
static const char* SERVICE_TAG;
|
||||||
|
|
||||||
|
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data);
|
||||||
|
|
||||||
#endif
|
#endif
|
Reference in New Issue
Block a user