Problème de connexion a une base de donnée

Bonjour , je demande aujourd'hui votre aide car je bloque sur un problème, comme dit dans le titre ma carte arduino (jumelé a une wifishield) n'arrive pas a se connecté ( oú a écrire ) dans la base de donnée.
voici mon code:

#include <SPI.h> // bibliothèque de la liaison série
#include <WiFi.h> //Inclure la bibliothèque wifi ECRIRE AVEC DES STRINGS

char ssid[] = "STI2DSIN"; // your network SSID (name)
char pass[] = "sti2dsin"; // your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

int CAPTEUR_TEMP_PIN = 4; // adressage du capteur de temperature (PIN) //
int temp = 0; //définition de la variable entière (integer) //
float temperature = 0; // variable temperature en flottant //
float const_can = 0.0048828; // constante du convertisseur //
WiFiClient client;
String data;
String stringVal;

WiFiServer server(80); //Initialise le serveur wifi, port 80 par défaut pour http

void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600); //Affichage écran du PC
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port 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);
}

String fv = WiFi.firmwareVersion();
if (fv != "1.1.0") {
Serial.println("Please upgrade the firmware");
}

// attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
Serial.print("Tentative de connexion au reseau 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);
}
server.begin();
// you're connected now, so print out the status:
printWifiStatus();
analogRead(CAPTEUR_TEMP_PIN);
}

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 boy ()
{
temp = analogRead(CAPTEUR_TEMP_PIN); // lecture du capteur de température //
temperature = (((temp*const_can)*1000)-500)/10; //calcul//

if (client.connect("10.172.2.77",80)) { // remplacer par l'adresse IP de votre serveur-ordi
String printwifiarduino = "GET /projet/add.php?temp1=";
String cdrole = printwifiarduino + temperature ;
client.print (cdrole);
client.println( " HTTP/1.1");
client.println( "Host: 10.172.2.77" );
client.println( "Content-Type: application/x-www-form-urlencoded" );
client.println( "Connection: close" );
client.println();
client.println();
client.stop();
Serial.print("donneeecrite");
Serial.println(temperature);
}
else
{
Serial.println("problème de connection 56");
}
if (client.connected()) {
client.stop(); // DISCONNECT FROM THE SERVER
}
delay(30000); // attente en millisecondes
}
void loop()
{
boy();
}

le moniteur me dis ça:

Tentative de connexion au reseau SSID : STI2DSIN
SSID: STI2DSIN
IP Address: 10.172.2.77
signal strength (RSSI):-59 dBm
problème de connection 56
problème de connection 56
problème de connection 56
No Socket available
problème de connection 56
No Socket available

et ça en boucle.

je ne sais vraiment pas quoi faire help ! :cry:

As-tu fait ce qui est dit dans le commentaire ci :

if (client.connect("10.172.2.77",80)) { // remplacer par l'adresse IP de votre serveur-ordi

j'ai mis l'ip donné par le moniteur
''IP Address: 10.172.2.77''

C'est pourtant cette ligne qui est en cause. Que se passe-t-il si tu commentes la ligne :

client.stop();

j'ai toujours le message d'erreur

As-tu testé un sketch plus simple :

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

char ssid[] = "STI2DSIN";          //  your network SSID (name) 
char pass[] = "sti2dsin";   // your network password

int status = WL_IDLE_STATUS;
char servername[]="10.172.2.77";  // remote server we will connect to

WiFiClient client;

void setup() {
  Serial.begin(9600);
  Serial.println("Attempting to connect to WPA network...");
  Serial.print("SSID: ");
  Serial.println(ssid);

  status = WiFi.begin(ssid, pass);
  if ( status != WL_CONNECTED) { 
    Serial.println("Couldn't get a wifi connection");
    // don't do anything else:
    while(true);
  } 
  else {
    Serial.println("Connected to wifi");
    Serial.println("\nStarting connection...");
    // if you get a connection, report back via serial:
    if (client.connect(servername, 80)) {
      Serial.println("connected");
      // Make a HTTP request:
      client.println("GET /search?q=arduino HTTP/1.0");
      client.println();
    }
  }
}

void loop() {

}

Si tu n'obtiens pas 'connected', c'est que le problème vient de ton serveur (10.172.2.77) qui ne répond pas ou est mal configuré.

ton code marche bien, j'ai rajouté ''Serial.print("donnée ecrite ");
Serial.println(temperature); '' a la fin pour afficher la température voir si l'info passe et elle s'affiche mais dans la base de donnée toujours rien.
alors que quand je tape ''127.0.0.1//projet_arduino/add.php?temp1=25'' 25 aparait dans la bdd

OK, ça avance, donc le problème vient de ces lignes :

  String printwifiarduino =  "GET /projet/add.php?temp1=";
  String cdrole = printwifiarduino + temperature ;
  client.print (cdrole);
  client.println( " HTTP/1.1");
  client.println( "Host: 10.172.2.77" );
  client.println( "Content-Type: application/x-www-form-urlencoded" );
  client.println( "Connection: close" );
  client.println();
  client.println();
  client.stop();

qui n'écrivent pas la donnée sur le serveur.
Je pense que tu trouveras la solution ici...

j'ai déja lu ces rubriques mais elles ne m'aides pas, le code est similaire au mien mais ne marche pas.

C'est similaire mais pas pareil. Moi, je ne connais pas les syntaxes HTML donc je ne sais pas aider plus que ça. Dans l'exemple, il fait ça :

client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("
");       
          }
          client.println("</html>");

Il écrit d'abord une sorte de header (HTTP/1.1 200 OK) puis puis et ensuite il écrit la donnée mesurée

client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);

