Author Topic: arduino compilation error  (Read 708 times)

0 Members and 1 Guest are viewing this topic.

Offline gonejkoTopic starter

  • Newbie
  • Posts: 2
  • Country: tr
arduino compilation error
« on: January 22, 2024, 06:00:25 pm »
Hello,

I get a compilation error when uploading code to arduino
where am I going wrong





Code: [Select]

#include  <SoftwareSerial.h>

// Yazılım seri bağlantı noktasını yapılandırma
SoftwareSerial SIM900(7, 8);

// Gelen SMS karakterlerini kaydetmek için değişken
char incoming_char=0;
//Allarm  status
byte allarmSent = LOW;

void setup() {

  // Vin algılama için pin 2'yi giriş olarak ayarlayın
  pinMode(2,INPUT);
  // Arduino, SIM900 GSM shield ile 19200 baud hızında iletişim kurar
  SIM900.begin(19200);
  // GSM shield ağda oturum açması için zaman verin
  delay(30000);
  // SIM900'ü SMS moduna ayarlamak için AT komutu
  SIM900.print("AT+CMGF=1\
"); 
  delay(100);
  sendSMSready();
  // Modülü, SMS verilerini alındıktan sonra seri çıkışa gönderecek şekilde ayarlayın
  // SIM900.print("AT+CNMI=2,2,0,0,0\
");
  // delay(100);
}

void  loop()
{
  // GSM kalkanının gönderdiği herhangi bir metni seri monitörde görüntüleme
  if(SIM900.available() >0) {
    // Hücresel seri bağlantı noktasından karakteri al
    incoming_char=SIM900.read();
    // Gelen karakteri terminale yazdırır
    Serial.print(incoming_char);
  }
  while (digitalRead(2)  == HIGH) {}
  if(digitalRead(2) == LOW && allarmSent == LOW) {
    // 1" daha bekleyin ve pin 2 zaten DÜŞÜK ise mesaj gönderin
    delay(1000);
    if(digitalRead(2)  == LOW) sendSMSallarm();
  }
  while (digitalRead(2) == LOW) {}
  if(digitalRead(2)  == HIGH && allarmSent == HIGH) sendSMSallarmOFF();
}

void sendSMSallarm()
{
  // Alıcının cep telefonu numarasını uluslararası formatta ayarlayın
  SIM900.println("AT  + CMGS = \\"+905458587878\\"");
  delay(100);
  // SMS mesajını ayarla
  SIM900.println("*** test3 ***");
  delay(100);
  // AT komutunu ^Z ile sonlandırın, ASCII kodu 26
  SIM900.println((char)26);
  delay(100);
  SIM900.println();
  // Modüle SMS göndermesi için zaman verin
  delay(5000);
  allarmSent  = HIGH;
}

void sendSMSallarmOFF()
{
  // Alıcının cep telefonu numarasını uluslararası formatta ayarlayın
  SIM900.println("AT + CMGS = \\"+905458587878\\""); 
  delay(100);
  // SMS mesajını ayarla
  SIM900.println("*** test 2 ***");
  delay(100);
  // AT komutunu ^Z ile sonlandırın, ASCII kodu 26
  SIM900.println((char)26);
  delay(100);
  SIM900.println();
  // Modüle SMS göndermesi için zaman verin
  delay(5000);
  allarmSent = LOW;
}

void  sendSMSready()
{
  // Alıcının cep telefonu numarasını uluslararası formatta ayarlayın
  SIM900.println("AT + CMGS = \\"+905458587878\\"");
  delay(100);
  //  SMS mesajını ayarla
  SIM900.println("*** test 1 ***");
  delay(100);
  // AT komutunu ^Z ile sonlandırın, ASCII kodu 26
  SIM900.println((char)26);
  delay(100);
  SIM900.println();
  // Modüle SMS göndermesi için zaman verin
  delay(5000);
}
 

Offline agehall

  • Frequent Contributor
  • **
  • Posts: 383
  • Country: se
Re: arduino compilation error
« Reply #1 on: January 22, 2024, 06:22:42 pm »
You have ”\
” where you should have “\n”.
 

Offline gonejkoTopic starter

  • Newbie
  • Posts: 2
  • Country: tr
Re: arduino compilation error
« Reply #2 on: January 22, 2024, 06:35:43 pm »
You have ”\
” where you should have “\n”.

but this is a working code why is it giving me an error.

also where exactly should I fix in the line.
 

Offline MarkT

  • Frequent Contributor
  • **
  • Posts: 367
  • Country: gb
Re: arduino compilation error
« Reply #3 on: January 22, 2024, 07:12:05 pm »
  SIM900.println("AT  + CMGS = \\"+905458587878\\"");

For instance this line broken. Backslash confusion?

