Hello Everyoune,
I've my Arduino YUN with a protoshield and some gas sensors (metane, idrogene, temperature, humidity).
I've got to send these values via POST to a web service in PHP. Knowing that:
1) Arduino YUN is connected to a WiFi Router which is connected to the internet (my smartphone working as WiFi Router);
2) The WS works well because when getting post variables from other sources it saves and visualizes data;
3) Arduino YUN is connected to WiFi Router via WiFi and to the PC (which is also connected to the same Router wirelessly) via USB, so I can check serial messages via Serial Monitor on the PC, and also checking on the internet if data are sent and visualized.
So, the fact is, even if everybody sends data the same way (see the sketch below) it doesn't work for me. I've also tried to use another Arduino YUN, but nothing. The sketch is:
#include <Bridge.h>
#include <Console.h>
#include <FileIO.h>
#include <HttpClient.h>
#include <Mailbox.h>
#include <Process.h>
#include <YunClient.h>
#include <YunServer.h>
#include <dht.h>
#include <SPI.h>
//IP Address of the sever on which there is the WS: http://www.mywebsite.com/
IPAddress server(XX,XX,XX,XX);
YunClient client;
dht DHT;
#define DHT11_PIN 2
int temp;
int hum;
int metano;
int idrogeno;
int led_giallo = 13;
int led_rosso = 12;
String parametri =""; //String of POST parameters
void setup()
{
Bridge.begin();
Serial.begin(9600);
pinMode(led_rosso,OUTPUT);
pinMode(led_giallo,OUTPUT);
digitalWrite(led_giallo,HIGH);
digitalWrite(led_rosso,LOW);
delay(2500);
digitalWrite(led_giallo,LOW);
}
void loop()
{
//measures
metano = analogRead(0);
idrogeno = analogRead(1);
hum = (int) DHT.humidity;
temp = (int) DHT.temperature;
if (client.connect(server, 80)) {
Serial.println("connected");
delay(2500);
parametri="temp="+String(temp) + "&hum="+ String(hum)+"&metano="+String(metano)+"&idrogeno="+String(idrogeno);
client.println("POST /test/arduino/add.php HTTP/1.1");
client.println("Host: XX.XX.XX.XX");
client.print("Content-length:");
client.println(parametri.length());
Serial.println(parametri);
client.println("Connection: Close");
client.println("Content-Type: application/x-www-form-urlencoded;");
client.println();
client.println(parametri);
}else{
Serial.println("connection failed");
digitalWrite(led_rosso,HIGH);
delay(1000);
}
if(client.connected()){
client.stop(); //disconnect from server
}
delay(2000);
}
Could anyone help me? Why data does't arrive to the WS?
Thank you all, very much!!!