Arduino Code for POST request
#include <Bridge.h>
#include <HttpClient.h>
#include <YunClient.h>
//IPAddress server(192,168,1,200);
byte php_server[] = {192,168,1,9};
YunClient client;
String data = "", datax="", datay="", dataz="";
unsigned long ts_0 = 0, tr_0 = 0, t_read = 100;
int counter=0;
void setup() {
// put your setup code here, to run once:
Bridge.begin();
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
if((millis()-tr_0>=t_read)) {
if(counter<49) {
counter++;
}
else if(counter == 49) {
//Serial.print("sent");
String dat = "0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12";
send_to_ws(dat);
Serial.println(dat);
counter = 0;
}
tr_0=millis();
}
}
void send_to_ws(String data) {
if(client.connect(php_server, 80)) {
Serial.println("Connected");
client.println("POST /arduino/add.php HTTP/1.1");
client.print("Content-Length:");
client.println(data.length());
Serial.println(data.length());
Serial.println(data);
client.println("Connection: Close");
client.println("Host:192.168.1.9");
client.println("Content-Type: application/x-www-form-urlencoded");
client.println();
client.println(data);
} else {
Serial.println("Connection error");
}
}
Serial monitor output when running this sketch, It prints it in the serial monitor but only blank data is being pushed in the database of the server
