Hello Everyone:
A Video on Utube shows how to input json data to mySQL database
But there is a problem, the author left some contents unrevealed.
I have followed the steps to make arduino code, but it didn't work.
The code stopped at if (client.connect(server, 80)), and it didn't print anything.
Could someone help me?
Many thanks.
/* Arduino Yun sketch write sensor data to mysql*/
//Include Arduino Yun Lib
#include <Bridge.h>
#include <BridgeClient.h>
#include <SPI.h>
//Wamp server IP adress
const char *server = "192.168.2.108";
//MYSQL table name
const char *table_name = "yundata";
BridgeClient client;
char buffer[64];
/*Send HTTP POST request to the REST PHP/Mysql data API */
void send_request(){
Serial.println("\n connecting");
if (client.connect(server, 80)) {
Serial.println("sending ");
Serial.println("344");
//POST URI
sprintf(buffer, "POST /yundataphp/InsertIotJsonRESTdata.php HTTP/1.1");
client.println(buffer);
Serial.println(buffer); //Debug
//Host header
sprintf(buffer, "Host: %s", server);
client.println(buffer);
Serial.println(buffer); //Debug
//JSON content type
client.println("Content-Type: application/json");
Serial.println("Content-Type: application/json"); //Debug
//POST body
sprintf(buffer, "{ \"T1\" : \"26\" , \"M1\" : \"57\" , \"date\" : \"2016-02-08 00:25:48\" }", "344");
//Content Length
client.println("content-Length: ");
Serial.println("content-Length: "); //Debug
client.println(strlen(buffer));
Serial.println(strlen(buffer)); //Debug
//End of Headers
client.println();
Serial.println(); //Debug
//Request body
client.println(buffer);
Serial.println(buffer); //Debug
} else {
Serial.println("connection failed");
}
}
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
send_request();
}