Adafruit FONA 800H breakout
Dependencies: mbed
Diff: Adafruit_FONA.h
- Revision:
- 15:19a02a88836a
- Parent:
- 10:9dd3e49dec97
- Child:
- 16:18750ad91289
--- a/Adafruit_FONA.h Wed Mar 30 02:00:59 2016 +0000 +++ b/Adafruit_FONA.h Wed Mar 30 02:35:20 2016 +0000 @@ -291,10 +291,25 @@ bool getSMSSender(uint8_t i, char *sender, int senderlen); // Time---------------------------------------------------------------------- + /** Enable FONA to sync time with the cellular network + @param onoff on = true, off = false + @return TRUE if successful + */ bool enableNetworkTimeSync(bool onoff); + + /** Enable FONA to sync time with the time server + @param onoff true = on, false = off + @return TRUE if successful + */ bool enableNTPTimeSync(bool onoff, const char* ntpserver=0); + + /** Retrieve the current time from the enabled server + @param buff char array to store time value. Given as "yy/MM/dd,hh:mm:ss+zz" + @param maxlen Maximum length of the char array + @return TRUE if successful + */ bool getTime(char* buff, uint16_t maxlen); - + // GPRS handling---------------------------------------------------------------------- bool enableGPRS(bool onoff); uint8_t GPRSstate(void); @@ -308,7 +323,7 @@ uint8_t getGPS(uint8_t arg, char *buffer, uint8_t maxbuff); bool getGPS(float *lat, float *lon, float *speed_kph=0, float *heading=0, float *altitude=0); bool enableGPSNMEA(uint8_t nmea); - + // TCP raw connections---------------------------------------------------------------------- bool TCPconnect(char *server, uint16_t port); bool TCPclose(void); @@ -316,7 +331,7 @@ bool TCPsend(char *packet, uint8_t len); uint16_t TCPavailable(void); uint16_t TCPread(uint8_t *buff, uint8_t len); - + // HTTP low level interface (maps directly to SIM800 commands).---------------------------------------------------------------------- bool HTTP_init(); bool HTTP_term(); @@ -328,76 +343,101 @@ bool HTTP_action(uint8_t method, uint16_t *status, uint16_t *datalen, int32_t timeout = 10000); bool HTTP_readall(uint16_t *datalen); bool HTTP_ssl(bool onoff); - + // HTTP high level interface (easier to use, less flexible).---------------------------------------------------------------------- bool HTTP_GET_start(char *url, uint16_t *status, uint16_t *datalen); void HTTP_GET_end(void); bool HTTP_POST_start(char *url, const char* contenttype, const uint8_t *postdata, uint16_t postdatalen, uint16_t *status, uint16_t *datalen); void HTTP_POST_end(void); void setUserAgent(const char* useragent); - + // HTTPS---------------------------------------------------------------------- void setHTTPSRedirect(bool onoff); - + // PWM (buzzer)---------------------------------------------------------------------- + /** Control the buzzer capability of the PWM out on the FONA + @param period of the buzzing cycle (max 2000) + @param duty the duty cycle of the buzzer (0 to 100) + @return TRUE if successful + */ bool setPWM(uint16_t period, uint8_t duty = 50); - + // Phone calls---------------------------------------------------------------------- + /** Call a phone + @param phonenum a character array of the phone number + @return TRUE if successful + */ bool callPhone(char *phonenum); + + /** Hang up a phone call + */ bool hangUp(void); + + /** Answer a phone call + */ bool pickUp(void); + + /** Enable/disable caller ID + @param enable true to enable, false to disable + @return TRUE if successful + */ bool callerIdNotification(bool enable); + + /** Retrieve the incoming call number + @param phonenum a character array of the phone number calling + @return TRUE if successful + */ bool incomingCallNumber(char* phonenum); - + // Helper functions to verify responses. bool expectReply(const char* reply, uint16_t timeout = 10000); - + private: DigitalOut _rstpin; InterruptIn _ringIndicatorInterruptIn; - + char replybuffer[255]; // the output of getreply(), readline() is the function that changes the replybuffer char* apn; char* apnusername; char* apnpassword; bool httpsredirect; char* useragent; - + volatile bool _incomingCall; EventListener *eventListener; Serial mySerial; - + // Circular buffer used to receive serial data from an interruption int rxBuffer[RX_BUFFER_SIZE + 1]; volatile int rxBufferInIndex; // Index where new data is added to the buffer volatile int rxBufferOutIndex; // Index where data is removed from the buffer char currentReceivedLine[RX_BUFFER_SIZE]; // Array containing the current received line int currentReceivedLineSize; - + inline bool isRxBufferFull() { return ((rxBufferInIndex + 1) % RX_BUFFER_SIZE) == rxBufferOutIndex; } - + inline bool isRxBufferEmpty() { return rxBufferInIndex == rxBufferOutIndex; } - + inline void incrementRxBufferInIndex() { rxBufferInIndex = (rxBufferInIndex + 1) % RX_BUFFER_SIZE; } - + inline void incrementRxBufferOutIndex() { rxBufferOutIndex = (rxBufferOutIndex + 1) % RX_BUFFER_SIZE; } - + /** * Method called when Serial data is received (interrupt routine). */ void onSerialDataReceived(); - + // HTTP helpers bool HTTP_setup(char *url); - + void flushInput(); uint16_t readRaw(uint16_t b); uint8_t readline(uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS, bool multiline = false); @@ -406,19 +446,19 @@ uint8_t getReply(const char* prefix, int32_t suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); uint8_t getReply(const char* prefix, int32_t suffix1, int32_t suffix2, uint16_t timeout); // Don't set default value or else function call is ambiguous. uint8_t getReplyQuoted(const char* prefix, const char* suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); - + bool sendCheckReply(const char* send, const char* reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); bool sendCheckReply(const char* prefix, char *suffix, const char* reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); bool sendCheckReply(const char* prefix, int32_t suffix, const char* reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); bool sendCheckReply(const char* prefix, int32_t suffix, int32_t suffix2, const char* reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); bool sendCheckReplyQuoted(const char* prefix, const char* suffix, const char* reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); - + bool parseReply(const char* toreply, uint16_t *v, char divider = ',', uint8_t index=0); bool parseReply(const char* toreply, char *v, char divider = ',', uint8_t index=0); bool parseReplyQuoted(const char* toreply, char* v, int maxlen, char divider, uint8_t index); - + bool sendParseReply(const char* tosend, const char* toreply, uint16_t *v, char divider = ',', uint8_t index = 0); - + void onIncomingCall(); };