Example of using the mDot UDK with the X-NUCLEO-IKS01A2 board

Dependencies:   MTS_X_NUCLEO_IKS01A2 libmDot-mbed5

Fork of mDot-IKS01A1 by Peter Ferland

Revision:
12:63e90d375afd
Parent:
10:1e3e3ab9c29c
Child:
13:e165a137c3af
--- a/main.cpp	Tue Feb 14 20:36:21 2017 +0000
+++ b/main.cpp	Fri Jan 26 17:39:50 2018 +0000
@@ -1,39 +1,49 @@
 #include "mbed.h"
 #include "mDot.h"
-#include "x_nucleo_iks01a1.h"
+#include "XNucleoIKS01A2.h"
 #include "dot_util.h"
 #include "RadioEvent.h"
 #include <cmath>
 
+#define TTN
+
 // mDot UDK board demo with X-NUCLEO-IKS01A1 sensor card
 // For more examples see the Dot-Examples project:
 // https://developer.mbed.org/teams/MultiTech/code/Dot-Examples/
 
 // This triggers an I2C issue in mbed-os 5.1.5
 // Use any other revision to compile. (Tested with libmDot-dev/mbed-os 5.2.2
-#define SENET
+//#define ACTILITY
 #ifdef ACTILITY
 // Network Id for Senet public network
 static uint8_t network_id[] = {0xF0, 0x3D, 0x29,0xAC,0x71,0x00,0x00, 0x00};
