Seg 5: Arduino code

(6) Arduino code

void setup()

{

Serial.begin(115200);//set baud value

}

void loop()

{

int n=analogRead(A0);//define A0 as the received port

float vol=n*(5.0/1023*100);//voltage signal to temperature

upload_sensor(vol);//sub-function

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=ycf&ps=ycf&sensor_name=arduino&data=”);

//设置协议

Serial.print(buf); //stored at buf temporally

Serial.print(vol);//use temperature data vol

Serial.println(” HTTP/1.1″); //HTTP protocol name

Serial.println(“Host: api.cduino.com”);//set server website

Serial.println(“Connection: close”);//data transmission is finished, and connection is closed.

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. At the same time, you can track the data transmission on the monitor at the Arduino soft-platform, which is shown in the red label. The temperature is 25.90, and this data has been transmitted to the remote server cloud by wifi networks.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>