4 #ifndef ADAFRUIT_FONA_H 5 #define ADAFRUIT_FONA_H 7 #include "includes/FONAConfig.h" 8 #include "includes/FONAExtIncludes.h" 9 #include "includes/platform/FONAPlatform.h" 23 #define FONA_PREF_SMS_STORAGE "\"SM\"" 26 #define FONA_HEADSETAUDIO 0 27 #define FONA_EXTAUDIO 1 29 #define FONA_STTONE_DIALTONE 1 30 #define FONA_STTONE_BUSY 2 31 #define FONA_STTONE_CONGESTION 3 32 #define FONA_STTONE_PATHACK 4 33 #define FONA_STTONE_DROPPED 5 34 #define FONA_STTONE_ERROR 6 35 #define FONA_STTONE_CALLWAIT 7 36 #define FONA_STTONE_RINGING 8 37 #define FONA_STTONE_BEEP 16 38 #define FONA_STTONE_POSTONE 17 39 #define FONA_STTONE_ERRTONE 18 40 #define FONA_STTONE_INDIANDIALTONE 19 41 #define FONA_STTONE_USADIALTONE 20 43 #define FONA_DEFAULT_TIMEOUT_MS 500 45 #define FONA_HTTP_GET 0 46 #define FONA_HTTP_POST 1 47 #define FONA_HTTP_HEAD 2 49 #define FONA_CALL_READY 0 50 #define FONA_CALL_FAILED 1 51 #define FONA_CALL_UNKNOWN 2 52 #define FONA_CALL_RINGING 3 53 #define FONA_CALL_INPROGRESS 4 59 bool begin(FONAStreamType &port);
64 size_t write(uint8_t x);
74 bool readRTC(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *hr,
75 uint8_t *min, uint8_t *sec);
101 bool FMradio(
bool onoff, uint8_t a = FONA_HEADSETAUDIO);
110 bool readSMS(uint8_t message_index,
char *smsbuff, uint16_t max,
112 bool sendSMS(
char *smsaddr,
char *smsmsg);
114 bool getSMSSender(uint8_t message_index,
char *sender,
int senderlen);
115 bool sendUSSD(
char *ussdmsg,
char *ussdbuff, uint16_t maxlen,
121 bool getTime(
char *time_buffer, uint16_t maxlen);
126 bool getGSMLoc(uint16_t *replycode,
char *buff, uint16_t maxlen);
129 FONAFlashStringPtr username = 0,
130 FONAFlashStringPtr password = 0);
135 uint8_t
getGPS(uint8_t arg,
char *buffer, uint8_t maxbuff);
136 bool getGPS(
float *lat,
float *lon,
float *speed_kph = 0,
float *heading = 0,
137 float *altitude = 0);
144 bool TCPsend(
char *data, uint8_t len);
146 uint16_t
TCPread(uint8_t *buff, uint8_t len);
151 void HTTP_para_start(FONAFlashStringPtr parameter,
bool quoted =
true);
153 bool HTTP_para(FONAFlashStringPtr parameter,
const char *value);
154 bool HTTP_para(FONAFlashStringPtr parameter, FONAFlashStringPtr value);
155 bool HTTP_para(FONAFlashStringPtr parameter, int32_t value);
156 bool HTTP_data(uint32_t size, uint32_t maxTime = 10000);
157 bool HTTP_action(uint8_t method, uint16_t *status, uint16_t *datalen,
158 int32_t timeout = 10000);
163 bool HTTP_GET_start(
char *url, uint16_t *status, uint16_t *datalen);
166 const uint8_t *postdata, uint16_t postdatalen,
167 uint16_t *status, uint16_t *datalen);
175 bool setPWM(uint16_t period, uint8_t duty = 50);
186 bool expectReply(FONAFlashStringPtr reply, uint16_t timeout = 10000);
188 uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
189 bool sendCheckReply(FONAFlashStringPtr send, FONAFlashStringPtr reply,
190 uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
192 uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
210 uint16_t
readRaw(uint16_t read_length);
211 uint8_t
readline(uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS,
212 bool multiline =
false);
213 uint8_t
getReply(
char *send, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
214 uint8_t
getReply(FONAFlashStringPtr send,
215 uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
216 uint8_t
getReply(FONAFlashStringPtr prefix,
char *suffix,
217 uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
218 uint8_t
getReply(FONAFlashStringPtr prefix, int32_t suffix,
219 uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
220 uint8_t
getReply(FONAFlashStringPtr prefix, int32_t suffix1, int32_t suffix2,
223 uint8_t
getReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix,
224 uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
227 FONAFlashStringPtr reply,
228 uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
230 FONAFlashStringPtr reply,
231 uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
233 int32_t suffix2, FONAFlashStringPtr reply,
234 uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
236 FONAFlashStringPtr suffix, FONAFlashStringPtr reply,
237 uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
239 bool parseReply(FONAFlashStringPtr toreply, uint16_t *v,
char divider =
',',
241 bool parseReply(FONAFlashStringPtr toreply,
char *v,
char divider =
',',
244 char divider, uint8_t index);
246 bool sendParseReply(FONAFlashStringPtr tosend, FONAFlashStringPtr toreply,
247 uint16_t *v,
char divider =
',', uint8_t index = 0);
275 bool parseReply(FONAFlashStringPtr toreply,
float *f,
char divider,
278 bool sendParseReply(FONAFlashStringPtr tosend, FONAFlashStringPtr toreply,
279 float *f,
char divider =
',', uint8_t index = 0);
bool sendUSSD(char *ussdmsg, char *ussdbuff, uint16_t maxlen, uint16_t *readlen)
Send USSD.
Definition: Adafruit_FONA.cpp:950
bool enableGPRS(bool onoff)
Enable GPRS.
Definition: Adafruit_FONA.cpp:1580
static void onIncomingCall()
On incoming call callback.
Definition: Adafruit_FONA.cpp:673
uint16_t TCPavailable(void)
Check if TCP bytes are available.
Definition: Adafruit_FONA.cpp:1945
bool setBaudrate(uint16_t baud)
Set the baud rate that the module will use.
Definition: Adafruit_FONA.cpp:181
uint16_t readRaw(uint16_t read_length)
Read directly into the reply buffer.
Definition: Adafruit_FONA.cpp:2416
int8_t getFMSignalLevel(uint16_t station)
Gets the current FM signal level.
Definition: Adafruit_FONA.cpp:556
size_t write(uint8_t x)
Serial write.
Definition: Adafruit_FONA.cpp:2376
void setGPRSNetworkSettings(FONAFlashStringPtr apn, FONAFlashStringPtr username=0, FONAFlashStringPtr password=0)
Set the GPRS network settings.
Definition: Adafruit_FONA.cpp:1764
uint8_t getVolume(void)
Get the current volume level.
Definition: Adafruit_FONA.cpp:409
bool getBattVoltage(uint16_t *v)
Get the current batery voltage.
Definition: Adafruit_FONA.cpp:248
FONAFlashStringPtr apn
Access point name.
Definition: Adafruit_FONA.h:199
uint8_t getIMEI(char *imei)
Get the IMEI.
Definition: Adafruit_FONA.cpp:338
bool getTime(char *time_buffer, uint16_t maxlen)
Get the current time.
Definition: Adafruit_FONA.cpp:1058
static bool _incomingCall
Incoming call state var.
Definition: Adafruit_FONA.h:249
bool sendSMS(char *smsaddr, char *smsmsg)
Send an SMS Message from a buffer provided.
Definition: Adafruit_FONA.cpp:876
bool setSMSInterrupt(uint8_t i)
Attach an interrupt for SMS notifications.
Definition: Adafruit_FONA.cpp:751
bool incomingCallNumber(char *phonenum)
Get the number of the incoming call.
Definition: Adafruit_FONA.cpp:707
bool enableNTPTimeSync(bool onoff, FONAFlashStringPtr ntpserver=0)
Enable NTP time sync.
Definition: Adafruit_FONA.cpp:1019
FONAFlashStringPtr apnusername
Access point username.
Definition: Adafruit_FONA.h:200
bool getADCVoltage(uint16_t *v)
Get the current ADC voltage.
Definition: Adafruit_FONA.cpp:284
Adafruit_FONA_3G(int8_t reset_pin)
Construct a new Adafruit_FONA_3G object.
Definition: Adafruit_FONA.h:263
bool enableGPS(bool onoff)
Enable GPS.
Definition: Adafruit_FONA.cpp:1081
bool readRTC(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *hr, uint8_t *min, uint8_t *sec)
Read the Real Time Clock.
Definition: Adafruit_FONA.cpp:201
bool sendCheckReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, FONAFlashStringPtr reply, uint16_t timeout=FONA_DEFAULT_TIMEOUT_MS)
Send data and verify the response matches an expected response.
Definition: Adafruit_FONA.cpp:2764
bool TCPconnected(void)
Check the TCP connection status.
Definition: Adafruit_FONA.cpp:1892
bool TCPclose(void)
Close the TCP connection.
Definition: Adafruit_FONA.cpp:1883
uint8_t readline(uint16_t timeout=FONA_DEFAULT_TIMEOUT_MS, bool multiline=false)
Read a single line or up to 254 bytes.
Definition: Adafruit_FONA.cpp:2439
bool hangUp(void)
End the current call.
Definition: Adafruit_FONA.cpp:641
int peek(void)
Serial peek.
Definition: Adafruit_FONA.cpp:2390
bool HTTP_GET_start(char *url, uint16_t *status, uint16_t *datalen)
Start a HTTP GET request.
Definition: Adafruit_FONA.cpp:2180
bool HTTP_data(uint32_t size, uint32_t maxTime=10000)
Begin sending data via HTTP.
Definition: Adafruit_FONA.cpp:2094
bool HTTP_ssl(bool onoff)
Enable or disable SSL.
Definition: Adafruit_FONA.cpp:2163
bool setPWM(uint16_t period, uint8_t duty=50)
Set the PWM Period and Duty Cycle.
Definition: Adafruit_FONA.cpp:590
uint8_t GPRSstate(void)
Get the GPRS state.
Definition: Adafruit_FONA.cpp:1749
bool setMicVolume(uint8_t a, uint8_t level)
Set the microphone gain.
Definition: Adafruit_FONA.cpp:478
bool sendParseReply(FONAFlashStringPtr tosend, FONAFlashStringPtr toreply, uint16_t *v, char divider=',', uint8_t index=0)
Send data and parse the reply.
Definition: Adafruit_FONA.cpp:2902
char replybuffer[255]
buffer for holding replies from the module
Definition: Adafruit_FONA.h:198
int8_t getFMVolume(void)
Get the current volume level.
Definition: Adafruit_FONA.cpp:541
int read(void)
Serial read.
Definition: Adafruit_FONA.cpp:2384
FONAFlashStringPtr apnpassword
Access point password.
Definition: Adafruit_FONA.h:201
FONAFlashStringPtr useragent
User agent used when making requests.
Definition: Adafruit_FONA.h:203
uint8_t getReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, uint16_t timeout=FONA_DEFAULT_TIMEOUT_MS)
Send command prefix and suffix, returning the response length.
Definition: Adafruit_FONA.cpp:2623
bool callerIdNotification(bool enable, uint8_t interrupt=0)
Enable or disable caller ID.
Definition: Adafruit_FONA.cpp:690
uint16_t TCPread(uint8_t *buff, uint8_t len)
Read from a TCP socket.
Definition: Adafruit_FONA.cpp:1963
uint8_t type()
Get the module type.
Definition: Adafruit_FONA.cpp:64
uint8_t getGPS(uint8_t arg, char *buffer, uint8_t maxbuff)
Fill a buffer with the current GPS reading.
Definition: Adafruit_FONA.cpp:1209
void HTTP_POST_end(void)
End an HTTP POST request.
Definition: Adafruit_FONA.cpp:2293
bool parseReply(FONAFlashStringPtr toreply, uint16_t *v, char divider=',', uint8_t index=0)
Parse a string in the response fields using a designated separator and copy the value at the specifie...
Definition: Adafruit_FONA.cpp:2782
bool readSMS(uint8_t message_index, char *smsbuff, uint16_t max, uint16_t *readsize)
Read an SMS message into a provided buffer.
Definition: Adafruit_FONA.cpp:788
bool pickUp(void)
Answer a call.
Definition: Adafruit_FONA.cpp:659
bool HTTP_readall(uint16_t *datalen)
Read all available HTTP data.
Definition: Adafruit_FONA.cpp:2149
void setHTTPSRedirect(bool onoff)
Set the HTTPS redirect flag.
Definition: Adafruit_FONA.cpp:2308
void flush()
Flush the serial data.
Definition: Adafruit_FONA.cpp:2395
int8_t _rstpin
Reset pin.
Definition: Adafruit_FONA.h:195
bool enableRTC(uint8_t mode)
Enable the Real Time Clock.
Definition: Adafruit_FONA.cpp:233
bool TCPsend(char *data, uint8_t len)
Send data via TCP.
Definition: Adafruit_FONA.cpp:1910
bool getSMSSender(uint8_t message_index, char *sender, int senderlen)
Retrieve the sender of the specified SMS message and copy it as a string to the sender buffer...
Definition: Adafruit_FONA.cpp:844
bool httpsredirect
HTTPS redirect state.
Definition: Adafruit_FONA.h:202
bool setAudio(uint8_t audio_output)
Set the audio ouput.
Definition: Adafruit_FONA.cpp:398
uint8_t getNetworkStatus(void)
Gets the current network status.
Definition: Adafruit_FONA.cpp:366
FONAStreamType * mySerial
Serial connection.
Definition: Adafruit_FONA.h:252
uint8_t getSMSInterrupt(void)
Get the current SMS Iterrupt.
Definition: Adafruit_FONA.cpp:736
Definition: Adafruit_FONA.h:56
bool playToolkitTone(uint8_t t, uint16_t len)
Play a toolkit tone.
Definition: Adafruit_FONA.cpp:450
bool callPhone(char *phonenum)
Call a phone number.
Definition: Adafruit_FONA.cpp:607
bool enableGPSNMEA(uint8_t enable_value)
Enable GPS NMEA output.
Definition: Adafruit_FONA.cpp:1554
uint8_t getReply(char *send, uint16_t timeout=FONA_DEFAULT_TIMEOUT_MS)
Send a command and return the reply.
Definition: Adafruit_FONA.cpp:2482
int available(void)
Serial data available.
Definition: Adafruit_FONA.cpp:2369
bool setFMVolume(uint8_t i)
Set the FM Radio Volume.
Definition: Adafruit_FONA.cpp:528
bool HTTP_init()
Initialize HTTP.
Definition: Adafruit_FONA.cpp:1996
bool HTTP_para(FONAFlashStringPtr parameter, const char *value)
Send HTTP parameter.
Definition: Adafruit_FONA.cpp:2053
FONAFlashStringPtr ok_reply
OK reply for successful requests.
Definition: Adafruit_FONA.h:204
bool begin(FONAStreamType &port)
Connect to the cell module.
Definition: Adafruit_FONA.cpp:71
bool playDTMF(char tone)
Play a DTMF/Key tone.
Definition: Adafruit_FONA.cpp:434
uint8_t getCallStatus(void)
Get the current call status.
Definition: Adafruit_FONA.cpp:628
bool setVolume(uint8_t volume_level)
Set the volume.
Definition: Adafruit_FONA.cpp:424
Adafruit_FONA(int8_t r)
Construct a new Adafruit_FONA object.
Definition: Adafruit_FONA.cpp:47
uint8_t getSIMCCID(char *ccid)
Get the SIM CCID.
Definition: Adafruit_FONA.cpp:313
void HTTP_GET_end(void)
End an HTTP GET.
Definition: Adafruit_FONA.cpp:2241
bool HTTP_setup(char *url)
Configure an HTTP request.
Definition: Adafruit_FONA.cpp:2318
Definition: Adafruit_FONA.h:255
uint8_t getRSSI(void)
get the current Received Signal Strength Indication
Definition: Adafruit_FONA.cpp:379
bool HTTP_POST_start(char *url, FONAFlashStringPtr contenttype, const uint8_t *postdata, uint16_t postdatalen, uint16_t *status, uint16_t *datalen)
Start an HTTP POST request.
Definition: Adafruit_FONA.cpp:2256
int8_t GPSstatus(void)
Get teh GPS status.
Definition: Adafruit_FONA.cpp:1147
void setUserAgent(FONAFlashStringPtr useragent)
Set the User Agent for HTTP requests.
Definition: Adafruit_FONA.cpp:2300
uint8_t unlockSIM(char *pin)
Unlock the sim with a provided PIN.
Definition: Adafruit_FONA.cpp:296
bool HTTP_action(uint8_t method, uint16_t *status, uint16_t *datalen, int32_t timeout=10000)
Make an HTTP Request.
Definition: Adafruit_FONA.cpp:2126
bool sendCheckReply(char *send, char *reply, uint16_t timeout=FONA_DEFAULT_TIMEOUT_MS)
Send data and verify the response matches an expected response.
Definition: Adafruit_FONA.cpp:2655
int8_t getNumSMS(void)
Get the number of SMS.
Definition: Adafruit_FONA.cpp:759
uint8_t _type
Module type.
Definition: Adafruit_FONA.h:196
bool FMradio(bool onoff, uint8_t a=FONA_HEADSETAUDIO)
Turn the FM Radio on or off.
Definition: Adafruit_FONA.cpp:497
bool TCPconnect(char *server, uint16_t port)
Start a TCP connection.
Definition: Adafruit_FONA.cpp:1842
bool getBattPercent(uint16_t *p)
Get the percentage charge of battery as reported by sim800.
Definition: Adafruit_FONA.cpp:274
void flushInput()
Read all available serial input to flush pending data.
Definition: Adafruit_FONA.cpp:2400
bool parseReplyQuoted(FONAFlashStringPtr toreply, char *v, int maxlen, char divider, uint8_t index)
Parse a string in the response fields using a designated separator and copy the string (without quote...
Definition: Adafruit_FONA.cpp:2855
bool expectReply(FONAFlashStringPtr reply, uint16_t timeout=10000)
Check if the received reply matches the expectation.
Definition: Adafruit_FONA.cpp:2353
bool HTTP_para_end(bool quoted=true)
Finish sending an HTTP parameter.
Definition: Adafruit_FONA.cpp:2037
bool enableNetworkTimeSync(bool onoff)
Enable network time sync.
Definition: Adafruit_FONA.cpp:998
bool getGSMLoc(uint16_t *replycode, char *buff, uint16_t maxlen)
Get GSM location.
Definition: Adafruit_FONA.cpp:1780
bool HTTP_term()
Terminate HTTP.
Definition: Adafruit_FONA.cpp:2005
void HTTP_para_start(FONAFlashStringPtr parameter, bool quoted=true)
Start sending an HTTP parameter.
Definition: Adafruit_FONA.cpp:2015
bool tuneFMradio(uint16_t station)
Set the FM Radio station.
Definition: Adafruit_FONA.cpp:514
bool deleteSMS(uint8_t message_index)
Delete an SMS Message.
Definition: Adafruit_FONA.cpp:925