Всем привет!
К примеру я передаю такой массив [inline]
\xFB\xFB\xFB\x00\x02\x01\x02\xFA\xFA\xFA
[/inline]
Та часть, которая идёт до "x00" приходит, а остальное нет. Если я заменяю \x00", то весь массив приходит.
Я так понимаю, что получение идёт до того момента пока байт не будет равен нулю. Я в принципе передаю длину массива, можно как-то сказать, сколько он должен получить и чтобы не обрывался если приходит "\x00"?
К примеру я передаю такой массив [inline]
\xFB\xFB\xFB\x00\x02\x01\x02\xFA\xFA\xFA
[/inline]
Та часть, которая идёт до "x00" приходит, а остальное нет. Если я заменяю \x00", то весь массив приходит.
Я так понимаю, что получение идёт до того момента пока байт не будет равен нулю. Я в принципе передаю длину массива, можно как-то сказать, сколько он должен получить и чтобы не обрывался если приходит "\x00"?
Код:
#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<string.h>
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);
}
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\n",data);
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,strlen(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");
}
}
Последнее редактирование: