ciao,
ho un problema io voglio collegare il mio arduino a internet in modo tale
da poter passare dai dati a uno script php che risiede su un server altervista,
il mio problema sta nel fatto che non si connette al server.
P.S. vi ricordo che sono alle prime armi
#include <SPI.h>
#include <Ethernet.h>
#include <WeatherShield1.h>
#define RXBUFFERLENGTH 4
WeatherShield1 weatherShield;
float fTemperature = 0.0f;
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xFE, 0x72};
byte ip[] = {192, 168, 0, 200};
byte server [] = { 176, 9, 63, 23 }; //176.9.63.23
byte gateway [] = { 192, 168, 1, 1 } ;
byte subnet [] = { 255, 255, 255, 0 } ;
void setup() {
Serial.begin ( 9600 ) ;
Ethernet.begin ( mac, ip, gateway, subnet );
}
void loop() {
/* This is the buffer for the answers */
unsigned char ucBuffer[RXBUFFERLENGTH];
/* Check for the weather shield connection */
if (weatherShield.sendCommand(CMD_ECHO_PAR, 100, ucBuffer)) {}
/* Start reading temperature */
unsigned short shTemperature = 0;
if (weatherShield.sendCommand(CMD_GETTEMP_C_AVG, 0, ucBuffer))
fTemperature = weatherShield.decodeFloatValue(ucBuffer);
if (weatherShield.sendCommand(CMD_GETTEMP_C_RAW, 0, ucBuffer))
shTemperature = weatherShield.decodeShortValue(ucBuffer);
Serial.print ( " Connecting..." ) ;
EthernetClient client ;
if ( client.connect(server, 21) )
{
Serial.println ( " Connected. " ) ;
Serial.println ( fTemperature ) ; // Le seguenti istruzion inviano il dato allo script PHP:
client.print ( "GET http://ncmeteo.altervista.org/arduino/inserimento.php?fTemperature=" ) ;
client.print ( fTemperature ) ;
client.println (" HTTP/1.1" ) ;
client.println ( "Host: http://ncmeteo.altervista.org" ) ;
client.println () ;
Serial.println ( "disconnecting." ) ;
client.stop();
}
// if the server's disconnected, stop the client:
else
{
Serial.println();
Serial.println ( "disconnecting..." ) ;
client.stop();
while ( client.status() != 0 ){}
delay ( 5 ) ;
}
delay(5000);
}
grazie