Send data from node to server using serial forwarder
How to send data from node to server using serial forwarder?
Sending data from node to server is more straightforward than the other way.
To send data to server, you need to send the full packet of TOS2 packet, this means your packet will include:
frame byte(0x7E)
protocol type(currently)
CRC16
The standard packet format for TinyOS 2 is in last wiki page.
You need to package the data packet on node and also calculate CRC for them.
Example:
Suppose you have a payload which contains 3 number: {2,2,2}
Then the format you need to send to the serial port using uart1_writeb() is:
{126, 68, 1, 0, 0, 0, 0, 102, 3, 0, 0, 2, 2, 2, 151, 168, 126}
The length of this packet is 17 bytes.
Note that you need to skip the packet if necessary.
How to receive the data from node on server?
Suppose you have a python script on the server. The python script need a socket to connect
to port 9002 on the server(localhost). Then send handshake signal {85, 32}. This step
is the same as sendig data from server.
Using the example packet above, when the node send this packet to server, the python script
that has already been connected to port 9002 will first receive a number indicate the length
of the incoming packet. Notice here, the length isn't for the whole packet.
Data send from node:
{126, 68, 1, 0, 0, 0, 0, 102, 3, 0, 0, 2, 2, 2, 151, 168, 126}
Data received at server python script:
{15, 1, 0, 0, 0, 0, 102, 3, 0, 0, 2, 2, 2, 151, 168, 126}
The first byte 15 indicates that the packet is 15-byte-long. The serial forwarder
won't forward the first frame byte and the protocol type byte. So the 17-byte-long original
is forwarder as a 15-byte-long packet.
NOTICE:
Don't send any debug information during the sending of packet, or the transmission will be disrupted, the serial forwarder won't be able to recognize the packet.
My understanding of the code:
The code for handling serial packet on the node is in /sw/python/wsntestbed/clientlib/handler.py