GSM library for nucleo L152RE
Dependencies: Adafruit_GSM
Revision 3:922cf54e97ec, committed 2015-12-07
- Comitter:
- ptcrews
- Date:
- Mon Dec 07 00:05:29 2015 +0000
- Parent:
- 2:7f509d0d5c0e
- Commit message:
- Added comments.
Changed in this revision
GSM_Wrapper.cpp | Show annotated file Show diff for this revision Revisions of this file |
GSM_Wrapper.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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();
--- a/GSM_Wrapper.h Sat Dec 05 07:33:10 2015 +0000 +++ b/GSM_Wrapper.h Mon Dec 07 00:05:29 2015 +0000 @@ -1,9 +1,18 @@ #include "Adafruit_FONA.h" #include "main.h" +#include "storage.h" + +#define FONA_BAUD_RATE 9600 // FONA baud rate +#define ENABLE_GPRS_ATTEMPTS 5 // Number of attempts to enable GPRS if it fails #ifndef _GSM_WRAPPER_CLASS #define _GSM_WRAPPER_CLASS +/* Class: GSM_Sensor + * ----------------- + * A "wrapper" class for the GSM library, abstracting + * the Adafruit GSM library for use in this project. + */ class GSM_Sensor { public: GSM_Sensor(): fona(FONA_TX, FONA_RX, FONA_RST, FONA_RI), key(FONA_KEY) {}