Send bytearray over tcp with 0x00?
Posted: Sun Jan 31, 2016 4:02 pm
Hi all,
I'll send a bytearray through tcp connection like
but my esp8266 don't recieve bytes until x00 byte
Here is my code(simple tcp recieve):
Output on ESP8266 site:
Can someone help me?
I'll send a bytearray through tcp connection like
\xFB\xFB\xFB\x00\x12\x01\x02\x03\x04\x05\x06\x07\b\t\n\xFA\xFA\xFA
but my esp8266 don't recieve bytes until x00 byte
Here is my code(simple tcp recieve):
Code: Select all
#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>
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");
}
}
Output on ESP8266 site:
Code: Select all
Data: \0xfb\0xfb\0xfb
Len: 18
Can someone help me?