0

error:

C:\Users\mrtas\Desktop\sketch_may23a\sketch_may23a.ino: In function 'void setup()':

C:\Users\mrtas\Desktop\sketch_may23a\sketch_may23a.ino:41:24:
warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

   WiFi.begin(SSID, PASS);   //Begin WiFi
              ^     ^

code:

#include <DHT.h>
#include <WiFi.h>
#define DHTTYPE DHT11
#define DHTPIN 5

DHT dht(DHTPIN, DHTTYPE);

String msg = "GET /update?key=TWE505JXFTXDPNB3";
float temp;
char SSID;
char Pass;

int hum;

String tempC;

int error;
void updateTemp();
#define SSID "wifi name"

#define PASS "wifi pass"

#define IP "184.106.153.149"

void setup()
{
  dht.begin();
  Serial.begin(9600);
  delay(10);

  // Connect to WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(SSID);
  WiFi.begin(SSID, PASS);     //Begin WiFi

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
}

void loop() {
start:
  error = 0;

  temp = dht.readTemperature();
  hum = dht.readHumidity();

  char buffer[10];
  tempC = dtostrf(temp, 4, 1, buffer);
  updateTemp();

  if (error == 1) {
    goto start;
  }
  delay(5000);
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += IP;
  cmd += "\",80";
  Serial.println(cmd);
  delay(2000);

  if (Serial.find("Error")) {
    return;
  }
  cmd = msg ;
  cmd += "&field1=";
  cmd += tempC;
  cmd += "&field2=";
  cmd += String(hum);
  cmd += "\r\n";
  Serial.print("AT+CIPSEND=");
  Serial.println(cmd.length());

  if (Serial.find(">")) {
    Serial.print(cmd);
  }
  else {
    Serial.println("AT+CIPCLOSE");
    //Resend...
    error = 1;
  }

  Serial.println("AT+CWMODE=1");
  delay(2000);
}

boolean connectWiFi()
{
  String cmd = "AT+CWJAP=\"";
  cmd += SSID;
  cmd += "\",\"";
  cmd += PASS;
  cmd += "\"";
  Serial.println(cmd);
  delay(5000);

  if (Serial.find("OK")) {
    return true;
  }
  return false;
}
8
  • 1
    We need the full error message, including the information where the compiler found the problem in your code. Please add that to your question Commented Jun 5, 2022 at 15:06
  • C:\Users\mrtas\Desktop\sketch_may23a\sketch_may23a.ino: In function 'void setup()': C:\Users\mrtas\Desktop\sketch_may23a\sketch_may23a.ino:38:24: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] WiFi.begin(SSID, PASS); //Begin WiFi ^ ^ Commented Jun 5, 2022 at 15:38
  • 4
    1. Please add the error message to the question (click on “edit”) rather than as a comment. 2. This looks suspiciously like an issue of the WiFi library that was fixed five years ago. What version of the library are you using? Commented Jun 5, 2022 at 16:19
  • that's a warning, not an error ... does the compilation actually abort? Commented Jun 5, 2022 at 18:01
  • 1
    WiFi.h and AT commands mix? what are you doing? Commented Jun 5, 2022 at 18:43

1 Answer 1

2

It's basically a bug in the library which is expecting "char *" when you are supplying "const char *.

You could work around it by changing:

#define SSID "wifi name"
#define PASS "wifi pass"

to:

char SSID [] =  "wifi name";
char PASS [] =  "wifi pass";

That makes them non-const so the error message should go away.

Not tested. But that is the general idea.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.