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/

Committer:
quicksand
Date:
Fri Oct 30 14:10:26 2015 +0000
Revision:
0:49858c4c3500
Child:
1:897a1b3f0955
First version of a simple code-example using the QW GPS Shield

Who changed what in which revision?

UserRevisionLine numberNew contents of line
quicksand 0:49858c4c3500 1 #include "mbed.h"
quicksand 0:49858c4c3500 2
quicksand 0:49858c4c3500 3 DigitalOut LED_0 (PB_6);
quicksand 0:49858c4c3500 4 DigitalOut LED_1 (PA_7);
quicksand 0:49858c4c3500 5 DigitalOut LED_2 (PA_6);
quicksand 0:49858c4c3500 6 DigitalOut LED_3 (PA_5);
quicksand 0:49858c4c3500 7 InterruptIn SW1(PB_10);
quicksand 0:49858c4c3500 8 InterruptIn SW2(PA_8);
quicksand 0:49858c4c3500 9
quicksand 0:49858c4c3500 10 Ticker hartbeat;
quicksand 0:49858c4c3500 11
quicksand 0:49858c4c3500 12 typedef struct{
quicksand 0:49858c4c3500 13 bool busy;
quicksand 0:49858c4c3500 14 char button;
quicksand 0:49858c4c3500 15 } TX_BUTTON;
quicksand 0:49858c4c3500 16
quicksand 0:49858c4c3500 17 TX_BUTTON Button_tx;
quicksand 0:49858c4c3500 18
quicksand 0:49858c4c3500 19 void beat() {
quicksand 0:49858c4c3500 20 LED_0 = !LED_0;
quicksand 0:49858c4c3500 21 }
quicksand 0:49858c4c3500 22
quicksand 0:49858c4c3500 23 //Virtual serial port over USB
quicksand 0:49858c4c3500 24 Serial pc(USBTX, USBRX);
quicksand 0:49858c4c3500 25 Serial modem(PA_9, PA_10);
quicksand 0:49858c4c3500 26
quicksand 0:49858c4c3500 27 void sw1interrupt(){
quicksand 0:49858c4c3500 28 pc.printf("Button 1 pressed, sending sigfox message (command is AT$SF=42 55 54 54 4f 4e 20 31 00 00 00 00,2,0)\n");
quicksand 0:49858c4c3500 29 modem.printf("AT$SF=42 55 54 54 4f 4e 20 31 00 00 00 00,2,0\n");
quicksand 0:49858c4c3500 30 LED_1 = 0;
quicksand 0:49858c4c3500 31 wait(0.25);
quicksand 0:49858c4c3500 32 // Flush the echo of the command:
quicksand 0:49858c4c3500 33 while(modem.readable()) modem.getc();
quicksand 0:49858c4c3500 34 Button_tx.busy = true;
quicksand 0:49858c4c3500 35 Button_tx.button = 1;
quicksand 0:49858c4c3500 36 }
quicksand 0:49858c4c3500 37
quicksand 0:49858c4c3500 38 void sw2interrupt(){
quicksand 0:49858c4c3500 39 pc.printf("Button 2 pressed, sending sigfox message (command is AT$SF=42 55 54 54 4f 4e 20 32 00 00 00 00,2,0)\n");
quicksand 0:49858c4c3500 40 modem.printf("AT$SF=42 55 54 54 4f 4e 20 32 00 00 00 00,2,0\n");
quicksand 0:49858c4c3500 41 LED_2 = 0;
quicksand 0:49858c4c3500 42 wait(0.25);
quicksand 0:49858c4c3500 43 // Flush the echo of the command:
quicksand 0:49858c4c3500 44 while(modem.readable()) modem.getc();
quicksand 0:49858c4c3500 45 Button_tx.busy = true;
quicksand 0:49858c4c3500 46 Button_tx.button = 2;
quicksand 0:49858c4c3500 47 }
quicksand 0:49858c4c3500 48
quicksand 0:49858c4c3500 49 int main() {
quicksand 0:49858c4c3500 50
quicksand 0:49858c4c3500 51 LED_0 = 1;
quicksand 0:49858c4c3500 52 LED_1 = 1;
quicksand 0:49858c4c3500 53 LED_2 = 1;
quicksand 0:49858c4c3500 54 LED_3 = 1;
quicksand 0:49858c4c3500 55 hartbeat.attach(&beat, 0.5);
quicksand 0:49858c4c3500 56 Button_tx.busy = false;
quicksand 0:49858c4c3500 57 Button_tx.button = 0;
quicksand 0:49858c4c3500 58 SW2.fall(&sw1interrupt);
quicksand 0:49858c4c3500 59 SW1.fall(&sw2interrupt);
quicksand 0:49858c4c3500 60 char responsebuffer[2];
quicksand 0:49858c4c3500 61 char c;
quicksand 0:49858c4c3500 62 while(1) {
quicksand 0:49858c4c3500 63 if(pc.readable()) {
quicksand 0:49858c4c3500 64 modem.putc(pc.getc());
quicksand 0:49858c4c3500 65 }
quicksand 0:49858c4c3500 66
quicksand 0:49858c4c3500 67 if(modem.readable()) {
quicksand 0:49858c4c3500 68 c = modem.getc();
quicksand 0:49858c4c3500 69 responsebuffer[0] = responsebuffer[1];
quicksand 0:49858c4c3500 70 responsebuffer[1] = c;
quicksand 0:49858c4c3500 71 if(Button_tx.busy)
quicksand 0:49858c4c3500 72 {
quicksand 0:49858c4c3500 73 if(responsebuffer[0] == 'O' && responsebuffer[1] == 'K' )
quicksand 0:49858c4c3500 74 {
quicksand 0:49858c4c3500 75 // Everything went fine, turn off the LED
quicksand 0:49858c4c3500 76 Button_tx.busy = false;
quicksand 0:49858c4c3500 77 if(Button_tx.button == 1) LED_1 = 1;
quicksand 0:49858c4c3500 78 if(Button_tx.button == 2) LED_2 = 1;
quicksand 0:49858c4c3500 79 }
quicksand 0:49858c4c3500 80 }
quicksand 0:49858c4c3500 81 pc.putc(c);
quicksand 0:49858c4c3500 82 }
quicksand 0:49858c4c3500 83 }
quicksand 0:49858c4c3500 84 }