probleme mac -> pc

boujour, mon code marche tres bien sur mac mais quand j’arrive sur pc j’ai c’est erreurs

C:\Users\franc\Downloads\sketch_may24b\sketch_may24b.ino: In function 'void reset()':

C:\Users\franc\Downloads\sketch_may24b\sketch_may24b.ino:28:19: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

   if(esp.find("OK") ) Serial.println("Module Reset");

                   ^

C:\Users\franc\Downloads\sketch_may24b\sketch_may24b.ino: In function 'void connectWifi()':

C:\Users\franc\Downloads\sketch_may24b\sketch_may24b.ino:37:19: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

   if(esp.find("OK")) {

                   ^

C:\Users\franc\Downloads\sketch_may24b\sketch_may24b.ino: In function 'void httppost()':

C:\Users\franc\Downloads\sketch_may24b\sketch_may24b.ino:109:18: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

 if( esp.find("OK")) {

                  ^

C:\Users\franc\Downloads\sketch_may24b\sketch_may24b.ino:140:16: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

 if(esp.find(">")) { Serial.println("Sending.."); esp.print(postRequest);

                ^

C:\Users\franc\Downloads\sketch_may24b\sketch_may24b.ino:142:23: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

 if( esp.find("SEND OK")) { Serial.println("Packet sent");

                       ^

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino\main.cpp: In function 'main':

C:\Users\franc\Downloads\sketch_may24b\sketch_may24b.ino:97:6: warning: offset outside bounds of constant string

 data = "data=" + 50;// data sent must be under this form //name1=value1&name2=value2.

      ^

voici le code

#include "SoftwareSerial.h"
String ssid ="Colonna";
String password="***";
SoftwareSerial esp(10, 11);// RX, TX
String data;
String server = "192.168.1.81"; // www.example.com
String uri = "/data/add_data/elec";// our example is /esppost.php
int DHpin = 13;//sensor pin
byte dat [5];
String temp ,hum;

void setup() {
  pinMode (DHpin, OUTPUT);
  esp.begin(115200);
  Serial.begin(115200);
  Serial.println("check");
  reset();
  Serial.println("check");
  connectWifi();
  Serial.println("check");
}

//reset the esp8266 module

void reset() {
  esp.println("AT+RST");
  delay(1000);
  if(esp.find("OK") ) Serial.println("Module Reset");
}

//connect to your wifi network

void connectWifi() {
  String cmd = "AT+CWJAP=\"" +ssid+"\",\"" + password + "\"";
  esp.println(cmd);
  delay(4000);
  if(esp.find("OK")) {
    Serial.println("Connected!");
  }
  else {
    connectWifi();
    Serial.println("Cannot connect to wifi"); }
  }
  byte read_data () {
  byte data;
  for (int i = 0; i < 8; i ++) {
  if (digitalRead (DHpin) == LOW) {
  while (digitalRead (DHpin) == LOW); // wait for 50us
    delayMicroseconds (30); // determine the duration of the high level to determine the data is '0 'or '1'
    if (digitalRead (DHpin) == HIGH)
      data |= (1 << (7-i)); // high front and low in the post
    while (digitalRead (DHpin) == HIGH);
  }

  } 
  
 return data; 
 }

void start_test () {

digitalWrite (DHpin, LOW); // bus down, send start signal
delay (30); // delay greater than 18ms, so DHT11 start signal can be detected
digitalWrite (DHpin, HIGH);
delayMicroseconds (40); // Wait for DHT11 response
pinMode (DHpin, INPUT);
while (digitalRead (DHpin) == HIGH);
delayMicroseconds (80);
// DHT11 response, pulled the bus 80us
if (digitalRead (DHpin) == LOW);
delayMicroseconds (80);
// DHT11 80us after the bus pulled to start sending data
for (int i = 0; i < 4; i ++)

// receive temperature and humidity data, the parity bit is not considered

dat[i] = read_data ();

pinMode (DHpin, OUTPUT);

digitalWrite (DHpin, HIGH);

// send data once after releasing the bus, wait for the host to open the next Start signal

}

void loop () {
Serial.println("avant start test");
//start_test ();

// convert the bit data to string form
Serial.println("apres start test");
hum = String(dat[0]);

temp= String(dat[2]);

data = "data=" + 50;// data sent must be under this form //name1=value1&name2=value2.

httppost();

delay(1000);

}

void httppost () {

esp.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");//start a TCP connection.

if( esp.find("OK")) {

Serial.println("TCP connection ready");

}else{
  Serial.println("error TCP");
}
  delay(1000);

String postRequest =

"POST " + uri + " HTTP/1.0\r\n" +

"Host: " + server + "\r\n" +

"Accept: *" + "/" + "*\r\n" +

"Content-Length: " + data.length() + "\r\n" +

"Content-Type: application/x-www-form-urlencoded\r\n" +

"\r\n" + data;

String sendCmd = "AT+CIPSEND=";//determine the number of caracters to be sent.

esp.print(sendCmd);

esp.println(postRequest.length() );

delay(500);

if(esp.find(">")) { Serial.println("Sending.."); esp.print(postRequest);

if( esp.find("SEND OK")) { Serial.println("Packet sent");

while (esp.available()) {

String tmpResp = esp.readString();

Serial.println(tmpResp);

}

// close the connection

esp.println("AT+CIPCLOSE");

}

}}

merci :slight_smile:

Bonjour,

Ce sont des warning, tu peux régler le niveau des warning dans préférence. Peut être que le réglage par défaut n'est pas le même sur mac et PC.
Ceci est du que find() attend un char * comme paramètre et non un const char *. Tu peux éviter ce warning en castant en char *

  if (esp.find((char *)"OK") ) Serial.println("Module Reset");

Ceci dit, il y a un (petit) problème dans la librairie car find() devrait attendre un const char * comme argument