Salve a tutti.
Mi potreste dire cosa c’è che non va in questo sketch? Una versione simile per ethernet shield funziona. Questa specifica per WiFi shield non funziona: nello spreadsheet non ho alcuna risposta. Ovviamente se provo a fare una richiesta da browser (http://api.pushingbox.com/pushingbox?devid=xxxx&seconds=100) funziona. Le due voci del Client.print sono messe come commento perché pensavo che fosse il concatenamento a dare problemi ma in realtà anche con una sola voce, quella relativa al “time”, non va.
Uso la IDE 1.0.5 ed Arduino UNO r3.
#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
unsigned long time; //time in seconds
const int splSensor = A5; // the SPL output is connected to analog pin 5
char wifissid[] = "xxx"; // your network SSID (name)
char wifipass[] = "xxx"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
char server[] = "api.pushingbox.com";
// Initialize the client library
WiFiClient client;
void setup() {
Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
// attempt to connect using WPA2 encryption:
Serial.println("Attempting to connect to WPA network...");
status = WiFi.begin(wifissid, wifipass);
// if you're not connected, stop here:
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
while(true);
}
// if you are connected, print out info about the connection:
else {
Serial.println("Connected to network");
}
}
void loop() {
Serial.print("secondi dall'avvio del programma:, ");
time = millis()/1000;
Serial.print(time); //prints time since program started
Serial.print(", FreetronicsSPL:, ");
Serial.print(analogRead(splSensor), DEC); //print the SPL value to serial
Serial.println(",");
// Make a HTTP request to the server:
if (client.connect(server, 80)) {
Serial.println("Connected");
client.print("GET /pushingbox?devid=xxxx&seconds=");
client.print(time);
//client.print("&freetronics_SPL=");
//client.print(analogRead(splSensor), DEC);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("User-Agent: Arduino");
client.println("Connection: close");
client.println();
client.stop();
}
delay(1000); // delay to avoid overloading the serial port buffer
}
Ovviamente, dove ci sono i valori “xxx” è perché ho preferito non condividere i dati personali.