首先需要和DF道个歉,其实很早就收到了DF寄送的FireBeetle开发板,当时恰逢毕设工作的最后阶段,本想利用上这块板子参与毕设的一些工作,怎料低估了Arduino迁移到ESP-IDF的难度,试做了两个电灯demo后无奈只能弃用,一弃用就一直搁置到现在,前两天刚完成毕设答辩,现在才有空完成这份迟到的试用报告
首先对主控进行例行描述,ESP32-C6 是乐鑫首款支持 Wi-Fi 6 的 SoC,集成 2.4 GHz Wi-Fi 6、Bluetooth 5 (LE) 和 802.15.4 协议,能够为物联网产品提供行业领先的射频性能、完善的安全机制和丰富的内存资源。它搭载一个时钟频率最高 160 MHz 的高性能 RISC-V 32 位处理器,和一个时钟频率最高 20 MHz 的低功耗 RISC-V 32 位处理器,内置 512 KB SRAM,320 KB ROM,并支持外接 flash。ESP32-C6 拥有 30 个 (QFN40) 或 22 个 (QFN32) 可编程 GPIO 管脚,支持 SPI、UART、I2C、I2S、RMT、TWAI、PWM、电机控制 PWM 和 SDIO。它还集成了一个 12 位 ADC 和一个温度传感器。
FireBeetle这块板子比较特别的是自带了一个我头一次见的太阳能锂电池充电功能,虽然我手头没有太阳能板无法测试,但不得不说结合太阳能供电的开发板在开发户外物联网设备时应该可以减少一定工作。
本试用报告使用ESP-IDF的例程examples/bluetooth/bluedroid/ble/gatt_server测试一下蓝牙连接,使用Visual Studio Code+Platformio+esp-idf的编程编译环境测试,esp-idf版本5.2.1,需要注意platformio配置时需要选择esp32-c6-devkitm-1。
demo链接gatt_server,对其中部分代码修改进行点灯
- <div style="color: rgb(204, 204, 204); background-color: rgb(31, 31, 31); font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;"><div> <span style="color: #c586c0;">case</span> <span style="color: #4fc1ff;">ESP_GATTS_WRITE_EVT</span>: {</div><div> <span style="color: #569cd6;">char</span> <span style="color: #9cdcfe;">ch</span>[<span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">len</span> <span style="color: #d4d4d4;">+</span> <span style="color: #b5cea8;">1</span>];</div><div> <span style="color: #9cdcfe;">ch</span>[<span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">len</span>] <span style="color: #d4d4d4;">=</span> <span style="color: #ce9178;">'</span><span style="color: #d7ba7d;">\0</span><span style="color: #ce9178;">'</span>;</div><div> <span style="color: #569cd6;">ESP_LOGI</span>(<span style="color: #569cd6;">GATTS_TAG</span>, <span style="color: #ce9178;">"GATT_WRITE_EVT, conn_id </span><span style="color: #9cdcfe;">%d</span><span style="color: #ce9178;">, trans_id %"</span> <span style="color: #569cd6;">PRIu32</span> <span style="color: #ce9178;">", handle </span><span style="color: #9cdcfe;">%d</span><span style="color: #ce9178;">"</span>, <span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">conn_id</span>, <span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">trans_id</span>, <span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">handle</span>);</div><div> <span style="color: #c586c0;">if</span> (<span style="color: #d4d4d4;">!</span><span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">is_prep</span>){</div><div> <span style="color: #c586c0;">for</span> (<span style="color: #569cd6;">int</span> <span style="color: #9cdcfe;">i</span> <span style="color: #d4d4d4;">=</span> <span style="color: #b5cea8;">0</span>; <span style="color: #9cdcfe;">i</span> <span style="color: #d4d4d4;"><</span> <span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">len</span>; <span style="color: #9cdcfe;">i</span><span style="color: #d4d4d4;">++</span>)</div><div> {</div><div> <span style="color: #9cdcfe;">ch</span>[<span style="color: #9cdcfe;">i</span>]<span style="color: #d4d4d4;">=</span><span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">value</span>[<span style="color: #9cdcfe;">i</span>];</div><div> }</div><div> <span style="color: #569cd6;">ESP_LOGI</span>(<span style="color: #569cd6;">GATTS_TAG</span>, <span style="color: #ce9178;">"GATT_WRITE_EVT, value len </span><span style="color: #9cdcfe;">%d</span><span style="color: #ce9178;">, value :"</span>, <span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">len</span>);</div><div> <span style="color: #569cd6;">esp_log_buffer_char</span>(GATTS_TAG, <span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">value</span>, <span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">len</span>);</div><div> <span style="color: #569cd6;">ESP_LOGI</span>(<span style="color: #569cd6;">GATTS_TAG</span>, <span style="color: #ce9178;">"RECEIVE MESSAGE:"</span>);</div><div> <span style="color: #569cd6;">esp_log_buffer_char</span>(GATTS_TAG, ch, <span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">len</span><span style="color: #d4d4d4;">+</span><span style="color: #b5cea8;">1</span>);</div><div> <span style="color: #c586c0;">if</span> (<span style="color: #d4d4d4;">!</span><span style="color: #dcdcaa;">strcmp</span>(<span style="color: #9cdcfe;">ch</span>, <span style="color: #ce9178;">"LED_ON"</span>))</div><div> {</div><div> <span style="color: #dcdcaa;">gpio_set_level</span>(<span style="color: #b5cea8;">15</span>,<span style="color: #b5cea8;">1</span>);</div><div> }</div><div> <span style="color: #c586c0;">else</span> <span style="color: #c586c0;">if</span> (<span style="color: #d4d4d4;">!</span><span style="color: #dcdcaa;">strcmp</span>(<span style="color: #9cdcfe;">ch</span>, <span style="color: #ce9178;">"LED_OFF"</span>))</div><div> {</div><div> <span style="color: #dcdcaa;">gpio_set_level</span>(<span style="color: #b5cea8;">15</span>,<span style="color: #b5cea8;">0</span>);</div><div> }<span style="color: #6a9955;">//点灯</span></div><div> </div><div> <span style="color: #c586c0;">if</span> (<span style="color: #9cdcfe;">gl_profile_tab</span>[<span style="color: #569cd6;">PROFILE_B_APP_ID</span>].<span style="color: #9cdcfe;">descr_handle</span> <span style="color: #d4d4d4;">==</span> <span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">handle</span> <span style="color: #d4d4d4;">&&</span> <span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">len</span> <span style="color: #d4d4d4;">==</span> <span style="color: #b5cea8;">2</span>){</div><div> <span style="color: #4ec9b0;">uint16_t</span> <span style="color: #9cdcfe;">descr_value</span><span style="color: #d4d4d4;">=</span> <span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">value</span>[<span style="color: #b5cea8;">1</span>]<span style="color: #d4d4d4;"><<</span><span style="color: #b5cea8;">8</span> <span style="color: #d4d4d4;">|</span> <span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">value</span>[<span style="color: #b5cea8;">0</span>];</div><div> <span style="color: #c586c0;">if</span> (<span style="color: #9cdcfe;">descr_value</span> <span style="color: #d4d4d4;">==</span> <span style="color: #b5cea8;">0x0001</span>){</div><div> <span style="color: #c586c0;">if</span> (<span style="color: #9cdcfe;">b_property</span> <span style="color: #d4d4d4;">&</span> <span style="color: #569cd6;">ESP_GATT_CHAR_PROP_BIT_NOTIFY</span>){</div><div> <span style="color: #569cd6;">ESP_LOGI</span>(<span style="color: #569cd6;">GATTS_TAG</span>, <span style="color: #ce9178;">"notify enable"</span>);</div><div> <span style="color: #4ec9b0;">uint8_t</span> <span style="color: #9cdcfe;">notify_data</span>[<span style="color: #b5cea8;">15</span>];</div><div> <span style="color: #c586c0;">for</span> (<span style="color: #569cd6;">int</span> <span style="color: #9cdcfe;">i</span> <span style="color: #d4d4d4;">=</span> <span style="color: #b5cea8;">0</span>; <span style="color: #9cdcfe;">i</span> <span style="color: #d4d4d4;"><</span> <span style="color: #569cd6;">sizeof</span>(<span style="color: #9cdcfe;">notify_data</span>); <span style="color: #d4d4d4;">++</span><span style="color: #9cdcfe;">i</span>)</div><div> {</div><div> <span style="color: #9cdcfe;">notify_data</span>[<span style="color: #9cdcfe;">i</span>] <span style="color: #d4d4d4;">=</span> <span style="color: #9cdcfe;">i</span><span style="color: #d4d4d4;">%</span><span style="color: #b5cea8;">0xff</span>;</div><div> }</div><div> <span style="color: #6a9955;">//the size of notify_data[] need less than MTU size</span></div><div> <span style="color: #dcdcaa;">esp_ble_gatts_send_indicate</span>(<span style="color: #9cdcfe;">gatts_if</span>, <span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">conn_id</span>, <span style="color: #9cdcfe;">gl_profile_tab</span>[<span style="color: #569cd6;">PROFILE_B_APP_ID</span>].<span style="color: #9cdcfe;">char_handle</span>,</div><div> <span style="color: #569cd6;">sizeof</span>(<span style="color: #9cdcfe;">notify_data</span>), <span style="color: #9cdcfe;">notify_data</span>, <span style="color: #569cd6;">false</span>);</div><div> }</div><div> }<span style="color: #c586c0;">else</span> <span style="color: #c586c0;">if</span> (<span style="color: #9cdcfe;">descr_value</span> <span style="color: #d4d4d4;">==</span> <span style="color: #b5cea8;">0x0002</span>){</div><div> <span style="color: #c586c0;">if</span> (<span style="color: #9cdcfe;">b_property</span> <span style="color: #d4d4d4;">&</span> <span style="color: #569cd6;">ESP_GATT_CHAR_PROP_BIT_INDICATE</span>){</div><div> <span style="color: #569cd6;">ESP_LOGI</span>(<span style="color: #569cd6;">GATTS_TAG</span>, <span style="color: #ce9178;">"indicate enable"</span>);</div><div> <span style="color: #4ec9b0;">uint8_t</span> <span style="color: #9cdcfe;">indicate_data</span>[<span style="color: #b5cea8;">15</span>];</div><div> <span style="color: #c586c0;">for</span> (<span style="color: #569cd6;">int</span> <span style="color: #9cdcfe;">i</span> <span style="color: #d4d4d4;">=</span> <span style="color: #b5cea8;">0</span>; <span style="color: #9cdcfe;">i</span> <span style="color: #d4d4d4;"><</span> <span style="color: #569cd6;">sizeof</span>(<span style="color: #9cdcfe;">indicate_data</span>); <span style="color: #d4d4d4;">++</span><span style="color: #9cdcfe;">i</span>)</div><div> {</div><div> <span style="color: #9cdcfe;">indicate_data</span>[<span style="color: #9cdcfe;">i</span>] <span style="color: #d4d4d4;">=</span> <span style="color: #9cdcfe;">i</span><span style="color: #d4d4d4;">%</span><span style="color: #b5cea8;">0xff</span>;</div><div> }</div><div> <span style="color: #6a9955;">//the size of indicate_data[] need less than MTU size</span></div><div> <span style="color: #dcdcaa;">esp_ble_gatts_send_indicate</span>(<span style="color: #9cdcfe;">gatts_if</span>, <span style="color: #9cdcfe;">param</span>-><span style="color: #9cdcfe;">write</span>.<span style="color: #9cdcfe;">conn_id</span>, <span style="color: #9cdcfe;">gl_profile_tab</span>[<span style="color: #569cd6;">PROFILE_B_APP_ID</span>].<span style="color: #9cdcfe;">char_handle</span>,</div><div> <span style="color: #569cd6;">sizeof</span>(<span style="color: #9cdcfe;">indicate_data</span>), <span style="color: #9cdcfe;">indicate_data</span>, <span style="color: #569cd6;">true</span>);</div><div> }</div><div> }</div><div> <span style="color: #c586c0;">else</span> <span style="color: #c586c0;">if</span> (<span style="color: #9cdcfe;">descr_value</span> <span style="color: #d4d4d4;">==</span> <span style="color: #b5cea8;">0x0000</span>){</div><div> <span style="color: #569cd6;">ESP_LOGI</span>(<span style="color: #569cd6;">GATTS_TAG</span>, <span style="color: #ce9178;">"notify/indicate disable "</span>);</div><div> }<span style="color: #c586c0;">else</span>{</div><div> <span style="color: #569cd6;">ESP_LOGE</span>(<span style="color: #569cd6;">GATTS_TAG</span>, <span style="color: #ce9178;">"unknown value"</span>);</div><div> }</div>
- <div> }</div><div> }</div><div> <span style="color: #dcdcaa;">example_write_event_env</span>(<span style="color: #9cdcfe;">gatts_if</span>, <span style="color: #d4d4d4;">&</span><span style="color: #9cdcfe;">b_prepare_write_env</span>, <span style="color: #9cdcfe;">param</span>);</div><div> <span style="color: #c586c0;">break</span>;</div><div> }</div></div>
复制代码
实现简单点灯功能,已经DDL,只好是先交了这份试用报告,接下来有时间有精力了再学习下esp-idf或是直接上python,补上原先答应的zigbee的测试以及其他功能的测试吧。
|