Chat freely about anything...

User avatar
By Hdiouech Montassar
#82452 Can you help me please, i write this code but nothing happen, i don't know exactly the IP adresse that i should send to it the data and i think that there is other issues missing in my code !!! please i really need you help!!!
This is my arduino code:
Code: Select all#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;
}

This is my php code:
Code: Select all<?php
         
         
        $t=$_GET['temp1'];
          $bdd=new PDO('mysql:host=localhost;dbname=timelec','root','');
          $bdd-> query("INSERT INTO `thermodureKM3`(`temperaturezone1`) VALUES ('$t');");
        echo'DATA INSERTED';
      

?>