esp8266rtos3.0  wifi及mqtt

该博客介绍了如何使用ESP8266 RTOS SDK进行WiFi连接和MQTT通信。通过示例代码展示了从初始化WiFi、连接到MQTT服务器、发布和订阅消息的过程。主要涉及ESP8266、WiFi配置、MQTT事件处理等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/*
   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "esp_system.h"
#include "esp_wifi.h"
#include "driver/uart.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "mqtt_client.h"
#include "nvs_flash.h"

#define MQTT_HOST                  // MQTT服务端域名/IP地址    
#define MQTT_PORT           1883                                            // 网络连接端口号        
#define MQTT_CLIENT_ID         // 官方例程中是"Device_ID"        // 客户端标识符        
#define MQTT_USER                         // MQTT用户名                
#define MQTT_PASS              // MQTT密码                    

#define STA_SSID                     // WIFI名称                
#define STA_PASS                // WIFI密码                

TaskHandle_t wifi_Handle = NULL;
void wifi_Task(void *pvParameters);
static EventGroupHandle_t wifi_event_group;

const int WIFI_CONNECTED_BIT = BIT0;
static const char *TAG = "simple wifi";
static void mqtt_app_init(void);
char buf[4096];

static void delay_ms(uint16_t nms)
{
   vTaskDelay(nms / portTICK_PERIOD_MS);
}

static e

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值