Hi !
Im in a big project and I communicate with a GSM Click, using AltSoftSerial, this works fine (I can send a sms if I cross the hardware serial and AltSoftSerial, in order to write from my PC terminal to the modem the right AT commands). But for my application I need to have a lot of functions in an extern file, so I made a .c and a .h files.
My problem, now, is that I get many error, even in the header file which looks fine to me. I'll paste down there the header file and the error log, and attach the .c file and the .ino. In my opinion the .ino one and the .c one are not really relevant (maybe the top of the files is), anyway you'll know this better than I do so I put everything here.
The errors are things like "String undeclared", or "myGsmSerial undeclared" (declared at top of the file), or "error: expected ')' before 'strPinCode'" where strPinCode is a function parameter, and is supposed to be a String.
I'm using an Arduino Uno and my IDE is the Arduino one, 1.5.6-r2.
GSMClick.h
#ifndef __GSMCLICK__
#define __GSMCLICK__
#include <Arduino.h>
#include <AltSoftSerial.h>
/**************
* void gsm_setup(void)
* Configuration of the serial communication between the modem and the Arduino
* Beginning of the serial communication
* Configuration of the modem with the serial communication
**************/
void gsm_setup(void);
/**************
* int gsm_pinCode(String pinCode)
* Enters the PIN Code to unlock the SIM card
* String pinCode : PIN code of the inserted SIM card
* Returns an int for information. Possible return values :
* 0 : The PIN CODE is correct, therefore the SIM card is correctly unlocked
* -1 : The PIN CODE is wrong
* -2 : You need to enter the PUK code, call gsm_pukCode()
* -3 : timeout, modem didn't answer in time
* -4 : Other error, can't understand modem
* -5 : No SIM card inserted
**************/
int gsm_pinCode(String strPinCode);
/**************
* int gsm_pukCode(String pukCode, String newPinCode)
* Enters the PUK code to unlock the PUK-locked SIM card, and changes the PIN code
* String pukCode : The PUK code of the SIM card
* String newPinCode : The new PIN code of the SIM card
* Returns an int for information. Possible return values :
* 0 : The PUK code is correct and the PIN code was correctly modified
* -1 : SIM card already unlocked
* -2 : SIM card asks for SIM code, not PUK code
* -3 : Timeout, modem didn't answer in time
* -4 : Other error, can't understand modem
* -5 : No SIM card
**************/
int gsm_pukCode(String strPukCode, String strNewPinCode);
/**************
* int gsm_sendSMS(String smsText)
* Send a SMS
* String strSmsText : Content of the SMS, maximum 170 char, if more, last chars will be cut
* String strNumber : Number that will receive the SMS, must be in format "+12345678901"
* Return an int for information. Possible return values :
* 0 : The SMS was correctly sent
* -1 : SIM is PIN-locked
* -2 : SIM is PUK-locked
* -3 : Timeout, modem didn't answer in time
* -4 : Can't understand modem
* -5 : No SIM card
**************/
int gsm_sendSMS(String strSmsText, String strNumber);
/**************
* int gsm_getTime(int* hours, int* minutes)
* Get the actual time
* int* hours : Pointer on the hours' var
* int* minutes : Pointer on the minutes' var
* Return an int. Possible values :
* 0 : Time has been put in the right variables
* -1 : SIM needs the PIN code, call gsm_pinCode()
* -2 : SIM needs the PUK code, call gsm_pukCode()
* -3 : Timeout, the modem didn't answer in time
* -4 : Can't understand modem
* -5 : No SIM card
**************/
void gsm_getTime(int* hours, int* minutes);
/**************
* String gsm_readGsmSerial(void)
* Read the next incoming String on Serial, the String ends with \r\n
* Return value :
* String : The String that has been read
**************/
String gsm_readGsmSerial(void);
/**************
* void gsm_cleanSerial(void)
* Read the serial until there's nothing more to read
**************/
void gsm_cleanSerial(void);
/*****************************************************
// STATIC METHODS
/****************************************************/
/**************
* static int gsm_checkOk(void)
* Check if the GSM sends "OK", "ERROR", anything else or doesn't anwer in time
* Return an int. Possible values :
* 0 : Answer is "OK"
* -1 : Answer is "ERROR"
* -2 : Answer is something else
* -3 : Timeout, the modem didn't answer in time
**************/
static int gsm_checkOk(void);
/**************
* static void gsm_turnOn(void)
* Turns the GSM on after a 3s reset, lasts almost 5s
**************/
static void gsm_turnOn(void);
/**************
* static int gsm_waitAnswer(void)
* Wait for an answer
* Return an int. Possible values :
* 0 : There is an answer
* -1 : There is no answer in time
**************/
static int gsm_waitAnswer(void);
/**************
* static int gsm_checkSIM(void)
* Asks the SIM state
* Return an int. Possible values :
* 0 : SIM is READY
* -1 : SIM needs the PIN code, call gsm_pinCode()
* -2 : SIM needs the PUK code, call gsm_pukCode()
* -3 : Timeout, the modem didn't answer in time
* -4 : Can't understand modem
* -5 : No SIM card (not implemented yet) TODO
**************/
static int gsm_checkSIM(void);
#endif
Error log
Arduino : 1.5.6-r2 (Windows 7), Carte : "Arduino Uno"
In file included from GSMClick.c:1:
GSMClick.h:26: error: expected ')' before 'strPinCode'
GSMClick.h:41: error: expected ')' before 'strPukCode'
GSMClick.h:56: error: expected ')' before 'strSmsText'
GSMClick.h:79: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'gsm_readGsmSerial'
GSMClick.c:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'myGsmSerial'
GSMClick.c: In function 'gsm_setup':
GSMClick.c:22: error: 'myGsmSerial' undeclared (first use in this function)
GSMClick.c:22: error: (Each undeclared identifier is reported only once
GSMClick.c:22: error: for each function it appears in.)
GSMClick.c: At top level:
GSMClick.c:52: error: expected ')' before 'strPinCode'
GSMClick.c:98: error: expected ')' before 'strPukCode'
GSMClick.c:152: error: expected ')' before 'strSmsText'
GSMClick.c: In function 'gsm_getTime':
GSMClick.c:271: error: 'String' undeclared (first use in this function)
GSMClick.c:271: error: expected ';' before 'strAnswer'
GSMClick.c:290: error: 'myGsmSerial' undeclared (first use in this function)
GSMClick.c:300: error: 'strAnswer' undeclared (first use in this function)
GSMClick.c: At top level:
GSMClick.c:314: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'gsm_readGsmSerial'
GSMClick.c: In function 'gsm_cleanSerial':
GSMClick.c:351: error: 'myGsmSerial' undeclared (first use in this function)
GSMClick.c: In function 'gsm_checkOk':
GSMClick.c:375: error: 'strAnswer' undeclared (first use in this function)
GSMClick.c: In function 'gsm_waitAnswer':
GSMClick.c:418: error: 'gsm_readGsmSerial' undeclared (first use in this function)
GSMClick.c:418: error: expected ')' before 'or'
GSMClick.c: In function 'gsm_checkSIM':
GSMClick.c:442: error: 'String' undeclared (first use in this function)
GSMClick.c:442: error: expected ';' before 'strAnswer'
GSMClick.c:446: error: 'myGsmSerial' undeclared (first use in this function)
GSMClick.c:452: error: 'strAnswer' undeclared (first use in this function)
I did search on the web about this problem and I only found some old post from the time String wasn't in the basic Arduino lib. If someone could tell me what is wrong, probably in my header, that'd be very kind.
Thanks for the reading, and hopefully you'll see better than me what's wrong in this ...
GSMClick.c (11.4 KB)
GSMClick.ino (417 Bytes)