Please include error messages as text, not as an image,
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: arduino compilation error
« Reply #4 on: January 22, 2024, 08:15:06 pm »
Code: [Select]
  SIM900.print("AT+CMGF=1\
");

This is also an issue. Here the string is not normally terminated because the backslash followed by the " character is used to embed the " character in the string, therefore leaving the string open until the next " character is seen. The \ (backslash) character is an escape character in C. See this wikipedia article.

Normally the compiler will give a line number where it encounters the issue, and in this case you have to backtrack to the error.

Online newbrain

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: se
Re: arduino compilation error
« Reply #5 on: January 22, 2024, 08:20:58 pm »
Code: [Select]
  SIM900.println("AT + CMGS = \\"+905458587878\\""); 
I gather the intention is to print:
Quote
AT + CMGS = "+905458587878"
with the number between double quotes.
You need to escape the double quote, but a single backslash ( \ ) character is enough.
Code: [Select]
  SIM900.println("AT + CMGS = \"+905458587878\""); 

Writing \\ will generate a backslash in the string, not escape the following character.

If, instead, the idea is to pass the string to something that needs its own escaping of double quotes, you need three backslash: the first two generate the one in the output, the third one escape the double quote:
Code: [Select]
  SIM900.println("AT + CMGS = \\\"+905458587878\\\""); 
will generate:
Quote
AT + CMGS = \"+905458587878\"


but this is a working code why is it giving me an error.
If it does not compile, it is not working (or not written in C++).

Also this is valid C/C++ but probably does not do what you think it does (or, if it does there's no pint to it!):
Code: [Select]
  SIM900.print("AT+CMGF=1\
");
The code above is 100% equivalent to this:
Code: [Select]
  SIM900.print("AT+CMGF=1");
As a \ immediately followed by a newline is simply deleted from the source during parsing.
If a newline is wanted in the string, use the \n escape sequence, as already suggested.
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Online newbrain

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: se
Re: arduino compilation error
« Reply #6 on: January 22, 2024, 08:29:08 pm »
Code: [Select]
  SIM900.print("AT+CMGF=1\
");

This is also an issue.
No it's not, please check before giving answers to beginners.

That backslash does not appear at all after translation phase 2, where, quoting from ISO/IEC9899:2011, 5.1.1.2 Translation phases:
Quote
2. Each instance of a backslash character (\) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines
Same text appears in the C++ standards.
Pre-processing tokens - and string literals are pp - are parsed in phase three.
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: arduino compilation error
« Reply #7 on: January 23, 2024, 07:31:38 am »
Code: [Select]
  SIM900.print("AT+CMGF=1\
");

This is also an issue.
No it's not, please check before giving answers to beginners.

Sorry, you are absolutely right, and now that you pointed this out, I recall it as being a continuation character. Mainly used it in long macro definitions to continue on the next line.

Edit: I tried compiling the code on one of my machines with IDE version 1.8.8 and it gives a very direct indication of the actual errors and not just the bit shown in the original post. In hindsight I should have done that before posting my erroneous message. And in all fairness user agehall came to the same faulty conclusion before me.

Code: [Select]
Arduino: 1.8.8 (Linux), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

sketch_jan23a:53:3: error: stray '\' in program
   SIM900.println("AT  + CMGS = \\"+905458587878\\"");
   ^
sketch_jan23a:53:3: error: stray '\' in program
sketch_jan23a:70:3: error: stray '\' in program
   SIM900.println("AT + CMGS = \\"+905458587878\\"");
   ^
sketch_jan23a:70:3: error: stray '\' in program
sketch_jan23a:87:3: error: stray '\' in program
   SIM900.println("AT + CMGS = \\"+905458587878\\"");
   ^
sketch_jan23a:87:3: error: stray '\' in program
/home/peter/Arduino/sketch_jan23a/sketch_jan23a.ino: In function 'void sendSMSallarm()':
sketch_jan23a:53:50: error: expected ')' before string constant
   SIM900.println("AT  + CMGS = \\"+905458587878\\"");
                                                  ^
/home/peter/Arduino/sketch_jan23a/sketch_jan23a.ino: In function 'void sendSMSallarmOFF()':
sketch_jan23a:70:49: error: expected ')' before string constant
   SIM900.println("AT + CMGS = \\"+905458587878\\"");
                                                 ^
/home/peter/Arduino/sketch_jan23a/sketch_jan23a.ino: In function 'void sendSMSready()':
sketch_jan23a:87:49: error: expected ')' before string constant
   SIM900.println("AT + CMGS = \\"+905458587878\\"");
                                                 ^
exit status 1
stray '\' in program

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

As an additional pointer to the OP, using the println function for all the prints that need a new line at the end is better then to mix the different methods.
« Last Edit: January 23, 2024, 08:03:16 am by pcprogrammer »
 
The following users thanked this post: newbrain


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf