I have to send a jpeg by serial from a uart to an esp8266, the jpeg has 0 values in some places, if I send the zeros as is, the received frame contains the chars before the zeros, so what I do is that I send a '0' (0x30 ascii code) instead of a zero,
as you can see on the picture of the merge, on the right the jpeg I receive, on the left the normal jpeg, look at the fifth byte of the top, you will see the difference !
I can't work like that I really want to send char[i]= 0 and receive it
i also give you my code of sending :
for (i=0;i<244;i++){
if (Storage_ReadWrite_Buffer[i]!=0)
sprintf(Storage_ReadWrite_Buffer[i],"%c", Storage_ReadWrite_Buffer[i]);
else
Storage_ReadWrite_Buffer[i] = '0';
//sprintf(Storage_ReadWrite_Buffer[i],"%d", Storage_ReadWrite_Buffer[i]);
}
RS485_Send_CHAN_A("<",1);
RS485_Send_CHAN_A(Storage_ReadWrite_Buffer,244);
// RS485_Send_CHAN_A(">",1);
RS485_Send_CHAN_A("\0",1);
that is the code in the esp to get data :
void loop() {
recvWithStartEndMarkers();
showNewData();
}
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static int ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
//delay(5);
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
compteur++;
ndx++;
if (ndx >= numChars-1) {
ndx = 0;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
//Serial.println(ndx,DEC);
recvInProgress = false;
ndx = 0;
//publish_image();
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
for(int comp;comp<6000;comp++){
receivedChars[comp] = 0;
}
}
}
}
void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChars);
//Serial.println(receivedChars[4],HEX);
newData = false;
publish_image();
}
}