完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我将通过 tcp 连接发送一个 bytearray,例如
但是我的 esp8266 直到 x00 字节才接收到字节 这是我的代码(简单的 tcp 接收): 代码:全选#include "ets_sys.h" #include "osapi.h" #include "os_type.h" #include "user_interface.h" #include "espconn.h" #include "mem.h" #include "gpio.h" #include "user_config.h" #include "../driver/uart.h" #include LOCAL uint16_t server_timeover = 60*60*12; // yes. 12h timeout. so what? :) static struct espconn httpconfig_conn; static esp_tcp httpconfig_tcp_conn; void user_init(void){ uart_init(BIT_RATE_115200,BIT_RATE_115200); //connect wifi connect_wifi(); httpconfig_conn_init(); } void ICACHE_FLASH_ATTR httpconfig_conn_init() { httpconfig_conn.type=ESPCONN_TCP; httpconfig_conn.state=ESPCONN_NONE; httpconfig_tcp_conn.local_port=4040; httpconfig_conn.proto.tcp=&httpconfig_tcp_conn; espconn_regist_connectcb(&httpconfig_conn, httpconfig_connected_cb); espconn_accept(&httpconfig_conn); espconn_regist_time(&httpconfig_conn, server_timeover, 0); } static void ICACHE_FLASH_ATTR httpconfig_recv_cb(void *arg, char *data, unsigned short len) { struct espconn *conn=(struct espconn *)arg; os_printf("Data: %s\nLen: %d\n", data, len); espconn_disconnect(conn); } static void ICACHE_FLASH_ATTR httpconfig_recon_cb(void *arg, sint8 err) { } static void ICACHE_FLASH_ATTR httpconfig_discon_cb(void *arg) { char info[] = "Client disconnected\r\n"; uart0_tx_buffer(info,sizeof(info)); } static void ICACHE_FLASH_ATTR httpconfig_sent_cb(void *arg) { } static void ICACHE_FLASH_ATTR httpconfig_connected_cb(void *arg) { struct espconn *conn=arg; espconn_regist_recvcb (conn, httpconfig_recv_cb); espconn_regist_reconcb (conn, httpconfig_recon_cb); espconn_regist_disconcb(conn, httpconfig_discon_cb); espconn_regist_sentcb (conn, httpconfig_sent_cb); } static void ICACHE_FLASH_ATTR connect_wifi(){ struct station_config stationConf; wifi_set_opmode( STATION_MODE ); //wifi config const char ssid[20] = SSID; const char password[30] = SSID_PASSWORD; if(wifi_get_opmode() == STATION_MODE){ os_printf("STATION_MODE is set\r\n"); os_memcpy(&stationConf.ssid, ssid, 30); os_memcpy(&stationConf.password, password,30); os_printf("Wifi info: %s, %s\r\n", SSID, SSID_PASSWORD); wifi_station_set_config(&stationConf); wifi_station_connect(); os_printf("Connected...\r\n"); } else { os_printf("Err: STATION_MODE not set\r\n"); } } ESP8266 站点上的输出: 代码:全选Data: \0xfb\0xfb\0xfb Len: 18 |
|
相关推荐
1个回答
|
|
在发送字节数组时,您可以使用以下代码使用0x00通过tcp发送字节数组:
``` const uint8_t data[] = {0x12, 0x34, 0x56, 0x00, 0x78}; espconn_sent(pesp_conn, data, sizeof data); ``` 其中,data[]是这个bytearray,pesp_conn是您的espconn结构体。`espconn_sent()`函数用于将数据发送到对端。 |
|
|
|
只有小组成员才能发言,加入小组>>
407浏览 6评论
339浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
321浏览 5评论
322浏览 4评论
310浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-16 14:24 , Processed in 0.764124 second(s), Total 76, Slave 60 queries .
Powered by 电子发烧友网
© 2015 www.ws-dc.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号