Go Down

Topic: erreur de code  (Read 595 times) previous topic - next topic

hbachetti

C'est portant clair :

 return 0; // in case of a not match add 1 to the time out and return 0  }

Une accolade en fin de commentaire ... tu crois que c'est normal ?
Et il en manque deux autres.

Et ceci :

char CPIN[] = "AT+CPIN=\"0000\""; // pin code if required #define SEND_MSG_NUM "AT+CMGS=\"0503000000\"\r\n"   // Phone Number to  Receive SMS MSG  
#define SEND_MSG_TXT "Motheebotonics ! GSM is Working" // SMS TEXT DATA  #define CALL_NUM "ATD0503000000;\r\n"    // Emergency Call Number For Motion  

Il faudrait apprendre l'utilisation des commentaires.

J'ai déjà donné toutes les infos en #6.

Maintenant si lire ces infos te pose un problème ...

Linux is like a wigwam: no Windows, no Gates, and an Apache inside ...

lesept

#16
Apr 13, 2019, 06:19 pm Last Edit: Apr 13, 2019, 06:25 pm by lesept
Quote
before 'clearBuff'"
L'erreur peut se trouver avant cette ligne : montre aussi les lignes avant clearBuff()

... OK, le code est ici

Si on le copie dans l'IDE'on fait CTRL T on voit qu'il manque des } car le setup commence au milieu de la ligne :

Code: [Select]
...
        GSerial.print("\r\n");
        delay(10);
      }
    }
    //******************** SETUP Arduino ****************
    void setup() {

      Serial.begin(9600); //Set BaudRate to default baud rate 9600 for both computer and GSM
      GSerial.begin(9600);
...

Même chose pour la routine juste avant
Code: [Select]
   void delete_msgs() {
et celle d'avant
Code: [Select]
   void read_txt(void)
et celle d'avant
Code: [Select]
   void send_call()
etc. Jusqu'à arriver à
Code: [Select]
int Hand(char *s)
pour laquelle il manque 2 niveaux d'accolades fermantes

Donc essaye d'ajouter
Code: [Select]
 }
}

après la ligne 122, juste avant
Code: [Select]
// setup for GSM using AT Commands
void AT(void)
{
  clearBuff();

Ça devrait régler le problème, au moins pour cette erreur de compilation...


Hbachetti : ADJSoftwareSerial.h est dans une bibliothèque appelée Adjusted SoftwareSerial qui est fournie sur le site.

EDIT : la bonne solution est celle d'hbachetti : il faut "libérer" ces deux } comme ceci
Code: [Select]
    return -1; // in case of a time out return -1
  }
  g_timeout++;
  return 0; // in case of a not match add 1 to the time out and return 0
}

et même chose ici
Code: [Select]
      send_call(); // calling for emergency      }
Et corriger les define :
Code: [Select]
char CPIN[] = "AT+CPIN=\"0000\""; // pin code if required
#define SEND_MSG_NUM "AT+CMGS=\"0503000000\"\r\n"   // Phone Number to  Receive SMS MSG
#define SEND_MSG_TXT "Motheebotonics ! GSM is Working" // SMS TEXT DATA 
#define CALL_NUM "ATD0503000000;\r\n"    // Emergency Call Number For Motion
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

infobarquee

Code: [Select]
// Software Serial Library
#include <ADJSoftwareSerial.h>

// Setup  pin 2 and 3 as RX, TX for Software Serial
SoftwareSerial GSerial(2, 3); // RX, TX

//Defining Variables

//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 10;

//the time when the sensor outputs a low impulse
long unsigned int lowIn;

//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000;

// the use for these variables will be defined in the LOOP Function
boolean lockLow = true;
boolean takeLowTime;

//the digital pin connected to the PIR sensor's output
int pirPin = 7;

// This is the pin for the connected pir LED
//تجديد منفذ 9 باسم pirled
int pirled = 9;

