arduino的esp32程序无法上传_使用esp32-Arduino+PubSubClient+mqtt 上传数据到中移动OneNet...

该博客介绍了如何使用ESP32-doit-dev-v1开发板通过Arduino IDE和PubSubClient库连接到中移动OneNet平台,进行MQTT协议的数据发布。主要内容包括修改库文件以适配ESP32,配置WiFi连接,构造JSON格式的payload数据包,并在接收到特定消息时控制板上的LED灯状态。

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

使用esp32-doit-dev-v1开发板,测试mqtt协议, 发布(publish)到onenet 平台。

注意:

1.使用的mqtt arduino 客户端是 pubsubclient 库。其默认是ESP8266, 所以例子例包换文件“Wifi8266.h”,可以改为"Wifi.h"就可以。

2.关键是按照mqtt的onenet文档,编制payload数据包。其具体格式有多种类型。调试的是最简单的type3, json数据2 形式。

/*

Basic ESP8266 MQTT example

This sketch demonstrates the capabilities of the pubsub library in combination

with the ESP8266 board/library.

It connects to an MQTT server then:

- publishes "hello world" to the topic "outTopic" every two seconds

- subscribes to the topic "inTopic", printing out any messages

it receives. NB - it assumes the received payloads are strings not binary

- If the first character of the topic "inTopic" is an 1, switch ON the ESP Led,

else switch it off

It will reconnect to the server if the connection is lost using a blocking

reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to

achieve the same result without blocking the main loop.

To install the ESP8266 board, (using Arduino 1.6.4+):

- Add the following 3rd party board manager under "File -> Preferences -> Additional Boards Manager URLs":

http://arduino.esp8266.com/stable/package_esp8266com_inde

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值