Hello, i have a problem using Ethernet library. Client.write() can't take int[] or float[], only char[] and byte[]. So my question is what's the solution for sending an array with negative numbers or floating point numbers to another device ?
You should convert to a character array. You'll have problems with ints and floats, especially using a GET request.
Hmm, what about if i have long numbers ? Do you mean that i have to convert all of them to chars and then sending ? Wouldn't it be a huge mess on the receiving side ? How can i know whether my sensors will give negative values or not ? These chars will be like '1' '2' '4' '-' '1 '2' - '3' '-' '3' ',' '4' so... on the receiving side there is no way to order them somehow ? Isn't it ? I just can't imagine it.
Thanks for replaying.
It will be a huge mess if you are using a GET request and attempt to send an illegal character.
Is the "other device" a web server as SurferTim assumes? If you just use TCP connection and can define your own protocol over it, you don't have to convert much but simply transfer the binary data. This implies that you have the same processor platform on both sides otherwise it's better to convert to an ASCII format.
Hmm.. i am not sure whether i got what you said. The client sends a byte to the server and then the server choose which array to return. The other device is my pc(client). What did you mean by "simply transfer the binary data" and what to convert to ASCII, also on which side ? I am kinda confused.
Have you considered UDP? That is my favorite protocol for this type of communication. How often do you send/receive?
I've heard that there is no ordering of messages with UDP. Isn't UDP for completely different kind of data ? I receive each hour.
UDP is for a completely different kind of data. The kind you want to use.
If used over the internet, there can be the possibility of packets arriving out of order, but that is normally when they are sent in rapid succession, like several per second, not once per hour.
What OS does your server run? I have UDP code for Linux.
The other device is my pc(client).
So your other device is your PC. Why do you define it as the client? Anyway, it doesn't really matter.
What did you mean by "simply transfer the binary data" and what to convert to ASCII, also on which side ?
As your PC is probably is based on the Intel x86 platform you use the same "endianness" as the AVR compiler (the processor cannot handle more than 8bit data). So you can transfer the data in binary format this way:
uint16_t my_int_val = 0x1234;
client.write((char *)&my_int_val, 2);
To send in ASCII format you can use the print method as you would on the Serial interface (EthernetClient inherits Client->Stream->Print):
uint16_t my_int_val = 0x1234;
client.println(my_int_val);