Ce n'est pas ce que tu fais. Essaie d'appliquer cet exemple à ton cas particulier, ça devrait le faire...

Bonjour,

nathan77:
j'ai mis l'ip donné par le moniteur
''IP Address: 10.172.2.77''

il me semble que ceci est l'adresse IP de ton arduino et ce n'est pas lui qui est serveur de la bdd ?

nathan77:
alors que quand je tape ''127.0.0.1//projet_arduino/add.php?temp1=25'' 25 aparait dans la bdd

la tu es sur le serveur de bdd (c'est son adresse de loopback) qui est (un PC , ...)?
il faut donc que tu récupères la véritable adresse IP du serveur x.y.z.w
ensuite tu peux essayer depuis un autre pc connecté au réseau ton test "x.y.z.w//projet_arduino/add.php?temp1=25''
et si ça fonctionne tu modifie :

if (client.connect("x.y.z.w",80)) { // remplacer par l'adresse IP de votre serveur-ordi

ensuite il faut mettre en cohérence ta requête GET avec la ligne de ton test
et par la même occasion tu édites ton post initial pour mettre ton code entre balises code

lesept, le code que tu me propose sert a ecrire une page html et non a inscrire une donnée dans la base de donnée et m'est donc inutile.

rjnc38 j'avais bien un probleme d'ouverture de port 80 que j'ai reussi a regler,je peux maintenant ecrire sur ma base de donnée depuis un autre ordinateur mais toujours pas avec ma carte arduino !

nathan77:
... je peux maintenant ecrire sur ma base de donnée depuis un autre ordinateur mais toujours pas avec ma carte arduino !

quelle est la ligne de test que tu a utilisé depuis un autre ordinateur ?
quelle est la requête envoyée par ton arduino ?
s'il y a différence ça ne peut pas fonctionner ....

Via l'ordinateur jái utilisé :"http://172.20.10.13/projet_arduino/add.php?temp1=28"

et via Arduino j'utilise :

if (client.connect(servername, 80)) {
Serial.println("connected");
// Make a HTTP request:
String printwifiarduino = "GET /projet_arduino/add.php?temp1=";
String cdrole = printwifiarduino + temperature ; ( temperature est égal a 28)
client.print (cdrole);
Serial.print("donnée ecrite ");
Serial.println(temperature);

postes ton code complet entre balises code

#include <SPI.h> // bibliothèque de la liaison série
#include <WiFi.h> //Inclure la bibliothèque wifi ECRIRE AVEC DES STRINGS


char ssid[] = "STI2DSIN";      // your network SSID (name)
char pass[] = "sti2dsin";   // your network password
int keyIndex = 0;                 // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

int CAPTEUR_TEMP_PIN = 4; // adressage du capteur de temperature (PIN) //
int temp = 0; //définition de la variable entière (integer) //
float temperature = 0; // variable temperature en flottant //
float const_can = 0.0048828; // constante du convertisseur //
WiFiClient client;
String data; 
String stringVal;


WiFiServer server(80);    //Initialise le serveur wifi, port 80 par défaut pour http

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);   //Affichage écran du PC
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port 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);
  }

  String fv = WiFi.firmwareVersion();
  if (fv != "1.1.0") {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Tentative de connexion au reseau 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(3000);
  }
  server.begin();
  // you're connected now, so print out the status:
  printWifiStatus();
  analogRead(CAPTEUR_TEMP_PIN);
  }


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 boy ()
{
temp = analogRead(CAPTEUR_TEMP_PIN); // lecture du capteur de température //
temperature = (((temp*const_can)*1000)-500)/10;  //calcul//

if (client.connect("172.20.10.13",80)) { // remplacer par l'adresse IP de votre serveur-ordi
  String printwifiarduino =  "GET /projet_arduino/add.php?temp1=";
  String cdrole = printwifiarduino + temperature ;
client.print (cdrole);
client.println( " HTTP/1.1");
client.println( "Host: 172.20.10.13" );
client.println( "Content-Type: application/x-www-form-urlencoded" );
client.println( "Connection: close" );
client.println();
client.println();
client.stop();
Serial.print("donnee ecrite ");
Serial.println(temperature);
} 
else
{
Serial.println("problème de connection 56");
}
if (client.connected()) { 
client.stop(); // DISCONNECT FROM THE SERVER
}
delay(3000); // attente en millisecondes
}
void loop()
{
boy();
}

voila désolé :sweat_smile:

tu peux essayer de rajouter après les #include
byte serverbdd[] = { 172, 20, 10, 13 };

et modifier ta ligne par
if (client.connect(serverbdd, 80))

et rajouter après client.print (cdrole); la ligne
Serial.println (cdrole);

et copier le résultat complet de la console

Voila ce que marque la console apres ajout de toute tes modifications :

Tentative de connexion au reseau SSID : Bbox-A7B77C9A
SSID: Bbox-A7B77C9A
IP Adress: 192.168.1.93
signal strenght (RSSI): -70 dBm
GET /projet_arduino/add.php?temp1=184.37
donnee ecrite 184.37

Mais ça n’écris toujours pas dans ma bdd

tu peux :
supprimer la ligne client.println( "Content-Type: application/x-www-form-urlencoded" ); qui sert en méthode POST
essayer depuis un ordi "http://172.20.10.13/projet_arduino/add.php?temp1=184.37"
regarder les log du serveur
....
question : ton serveur, ton PC, ton arduino appartiennent au même sous-réseau ?