I'm trying to send data from Simulink to an MKR1000 board using a TCP/IP Send block. I can send the data just fine, but when I read it using the client.read() function on arduino IDE, the value doesn't make any sense and I can't figure out what is happening.
I know the value is supposed to be a byte, but the format I'm getting is weird and I can't figure out if it's a mysterious baseWhatever number or something else. Here's the data I'm reading (on the right) for sent numbers from Simulink (on the left):
If it's a byte isn't it supposed to be only 1s and 0s? It seems like I'm getting a byte made of other bytes.
Does anyone know how I can convert these values to int? I've searched for hours but couldn't find a solution. I've already tried all of the Arduino data type conversion functions.
Thanks for the replies. After trying a few things I was able to figure out what the problem was:
The value I was sending from Simulink was a double, which size is 8 bytes (or 64 bits), and it was supposed to have the size of 1 byte (or 8 bits). The client.read() function from the WiFi101 library reads sent bytes, one at a time. After I added a data conversion block in Simulink from double to int8 type I was able to read the right values.
Another info in case someone struggles with a similar problem is that the client.read() function only works with unsigned integers. Negative numbers are represented as positive, starting from 255. So for example, if you send -1, the function will output 255; -2 will be 254, etc