本帖最后由 efans_96f886 于 2021-8-12 11:47 编辑
0x1 WIFI 连接
ESP32-C3提供很多WIFI Demo,挑选几个demo学习一下wifi开发:
- ESP-IDFexampleswifi:
- ├── espnow
- ├── fast_scan
- ├── ftm
- ├── getting_started
- │ ├── softAP
- │ └── station
- ├── iperf
- ├── power_save
- ├── scan
- ├── simple_sniffer
- ├── smart_config
- ├── wifi_easy_connect
- │ └── dpp-enrollee
- ├── wpa2_enterprise
- └── wps
复制代码
看getting_started/station例子: 打开 手机热点,设置账号密码。修改station代码填写账号密码,SSID是WIIF名称:
- // stationmainstation_example_main.c:L27
- #define EXAMPLE_ESP_WIFI_SSID "HONOR 30 Pro"
- #define EXAMPLE_ESP_WIFI_PASS "43214321"
- // 编译、刷机、串口 三连
- idf.py set-target esp32c3
- idf.py -p COM11 build flash monitor
复制代码
连接成功之后,会显示IP和wifi账好密码:
2. 测试连接状态 这时把电脑也连上这个热点,可以ping通手机设备:
- ping 192.168.43.115
- Pinging 192.168.43.115 with 32 bytes of data:
- Reply from 192.168.43.115: bytes=32 time=724ms TTL=255
- Reply from 192.168.43.115: bytes=32 time=213ms TTL=255
- Reply from 192.168.43.115: bytes=32 time=236ms TTL=255
- Reply from 192.168.43.115: bytes=32 time=32ms TTL=255
- Ping statistics for 192.168.43.115:
- Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
- Approximate round trip times in milli-seconds:
- Minimum = 32ms, Maximum = 724ms, Average = 301ms
复制代码
0x2 Coap协议
examplesprotocolscoap_server例子。 这次不能直接修改文件填wifi密码了,需要通过menuconfig来配置。
- idf.py set-target esp32c3
- # 设置wifi
- idf.py menuconfig
- Example Connection Configuration --->
- * Set WiFi SSID under Example Configuration
- * Set WiFi Password under Example Configuration
- Example CoAP Client Configuration --->
- * If PSK, Set CoAP Preshared Key to use in connection to the server
- Component config --->
- CoAP Configuration --->
- * Set encryption method definition, PSK (default) or PKI
- * Enable CoAP debugging if required
- # 三连
- idf.py -p COM11 build flash monitor
复制代码
还需要一个COAP客户端去测试连接,去github随便找了个go语言写的:https://github.com/plgd-dev/go-coap 拿到本地PC编译运行,将电脑和ESP32-C3都连自己的手机热点,发现连接超时:
搜了下,发现COAP的端口应该是5683,这个项目里面填5688显然是不对的。改过来之后,能连接成功正常获得响应:
0x3. MQTT
给跪了,这个编辑器体验太差,一不小心就丢内容,这篇编辑了3次,实在是写不下去了。附上我博客的原始连接:
https://www.yuque.com/docs/share/8501b609-15c7-4118-b44a-c584eb48d79a?# 《ESP32-C3 (RISCV架构) 开发》
|