As per title, I am trying to send an array of float using TcpClient. Is this possible? should I convert it into bytes before? if so, how?
i’ve tried both
A simple client.write((const uint8_t*)array, sizeof(array)) should do too.
But when you say “neither works”, the resulting error message is the first help you get.
And posting the exact error message(s) would be good practice too
test2.cpp:125:37: error: no matching function for call to 'TCPClient::write(float (*)[5], unsigned int)'
^
test2.cpp:125:37: note: candidates are:
In file included from ./inc/application.h:56:0,
from test2.cpp:2:
../wiring/inc/spark_wiring_tcpclient.h:47:17: note: virtual size_t TCPClient::write(uint8_t)
I should have understood unit8_t was the way to go.
is memcpy() a good way to convert floats into unit8_t? I
You could use memcpy(), but there is no need since you already have a byte array filled with your data in memory, just tell the function the pointer you provide is pointing to a byte array.
That’s exactly what my suggested type cast does.
For example, you have a float myFArray[5] and by doing this (uint8_t*)myFArray you “fool” the compiler into beliefing the pointer points to an uint8_t[]. And since sizeof(myFArray) returns the number of bytes occupied by your float array (5 elements with 4 byte each = 20), you’ll pass all the bytes making up all your floats into the function.
There are multiple ways on the Photons side and on the remote side, but before you bother with that, first check if both sides don’t already agree there
If you really have to convert, do it on the side you are most comfortable with.