This commit is contained in:
2025-07-23 22:13:18 -04:00
parent 27a902d543
commit f72742cdfd
2 changed files with 37 additions and 0 deletions

View File

@@ -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;
}
}

View File

@@ -1,4 +1,14 @@
#ifndef __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