Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By de1m
#40106 Hi all,
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 allData: \0xfb\0xfb\0xfb
Len: 18


Can someone help me?
User avatar
By dkinzer
#40182 Given that the %s format control is specified to take a null terminated string I'm not sure why you would expect a different result. If you want to output a series of bytes that might contain a null you'll have to write your own routine.
User avatar
By de1m
#40284
martinayotte wrote:As @dkinzer said, that's absolutely normal if you are printing data as a string.
You should do it somehow like that :


thank you, it's working now. ;)