我将通过 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
0