-2

I got this error in the following program:

#include <SoftwareSerial.h>
#include <dht.h>
dht DHT;
int a;
String temp;
String humid;
SoftwareSerial esp(0, 1);
#define SSID "abcd"
#define PASS "99999999"

void sendAT(String cmd) {
  Serial.print("SEND=");
  esp.println("cmd");
  Serial.println("cmd");
}

boolean connectwifi() {
  Serial.println("AT+CWMODE=1");
  delay(2000);
  Serial.println("AT+CWLAP");
  String cmd="AT+CWJAP="\"abcd"\",\"99999999"\";
  sendAT(cmd);
  delay(5000);
  if (Serial.find("ERROR")){
    Serial.println("Recieved:Error could not connect");
    return false;
  }
  else{
    Serial.println("Wifi connected \n");

  }
  cmd="AT+CIPMUX=0";
  sendAT(cmd);
  if(Serial.find("Error")){
    esp.print("RECIEVED ERROR");
    return false;
  }
}

  void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  esp.begin(115200);
  send("AT");
  delay(5000);
  if(Serial.find("OK")){
    Serial.println("Recieved:OK\n ESP ready to send data\n");
    connectwifi();

  }

}

  void loop() {
  // put your main code here, to run repeatedly:
  a=DHT.read11(5);
  temp=DHT.temperature;
  humid=DHT.humidity;
  Serial.println("temperature: ");
  Serial.println(temp);
  Serial.println("humidity: ");
  Serial.println(humid);
  Serial.print("\n");
  updateTS(temp,humid);
  delay(3000);




}


void updateTS(String T, String H){
  String cmd="AT+CIPSTATRT=\"TCP\",\"api.thingspeak.com\",80";
  sendAt(cmd);
  delay (2000);
  if (Serial.find("Error")){
    Serial.print("Recieved :Error\n EXIT1");
    return;
  }
  cmd="GET/update?key=CJWN3VJZCQVTJD2J&field1="+T+"&field2+"+H+"\r\n";
  Serial.println("AT+CIPSEND=");
  Serial.println(cmd length());
  if (Serial.find(">")){
    esp.print(">");
    esp.print(cmd);
    Serial.println(cmd);
    }
    else{
      sendAT("AT+CIPCLOSE");
    }
    if (Serial.find("Error")){
      Serial.println("Recieved: Error \n EXIT2");
    }
    Serial.println();
}
    }
}

The error message displayed is:

arduinoo_sketch:21: error: stray '\' in program

   String cmd="AT+CWJAP="\"abcd"\",\"99999999"\";

   ^

arduinoo_sketch:21: error: stray '\' in program

arduinoo_sketch:21: error: stray '\' in program

C:\Users\lenovo\Documents\Arduino\arduinoo_sketch\arduinoo_sketch.ino:21:47: warning: missing terminating " character

   String cmd="AT+CWJAP="\"abcd"\",\"99999999"\";

                                               ^

arduinoo_sketch:21: error: missing terminating " character

   String cmd="AT+CWJAP="\"abcd"\",\"99999999"\";

   ^

C:\Users\lenovo\Documents\Arduino\arduinoo_sketch\arduinoo_sketch.ino: In function 'boolean connectwifi()':

arduinoo_sketch:22: error: expected ',' or ';' before 'sendAT'

   sendAT(cmd);

   ^

C:\Users\lenovo\Documents\Arduino\arduinoo_sketch\arduinoo_sketch.ino:24:26: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

   if (Serial.find("ERROR")){

                          ^

C:\Users\lenovo\Documents\Arduino\arduinoo_sketch\arduinoo_sketch.ino:34:25: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

   if(Serial.find("Error")){

                         ^

C:\Users\lenovo\Documents\Arduino\arduinoo_sketch\arduinoo_sketch.ino: In function 'void setup()':

arduinoo_sketch:44: error: 'send' was not declared in this scope

   send("AT");

            ^

C:\Users\lenovo\Documents\Arduino\arduinoo_sketch\arduinoo_sketch.ino:46:22: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

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

                      ^

C:\Users\lenovo\Documents\Arduino\arduinoo_sketch\arduinoo_sketch.ino: In function 'void loop()':

arduinoo_sketch:64: error: 'updateTS' was not declared in this scope

   updateTS(temp,humid);

                      ^

C:\Users\lenovo\Documents\Arduino\arduinoo_sketch\arduinoo_sketch.ino: In function 'void updateTS(String, String)':

arduinoo_sketch:75: error: 'sendAt' was not declared in this scope

   sendAt(cmd);

             ^

C:\Users\lenovo\Documents\Arduino\arduinoo_sketch\arduinoo_sketch.ino:77:26: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

   if (Serial.find("Error")){

                          ^

arduinoo_sketch:83: error: expected ')' before 'length'

   Serial.println(cmd length());

                      ^

C:\Users\lenovo\Documents\Arduino\arduinoo_sketch\arduinoo_sketch.ino:84:22: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

   if (Serial.find(">")){

                      ^

C:\Users\lenovo\Documents\Arduino\arduinoo_sketch\arduinoo_sketch.ino:92:28: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

     if (Serial.find("Error")){

                            ^

C:\Users\lenovo\Documents\Arduino\arduinoo_sketch\arduinoo_sketch.ino: At global scope:

arduinoo_sketch:97: error: expected declaration before '}' token

     }

     ^

exit status 1
stray '\' in 
  • Syntax highlighting should have given you a hint. – gre_gor Apr 3 '18 at 18:35
  • Offhand, I spotted that where it says String cmd="AT+CWJAP="\"abcd"\",\"99999999"\"; it should say String cmd="AT+CWJAP="\"abcd"\",\"99999999\"; - before I saw the error messages - the compiler caught it - so just chase down each line indicated in the error messages. – SDsolar Apr 5 '18 at 2:22
2

By properly formatting your code (ctrl-T in the IDE), you realize what is wrong with your code... In

  String cmd = "AT+CWJAP="\"abcd"\",\"99999999"\";
               sendAT(cmd);

See how sendAT(cmd); is indented as if it was part of the previous line? It means you have some trouble with the quotes.

1

At least one example is here:

String cmd="AT+CWJAP="\"abcd"\",\"99999999"\";

You probably meant

String cmd="AT+CWJAP=\"abcd\",\"99999999\"";

This is a pretty trivial issue, you should be able to fix it simply by proofreading your sketch carefully.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.