GSM library for nucleo L152RE

Dependencies:   Adafruit_GSM

Dependents:   Full-Project

Revision:
1:9e13d8a84808
Child:
3:922cf54e97ec
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GSM_Wrapper.cpp	Sat Dec 05 07:29:49 2015 +0000
@@ -0,0 +1,69 @@
+#include "GSM_Wrapper.h"
+
+void GSM_Sensor::changePowerState()
+{
+    key.write(1);
+    wait(2);
+    key.write(0);
+    wait(2);
+    key.write(1);
+    wait(2);
+}
+
+void GSM_Sensor::setup()
+{
+    printf("Starting FONA\n");
+    if(!fona.begin(9600)){
+        changePowerState();
+        printf("Cannot find FONA\n");
+        wait(2);
+    }
+    if(!fona.begin(9600)){
+        changePowerState(); 
+        return;
+    }
+    printf("After begin\n");
+    fona.setGPRSNetworkSettings("pwg", "", "");
+    printf("After set setting\n");
+    bool enable = false;
+    int i = 0;
+    while(enable != true) {
+        if(i > 5) break;
+        i++;
+        fona.enableGPRS(true);
+        fona.enableGPRS(false);
+        enable = fona.enableGPRS(true);
+    }
+    printf("After enable\n");
+}
+
+bool GSM_Sensor::sendOverHTTP(char* url, uint8_t* data, int dlength)
+{
+    uint16_t statuscode;
+    int16_t length;
+    if (!fona.HTTP_POST_start(url, "text/plain", data, dlength, &statuscode, (uint16_t *)&length)) {
+        printf("Failed!\r\n");
+        return false;
+    }
+    while (length > 0) {
+        while (fona.readable()) {
+            char c = fona.getc();
+            putchar(c);
+            length--;
+            if (! length) break;
+        }
+    }
+    printf("\r\n****\r\n");
+    fona.HTTP_POST_end();
+    return true;
+}
+
+bool GSM_Sensor::send(uint8_t* data, size_t size)
+{
+    setup();
+    printf("Setup GSM\n");
+    bool res = sendOverHTTP(URL, data, size);
+    if(!res) res = sendOverHTTP(URL, data, size);
+    printf("After sent data\n");   
+    return res;
+}
\ No newline at end of file