Hi, I am using ESP32 Dev Module to receive image data of size 75kb from a raspberry pi through a tcp connection. I store the data received in a byte array and print the HEX data. The issue the ESP resets whenever I try to print the data. I have tried to print the data while receiving the data and the it print the whole data received. I need help understanding the problem.
#include <WiFi.h>
WiFiClient client;
int ledPin = 5;
String recvString = "";
const int port = 8888; //Port number
const IPAddress server();
//Server connect to WiFi Network
const char *ssid = "MW40VD_19E7"; //Enter your wifi SSID
const char *password = ""; //Enter your wifi Password
void writeString(String stringData) {
for (int i = 0; i < stringData.length(); i++) {
client.write(stringData[i]);
}
}
uint8_t recvWithStartEndMarker() {
boolean endData = false;
const byte numChars = 32;
char receivedChars[numChars];
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while(client.available()>0){
rc = client.read();
if (rc == startMarker) {
recvInProgress = true;
}
else if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
ndx = 0;
recvInProgress = false;
uint8_t dataRecv = atoi(receivedChars);
return dataRecv;
}
}
}
}
void imgbyteArray(){
uint8_t receivedByte[96000];
uint32_t starttime = millis();
int i = 0;
long calc_data = 0;
int a = 0;
int b = 0;
int c = 0;
// while(i < 4) {
// if (client.available()) {
// uint8_t imgData = recvWithStartEndMarker();
// calc_data = (imgData * pow(256, i)) + calc_data;
// i++;
// }
// }
// Serial.println(String(calc_data));
while(i < 96000 && (millis() - starttime < 22000)) {
if (client.available()) {
uint8_t imgData = recvWithStartEndMarker();
receivedByte[i++] = imgData;
}
}
Serial.println(i);
for (int j = 0; j < i; j++) {
printHex(receivedByte[j], 2);
}
}
void printHex(int num, int precision) {
char tmp[16];
char format[128];
sprintf(format, "%%.%dX", precision);
sprintf(tmp, format, num);
Serial.print(tmp);
}
void setup()
{
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.println();
WiFi.begin(ssid, password); //Connect to wifi
// Wait for connection
Serial.println("Connecting to Wifi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
char imgchr;
if (client.connect(server, port)) {
Serial.println("Client Connected");
digitalWrite(ledPin, HIGH);
}
else {
Serial.println("No Connection");
delay(500);
return;
}
while(client.connected()){
while(client.available()>0){
imgbyteArray();
}
while(Serial.available()>0)
{
client.write(Serial.read());
}
}
client.stop();
Serial.println("Client disconnected");
digitalWrite(ledPin, LOW);
}
the Error
ets Jun 8 2016 00:22:57
rst:0x8 (TG1WDT_SYS_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
Connecting to Wifi
.