Buona sera a tutti,
ho fatto un progettino con arduino + ethernet shield praticamente uso l Arduino sia come webserver che webclient per accendere un led dal browser e richiamo una pagina asp che mi aggiorna lo stato sul database.
adesso vorrei fare la stessa cosa però usando il nuovo Wifi shield ufficiale di arduino ho provato a copiare lo stesso codice e cambiando le librerie ect.. ma non mi funziona benissimo cioè mi fa un giro accende il led aggiorna il database e si disconnette e non risponde più alle richieste del browser
posto lo sketch ethernet funzionante da convertire in wifi shield
ethernet:
//zoomkat 7-03-12, combined client and server
//simple button GET with iframe code
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //assign arduino mac address
byte ip[] = {192, 168, 1, 5 }; // ip in lan assigned to arduino
byte gateway[] = {192, 168, 1, 1 }; // internet access via router
byte subnet[] = {255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port arduino server will use
EthernetClient client;
//char serverName[] = "web.comporium.net"; // (DNS) web page server
byte serverName[] = { 192,168,1,200 }; // (IP) server IP address
String readString; //used by server to capture GET request
void sendGET(char,String);
void controllo_led(int,String);
const int INDICE_PIN = 4; // definisce una costante per il numero di pin
String comandGET[INDICE_PIN] = {"01","02","03","04"}; // COMANDI GET INVIATI DAL BROWSER
int pinLed[INDICE_PIN] = {2,3,4,5}; // I LED IN COPIA CON I COMANDI GET
void setup(){
for(int indice = 0; indice < 4; indice++)
{
pinMode(pinLed[indice], OUTPUT); // dichiara il LED come output
digitalWrite(pinLed[indice], LOW); // inizializzo tutti i led "SPENTI"
}
Ethernet.begin(mac,ip,gateway,gateway,subnet);
server.begin();
Serial.begin(9600);
Serial.println("ARDUINO GESTIONE SCAFFALI"); // what to do to test client
}
void loop(){
// check for serial input
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.print("readString:");
Serial.print(readString); //print to serial monitor for debuging
//now output HTML data header
if(readString.indexOf('?') >=0) { //don't send new page
client.println(F("HTTP/1.1 204 Zoomkat"));
client.println();
client.println();
}
else {
client.println(F("HTTP/1.1 200 OK")); //send new page on browser request
client.println(F("Content-Type: text/html"));
client.println();
client.println(F("<HTML>"));
client.println(F("<HEAD>"));
client.println(F("<TITLE>Arduino GET test page</TITLE>"));
client.println(F("</HEAD>"));
client.println(F("<BODY>"));
client.println(F("<H1>ARDUINO MEGAZZINO</H1>"));
// DIY buttons
client.println(F("Pin4"));
client.println(F("<a href=/?cod=000000&pos=01 target=inlineframe>ON</a>"));
client.println(F("Pin5"));
client.println(F("<a href=/?cod=111111&pos=22 target=inlineframe>ON</a>"));
client.println(F("Pin6"));
client.println(F("<a href=/?cod=222222&pos=33 target=inlineframe>ON</a>"));
client.println(F("<IFRAME name=inlineframe style='display:none'>"));
client.println(F("</IFRAME>"));
client.println(F("</BODY>"));
client.println(F("</HTML>"));
}
delay(1);
//stopping client
client.stop();
/*
///////////////////// control arduino pin
if(readString.indexOf('1') >0)//checks for 2
{
controllo_led(led_1); // set pin 5 high
Serial.println("Led 5 On");
Serial.println();
}
if(readString.indexOf('2') >0)//checks for 2
{
controllo_led(led_2); // set pin 5 high
Serial.println("Led 5 On");
Serial.println();
}
if(readString.indexOf('3') >0)//checks for 2
{
controllo_led(led_3); // set pin 5 high
Serial.println("Led 5 On");
Serial.println();
}
if (pos == "01")
{
controllo_led(led_1,cod); // set pin 5 high
Serial.println("Led 5 On");
}
*/
//GET /?cod=000000&pos=01 HTTP/1.1
String cod=readString.substring(10,16);
String pos=readString.substring(21,23);
Serial.println(cod);
Serial.println(pos);
for(int indice = 0; indice < INDICE_PIN; indice++)
{
String stato=comandGET[indice];
if (pos == stato)
{
int stato = digitalRead(pinLed[indice]);
if ( stato == LOW)
{
for(int indice = 0; indice < 4; indice++)
{
digitalWrite(pinLed[indice], LOW); // spengo tutti i led
}
digitalWrite(pinLed[indice], HIGH);
}
else if ( stato == HIGH )
{
digitalWrite(pinLed[indice], LOW);
int stato = digitalRead(pinLed[indice]);
if ( stato == LOW)
{
String stato="1";
sendGET(cod,stato);
}
}
}
}
//clearing string for next read
readString="";
}
}
}
}
}
//*************************************************CONTROLLO DEI LED ON/OFF***************************************
/*void controllo_led(int pin,String cod)
{
int stato = digitalRead(pin);
if ( stato == LOW)
{
digitalWrite(pin, HIGH);
int stato = digitalRead(pin);
if ( stato == HIGH)
{
String stato="1";
sendGET(cod,stato);
}
else
{
String stato="0";
sendGET(cod,stato);
}
}
else if ( stato == HIGH )
{
digitalWrite(pin, LOW);
int stato = digitalRead(pin);
if ( stato == LOW)
{
String stato="1";
sendGET(cod,stato);
}
else
{
String stato="0";
sendGET(cod,stato);
}
}
}
*/
//////////////////////////
void sendGET(String cod, String stato) //client function to send and receive GET data from external server.
{
if (client.connect(serverName, 80)) {
Serial.println("connected");
/* String cod="000007";
String stato="1";*/
String invio_conferma="GET /Arduino2.asp?cod=" + cod + "&" + "stato=" + stato + " HTTP/1.0"; // GET /Arduino2.asp?cod=000008&stato=1 HTTP/1.0
Serial.println(invio_conferma);
Serial.println();
client.println(invio_conferma);
client.println();
}
else {
Serial.println("connection failed");
Serial.println();
}
while(client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available()) { //connected or data available
char c = client.read();
Serial.print(c);
}
Serial.println();
Serial.println("disconnecting.");
Serial.println("==================");
Serial.println();
client.stop();
}
spero che riuscite ad aiutarmi grazie mille e buona serata a tutti