// This is the pin for the connected SMS LED
//تجديد منفذ 10 باسم txtled
int txtled = 10;

//************** WARNING: put value = 0 if you don't want the GSM to delete any msgs from SIM Card*********************

// the number of msgs deleted after recieving your control SMS this is to not max your SIM memory
#define NUM_MSGS_DELETE 5

//recive buffer max number of char
#define MAXCHAR 200
//recive gsm module back signal
char buff[MAXCHAR];
//recive index
int j = 0;
//track time for the GSM to response
int g_timeout = 0;

// AT COMMANDS

////////////////////////////////  Insert your Data   //////////////////////////////////////////////
char CPIN[] = "AT+CPIN=\"0000\""; // pin code if required
#define SEND_MSG_NUM "AT+CMGS=\"0503000000\"\r\n"   // Phone Number to  Receive SMS MSG 
#define SEND_MSG_TXT "Motheebotonics ! GSM is Working" // SMS TEXT DATA 
#define CALL_NUM "ATD0503000000;\r\n"    // Emergency Call Number For Motion 
////////////////////////////////  Insert your Data   



//  clean buffer
void clearBuff(void)
{
  for (j = 0; j <= MAXCHAR; j++)
  {
    buff[j] = 0x00;
  }
  j = 0;
}

// reads the input from GSM and saves it to buffer
int readSerial(char result[])
{
  int i = 0;
  //delay(200);
  while (GSerial.available() > 0)
  {
    char inChar = GSerial.read();
    Serial.write(inChar);

    if (inChar != '\r')
    {
      result[i] = inChar;
      i++;
    }
    if (i >= MAXCHAR - 1 )
    {
      result[i] = '\0';
      GSerial.flush();
      return 0;
    }
  }

  result[i] = '\0';
  GSerial.flush();
  return 0;

}


// handles the wait for a response from GSM that exactly match the provided String
int Hand(char *s){

  clearBuff();
  //delay(300);
  readSerial(buff);
  if (strstr(buff, s) != NULL)
  {
    g_timeout = 0;
    clearBuff();
    return 1;// in case of a match return 1 
  }
  if (g_timeout > 50)
  {
    g_timeout = 0;
    return -1; // in case of a time out return -1   
    }
  g_timeout++;
  return 0; // in case of a not match add 1 to the time out and return 0 
  }


// setup for GSM using AT Commands
void AT(void){
  clearBuff();
  GSerial.println("ATE0"); //check if connected to GSM 
  GSerial.flush();
  Serial.println("ATE0");
  delay(500);
  readSerial(buff);
  while (strstr(buff, "OK") == NULL)
  {
    clearBuff();
    GSerial.println("ATE0");
    GSerial.flush();
    Serial.println("ATE0");
    delay(500);
    readSerial(buff);
  }
  Serial.println("Module is Working");
  while (1)
  {
    clearBuff();
    GSerial.println("AT+CREG?"); // Network registration
    GSerial.flush();
    delay(500);
    readSerial(buff);
    // check if 1 (home network) or 5 (roaming)
    if ((strstr(buff, "0,1") != NULL) || (strstr(buff, "0,5") != NULL))
    {
      clearBuff();
      break;
    }
    else
    {
      delay(1000);
    }
  }
  clearBuff();
  GSerial.println("AT+CMGF=1\r");// set SMS to TEXT MODE  delay(500);
  while (Hand("OK") == 0);
  Serial.println("SMS TEXT MODE Done");

  clearBuff();
  GSerial.println("AT+CPMS=\"SM\"\r\n");// set memory to SIM  delay(500);
  while (Hand("OK") == 0);
  return;
}

void send_txt(){
  clearBuff();
  GSerial.println("AT+CMGF=1\r");
  delay(500);
  while (Hand("OK") == 0);

  clearBuff();
  GSerial.println(SEND_MSG_NUM);
  delay(500);
  while (Hand(">") == 0);

  GSerial.println(SEND_MSG_TXT);
  delay(1000);
  while (Hand("OK") == 0);
  return;
}

