Arduino wifi

Bonjour à tous,

Je tente d’utiliser un shield arduino WI-Fi. J’ai tenté d’adapter un sketch afin de faire en sorte qu’il envoit une requête lorsque le pin 3 est à l’état haut.

Voici ce que j’ai, la connexion est établie mais je reçois un “connection failed”. J’ai probablement commis une faute fondamentale mais pour un novice c’est pas toujours évident. Si quelqu’un peut jeter un coup d’oeil en bas du sketch afin de déceler un truc qui cloche, j’en serai très heureux.

#include <SPI.h>
#include <WiFi.h>

char ssid[] = "WiFi-2.4-5186";     //  your network SSID (name)
char pass[] = "coucou";    // your network password
char DEVID1[] = "v796676ED0182CB9";  

//Numeric Pin where you connect your switch
uint8_t pinDevid1 = 3; // Example : the mailbox switch is connect to the Pin 3

// Debug mode
boolean DEBUG = true;

char serverName[] = "api.pushingbox.com";

boolean pinDevid1State = false;                // Save the last state of the Pin for DEVID1
boolean lastConnected = false;                 // State of the connection last time through the main loop

// Initialize the client library
WiFiClient client;


int status = WL_IDLE_STATUS;     // the Wifi radio's status

void setup() {
  // initialize serial:
  Serial.begin(9600);

    pinMode(pinDevid1, INPUT);

  // attempt to connect using WPA2 encryption:
  Serial.println("Attempting to connect to WPA network...");
  status = WiFi.begin(ssid, pass);

  // 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()
{
      ////
      // Listening for the pinDevid1 state
      ////
      if (digitalRead(pinDevid1) == HIGH && pinDevid1State == false) // switch on pinDevid1 is ON 
      {
        if(DEBUG){Serial.println("pinDevid1 is HIGH");}
        pinDevid1State = true;
        //Sending request to PushingBox when the pin is HIGH
        sendToPushingBox(DEVID1);
      }

      //DEBUG part
      // this write the respons from PushingBox Server.
      // You should see a "200 OK"
      if (client.available()) {
        char c = client.read();
        if(DEBUG){Serial.print(c);}
      }
      
      // if there's no net connection, but there was one last time
      // through the loop, then stop the client:
      if (!client.connected() && lastConnected) {
        if(DEBUG){Serial.println();}
        if(DEBUG){Serial.println("disconnecting.");}
        client.stop();
      }
      lastConnected = client.connected();
}


//Function for sending the request to PushingBox

void sendToPushingBox(char devid[]){
  client.stop();
  if(DEBUG){Serial.println("connecting...");}

  if (client.connect(serverName, 80)) {
    if(DEBUG){Serial.println("connected");}

    if(DEBUG){Serial.println("sendind request");}
    client.print("GET /pushingbox?devid=");
    client.print(devid);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(serverName);
    client.println("User-Agent: Arduino");
    client.println();
  } 
  else {
    if(DEBUG){Serial.println("connection failed");}
  }
}

Salut,

tu peut tenter de simuler le code de l’arduino avec un simple commande telnet du genre

telnet www.pushingbox.com 80
GET /pushingbox?devid=vEE18BC1C82D7B73 HTTP/1.1
Host: api.pushingbox.com
User-Agent: Arduino

Je l’ai fait, voici ce que le serveur répond.

HTTP/1.1 403 AccountIsDisabled
Set-Cookie: 60gpBAK=R1224194687; path=/; expires=Wed, 23-Dec-2015 08:47:18 GMT
Date: Wed, 23 Dec 2015 07:25:50 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: 60gp=R1863915771; path=/; expires=Wed, 23-Dec-2015 08:30:00 GMT
Server: Apache
Content-Location: pushingbox.php
Vary: negotiate,Accept-Encoding
TCN: choice
X-Powered-By: PHP/5.4.45

49
<?xml version="1.0" encoding="UTF-8"?><error>Daily limit exceeded</error>
0

Il semble que ton compte Pushingbox soit dévalidé pour cause de sur-utilisation.

Non Landid,

J'avais changé l'ID pushinbox pour ne pas le rendre trop publique.

La requête http à partir d'un autre sketch (arduino + carte ethernet) fonctionne bien, c'est l'adaptation à cette carte WiFi qui pose problème.

Voici un device ID de test: v796676ED0182CB9. Je vais éditer le post.

Merci encore une fois.

OK, merci de préciser aussi:

  • quelle modèle de carte Wifi tu utilises.

  • la ligne de code correspondante quand tu dit "la connexion est établie"

bonjour,
fais un serial print de toutes tes lignes lors de la connexion afin de vérifier que tout est envoyé comme il faut.

Voici

Attempting to connect to WPA network...
Connected to network
pinDevid1 is HIGH
connecting...
connection failed

Ma carte a la référence A000058 Arduino WiFi Shield integreted antenne

Il m'a fallut 5 min avant de pouvoir éditer et de corriger le numéro de la carte :slight_smile: Sorry

J'ai trouvé sur le site un petit bout de code qu'il serait interessant d'ajouter à la fin de ton sketch pour le debug

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

Tu pourrais par exemple le faire dérouler en ajoutant une ligne ici

  // if you are connected, print out info about the connection:
  else {
    Serial.println("Connected to network");
    if(DEBUG){printWifiStatus();}
  }

Bon ca ne va pas résoudre le problème mais avec ces infos tu seras sure que le shield est bien connecté. Envoie nous la sortie du moniteur série.

J'ai vu aussi que certain codes de connexion étaient un peu différents et "donnaient" un peu plus de temps au shield pour se connecter. C'est que c'est rapide un Arduino et le wifi parfois pas trop. Tu peux sans doute changer ta phase de setup avec ceci

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while(true);
  }
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:    
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();
}

