A first code example to get you started with the QW (GPS) Shield for SIGFOX development. It provides a serial connection to the modem over usb and transmits a SIGFOX message upon a button press.

Dependencies:   mbed QW_Sensors

HelloWorld QW Development kit

Preloaded code example

The QW development kits ship with this code example. This example allows you to talk straight to the TD1208 modem when using a virtual com port (note: local echo is off). This code-example also sends a SIGFOX message whenever you press a button. The message contains the button number and the measured environment temperature. The first byte is always 0x01.

/media/uploads/quicksand/packetformat.jpg

More information and other example code can be found on the component page by clicking the link below: https://developer.mbed.org/components/QW-SIGFOX-Development-Kit/

Revision:
4:69df63eeb91e
Parent:
3:4da15d6e1429
Child:
5:ca670603d63d
--- a/main.cpp	Mon May 02 12:04:13 2016 +0000
+++ b/main.cpp	Tue Mar 14 14:54:35 2017 +0000
@@ -93,7 +93,6 @@
 /* TX data over Sigfox */
 void txData (uint8_t btn)
 {
-
     float    tAvg;
     char     command[32];
     sensor.Sense();
@@ -142,8 +141,13 @@
     /* Timeout for response of the modem */
     Timeout tmout;
     ser_timeout = false;
-    /* Buffer for incoming data */
-    char responsebuffer[6];
+    // check if ok or error is received
+    char * readyString = "OK";
+    char * readyStringPtr;
+    readyStringPtr = readyString;
+    char * errorString = "ERROR";
+    char * errorStringPtr;
+    errorStringPtr = errorString;
     /* Flag to set when we get 'OK' response */
     bool ok = false;
     bool error = false;
@@ -151,22 +155,24 @@
     modem.printf(command);
     /* Newline to activate command */
     modem.printf("\n");
-    /* Wait untill serial feedback, max 3 seconds before timeout */
-    tmout.attach(&sertmout, 3.0);
-    while(!modem.readable()&& ser_timeout == false);
-    while(!ok && !ser_timeout && !error) {
-        if(modem.readable()) {
-            for(int i = 0; i < 5; i++) {
-                responsebuffer[i] = responsebuffer[i+1];
+    /* Wait untill serial feedback, max 10 seconds before timeout */
+    tmout.attach(&sertmout, 10.0);
+    int c;
+    while(!ser_timeout && !ok && !error)
+        if(modem.readable())
+            while (((c = modem.getc()) > 0) && !ser_timeout  && !ok && !error) {
+                if ( (char)c == *readyStringPtr ) readyStringPtr++;
+                else readyStringPtr = readyString;
+                if ( *readyStringPtr == 0 ) {
+                    ok = true;
+                }
+                if ( (char)c == *errorStringPtr ) errorStringPtr++;
+                else errorStringPtr = errorString;
+                if ( *errorStringPtr == 0 ) {
+                    error = true;
+                }
             }
-            responsebuffer[5] = modem.getc();
-            if(responsebuffer[0] == '\r' && responsebuffer[1] == '\n' && responsebuffer[2] == 'O' && responsebuffer[3] == 'K' && responsebuffer[4] == '\r' && responsebuffer[5] == '\n' ) {
-                ok = true;
-            } else if(responsebuffer[0] == '\r' && responsebuffer[1] == '\n' && responsebuffer[2] == 'E' && responsebuffer[3] == 'R' && responsebuffer[4] == 'R' && responsebuffer[5] == 'O' ) {
-                error = true;
-            }
-        }
-    }
     tmout.detach();
-    return ok;
+    if(ser_timeout) return false;
+    else return ok;
 }
\ No newline at end of file