Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add upd support #50

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
07b5573
[WIP] Added some general TCPIP methods so the user can select between…
feinstein Nov 12, 2015
e6e72a6
Added Apn Address, Username and Password as regulars strings also, so…
feinstein Dec 2, 2015
873963a
Added new methods for enabling and disabling the GPRS connection.
feinstein Jan 21, 2016
926237c
Add support for M0
driverblock Dec 10, 2015
ec2272b
fixed bug
driverblock Jan 1, 2016
00ddfaa
updated library properties
driverblock Jan 1, 2016
383e8f7
minimize timeout on boot
ladyada Jan 10, 2016
2a04010
fixie for reset mode
ladyada Jan 10, 2016
8a0fc1e
add 800H test and fixed SMS reading for 800H
ladyada Jan 10, 2016
6ea7a6b
Let user change the default SMS storage location
ladyada Jan 11, 2016
b7e4def
Merge with the library reorganization.
psychogenic Jan 16, 2016
9a89a0f
fix sms counter
ladyada Jan 17, 2016
c19475c
add AT+CSTT & AT+CIICR to enableGPRS
ladyada Jan 18, 2016
935dd2e
add username and pass to AT+CSTT, may work? may not? who knows!
ladyada Jan 18, 2016
9fedb60
not tested on 3G
ladyada Jan 19, 2016
a0b20b6
Fix for AT+CSTT command call
bittailor Jan 20, 2016
9734329
Corrected the timeout of some AT commands (CIPSHUT, SAPBR, CIICR), ta…
feinstein Jan 22, 2016
68d9bef
Found some strings still not in flash memory space.
feinstein Jan 22, 2016
4641ef5
Removed the malloc/free code, making all the strings fixed size.
feinstein Jan 24, 2016
e135e3f
Included the Bearer Profile configurations on enable and disable meth…
feinstein Feb 3, 2016
ed35a41
Merge branch 'master' into add-upd-support.
feinstein Apr 4, 2016
5a124b4
Removed the fixed internal buffer. Now the user has to provide one at…
feinstein Jun 21, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
547 changes: 468 additions & 79 deletions Adafruit_FONA.cpp

Large diffs are not rendered by default.

47 changes: 40 additions & 7 deletions Adafruit_FONA.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@
#define FONA_CALL_RINGING 3
#define FONA_CALL_INPROGRESS 4

enum ConnectionType {
TCP,
UDP
};