-// Register at or Sign in to http://portal.senetco.com/ and register your NodeId to receive your AppId
-// {0xD3,0x5A,0x30,0x60,0xA6,0x0D,0x9E,0xEA,0xD9,0xA1,0x19,0x61,0x4F,0x29,0x9E,0x5B}
-static uint8_t network_key[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //{0xD3,0x5A,0x30,0x60,0xA6,0x0D,0x9E,0xEA,0xD9,0xA1,0x19,0x61,0x4F,0x29,0x9E,0x5B};
+static uint8_t network_key[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
 static uint8_t frequency_sub_band = 0;
 static bool public_network = true;
 #elif defined(SENET)
 // Network Id for Senet public network
 static uint8_t network_id[] = {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 AppId
-// {0xD3,0x5A,0x30,0x60,0xA6,0x0D,0x9E,0xEA,0xD9,0xA1,0x19,0x61,0x4F,0x29,0x9E,0x5B}
-static uint8_t network_key[] =  {0x5F,0x7B,0x08,0x15,0x55,0x69,0x9A,0x2E,0x3C,0x91,0xE3,0xFE,0xF0,0x2A,0x77,0x79};
+// 
+static uint8_t network_key[] =  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
 // 1 For Senet, configurable on your Conduit
 static uint8_t frequency_sub_band = 1;
 // True for Senet, false for your Conduit.
 static bool public_network = true;
+#elif defined(TTN)
+// Network Id for TheThingsNetwork public network
+static uint8_t network_id[] = {0x70,0xB3,0xD5,0x7E,0xD0,0x00,0x98,0xE6}; 
+// Network Key is known as "App Key" in TTN console
+static uint8_t network_key[] =  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+// FSB if supported by region
+static uint8_t frequency_sub_band = 1;
+
+static bool public_network = true;
+
 #else
 //Replace with settings on your Conduit
-static std::string network_name = "EcoLabTest";
-static std::string network_passphrase = "EcoLabTest"; 
+static std::string network_name = "TestTest";
+static std::string network_passphrase = "TestTest"; 
 // 1 For Senet, configurable on your Conduit
 static uint8_t frequency_sub_band = 1;
 // True for Senet, false for your Conduit.
@@ -55,16 +65,28 @@
     Serial pc(USBTX, USBRX);
     
     /* Instantiate the expansion board */
-    X_NUCLEO_IKS01A1 *mems_expansion_board = X_NUCLEO_IKS01A1::Instance(I2C_SDA, I2C_SCL, PC_1);
+    XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(I2C_SDA, I2C_SCL, PC_1);
     
     /* Retrieve the composing elements of the expansion board */
-    GyroSensor *gyroscope = mems_expansion_board->GetGyroscope();
-    MotionSensor *accelerometer = mems_expansion_board->GetAccelerometer();
+    /* Retrieve the composing elements of the expansion board */
+//    LSM303AGRMagSensor *magnetometer = mems_expansion_board->magnetometer;
+//    HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor;
+//    LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor;
+//    LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro;
+//    LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer;
+    GyroSensor *gyroscope = mems_expansion_board->acc_gyro;
+    mems_expansion_board->acc_gyro->enable_g();
+    MotionSensor *accelerometer = mems_expansion_board->accelerometer;
+    mems_expansion_board->accelerometer->enable();
     MagneticSensor *magnetometer = mems_expansion_board->magnetometer;
+    mems_expansion_board->magnetometer->enable();
     HumiditySensor *humidity_sensor = mems_expansion_board->ht_sensor;
+    mems_expansion_board->ht_sensor->enable();
     PressureSensor *pressure_sensor = mems_expansion_board->pt_sensor;
+    mems_expansion_board->pt_sensor->enable();
     TempSensor *temp_sensor1 = mems_expansion_board->ht_sensor;
     TempSensor *temp_sensor2 = mems_expansion_board->pt_sensor;
+    
     // Custom event handler for automatically displaying RX data
     RadioEvent events;
     pc.baud(115200);
@@ -103,7 +125,7 @@
         // in OTA and AUTO_OTA join modes, the credentials can be passed to the library as a name and passphrase or an ID and KEY
         // only one method or the other should be used!
         // network ID = crc64(network name)
-#if defined(SENET) || defined(ACTILITY)
+#if defined(SENET) || defined(ACTILITY) || defined(TTN)
         // network KEY = cmac(network passphrase)
         update_ota_config_id_key(network_id, network_key, frequency_sub_band, public_network, ack);
 #else
@@ -158,7 +180,7 @@
          * LPP 103
          * HEX: 67
          * Data size: 2
-         * Resolution: 0.1 degres C
+         * Resolution: 0.1 degrees C
          
          * Humidity sensor
          * IPSO: 3304
@@ -193,8 +215,8 @@
         float value1, value2;
         
         // HTS221 Humidity sensor
-        temp_sensor1->GetTemperature(&value1);
-        humidity_sensor->GetHumidity(&value2);
+        temp_sensor1->get_temperature(&value1);
+        humidity_sensor->get_humidity(&value2);
         
         //serialize data and append to packet
         // Cayenne data: temperature; tag is 0x67, 2 bytes signed, 0.1 C/bit
@@ -214,8 +236,8 @@
         logInfo("Temperature data %f", value1);
         logInfo("Humidity data: %f", value2);
         
-        pressure_sensor->GetPressure(&value1);
-        logInfo("PRessure data: %f", value1);
+        pressure_sensor->get_pressure(&value1);
+        logInfo("Pressure data: %f", value1);
         // pressure is reported in mbar, cayenne wants it in 0.1 hPa
         // 1mbar = 1 hPa
         temp = floor(value1 * 100.0f + 0.5f);
@@ -229,7 +251,7 @@
         // Get accelerometer data
         int32_t accel_vector[3];
         // returns in mG
-        accelerometer->Get_X_Axes(accel_vector);
+        accelerometer->get_x_axes(accel_vector);
         logInfo("Acclerometer Z axis: %d", accel_vector[2]);
         
         tx_data.push_back(uint8_t(4)); // data id
@@ -240,7 +262,8 @@
         }
         
         // Get gyro data
-        gyroscope->Get_G_Axes(accel_vector);
+        gyroscope->get_g_axes
+        (accel_vector);
         // gyro reports in milidegrees/sec, cayenne wants centidegrees/sec
         tx_data.push_back(uint8_t(5)); //data id
         tx_data.push_back(uint8_t(0x86)); // data type - gyrometer