0

I playing with a ESP32-CAM. I have a image encoded as jpg in a struct as this

typedef struct {
    uint8_t * buf;              /*!< Pointer to the pixel data */
    size_t len;                 /*!< Length of the buffer in bytes */
    size_t width;               /*!< Width of the buffer in pixels */
    size_t height;              /*!< Height of the buffer in pixels */
    pixformat_t format;         /*!< Format of the pixel data */
    struct timeval timestamp;   /*!< Timestamp since boot of the first DMA buffer of the frame */
} camera_fb_t;

It is apperant that the raw image data seem to be a uint8_t array.

I want to send this image data across a websocket connection. The send function for binary data has the following syntax

esp_websocket_client_send(client,(char *)fb->buf, 1000, portMAX_DELAY);

I get a compiler error if I change the pointer format from char to uint8_t. So I'm using the above syntax. Still it seems to work and the python websockets server receives data of some sort. In python the data looks like this when printed to the server terminal.

b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x0  etc.

I would like to know if I'm sending the binary jpg data in a suitable data format? I mean, it seems a bit strange to interpret the uint8 array as a char array. Should I perhaps encode it differently before sending it?

jdk
  • 11
  • 3
  • I think you need to use fb->len instead of 1000. – Ôrel Jul 25 '20 at 22:14
  • The char is 8 bits so this not strange, the issue can be signed or unsigned for char. – Ôrel Jul 25 '20 at 22:18
  • Thanks for the answer Ôrel! I have used fb->len. The length is about 250000. This value gave transmission errors until I reduced it. That is why it is set to 1000. This is another problem but I guess it belongs in a different thread. – jdk Jul 25 '20 at 22:25

1 Answers1

0

That 'send' function is NOT for binary data.

The image pixels are binary data.

Suggest using:

int esp_websocket_client_send_bin(esp_websocket_client_handle_t client, const char *data, int len, TickType_t timeout)

also note: .jpg images are always a multiple of 512 bytes, so the length should be a multiple of 512, never 1000

user3629249
  • 16,402
  • 1
  • 16
  • 17