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/

main.cpp

Committer:
quicksand
Date:
2015-10-30
Revision:
0:49858c4c3500
Child:
1:897a1b3f0955

File content as of revision 0:49858c4c3500:

#include "mbed.h"

DigitalOut LED_0 (PB_6);
DigitalOut LED_1 (PA_7);
DigitalOut LED_2 (PA_6);
DigitalOut LED_3 (PA_5);
InterruptIn SW1(PB_10);
InterruptIn SW2(PA_8);

Ticker hartbeat;

typedef struct{
   bool busy;
   char button;
} TX_BUTTON;

TX_BUTTON Button_tx;

void beat() {
    LED_0 = !LED_0;
}
 
//Virtual serial port over USB
Serial pc(USBTX, USBRX);
Serial modem(PA_9, PA_10);

void sw1interrupt(){
        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");
        modem.printf("AT$SF=42 55 54 54 4f 4e 20 31 00 00 00 00,2,0\n");
        LED_1 = 0;
        wait(0.25);
        // Flush the echo of the command:
        while(modem.readable()) modem.getc();
        Button_tx.busy = true;
        Button_tx.button = 1;
} 

void sw2interrupt(){
        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");
        modem.printf("AT$SF=42 55 54 54 4f 4e 20 32 00 00 00 00,2,0\n");
        LED_2 = 0;
        wait(0.25);
        // Flush the echo of the command:
        while(modem.readable()) modem.getc();
        Button_tx.busy = true;
        Button_tx.button = 2;           
} 

int main() {
    
    LED_0 = 1;
    LED_1 = 1;
    LED_2 = 1;
    LED_3 = 1;
    hartbeat.attach(&beat, 0.5);
    Button_tx.busy = false;
    Button_tx.button = 0;    
    SW2.fall(&sw1interrupt);
    SW1.fall(&sw2interrupt);
    char responsebuffer[2];
    char c; 
    while(1) {   
        if(pc.readable()) {
            modem.putc(pc.getc());
        }
        
        if(modem.readable()) {
            c = modem.getc();
            responsebuffer[0] = responsebuffer[1];
            responsebuffer[1] = c;
            if(Button_tx.busy)
            {
                if(responsebuffer[0] == 'O' && responsebuffer[1] == 'K' )
                {
                    // Everything went fine, turn off the LED
                    Button_tx.busy = false;
                    if(Button_tx.button == 1) LED_1 = 1;
                    if(Button_tx.button == 2) LED_2 = 1;
                }    
            }    
            pc.putc(c);
        }
    }
}