Monthly Archives: May 2014

Chapter Three: A Brief But Effective HTTP Communication between Arduino and Remote Server

 

3.1 Problem presentation: How to transmit the sensed temperature by LM35 to the remote server by TCP protocol based on Arduino platform.

 

In this chapter, based on the Arduino UNO R3 development board, we will realize the function that the sensed temperature data can be sent to the remote server by using wifi module. Furthermore, we can control the data to send or not. Similarly, by using this TCP communication protocol, you can control the network-based electronic devices at anywhere through your phone or other network communication ways (e.g., wifi).

 

3.2 Hardware

The required materials in this experiment are shown in Table 3-1.

Table 1-1: the required materials

number

name

quantity

function

note

1 

Arduino software

1

platform

 

2 

server

1

manager data

 

3 

WiFi module

1 

Wireless communication

 

4 

Arduino shield board

1 

Connection wifi

All version

5 

USB to serial RS232

1 

conversion

 

6 

5V/1A voltage adapter

1

voltage

 

7 

Antenna

1 

Transmit wifi signal

optional

8

Samsung mobile phone

1

Wifi hot spot

 

9

LM35 

1

Collect Temperature 

 

10

Breadboard and line

several

connection

 

11 

Cduino

1 

Development board

 

The hardware materials can be seen in Figrue 3-1. All of these modules can be found at www.smartarduino.com, where, the wifi module is updated the new one. The Arduino kit can be found at SmartArduino

