GSM library for nucleo L152RE
Dependencies: Adafruit_GSM
Diff: GSM_Wrapper.cpp
- Revision:
- 3:922cf54e97ec
- Parent:
- 1:9e13d8a84808
--- a/GSM_Wrapper.cpp Sat Dec 05 07:33:10 2015 +0000 +++ b/GSM_Wrapper.cpp Mon Dec 07 00:05:29 2015 +0000 @@ -1,5 +1,11 @@ #include "GSM_Wrapper.h" +/* Function: changePowerState + * -------------------------- + * Changes the power state by pulling the + * key to ground for 2 seconds (write(0)). No + * other way to turn GSM on/off. + */ void GSM_Sensor::changePowerState() { key.write(1); @@ -10,25 +16,33 @@ wait(2); } +/* Function: setup + * --------------- + * Has to be called each time the FONA + * is turned on. Sets the baud rate. Attempts + * to change the power state to turn it on if it + * fails. Sets up the network settings, then + * attempts to enable GPRS for ENABLE_GPRS_ATTEMPTS times. + */ void GSM_Sensor::setup() { printf("Starting FONA\n"); - if(!fona.begin(9600)){ + if(!fona.begin(FONA_BAUD_RATE)){ changePowerState(); printf("Cannot find FONA\n"); wait(2); } - if(!fona.begin(9600)){ + if(!fona.begin(FONA_BAUD_RATE)){ changePowerState(); return; } printf("After begin\n"); - fona.setGPRSNetworkSettings("pwg", "", ""); + fona.setGPRSNetworkSettings(NETWORK_APN, "", ""); // Note: May need to change other fields for different SIM cards printf("After set setting\n"); bool enable = false; int i = 0; while(enable != true) { - if(i > 5) break; + if(i > ENABLE_GPRS_ATTEMPTS) break; i++; fona.enableGPRS(true); fona.enableGPRS(false); @@ -37,6 +51,10 @@ printf("After enable\n"); } +/* Function: sendOverHTTP + * ---------------------- + * Sends the data over HTTP to the given URL. + */ bool GSM_Sensor::sendOverHTTP(char* url, uint8_t* data, int dlength) { uint16_t statuscode; @@ -58,6 +76,10 @@ return true; } +/* Function: send + * -------------- + * Public wrapper function for sendOverHTTP. + */ bool GSM_Sensor::send(uint8_t* data, size_t size) { setup();