void send_call(){
  clearBuff();
  GSerial.println("AT+CPAS\r");// check phone status before calling twice 
  GSerial.flush();
  delay(500);
  if (Hand("0") != 1) {
    Serial.println("Already calling");
    return;
  }
  GSerial.println(CALL_NUM);
  delay(2000);
  while (Hand("OK") == 0);
  delay(3000);
  return;
}

void read_txt(void){
  clearBuff();
  GSerial.println("AT+CMGL=\"REC UNREAD\"\r"); // an AT command to show all unread msgs and convert them to read 
  GSerial.flush();
  delay(500);
  clearBuff();
  readSerial(buff);
  if ((strstr(buff, "ON") != NULL)) { // is there ON in SMS? 
    digitalWrite(txtled, HIGH); // if yes then turn ON
    delete_msgs(); // delete all msgs 
    return;
  }

  if ((strstr(buff, "OFF") != NULL)) { // is there OFF in SMS?
    digitalWrite(txtled, LOW); // if yes then turn LED OFF
    delete_msgs(); // delete all msgs 
    return;
  }
  return;
}

// delete number of msgs specified earlier
void delete_msgs() {
  int i;
  Serial.println("Deleting ALL MSGs");
  for (i = 1; i < NUM_MSGS_DELETE + 1; i++) {
    GSerial.print("AT+CMGD=");
    GSerial.print(i);
    GSerial.print("\r\n");
    delay(10);
  }
}
//******************** SETUP Arduino ****************
void setup() {

  Serial.begin(9600); //Set BaudRate to default baud rate 9600 for both computer and GSM
  GSerial.begin(9600);
  GSerial.setTimeout(5000);// set Serial timeout
  pinMode(pirPin, INPUT);
  pinMode(pirled, OUTPUT);
  pinMode(txtled, OUTPUT);
  digitalWrite(pirPin, LOW);
  digitalWrite(txtled, LOW);
  digitalWrite(pirled, LOW);

  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
  for (int i = 0; i < calibrationTime; i++) {
    Serial.print(".");
    delay(1000);
  }
  Serial.println("SENSOR ACTIVE");
  delay(50);
  AT();
  Serial.println("GSM ACTIVE");
}

void loop() {

  // check if GSM receive any SMS, if so, then read it 
  if (GSerial.available() > 0) {
    Serial.println("check available");
    delay(2000);
    clearBuff();
    GSerial.println("AT+CPAS\r");// check phone status before calling twice 
    GSerial.flush();
    delay(500);
    if (Hand("0") != 1) {
    Serial.println("Already calling");
    }
    else{
       read_txt();
    }
  }

  if (digitalRead(pirPin) == HIGH) {
    digitalWrite(pirled, HIGH);   //motion detected, turn on LED
    if (lockLow) {
      //makes sure we wait for a transition to LOW before any further output is made:
      lockLow = false;
      Serial.println("---");
      Serial.print("motion detected at ");
      Serial.print(millis() / 1000);
      Serial.println(" sec");
      delay(100);
      send_call(); // calling for emergency     
      }
    takeLowTime = true;
  }

  if (digitalRead(pirPin) == LOW) {

    if (takeLowTime) {
      lowIn = millis();          //save the time of the transition from high to LOW 
      takeLowTime = false;
    }
    //if the sensor is low for more than the given pause, 
    //we assume that no more motion is going to happen 
  if (!lockLow && millis() - lowIn > pause) {
      //makes sure this block of code is only executed again after 
      //a new motion sequence has been detected
      lockLow = true;
      Serial.print("motion ended at ");
      Serial.print((millis() - pause) / 1000);
      Serial.println(" sec");
      delay(100);
      digitalWrite(pirled, LOW);//turn off led 
    }
  }
  delay(1000);
}

AUCUNE AIDE PAR MP

infobarquee

