[2017.6 Digital Twin] Server
Server
These days I concentrate on the program of the server. I hava done the job on the Arduino. Now I need transmitt it to a server.
First I design a Packet program. It can pack the different kinds of data together. eg. When the data are like these:
temperature = 25.3
switch = true
then the packet is like this:
2
temperature
switch
double
bool
25.3
true
which means,
>there are two variables.
>the names of variables are"temperature" and "switch"
>the types of variables are "double" and "bool"
>the values of variables are 25.3 and true
the packet will transmit through the serial to the raspberry pi. The Pi need to unpack the pack. And Raspberry pi can add some other information in the packet. like this:
3
temperature
switch
raspberry
double
bool
string
25.3
true
Hallo, I am Pi
and the raspberry pi transmit the data further to server.
about the server and client. I use socket program. This part wastes me a lot of time.
Because it need to write 3 Thread at each parts. They are
> Client/Server
> ReadHandlerThread
> WriteHandlerThread
Because it need to write 3 Thread at each parts. They are
> Client/Server
> ReadHandlerThread
> WriteHandlerThread
The Client/Server Thread is used to build connect between Client and Server. When the connection is built. The next two Threads start. They are used to receive or send data through socket.
Finially. I finish all the program. And at server, it can send the data back to Arduino. like this
评论
发表评论