how to send array of double through wifi

a_keivan
Posts: 2
Joined: Mon Oct 02, 2023 9:43 pm

how to send array of double through wifi

Postby a_keivan » Mon Oct 02, 2023 9:57 pm

Hi,

How can I pass array of doubles through the wifi?

I've been playing with client.write() and successfully passed strings, characters, integer numbers but when it comes to double numbers, i can't get it to work. I have some sensors data that uses decimal number and need help passing double values.

Thank you in advance

lbernstone
Posts: 829
Joined: Mon Jul 22, 2019 3:20 pm

Re: how to send array of double through wifi

Postby lbernstone » Tue Oct 03, 2023 3:24 am

Not sure exactly what you mean, but printf is the way to have precise control over your output. A double = long long = int64_t in esp32.

Code: Select all

double x = 9876543210;
Serial.printf("Output my double value: %ll\n", x);

a_keivan
Posts: 2
Joined: Mon Oct 02, 2023 9:43 pm

Re: how to send array of double through wifi

Postby a_keivan » Wed Oct 04, 2023 12:36 am

lbernstone wrote:
Tue Oct 03, 2023 3:24 am
Not sure exactly what you mean, but printf is the way to have precise control over your output. A double = long long = int64_t in esp32.

Code: Select all

double x = 9876543210;
Serial.printf("Output my double value: %ll\n", x);
thank you for your responce.

what if x is an array?

is there a way to pass x as an array? or do you have to printf each element of the array individually? if its a larger array say 20 elements it gets harder to printf/call each element individually.

Code: Select all

x [] = {9.12, 5.53, 7.23}

thanks

lbernstone
Posts: 829
Joined: Mon Jul 22, 2019 3:20 pm

Re: how to send array of double through wifi

Postby lbernstone » Thu Oct 05, 2023 1:42 am

Code: Select all

const float array1[] = {1.23, 4.56, 7.89};
void setup() {
  Serial.begin(115200);
  uint32_t array_count = sizeof(array1) / sizeof(float);
  if (array_count) {
    String buffer = String(array1[0]);
    for (int x=1; x<array_count; x++) {
      buffer += ", " + String(array1[x]);
    }
    Serial.println(buffer);
  }
}

Who is online

Users browsing this forum: No registered users and 90 guests