We have trams in Melbourne, but they look more like this:
Sorry, error of translation :-[ , in French the word is "trame", but I don't remember the english translation... packet ? datagram ?
On the other side I will decode the tram like this: First byte is the id -> convert this byte from hex to decimal ...
The "other side" is the server side.
My arduino will send data, in hex format, to an RF chip, and the chip will transfer this data to a server. On this server I must decode this data.
For example, the first byte is for the ID, two next byte for the first sensor, next byte for the second sensor etc etc.
(the server side is not the subject of this topic, it's just for understanding the problem)
I can't post all my code, because at this time it not exist because I don"t know how to convert my data.
That I want: send data from several sensor to a server.
For acquire the data I use an Arduino and for send the data I use an RF chip, with AT command, and I must send the data in hex format:
AT$1=AABBCCDDEEFF //Data in hex format
And the problem is that each value (in hex format) must have the same lenght over the time, because for decode I will use this:
Fisrt byte = ID
Next two byte = sensor1
Next byte = sensor2
Next four byte = sensor3
Next three byte = sensor4
So if the lenght of a value change (ie. The zero at the left are deleted), all my decoding function will not work.
For example the ensor1 is the DHT22's temperature, and sensor 2 is the humidity.
For the temperature (That can be negative, so I must use signed number):
(for simplify the example, I use unsigned)
Step 1 - I read 27.58°C
Step 2 - I will multiply by 100 to avoiding the comma: 2758
Step 3 - Converting to binary - two byte: 0000 1010 1100 0110
Step 4 - To Hex: 0AC6
Send the data to the server
Decode the data on the server: convert to decimal and divide by 100
No problem for step 1 and 2, but I don't know how I must do for the step 3
Several problem:
- A byte (data type on Arduino) are 8 bit, in this case they have 16 bit, how I can store this in Arduino (Word datatype can contain 16 bit, ok, But when I have a sensor which use 4 byte, how I can do ?)
- I must send the value on two byte, How I can keep the four zero at the left ?
Thanks for your help.