(http://www.smartarduino.com/arduino-development-board-cduino-base-power-adapter-omni_p94247.html).

Figure 3-1 Hardware

 

 

Before using WiFi module, you should set the corresponding parameters, which can be seen in the blog http://blog.smartarduino.com/ in Chapter Two.

 

Note that, the parameters setting of HTTP is different the one of TCP, which can be seen Figure 3-2.

Figure 3-2: HTTP parameters setting.

From Fig. 3-2, we know that, the protocol port should be 8080, and other parameters are the same as TCP. So, we can refer to the parameters setting of TCP.

 

3.2 Experiments

 

The corresponding code can be downloaded from github: https://github.com/SmartArduino/IoT-System-on-OpenSource/tree/master/ArduinoHTTP

 

About the experiments, it is the same as TCP. In other words, if we don’t send the command “begin”, the remote server cannot receive the sensed temperature data, as shown in Fig. 3-3.

Figrue 3-3: results without sending “begin”

But after send the “begin” (Fig. 3-4), the remote server can receive the sensed temperature data, which can be seen Fig. 3-5. The sensed data expressed by graph in Fig. 3-6 is also obtained, and also exhibited by table list in Fig. 3-7.

Figure 3-4: sending a command “begin”

 

 

 

Figure 3-5: results with sending “begin”

Figure 3-6: the sensed temperature data by graph

Figure 3-7: the sensed data exhibited by Table list

And, after sending a command “end” in Fig. 3-8, the remote server would not receive the sensed data, as shown in Fig. 3-9.

Figure 3-8: sending a command “end”

Figure 3-9: results after sending “end”

Chapter Two:A Brief TCP Communication between Arduino and Remote Server

 

2.1 Problem presentation: How to transmit the sensed temperature by LM35 to the remote server by TCP protocol based on Arduino platform.

 

In this chapter, based on the Arduino UNO R3 development board, we will realize the function that the sensed temperature data can be sent to the remote server by using wifi module. Furthermore, we can control the data to send or not. Similarly, by using this TCP communication protocol, you can control the network-based electronic devices at anywhere through your phone or other network communication ways (e.g., wifi).

 

2.2 Hardware

The required materials in this experiment are shown in Table 2-1.

Table 1-1: the required materials

number name quantity function note

1

Arduino software 1 platform

2

server 1 manager data

3

WiFi module 1 Wireless communication

4

Arduino shield board 1 Connection wifi All version

5

USB to serial RS232 1 conversion

6

5V/1A voltage adapter 1 voltage

7

Antenna 1 Transmit wifi signal optional

8

Samsung mobile phone 1 Wifi hot spot

9

LM35 1 Collect Temperature

10

Breadboard and line several connection

11

Cduino 1 Development board

The hardware materials can be seen in Figrue 2-1. All of these modules can be found at www.smartarduino.com, where, the wifi module is updated the new one. The Arduino kit can be found at SmartArduino

(http://www.smartarduino.com/arduino-development-board-cduino-base-power-adapter-omni_p94247.html).

Figure 2-1 Hardware

 

2.3 WiFi module parameters setting

 

For readers’ convenience, we will repeat the wifi module parameters setting by the following steps:

  1. Connect wifi module: find the signal transmitted by the wifi module in your PC, and double it to connect this wifi network;
  2. Login into the wifi local server: input the URL: http://192.168.16.254/, and input the default name (admin) and password (admin).

    Figure 2-2 login into wifi local server

     

  3. Parameters setting: You can set the corresponding parameters shown in Fig. 2-3. Note that, in our such experiment, we use phone as a wifi router (i.e., hot spot). Its name and password is SmartArduino and 12345678, respectively. The remote server is our IoT system (http://www.iot.fm/ext/examples/desktop/). Its IP is 50.116.16.236, and the TCP port is 9501. Certainly, you will change the parameters if you choose other communication ways and the remote server.


Figure 2-3 wifi module parameters setting

Warm prompt: to make sure the parameters setting right, you had better reset the wifi module to recover the default factory setting, as shown in Fig. 2-4.


Figure 2-4: reset wifi module

2.4 Experiment

After the above setting, you can download the Arduino code to the Cduino development board. The Arduino code can be download from the github (https://github.com/SmartArduino/IoT-System-on-OpenSource/tree/master/ArduinoTCP).

 

Then, open the serial monitor, we have the following result, as seen in Fig. 2-5. It is shown that, the sensor arduino is waiting for the command from the server.


Figure 2-5: experimental result by serial monitor

So, if we send a command “begin” to the sensor arduino, seen in Fig. 2-6.


Figure 2-6: send a command “begin” from the remote server.

and Arduino board also receives the command, then we will see that, the sensed data has been tested by serial monior, shown in Fig. 2-7.


Figure 2-7: the sensed data by using serial monitor.

At the same time, we can also see the sensed data at the remote server. Open the “Data Display”, and select the sensor “arduino” at the pie graph. We see the sensed temperature data by LM35, which is shown by the pulse in Fig. 2-8.


Figure 2-8: the sensed temperature data from Data Display.

In addition, we can use the “Data List” to see the concrete data value, as shown in Fig. 2-9. For example, at the time: 2014-05-22 08:07:15, the sensor “arduino” receives the temperature data “27.37″.


Figure 2-9: the concrete temperature data from “Data List”

If we send a command “end”, the remote server doesn’t receive the sensed temperature data, which can be seen Figs. 2-10, 11.


Figure 2-10: send a command “end” at the remote server.


Figure 2-11: the sensed data disappears after send an “end” command

 


How to use the IoT (internet of things) System(www.IoT.fm)

  1. Login into system

Anyone can use the default uid=demo and password=demo to login into the IoT system.


Fig. 1 Login into IoT system.

  1. User Guide

In this user guide, you can read many methods about the communication between Arduino and the remote server. That is, HTTP protocol and TCP protocol.

  1. Get API Key

Since in the Arduino code, we may use uid and password to set up a sensor node, and the Arduino code need the uid and password. To encrypt the password, in this part, the password has been encrypted for the safety. As shown in Fig. 2, the uid=demo, password=demo, and the key is c514c91e4ed341f263e458d44b3bb0a7.


Fig. 2 Generate the key

  1. Device Control

In the Device Control, we can add the sensor node. For example, in the first experiment, we set up a arduino node to receive the temperature from LM35 based on the Arduino board.


Fig. 3 Add a temperature sensor node “arduino”

Certainly, in this part, anyone can add or delete a sensor node. In addition, we can send a control command to control the sensor node. For example, we can send a “on” command to let a led light, and “off” to let a let dark.

  1. Data Display

In this part, you can read the sensed data from the Arduino board. For example, if you want to show the arduino sensor node data, you just let mouse move to arduino pie. At this time, you can read the arduino sensor data. The left below subfigure shows the history sensed data.


Fig. 4 Data disply

  1. Data List

Data List is used to check whether the sensed node upload the data succefully. Fig. 5 shows the sensed data from the LM35 on the Arduino board in the next experiment. So, we can know that LM35 has successfully upload the temperature to the remote server.


Fig. 4 Data exhibition at the remote server.

 

More stronger function are found in the near future. Please focus on it continually.

IoT-1 Temperature sent to Cloud Server by using Arduino and WiFi via HTTP Protocol

 

 

1.1 Problem presentation: how to use Arduino and wifi for sending temperature to the remote cloud server

In this section, we will give a presentation how can we send the sensed temperature data to the remote cloud server by using Arduino control board (Cduino) and WiFi module. Then, by login into the distributed clients, you can check the temperature around your lovers at any countries in the remote Atlantic side. Certainly, if using many types of sensors, you can check and read many other required information.

31.2 Hardware and software

The required materials in this experiment are shown in Table 1-1.

Table 1-1: the required materials

number name quantity function note

1

Arduino software 1 platform

2

server 1 Collection data

3

WiFi module 1 Wireless communication

4

Arduino shield board 1 Connection wifi All version

5

USB to serial RS232 1 conversion

6

5V/1A voltage adapter 1 voltage

7

Antenna 1 Transmit wifi signal optional

8

HTC mobile phone 1 Wifi hot spot

9

LM35 1 Collect Temperature

10

Breadboard and line several connection

11

Cduino 1 Development board

The hardware materials can be seen in Figrue 1-1. All of these modules can be found at www.smartarduino.com, where, the wifi module is updated the new one. Arduino kit can be found at

http://www.smartarduino.com/arduino-development-board-cduino-base-power-adapter-omni_p94247.html

Figure 1-1 Hardware

1.3 Work principle

The work principle for this experiment can be seen in Figure 1-2.

Figure 1-2 working principle

1.4 Experimental analysis

(1) draw the experimental schematics: According to the design idea, you can draw the experimental schematics, which is shown in Figure 1-3, and this principle of LM35 is the same as Section 8 from the Basic Part. To readers’ convenience, this figure is given here again. Compared with this experiment, it is short of Arduino shield board and wifi board. But the principle of collecting temperature by LM35 is the same as Section 8 in the Basic Part.

Figure 1-3 Experimental principle

(2) circuit connection: By the experimental principle, we firstly connect the circuit shown in Figure 1-4, where, the WiFi module has been updated into the new one, and a omni antenna is add for the better WiFi signal.

Figure 1-4 Experimental connection

(3) wifi network connection: when we power the wifi on the Arduino main board, we can get the wifi signal. But, for the stability of wifi signal, we should power the wifi shield board by the dedicated voltage adapter shown in Table 1-1. Note that, the wifi module could not be inserted in a wrong direction. If right, then the three led lights will be light (one red and other two is green); if wrong, just ONLY one red led is light. Or, you can connect it by Fig. 1-4.

If the inserted wifi module is right, after a short while, you can search a wifi signal in your compter named as Serial-WiFi transmitted by wifi module. Then double click the wifi network serial-wifi, and input the password ( the default password is 12345678) shown in Figure 1-5. In general, it is not necessary to input the password. Then, the serial-wifi network is connected.

Figure 1-5 Serial-WiFi connection

Note that, if you use the wifi module at the first time, to ensure the exactness of data configuration, wifi module needs to recover to the default factory settings (press the button RST on the Cduino shield board for 6 seconds, then power off and reboot for the wifi module, as shown in Figure 1-6. Also can see the method in Section 2).

Figure 1-6 Reset wifi module to the factory default setting.

This step is similar to open the wifi in our phone to surf the internet. It shows that the wifi module can transmit the wifi signal. Therefore, if wifi module connects a wifi hot spot, then we can let data send by wifi communication.

(4) set up wifi hot spot: Since there is no other wifi hot spot in our such experimental environment, then we use OUR HTC mobile phone to set up a wifi hot spot (wifi router is suitable). After this, temperature data can be sent by wifi to the cloud server. At first, open the “WLAN hot spot” in the mobile phone. At the same time, remember to open 3G network signal (very important), which can make temperature data collected by LM35 send to server in the remote cloud. In this experiment, the WLAN hot spot name in my HTC phone is set as “SmartArduino” for the mobile SSID, and password is “12345678″, as shown in Figure 1-7. You can also use the default name and password. However, for the input convenience, you had better to modify the default name and password.

Figure 1-7 wifi hot spot by HTC phone

 

(5) network configuration: This step is very important. If right, then you can do a successful experiment. When the computer finds and connects the wifi network Serial-WiFi from the wifi module successfully, you can input the website “192.168.16.254″ in the browser, and input the user name and password (both are “admin”) to configure the web data, which is shown in Figure 1-8.

Figure 1-8 Login into the wifi configure system.

After login into the wifi configure system, we can set the wifi module some parameters. The detailed parameters and information is shown in Figure 1-9.

Figure 1-9 Serial-WiFi network configurations

After set, then click apply, then my HTC phone will find a connection, which is shown in Figure 1-7. When configure the network data parameters, please specially note that the marked by red rectangle, and others can be default settings. Some notes are given as follows.

  1. At this time, wifi module can be viewed as a collection and transmission unite, which can send the collected temperature data to the server on the remote distributed cloud.
  2. SSID and Password are the same as the SSID and Password from the mobile phone (or wifi router).
  3. Remote ServerDomian/IP: It is pointed to the server IP address where the temperature data are stored at. In our such experiment, the IP address is 50.116.16.236, which is corresponding to the IoT system (www.IoT.fm). Anyone can use this server to do their own experiment.
  4. Locale/Remote Port: the server port number, here is 80.

After configure, click “Apply”. At this time, if you check your phone, there is a “1 user connects” in the bottom of the “WLAN hot spot”, as shown in Figure 1-7. This implies that, the wifi module on the Arduino board has been connected the mobile hot spot. That is, the wifi module has been connected the internet. Then the sensed temperature data by LM35 can be sent to the cloud server.

(6) Arduino code

//the sensed temperature data by LM35 is sent to the remote server 50.116.16.236 (www.IoT.fm)

void setup()

{

Serial.begin(115200);

}

void loop()

{

int n=analogRead(A0);

float vol=n*(5.0/1023*100);

upload_sensor(vol);

delay(5000);

}

 

void upload_sensor(float vol)

{

// send the HTTP PUT request:

char buf[200];

memset(buf,0,200);

int ret;

ret=sprintf(buf,”GET /upload.php?uid=demo&key=c514c91e4ed341f263e458d44b3bb0a7&sensor_name=arduino&data=”);

//here, uid=demo, and the key is encrypted by “Get API Key” on the IoT system

Serial.print(buf);

Serial.print(vol);

Serial.println(” HTTP/1.1″);

Serial.println(“Host: api.iot.fm”); //the remote server

Serial.println(“Connection: close”);

Serial.println();

}

Then you can download the above code to the Arduino control board. Note that, there is a switch. You should let the switch on the outside (O) when downloading the Arduino code. This is because the serial connection may affect the data download, which is shown in Figure 1-10.

Figure 1-10 Switch on the Cduino base board

At the same time, you can track the data transmission on the monitor at the Arduino soft-platform, which is shown in Figure 1-11 marked by the red label. The temperature is 26.39, and this data has been transmitted to the remote server cloud by wifi networks.

Figure 1-11 Data display on the Arduino serial monitor

(7) data connection at the end: if you finished the above six steps successfully, congratulations, you are successful. The temperature sensed by sensor LM35 has been successfully sent to the server on the internet by wifi module. The related temperature data can be exhibited in Figrue 1-12, which is obtained by click “Data List” in the IoT system. Note that, when you want to checkt the new sensed data from Arduino, you must refresh the IoT system to get the new sensed data.

Figure 1-12 Data List at server

1.5 Key notes and summaries

(1) Before configuring network parameters, to ensure the successful configuration, please recovery the wifi module to the default factory settings.

(2) Please ensure the exactness of data configuration, especially the settings about mobile phone and server IP address.