class Adafruit_FONA : public FONAStreamType {
public:
Adafruit_FONA(int8_t r);
Adafruit_FONA(int8_t rst, char externalBuffer[], size_t externalBufferSize);
boolean begin(FONAStreamType &port);
uint8_t type();

Expand Down Expand Up @@ -129,11 +134,15 @@ class Adafruit_FONA : public FONAStreamType {
boolean getTime(char *buff, uint16_t maxlen);

// GPRS handling
// deprecated, use only on legacy code.
boolean enableGPRS(boolean onoff);
boolean enableGPRS(void);
boolean disableGPRS(void);
uint8_t GPRSstate(void);
boolean getGSMLoc(uint16_t *replycode, char *buff, uint16_t maxlen);
boolean getGSMLoc(float *lat, float *lon);
void setGPRSNetworkSettings(FONAFlashStringPtr apn, FONAFlashStringPtr username=0, FONAFlashStringPtr password=0);
boolean setGPRSNetworkSettings(FONAFlashStringPtr apn, FONAFlashStringPtr username = NULL, FONAFlashStringPtr password = NULL);
boolean setGPRSNetworkSettings(const char *apn, const char *username = NULL, const char *password = NULL);

// GPS handling
boolean enableGPS(boolean onoff);
Expand All @@ -143,12 +152,23 @@ class Adafruit_FONA : public FONAStreamType {
boolean enableGPSNMEA(uint8_t nmea);

// TCP raw connections
// deprecated, use only on legacy code.
boolean TCPconnect(char *server, uint16_t port);
boolean TCPclose(void);
boolean TCPconnected(void);
boolean TCPsend(char *packet, uint8_t len);
uint16_t TCPavailable(void);
uint16_t TCPread(uint8_t *buff, uint8_t len);

// TCP/IP raw connections
boolean TcpipConnect(ConnectionType, char *server, uint16_t port);
boolean TcpipClose(void);
boolean TcpipConnected(void);
boolean TcpipSend(char *packet, uint8_t len);
uint16_t TcpipAvailable(void);
uint16_t TcpipRead(char *buff, uint8_t len);
boolean TcpipSetFixedPort(ConnectionType connType, uint16_t port);
boolean TcpipSetDynamicPort(ConnectionType connType);

// HTTP low level interface (maps directly to SIM800 commands).
boolean HTTP_init();
Expand Down Expand Up @@ -195,10 +215,17 @@ class Adafruit_FONA : public FONAStreamType {
int8_t _rstpin;
uint8_t _type;

char replybuffer[255];
FONAFlashStringPtr apn;
FONAFlashStringPtr apnusername;
FONAFlashStringPtr apnpassword;
char *replybuffer;
size_t replyBufferSize = 0;

FONAFlashStringPtr apn_P;
FONAFlashStringPtr apnUsername_P;
FONAFlashStringPtr apnPassword_P;

char apn[MAX_STRING_SIZE];
char apnUsername[MAX_STRING_SIZE];
char apnPassword[MAX_STRING_SIZE];

boolean httpsredirect;
FONAFlashStringPtr useragent;
FONAFlashStringPtr ok_reply;
Expand All @@ -215,11 +242,13 @@ class Adafruit_FONA : public FONAStreamType {
uint8_t getReply(FONAFlashStringPtr prefix, int32_t suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
uint8_t getReply(FONAFlashStringPtr prefix, int32_t suffix1, int32_t suffix2, uint16_t timeout); // Don't set default value or else function call is ambiguous.
uint8_t getReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
uint8_t getReplyQuoted(FONAFlashStringPtr prefix, const char *suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);

boolean sendCheckReply(FONAFlashStringPtr prefix, char *suffix, FONAFlashStringPtr reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
boolean sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, FONAFlashStringPtr reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
boolean sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, int32_t suffix2, FONAFlashStringPtr reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
boolean sendCheckReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, FONAFlashStringPtr reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
boolean sendCheckReplyQuoted(FONAFlashStringPtr prefix, const char *suffix, FONAFlashStringPtr reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);


boolean parseReply(FONAFlashStringPtr toreply,
Expand All @@ -233,6 +262,9 @@ class Adafruit_FONA : public FONAStreamType {
FONAFlashStringPtr toreply,
uint16_t *v, char divider = ',', uint8_t index=0);

boolean isStringValid(const char string[], size_t size);
boolean isStringValid(FONAFlashStringPtr string, size_t size);

static boolean _incomingCall;
static void onIncomingCall();

Expand All @@ -242,7 +274,8 @@ class Adafruit_FONA : public FONAStreamType {
class Adafruit_FONA_3G : public Adafruit_FONA {

public:
Adafruit_FONA_3G (int8_t r) : Adafruit_FONA(r) { _type = FONA3G_A; }
Adafruit_FONA_3G(int8_t rst, char externalBuffer[], size_t externalBufferSize) :
Adafruit_FONA(rst, externalBuffer, externalBufferSize) { _type = FONA3G_A; }

boolean getBattVoltage(uint16_t *v);
boolean playToolkitTone(uint8_t t, uint16_t len);
Expand Down
2 changes: 1 addition & 1 deletion examples/FONA3G_setbaud/FONA3G_setbaud.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ SoftwareSerial *fonaSerial = &fonaSS;
// Hardware serial is also possible!
// HardwareSerial *fonaSerial = &Serial1;

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
Adafruit_FONA fona = Adafruit_FONA(FONA_RST, replybuffer, sizeof(replybuffer));

uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);

Expand Down
2 changes: 1 addition & 1 deletion examples/FONA_SMS_Response/FONA_SMS_Response.ino
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ SoftwareSerial *fonaSerial = &fonaSS;
// Hardware serial is also possible!
// HardwareSerial *fonaSerial = &Serial1;

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
Adafruit_FONA fona = Adafruit_FONA(FONA_RST, replybuffer, sizeof(replybuffer));

uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);

Expand Down
104 changes: 97 additions & 7 deletions examples/FONAtest/FONAtest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ the commented section below at the end of the setup() function.
// this is a large buffer for replies
char replybuffer[255];

// this is a large buffer for FONA's internal use.
char fonabuffer[255];

// We default to using software serial. If you want to use hardware serial
// (because softserial isnt supported) comment out the following three lines
// and uncomment the HardwareSerial line
Expand All @@ -45,9 +48,9 @@ SoftwareSerial *fonaSerial = &fonaSS;
// HardwareSerial *fonaSerial = &Serial1;

// Use this for FONA 800 and 808s
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
Adafruit_FONA fona = Adafruit_FONA(FONA_RST, fonabuffer, sizeof(fonabuffer));
// Use this one for FONA 3G
//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);
//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST, fonabuffer, sizeof(fonabuffer));

uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);

Expand Down Expand Up @@ -154,7 +157,17 @@ void printMenu(void) {
Serial.println(F("[g] Disable GPRS"));
Serial.println(F("[l] Query GSMLOC (GPRS)"));
Serial.println(F("[w] Read webpage (GPRS)"));
Serial.println(F("[W] Post to website (GPRS)"));
Serial.println(F("[W] Post to website (GPRS)"));
// GPRS - TCPIP
Serial.println(F("[k] Connect to server using TCP"));
Serial.println(F("[K] Connect to server using UDP"));
Serial.println(F("[j] Close connection with server"));
Serial.println(F("[I] Check if connected to server"));
Serial.println(F("[Q] Send Packet to server"));
Serial.println(F("[J] Get how many bytes are available to read from the server"));
Serial.println(F("[X] Read Packet from server"));
Serial.println(F("[z] Set fixed port"));
Serial.println(F("[Z] set dynamic port"));

// GPS
if ((type == FONA3G_A) || (type == FONA3G_E) || (type == FONA808_V1) || (type == FONA808_V2)) {
Expand Down Expand Up @@ -690,14 +703,27 @@ void loop() {

case 'g': {
// turn GPRS off
if (!fona.enableGPRS(false))
if (!fona.disableGPRS())
Serial.println(F("Failed to turn off"));
break;
}
case 'G': {
// turn GPRS on
if (!fona.enableGPRS(true))
Serial.println(F("Failed to turn on"));
int retry = 0;
boolean success = false;
// turn GPRS on
fona.setGPRSNetworkSettings(F("myAPN.com"), F("myUsername"), F("myPassword"));

while (retry < 10) {
if (fona.enableGPRS()) {
success = false;
break;
}
delay(20);
retry++;
}
if (!success) {
Serial.println(F("Failed to turn on"));
}
break;
}
case 'l': {
Expand Down Expand Up @@ -791,6 +817,70 @@ void loop() {
fona.HTTP_POST_end();
break;
}

case 'k' : {
// Connect to server using TCP
if (!fona.TcpipConnect(TCP, "255.255.255.255", 12345)) {
Serial.println(F("Failed to connect with server using TCP"));
}
}
case 'K' : {
// Connect to server using UDP
if (!fona.TcpipConnect(UDP, "255.255.255.255", 12345)) {
Serial.println(F("Failed to connect with server using UDP"));
}
}
case 'j' : {
// Close connection with server
if (!fona.TcpipClose()) {
Serial.println(F("Failed to close the connection"));
}
}
case 'I' : {
// Check if connected to server
if (fona.TcpipConnected()) {
Serial.println(F("Connected!"));
}
else {
Serial.println(F("Not Connected!"));
}
}
case 'Q' : {
// Send Packet to server
char message[] = { 0xDE, 0xAD, 0xBE, 0xEF };
if (!fona.TcpipSend(message, sizeof(message))) {
Serial.println(F("Failed to send data to server"));
}
}

case 'J' : {
// Get how many bytes are available to read from the server
uint16_t replySize = fona.TcpipAvailable();
Serial.print(replySize);
Serial.println(F(" bytes are available to read from the server"));
}

case 'X' : {
// Read Packet from server
uint16_t replySize = 0;
replySize = fona.TcpipRead((uint8_t*)replybuffer, sizeof(replybuffer));
Serial.print(replySize);
Serial.println(F(" bytes read from server"));

}
case 'z' : {
// Set fixed port
if (!fona.TcpipSetFixedPort(UDP, 12345)) {
Serial.println(F("Failed to set fixed port"));
}
}
case 'Z' : {
// set dynamic port
if (!fona.TcpipSetDynamicPort(UDP)) {
Serial.println(F("Failed to set dynamic port"));
}
}

/*****************************************/

case 'S': {
Expand Down
7 changes: 5 additions & 2 deletions examples/GPS/GPS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ SoftwareSerial *fonaSerial = &fonaSS;
// Hardware serial is also possible!
// HardwareSerial *fonaSerial = &Serial1;

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
// this is a large buffer for FONA's internal use.
char fonabuffer[255];

Adafruit_FONA fona = Adafruit_FONA(FONA_RST, fonabuffer, sizeof(fonabuffer));

// Have a FONA 3G? use this object type instead
//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);
//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST, fonabuffer, sizeof(fonabuffer));


void setup() {
Expand Down
5 changes: 4 additions & 1 deletion examples/IncomingCall/IncomingCall.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ SoftwareSerial *fonaSerial = &fonaSS;
// Hardware serial is also possible!
// HardwareSerial *fonaSerial = &Serial1;

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
// this is a large buffer for FONA's internal use.
char fonabuffer[255];

Adafruit_FONA fona = Adafruit_FONA(FONA_RST, fonabuffer, sizeof(fonabuffer));

void setup() {
Serial.begin(115200);
Expand Down
4 changes: 2 additions & 2 deletions includes/FONAConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* DebugStream set in the appropriate platform/ header.
*/

#define ADAFRUIT_FONA_DEBUG

//#define ADAFRUIT_FONA_DEBUG
#define MAX_STRING_SIZE 100

#endif /* ADAFRUIT_FONA_LIBRARY_SRC_INCLUDES_FONACONFIG_H_ */
3 changes: 2 additions & 1 deletion includes/platform/FONAPlatStd.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ typedef const __FlashStringHelper * FONAFlashStringPtr;
// define prog_char_strncmp(a, b, c) strncmp_P((a), (b), (c))
#define prog_char_strstr(a, b) strstr_P((a), (b))
#define prog_char_strlen(a) strlen_P((a))
#define prog_char_strnlen(a, len) strnlen_P((a), (len))
#define prog_char_strcpy(to, fromprogmem) strcpy_P((to), (fromprogmem))
//define prog_char_strncpy(to, from, len) strncpy_P((to), (fromprogmem), (len))
#define prog_char_strncpy(to, fromprogmem, len) strncpy_P((to), (fromprogmem), (len))

#endif /* ADAFRUIT_FONA_LIBRARY_SRC_INCLUDES_PLATFORM_FONAPLATSTD_H_ */
7 changes: 7 additions & 0 deletions includes/platform/FONAPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,17 @@
#define prog_char_strlen(a) strlen((a))
#endif

#ifndef prog_char_strnlen
#define prog_char_strnlen(a, len) strnlen((a), (len))
#endif

#ifndef prog_char_strcpy
#define prog_char_strcpy(to, fromprogmem) strcpy((to), (fromprogmem))
#endif

#ifndef prog_char_strncpy
#define prog_char_strncpy(to, fromprogmem, len) strncpy_P((to), (fromprogmem), (len))
#endif


#endif /* ADAFRUIT_FONA_LIBRARY_SRC_INCLUDES_PLATFORM_FONAPLATFORM_H_ */