A simple HTTP communication protocol between wifi and Arduino

How to let the sensed data (e.g., temperature) on the Arduino send to the remote server? 

The following code is used to realize this function.

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=");

     Serial.print(buf); 

     Serial.print(vol);

     Serial.println(" HTTP/1.1");   

     Serial.println("Host: api.iot.fm");

     Serial.println("Connection: close");

     Serial.println(); 

 }

1.jpg

more details, see: http://blog.smartarduino.com/

A brief and effective TCP protocol for Arduino and WIFI

How to upload the sensed temperature by LM35 to the remote server? This is a very usual problem. In this illustrative example,  by using TCP protocol based on Arduino platform, can let the sensed data upload to the remote server through 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).

The code can be download from github: https://github.com/SmartArduino/IoT-System-on-OpenSource/tree/master/ArduinoTCP,

The complete blog: http://blog.smartarduino.com/

The experimental material: http://www.smartarduino.com/

1_1.jpg