voilà les erreurs qui ressortent
Quote
sketch/ADJSoftwareSerial.cpp:375:6: warning: always_inline function might not be inlinable [-Wattributes]
 void SoftwareSerial::setRxIntMsk(bool enable)

      ^
sketch/ADJSoftwareSerial.cpp:121:6: warning: always_inline function might not be inlinable [-Wattributes]
 void SoftwareSerial::recv()

      ^
/home/loic/sketchbook/gsm_test/gsm_test/gsm_test.ino: In function 'void AT()':
/home/loic/sketchbook/gsm_test/gsm_test/gsm_test.ino:159:19: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   while (Hand("OK") == 0);
                   ^
/home/loic/sketchbook/gsm_test/gsm_test/gsm_test.ino:164:19: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   while (Hand("OK") == 0);
                   ^
/home/loic/sketchbook/gsm_test/gsm_test/gsm_test.ino: In function 'void send_txt()':
/home/loic/sketchbook/gsm_test/gsm_test/gsm_test.ino:172:19: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   while (Hand("OK") == 0);
                   ^
/home/loic/sketchbook/gsm_test/gsm_test/gsm_test.ino:177:18: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   while (Hand(">") == 0);
                  ^
/home/loic/sketchbook/gsm_test/gsm_test/gsm_test.ino:181:19: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   while (Hand("OK") == 0);
                   ^
/home/loic/sketchbook/gsm_test/gsm_test/gsm_test.ino: In function 'void send_call()':
/home/loic/sketchbook/gsm_test/gsm_test/gsm_test.ino:190:15: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   if (Hand("0") != 1) {
               ^
/home/loic/sketchbook/gsm_test/gsm_test/gsm_test.ino:196:19: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   while (Hand("OK") == 0);
                   ^
/home/loic/sketchbook/gsm_test/gsm_test/gsm_test.ino: In function 'void loop()':
/home/loic/sketchbook/gsm_test/gsm_test/gsm_test.ino:268:17: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     if (Hand("0") != 1) {
                 ^
/home/loic/sketchbook/arduino-1.8.1/libraries/ADJSoftwareSerial/ADJSoftwareSerial.cpp:375:6: warning: always_inline function might not be inlinable [-Wattributes]
 void SoftwareSerial::setRxIntMsk(bool enable)

      ^
/home/loic/sketchbook/arduino-1.8.1/libraries/ADJSoftwareSerial/ADJSoftwareSerial.cpp:121:6: warning: always_inline function might not be inlinable [-Wattributes]
 void SoftwareSerial::recv()

      ^
libraries/ADJSoftwareSerial/ADJSoftwareSerial.cpp.o (symbol from plugin): In function `SoftwareSerial::read()':
(.text+0x0): multiple definition of `SoftwareSerial::read()'
sketch/ADJSoftwareSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/ADJSoftwareSerial/ADJSoftwareSerial.cpp.o (symbol from plugin): In function `SoftwareSerial::read()':
(.text+0x0): multiple definition of `SoftwareSerial::active_object'
.....
....
etc....

collect2: error: ld returned 1 exit status
exit status 1
Erreur de compilation pour la carte Arduino/Genuino Uno
AUCUNE AIDE PAR MP

theblocken

merci à tous pour votre aide

@infobarquee

merci de m'avoir éclairé concernant la liste d'erreurs, d'ailleurs ce qui est bizarre c'est que moi il y avait une seul erreurs , donc c'est pour sa que je ne comprenais pas tout, excusé moi si j'ai était un peu " chiant"  ou long à comprendre ...

@infobarquee merci pour la correction du code et pour le temps que sa ta pris :) ^^


infobarquee

2mn de temps pour vérifier via l'ide
la lib trucmuche serial est buggée amha
AUCUNE AIDE PAR MP

theblocken

#21
Apr 13, 2019, 09:41 pm Last Edit: Apr 13, 2019, 09:55 pm by theblocken
du coup vu quelle était beugé sa faisait tout beugé non ?

Go Up