pdeneye:
Voici

Attempting to connect to WPA network...
Connected to network
pinDevid1 is HIGH
connecting...
connection failed

Ma carte a la référence A000058 Arduino WiFi Shield integreted antenne

c'est plus le serial des infos envoyées dans le GET qu'il faut voir :wink:

Tu peux m'aider à obtenir ce que tu suggères d'obtenir ?

Faut-il rajouter un serial.print (...) ?

J’ai suis lees conseils de landid, enfin je crois, j’obtiens

Attempting to connect to SSID: WiFi-2.4-5136
Connected to wifi
SSID: WiFi-2.4-5136
IP Address: 192.168.1.20
signal strength (RSSI):-50 dBm
pinDevid1 is HIGH
connecting...
connection failed
SSID: WiFi-2.4-5136
ÿÿ Address: 192.168.1.20
signal strength (RSSI):-50 dBm

le code est

#include <SPI.h>
#include <WiFi.h>

char ssid[] = "WiFi-2.4-5136";     //  your network SSID (name)
char pass[] = "Yw47Q4mhWY2u";    // your network password
char DEVID1[] = "vEE13BC1C82D7B73";  

//Numeric Pin where you connect your switch
uint8_t pinDevid1 = 3; // Example : the mailbox switch is connect to the Pin 3

// Debug mode
boolean DEBUG = true;

char serverName[] = "api.pushingbox.com";

boolean pinDevid1State = false;                // Save the last state of the Pin for DEVID1
boolean lastConnected = false;                 // State of the connection last time through the main loop

// Initialize the client library
WiFiClient client;


int status = WL_IDLE_STATUS;     // the Wifi radio's status

