I'm measuring accelerations at "high frequency" (4kHz) from an accelerometer (ADXL355/ADXL357) to an esp32. It's crucial that no sample is lost while performing a measure which last say 2 seconds, thus I first record all the samples and then send the complete array of measures to a server over wifi knowing the IP and the port of the server.

The measures array is an int array of size 3bytes * 3axis * 4000Hz * 2seconds = 72000 bytes.

I tried to make an http server and send the measures array from the microcontroller to the server with a POST request and serializing the payload with json (ArduinoJSON library), but this is very costy in terms of memory, because I need to duplicate the array of measures and convert it to an array of strings.

Is there a better way to send this array over wifi to the server (some sort of stream?) optimizing the memory usage on the microcontroller? which arduino libraries may help in the task? could you link an example with code of a similar situation?

1 Answer 1


JSON is a format trivial to write: you do not need a library for this. For example, an array of numbers could be serialized like this:

void serialize_array(Print &client, int *data, int count) {
    for (int i = 0; i < count; i++) {
        client.print(i==count-1 ? ']' : ',');

This would effectively stream the data without storing the JSON representation in memory.

  • Thank you Edgar, what is the client parameter of type Print? Where could I find documentation on understanding how to set it for comunnicate with a given ip:port? Jun 21, 2023 at 9:38
  • 1
    @AlekseyFedorovich: client would be an instance of HttpClient, or EthernetClient, or WiFiClient, or... whatever you are sending your data to. It could even be Serial if you just want to check the payload on the serial monitor. See the documentation of whatever you would use to send an HTTP request. Jun 21, 2023 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.