Go Down

Topic: Sending an array of arrays of uint8_t and char through Node MCU (Read 1 time) previous topic - next topic

javad_habibi

Hi every one
I have a sensor that should send 1KB data every 40ms. I want to send this through ESP8266 (Nodemcu) to my laptop. This is my code:

Code: [Select]
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

/* Put your SSID & Password */
const char* ssid = "NodeMCU";  // Enter SSID here
const char* password = "12345678";  //Enter Password here

char  Data_mem[10][1024];
uint8_t Data_mem2[10][1024];

int a=0;

/* Put IP Address details */
IPAddress local_ip(192,168,1,1);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);

//ESP8266WebServer server(80);
WiFiServer server(80);                   

void setup() {
  Serial.begin(115200);
  WiFi.softAP(ssid, password);
  WiFi.softAPConfig(local_ip, gateway, subnet);
  delay(100);
 
  server.begin();
  server.setNoDelay(true);// Don't Permit TCP Buffering
  Serial.println("HTTP server started");

  //Data Init
     for(int j=0;j<10;j++){
        for(int i=0;i<1024;i++) {
            Data_mem[j][i]='G';
        }
      }

     for(int j=0;j<10;j++){
        for(int i=0;i<1024;i++) {
            Data_mem2[j][i]=10;
        }
      }
}

void loop () {
  WiFiClient client = server.available();
  if (client) {
    if (client.connected()){
      if(a==0){
        a=1;
        for(int j=0;j<10;j++)
          client.println(Data_mem2[j]);   
    }
      else{
        client.stop();  // terminates the connection with the client
      }
    }
  }
}


In this Code, i have 2 problem:
1- How to send an array of array of uint8_t through WiFi? (Each 1KB data(=Data_mem[j]) should send in one seprate packet)
In this code i get this error:
call of overloaded 'println(uint8_t [1024])' is ambiguous

2- If i want to send char instead of uint8_t through replace this line client.println(Data_mem2[j]), data sent. But what received is not 10 * 1024 =10240 bits. It is 56320 bits!(I have copied received data of packet sender in Microsoft Office Word and get the number of characters ('G'))
Note that code works true for sending   client.println(Data_mem[0]) and is 1024 bit. 

I need both array of array of uint8_t and char.

Thanks

PaulS

Quote
In this code i get this error:
call of overloaded 'println(uint8_t [1024])' is ambiguous
The println() method is not overloaded to print an array.

Suppose that it were. How would you decipher "1010101010101010101010101010..." in the receiving end?

Quote
2- If i want to send char instead of uint8_t through replace this line client.println(Data_mem2[j]), data sent. But what received is not 10 * 1024 =10240 bits. It is 56320 bits!
Data_mem is a 2D array of chars. It is NOT a 1D array of strings. You can NOT pass something that is not a string to a function that expects a string and expect that function to do anything useful.

You need to send ONE value at a time, adding delimiters between values as appropriate.

The problem there is that each println() call sends a packet, with very little payload per packet. So, you'd need to have a way of stuffing more than one value in a packet. To do that effectively, you need to determine what the payload size of a packet can be, and create a payload of approximately that size.
The art of getting good answers lies in asking good questions.

Go Up