/*void setup() {
  // initialize serial:
  Serial.begin(9600);

    pinMode(pinDevid1, INPUT);

  // attempt to connect using WPA2 encryption:
  Serial.println("Attempting to connect to WPA network...");
  status = WiFi.begin(ssid, pass);

  // 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 setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
      pinMode(pinDevid1, INPUT);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while(true);
  }
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:   
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();
}
void loop()
{
      ////
      // Listening for the pinDevid1 state
      ////
      if (digitalRead(pinDevid1) == HIGH && pinDevid1State == false) // switch on pinDevid1 is ON 
      {
        if(DEBUG){Serial.println("pinDevid1 is HIGH");}
        pinDevid1State = true;
        //Sending request to PushingBox when the pin is HIGH
        sendToPushingBox(DEVID1);
      }

      //DEBUG part
      // this write the respons from PushingBox Server.
      // You should see a "200 OK"
      if (client.available()) {
        char c = client.read();
        if(DEBUG){Serial.print(c);}
      }
      
      // if there's no net connection, but there was one last time
      // through the loop, then stop the client:
      if (!client.connected() && lastConnected) {
        if(DEBUG){Serial.println();}
        if(DEBUG){Serial.println("disconnecting.");}
        client.stop();
      }
      lastConnected = client.connected();
}


//Function for sending the request to PushingBox

void sendToPushingBox(char devid[]){
  client.stop();
  if(DEBUG){Serial.println("connecting...");}

  if (client.connect(serverName, 80)) {
    if(DEBUG){Serial.println("connected");}

    if(DEBUG){Serial.println("sendind request");}
    client.print("GET /pushingbox?devid=");
    client.print(devid);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(serverName);
    client.println("User-Agent: Arduino");
    client.println();
  } 
  else {
    if(DEBUG){Serial.println("connection failed");
     {void printWifiStatus();
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}}
  }
}
void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

pdeneye:
Tu peux m'aider à obtenir ce que tu suggères d'obtenir ?

Faut-il rajouter un serial.print (...) ?

c'est pas compliqué a faire quand même :wink:

void sendToPushingBox(char devid[]){
  client.stop();
  if(DEBUG){Serial.println("connecting...");}

  if (client.connect(serverName, 80)) {
 Serial.println(serverName);

    if(DEBUG){Serial.println("sendind request");}
    client.print("GET /pushingbox?devid=");
    client.print(devid);
 Serial.println(devid);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(serverName);
 Serial.println(serverName);
    client.println("User-Agent: Arduino");
    client.println();
  } 
...
...
...

Donc le test confirme que l’Arduino est bien connecté, il obtient un IP. A ce propos printWifiStatus est une fonction et il n’est pas nécessaire de répéter le code. Il suffit de l’appeler, j’ai un peu ‘corrigé’ le code en conséquence.

Essaie aussi ce que te propose Infobarquee, mais les chaines de requêtes http semblent bonnes je les ai testées au début du post même si elles retournaient un message d’erreur. Il semble que le script est bloqué et qu’il ne passe pas le test sur la ligne :

  if (client.connect(serverName, 80)) {

Mais là je suis à cours d’idée, sinon voici le code corrigé et vérifié. J’y ai ajouté quelques informations réseau supplémentaires. Si tu peux le relancer une fois de plus et retourner le résultat …

#include <SPI.h>
#include <WiFi.h>

char ssid[] = "WiFi-2.4-5136";     //  your network SSID (name)
char pass[] = "Yw47Q4mhWY2u";    // your network password
char DEVID1[] = "vEE13BC1C82D7B73"; 

//Numeric Pin where you connect your switch
uint8_t pinDevid1 = 3; // Example : the mailbox switch is connect to the Pin 3

// Debug mode
boolean DEBUG = true;

char serverName[] = "api.pushingbox.com";

boolean pinDevid1State = false;                // Save the last state of the Pin for DEVID1
boolean lastConnected = false;                 // State of the connection last time through the main loop

// Initialize the client library
WiFiClient client;

int status = WL_IDLE_STATUS;     // the Wifi radio's status

/*void setup() {
  // initialize serial:
  Serial.begin(9600);

    pinMode(pinDevid1, INPUT);

  // attempt to connect using WPA2 encryption:
  Serial.println("Attempting to connect to WPA network...");
  status = WiFi.begin(ssid, pass);

  // 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 setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
      pinMode(pinDevid1, INPUT);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while(true);
  }
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:   
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();
}
void loop()
{
      ////
      // Listening for the pinDevid1 state
      ////
      if (digitalRead(pinDevid1) == HIGH && pinDevid1State == false) // switch on pinDevid1 is ON
      {
        if(DEBUG){Serial.println("pinDevid1 is HIGH");}
        pinDevid1State = true;
        //Sending request to PushingBox when the pin is HIGH
        sendToPushingBox(DEVID1);
      }
      //DEBUG part
      // this write the respons from PushingBox Server.
      // You should see a "200 OK"
      if (client.available()) {
        char c = client.read();
        if(DEBUG){Serial.print(c);}
      }
     
      // if there's no net connection, but there was one last time
      // through the loop, then stop the client:
      if (!client.connected() && lastConnected) {
        if(DEBUG){Serial.println();}
        if(DEBUG){Serial.println("disconnecting.");}
        client.stop();
      }
      lastConnected = client.connected();
}


//Function for sending the request to PushingBox

void sendToPushingBox(char devid[]){
  client.stop();
  if(DEBUG){Serial.println("connecting...");}

  if (client.connect(serverName, 80)) {
    if(DEBUG){Serial.println("connected");}

    if(DEBUG){Serial.println("sendind request");}
    client.print("GET /pushingbox?devid=");
    client.print(devid);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(serverName);
    client.println("User-Agent: Arduino");
    client.println();
  }
  else {
    if(DEBUG){
      Serial.println("Connection failed");
      printWifiStatus();
    }
  }
}
void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  // print your WiFi shield's IP mask:
  IPAddress mk = WiFi.subnetMask();
  Serial.print("IP Mask: ");
  Serial.println(mk);
  // print your WiFi shield's IP gateway:
  IPAddress gw = WiFi.gatewayIP();
  Serial.print("IP Gateway: ");
  Serial.println(gw);
  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("Signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

@infoembarqué (avant de répondre à landid 5 min plus tard :slight_smile:

J’ai obtenu ça

Attempting to connect to SSID: WiFi-2.4-5136
Connected to wifi
SSID: WiFi-2.4-5136
IP Address: 192.168.1.20
signal strength (RSSI):-53 dBm
pinDevid1 is HIGH
connecting...
connection failed
api.pushingbox.com
vEE13BC1C82D7B73
SSID: WiFi-2.4-5136
ÿÿ Address: 192.168.1.20
signal strength (RSSI):-53 dBm

avec

#include <SPI.h>
#include <WiFi.h>

char ssid[] = "WiFi-2.4-5136";     //  your network SSID (name)
char pass[] = "Yw47Q4mhWY2u";    // your network password
char DEVID1[] = "vEE13BC1C82D7B73";  

//Numeric Pin where you connect your switch
uint8_t pinDevid1 = 3; // Example : the mailbox switch is connect to the Pin 3

// Debug mode
boolean DEBUG = true;

char serverName[] = "api.pushingbox.com";

boolean pinDevid1State = false;                // Save the last state of the Pin for DEVID1
boolean lastConnected = false;                 // State of the connection last time through the main loop

// Initialize the client library
WiFiClient client;


int status = WL_IDLE_STATUS;     // the Wifi radio's status

/*void setup() {
  // initialize serial:
  Serial.begin(9600);

    pinMode(pinDevid1, INPUT);

  // attempt to connect using WPA2 encryption:
  Serial.println("Attempting to connect to WPA network...");
  status = WiFi.begin(ssid, pass);

  // 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 setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
      pinMode(pinDevid1, INPUT);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while(true);
  }
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:   
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();
}
void loop()
{
      ////
      // Listening for the pinDevid1 state
      ////
      if (digitalRead(pinDevid1) == HIGH && pinDevid1State == false) // switch on pinDevid1 is ON 
      {
        if(DEBUG){Serial.println("pinDevid1 is HIGH");}
        pinDevid1State = true;
        //Sending request to PushingBox when the pin is HIGH
        sendToPushingBox(DEVID1);
      }

      //DEBUG part
      // this write the respons from PushingBox Server.
      // You should see a "200 OK"
      if (client.available()) {
        char c = client.read();
        if(DEBUG){Serial.print(c);}
      }
      
      // if there's no net connection, but there was one last time
      // through the loop, then stop the client:
      if (!client.connected() && lastConnected) {
        if(DEBUG){Serial.println();}
        if(DEBUG){Serial.println("disconnecting.");}
        client.stop();
      }
      lastConnected = client.connected();
}


//Function for sending the request to PushingBox

void sendToPushingBox(char devid[]){
  client.stop();
  if(DEBUG){Serial.println("connecting...");}

  if (client.connect(serverName, 80)) {
     Serial.println(serverName);
    if(DEBUG){Serial.println("connected");}

    if(DEBUG){Serial.println("sendind request");}
    client.print("GET /pushingbox?devid=");
    client.print(devid);
    Serial.println(devid);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(serverName);
     Serial.println(serverName);
    client.println("User-Agent: Arduino");
    client.println();
  } 
  else {
    if(DEBUG){Serial.println("connection failed");
         Serial.println(serverName);
             Serial.println(devid);
     {void printWifiStatus();
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}}
  }
}
void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

Voici landid et déjà merci pour ce que vous faites pour m’aider


Attempting to connect to SSID: WiFi-2.4-5136
Connected to wifi
SSID: WiFi-2.4-5136
IP Address: 192.168.1.20
IP Mask: 255.255.255.0
IP Gateway: 192.168.1.1
Signal strength (RSSI):-53 dBm
pinDevid1 is HIGH
connecting…
Connection failed
SSID: WiFi-2.4-5136
ÿÿ Address: 192.168.1.20
IP Mask: 255.255.255.0
IP Gateway: 192.168.1.1
Signal strength (RSSI):-53 dBm

Je viens de relire le code et en remettant au propre, j’ai vu une ligne du genre:

client.stop();

qui m’a semblée mal placée. Mais comme je n’ai pas de carte Wifi je ne peux pas tester. Je te post le code un peu ‘nettoyé’ après tout ces tests. Il faudrait que tu le charges tel quel pour tester, le tien comportant un souci de recopie de la fonction printWifiStatus()

Si c’a ne marche pas je pense qu’il y a un problème ailleurs sur le réseau du type firewall ???

#include <SPI.h>
#include <WiFi.h>

char ssid[] = "WiFi-2.4-5136";     //  your network SSID (name)
char pass[] = "Yw47Q4mhWY2u";    // your network password
char DEVID1[] = "vEE13BC1C82D7B73"; 

//Numeric Pin where you connect your switch
uint8_t pinDevid1 = 3; // Example : the mailbox switch is connect to the Pin 3

// Debug mode
boolean DEBUG = true;

char serverName[] = "api.pushingbox.com";

boolean pinDevid1State = false;                // Save the last state of the Pin for DEVID1
boolean lastConnected = false;                 // State of the connection last time through the main loop

// Initialize the client library
WiFiClient client;


int status = WL_IDLE_STATUS;     // the Wifi radio's status

/*void setup() {
  // initialize serial:
  Serial.begin(9600);

    pinMode(pinDevid1, INPUT);

  // attempt to connect using WPA2 encryption:
  Serial.println("Attempting to connect to WPA network...");
  status = WiFi.begin(ssid, pass);

  // 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 setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
      pinMode(pinDevid1, INPUT);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while(true);
  }
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:   
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();
}
void loop()
{
      ////
      // Listening for the pinDevid1 state
      ////
      if (digitalRead(pinDevid1) == HIGH && pinDevid1State == false) // switch on pinDevid1 is ON
      {
        if(DEBUG){Serial.println("pinDevid1 is HIGH");}
        pinDevid1State = true;
        //Sending request to PushingBox when the pin is HIGH
        sendToPushingBox(DEVID1);
      }
      //DEBUG part
      // this write the respons from PushingBox Server.
      // You should see a "200 OK"
      if (client.available()) {
        char c = client.read();
        if(DEBUG){Serial.print(c);}
      }
     
      // if there's no net connection, but there was one last time
      // through the loop, then stop the client:
      if (!client.connected() && lastConnected) {
        if(DEBUG){Serial.println();}
        if(DEBUG){Serial.println("disconnecting.");}
        client.stop();
      }
      lastConnected = client.connected();
}


//Function for sending the request to PushingBox

void sendToPushingBox(char devid[]){
  // client.stop();
  if(DEBUG){
    Serial.println("connecting...");
    Serial.print("Server name: ");
    Serial.println(serverName);
    Serial.print("Dev ID: ");
    Serial.println(devid);
    }

  if (client.connect(serverName, 80)) {
    if(DEBUG){Serial.println("connected");}

    if(DEBUG){Serial.println("sendind request");}
    client.print("GET /pushingbox?devid=");
    client.print(devid);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(serverName);
    client.println("User-Agent: Arduino");
    client.println();
  }
  else {
    if(DEBUG){
      Serial.println("Connection failed");
      printWifiStatus();
    }
  }
}

//Function to display Wifi network parameters

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

Voici le retour .... malheureusement similaire ....

Attempting to connect to SSID: WiFi-2.4-5136
Connected to wifi
SSID: WiFi-2.4-5136
IP Address: 192.168.1.20
signal strength (RSSI):-54 dBm
pinDevid1 is HIGH
connecting...
Server name: api.pushingbox.com
Dev ID: vEE13BC1C82D7B73
Connection failed
SSID: WiFi-2.4-5136
IP Address: 192.168.1.20
signal strength (RSSI):-54 dBm

Re,

bon et bien là il faut creuser :slight_smile:
Je tenterais de connecter un autre serveur (ex: google), en cherchant un peu sur le web on doit pouvoir trouver un autre usage a ce shield wifi. Essaie de trouvez un script déjà éprouvé.

Je ne vais plus avoir trop de connexion prochainement pour cause de vacances loin de l'Internet. Ne te décourage pas c'est en essayant de comprendre les problèmes que j'ai appris le plus.

Joyeux Noël (quand même) et bonnes fêtes de fin d'année.

Merci beaucoup,

Pareil pour moi, fêtes de famille et petit séjours alsaciens me feront du bien. Mais je n'abandonne pas, je vais suivre tes conseils et informerai le forum.

Joyeux Noel et une excellente année 2016.

Testé aussi avec une autre carte arduino uno pour écarter un problème à ce niveaux mais test négatif et résultat similaire. Pratiquement le même sketch en utilisation cablée (shield ethernet) fonctionne parfaitement.

A l'année prochaine :slight_smile: