Bnj a tts, j'ai passer une longue période d'essaie a fin d'envoyer des données d'un capteur de température(Thermocouple type k+Max6675) vers une base de données (phpMyadmin) en utilisant un ESP8266-01s
j'écrir le code arduino suivant:
#include <max6675.h>
#include <SoftwareSerial.h>
#define RX 10
#define TX 11
String AP = "guest";
String PASS = "00000000";
String Data;
int countTrueCommand;
int countTimeCommand;
boolean found = false;
int thermo_gnd_pin = 45;
int thermo_vcc_pin = 47;
int thermo_so_pin = 53;
int thermo_cs_pin = 51;
int thermo_sck_pin = 49;
MAX6675 thermocouple(thermo_sck_pin, thermo_cs_pin, thermo_so_pin);
int temp;
SoftwareSerial esp8266(RX, TX);
void setup()
{
pinMode(thermo_vcc_pin, OUTPUT);
pinMode(thermo_gnd_pin, OUTPUT);
digitalWrite(thermo_vcc_pin, HIGH);
digitalWrite(thermo_gnd_pin, LOW);
Serial.begin(9600);
esp8266.begin(115200);
sendCommand("AT", 5, "OK");
sendCommand("AT+CWMODE=1", 5, "OK");
sendCommand("AT+CWJAP=\"" + AP + "\",\"" + PASS + "\"", 20, "OK");
}
void loop()
{
temp =thermocouple.readCelsius();
Serial.print("Température=");
Serial.print(temp);
Serial.println(" °C");
String temp1= String(temp);
Data = "GET /KM3/machine1?temperaturezone1="+temp1;
sendCommand("AT+CIPMUX=1",5,"OK");
sendCommand("AT+CIPSTART=0,\"TCP\",\"127.0.0.1\",80",4,"OK");
sendCommand("AT+CIPSEND=0," +String(Data.length()+4),2,">");
esp8266.println(Data);delay(100);countTrueCommand++;
sendCommand("AT+CIPCLOSE=0",2,"OK");
}
void sendCommand(String command, int maxTime, char readReplay[]) {
Serial.print(countTrueCommand);
Serial.print(". AT command => ");
Serial.print(command);
Serial.print(" ");
while (countTimeCommand < (maxTime * 1))
{
esp8266.println(command);//AT+CIPSEND
if (esp8266.find(readReplay)) //OK
{
found = true;
break;
}
countTimeCommand++;
}
if (found == true)
{
Serial.println("Yes");
countTrueCommand++;
countTimeCommand = 0;
}
if (found == false)
{
Serial.println("Fail");
countTrueCommand = 0;
countTimeCommand = 0;
}
found = false;
}
et le code php suivant:
<?php
$t=$_GET['temp1'];
$bdd=new PDO('mysql:host=localhost;dbname=timelec','root','');
$bdd-> query("INSERT INTO `thermodureKM3`(`temperaturezone1`) VALUES ('$t');");
echo'DATA INSERTED';
?>
Je n'arrive a aucu'une résultat (pas de données ajoutées dans la base de données) et le moniteur série affiche fail donc il ya un astuce ici "
if (found == false)
{
Serial.println("Fail");
countTrueCommand = 0;
countTimeCommand = 0;
}
Aussi je suis pas sure de cette ligne sendCommand("AT+CIPSTART=0,\"TCP\",\"127.0.0.1\",80",4,"OK");
car je ne sais pas surement quel adresse IP je doit insert (j'utilise Wamp server comme serveur Web)
Sil vous plait veuillez m'aider pour que je puisse avancer et continuer mon PFE qui sera fini dans quelque semaines :o