Code example to regularly report light level and temperature over Sigfox on the QW dev kit

Dependencies:   QW_Sensors mbed

Fork of QW_Temperature_Light_Monitor by Lieven Hollevoet

This is a code example that demonstrates sending the light level sensor and temperature sensor output over Sigfox at regular time intervals.

The payload that is sent over the network consists of 3 bytes:

  • two bytes light level reading
  • one byte temperature reading.

Use this code example as a start to connect your own device over Sigfox with the QW development kit.

Files at this revision

API Documentation at this revision

Comitter:
quicksand
Date:
Mon May 02 12:03:27 2016 +0000
Parent:
1:b2c941af91c6
Commit message:
Added a header byte (0x02) that indicates this example. Added blinking LED to show the device is alive.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r b2c941af91c6 -r 33e92af45279 main.cpp
--- a/main.cpp	Tue Mar 08 09:48:32 2016 +0000
+++ b/main.cpp	Mon May 02 12:03:27 2016 +0000
@@ -48,6 +48,7 @@
 /* Ticker for scheduled transmissions */
 Ticker tTX;
 Ticker tSense;
+Ticker heartbeat;
 
 /* Function prototypes */
 void sw1interrupt();
@@ -69,8 +70,15 @@
 /* Serial connection to sigfox modem */
 Serial modem(PA_9, PA_10);
 
+void beat()
+{
+    LED_3 = !LED_3;
+}
+
 int main()
 {
+    /* Blinking LED */
+    heartbeat.attach(&beat, 0.5);
     /* Storage for VCNL4010 readout */
     unsigned char ID=0, Current=0;
     //unsigned int  ProxiValue=0, AmbiValue=0;
@@ -207,6 +215,8 @@
 void sw2interrupt()
 {
     pc.printf("\n\rButton 2 pressed\n\r");
+    LED_1 = 0;
+    handleIRQ1 = true;
 }
 
 void dataScheduledTX()
@@ -232,11 +242,12 @@
     char     command[32];
     
     VCNL4010.ReadAmbiOnDemand (&ambiValue);      // read ambi value on demand
+    sensor.Sense();
     tAvg = sensor.GetAverageTemp();
     tAvgByte = (int8_t)tAvg;
     ambiValueShort = (uint16_t)ambiValue;
 
-    sprintf(command, "AT$SF=%04X%02X,2,0\n", ambiValueShort, tAvgByte);
+    sprintf(command, "AT$SF=02%04X%02X,2,0\n", ambiValueShort, tAvgByte);
     
     pc.printf("Sending ambient light level %i cts and temperature %i degrees C over Sigfox\n", ambiValueShort, tAvgByte);
     pc.printf("using modem command: %s", command);