example using LOF sensor board and MEMS sensor board. not using senet packet format

Dependencies:   ST_INTERFACES Senet_Packet X_NUCLEO_53L0A1 X_NUCLEO_COMMON X_NUCLEO_IKS01A1 libmDot-mbed5

Fork of unh-hackathon-example by Mike Fiore

Revision:
5:1a52bf3f0fb9
Parent:
2:a0fb0b785bd6
--- a/main.cpp	Sat Apr 08 13:02:20 2017 +0000
+++ b/main.cpp	Sat Apr 08 11:06:17 2017 -0400
@@ -1,6 +1,21 @@
 #include "mbed.h"
 #include "x_nucleo_iks01a1.h"
 #include "x_nucleo_53l0a1.h"
+#include "senet_packet.h"
+#include "mDot.h"
+#include "dot_util.h"
+
+//////////////////////////////////////////////////////////////////////////
+// * these options must match the the Senet credentials for your device //
+// * edit their values to match your configuration                      //
+/////////////////////////////////////////////////////////////////////////
+// Network Id for Senet public network
+static uint8_t app_eui[] = { 0x00, 0x25, 0x0C, 0x00, 0x00, 0x01, 0x00, 0x01 };
+// Register at or Sign in to http://portal.senetco.com/ and register your NodeId to receive your ApKey
+// replace this default key with yours
+static uint8_t app_key[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+mDot* dot = NULL;
 
 DevI2C i2c(D14, D15);
 
@@ -81,7 +96,12 @@
     int32_t axes[3];
     int ret;
     int status;
-    uint32_t distance;
+    uint32_t distance;    
+    std::vector<uint8_t> tx_data;
+    uint8_t buffer[64];
+    float value;
+        
+    SensorPacket packet(buffer, sizeof(buffer));
 
     printf("\r\n--- Application starting up ---\r\n");
 
@@ -91,8 +111,40 @@
     printf("\r\n--- Initializing range board ---\r\n");
     start_range_board();
 
+    printf("\r\n--- Initializing LoRa stack ---\r\n");
+    // get a handle to the stack
+    dot = mDot::getInstance();
+    // reset config to start from a known state
+    dot->resetConfig();
+    dot->resetNetworkSession();
+    dot->setLogLevel(mts::MTSLog::INFO_LEVEL);
+    if (dot->getJoinMode() != mDot::OTA) {
+        logInfo("changing network join mode to OTA");
+        if (dot->setJoinMode(mDot::OTA) != mDot::MDOT_OK) {
+            logError("failed to set network join mode to OTA");
+        }
+    }
+    update_ota_config_id_key(app_eui, app_key, 0, true, 0);
+    // save changes to configuration
+    logInfo("saving configuration");
+    if (!dot->saveConfig()) {
+        logError("failed to save configuration");
+    }
+
+    // display configuration
+    display_config();
+
+    // join network
     while (true) {
+        if (dot->joinNetwork() == mDot::MDOT_OK) {
+            break;
+        }
 
+        wait(1);
+    }
+
+    while (true) {
+        // display sensor data on debug port
         ret = temp_sensor1->get_temperature(&value1);
         if (ret) {
             printf("failed to get temp C\r\n");
@@ -102,8 +154,6 @@
             printf("failed to get humidity\r\n");
         }
         printf("HTS221: [temp] %7s°C,   [hum] %s%%\r\n", printDouble(buffer1, value1), printDouble(buffer2, value2));
-        //printf("HTS221: [temp] %f°C\r\n", value1);
-        //printf("HTS221: [hum] %f%%\r\n", value2);
 
         ret = temp_sensor2->get_fahrenheit(&value1);
         if (ret) {
@@ -114,8 +164,6 @@
             printf("failed to get pressure F\r\n");
         }
         printf("LPS25H: [temp] %7s°F, [press] %smbar\r\n", printDouble(buffer1, value1), printDouble(buffer2, value2));
-        //printf("LPS25H: [temp] %f°F\r\n", value1);
-        //printf("LPS25H: [press] %fmbar\r\n", value2);
 
         ret = magnetometer->get_m_axes(axes);
         if (ret) {
@@ -142,6 +190,23 @@
             printf("failed to get distance - possibly out of range!\r\n");
         }
 
+        // add temperature to packet - slot 0, sensor type 2
+        packet.addSensorValue(0, 2, (int16_t)value1);
+
+        // add distance to packet - slot 1, sensor type 3
+        packet.addSensorValue(1, 3, (int16_t)distance);
+
+        // add pressure to packet - slot 2, sensor type 4
+        packet.addSensorValue(2, 4, (int16_t)value2);
+
+        //serialize and send the data
+        packet.serialize();
+        tx_data.assign(packet.payload(), packet.payload() + packet.length());
+
+        if (dot->send(tx_data) != mDot::MDOT_OK) {
+            printf("failed to send data!\r\n");
+        }
+
         wait(1);
     }
 }