mDot EVB to M2X demo.

Dependencies:   DOGS102 ISL29011 MMA845x MPL3115A2 NCP5623B libmDot mbed-rtos mbed-src

Fork of MTDOT-EVBDemo by Multi-Hackers

Revision:
4:71e411fbd9ff
Parent:
3:68e974f5f532
Child:
5:72d4d95e1d42
--- a/main.cpp	Wed Jul 15 14:20:33 2015 +0000
+++ b/main.cpp	Thu Jul 16 21:00:37 2015 +0000
@@ -28,6 +28,8 @@
  *
  * 1.03 TAB 7/15/15 Added threads for push button switch debounce.
  *
+ * 1.04 JCM 7/16/15 Updated application to use with ATT m2x
+ *
  */
 
 #include "mbed.h"
@@ -43,6 +45,38 @@
 #include <string>
 #include <vector>
 
+
+
+/*
+ * Conduit AEP settings
+ *
+ * AEP settings can be found at: https://<ip-address>/lora_network.html
+ */
+static std::string config_network_name = "testtest";
+static std::string config_network_pass = "memememe";
+static uint8_t config_frequency_sub_band = 5;
+
+/*
+ * M2X settings
+ *
+ * M2X settings can be found at: https://m2x.att.com/devices
+ * Once a device is added you will see DEVICE ID and PRIMARY API KEY fields
+ * for the device.
+ */
+const char *m2x_device = "b621939e08743f9befaa46840dcb0388";
+const char *m2x_key = "ee32d3c67ca64408e20bd471dcdbd4ff";
+
+/*
+ * config_app_id and config_app_key are for public networks.
+ */
+/*
+static uint8_t app_id[8] = {0x00,0x01,0x02,0x03,0x0A,0x0B,0x0C,0x0D};
+std::vector<uint8_t> config_app_id;
+static uint8_t app_key[16] = {0x00,0x01,0x02,0x03,0x0A,0x0B,0x0C,0x0D};
+std::vector<uint8_t> config_app_key;
+*/
+
+
 enum LED1_COLOR {
     RED = 0,
     GREEN = 1
@@ -96,24 +130,12 @@
 
 SPI mDotspi(PA_7,PA_6,PA_5);					// mDot external SPI mDot11, mDot4, and mDot18
 
-/* **** replace these values with the proper public or private network settings ****
- * config_network_nameand config_network_pass are for private networks.
- */
-static std::string config_network_name = "TAB-CubeNet";
-static std::string config_network_pass = "1nt3gral";
-static uint8_t config_frequency_sub_band = 5;
 
-/*  config_app_id and config_app_key are for public networks.
-static uint8_t app_id[8] = {0x00,0x01,0x02,0x03,0x0A,0x0B,0x0C,0x0D};
-std::vector<uint8_t> config_app_id;
-static uint8_t app_key[16] = {0x00,0x01,0x02,0x03,0x0A,0x0B,0x0C,0x0D};
-std::vector<uint8_t> config_app_key;
-*/
 
 uint8_t result, pckt_time=10;
 char data;
 unsigned char test;
-char txtstr[17];
+char txtstr[64];
 int32_t num_whole, mdot_ret;
 uint32_t pressure;
 int16_t num_frac;
@@ -149,12 +171,11 @@
 
 int main()
 {
-
-    std::vector<uint8_t> mdot_data;
+    std::vector<uint8_t> lora_pl;
     std::vector<uint8_t> mdot_EUI;
     uint16_t i = 0;
 
-    debugUART.baud(921600);
+    debugUART.baud(115200);
 //  mDotUART.baud(9600);    // mdot UART unused but available on external connector
 
     Thread thread_1(pb1_debounce);						// threads for de-bouncing pushbutton switches
@@ -399,6 +420,24 @@
     pckt_time = 10;
     i = 0;
 
+    lora_pl.clear();
+    lora_pl.push_back(19);
+    lora_pl.push_back(strlen(m2x_device));
+    lora_pl.insert(lora_pl.end(), m2x_device, m2x_device + strlen(m2x_device));
+    while ((mdot_ret = mdot_radio->send(lora_pl)) != mDot::MDOT_OK) {
+        log_error(mdot_radio, "Failed to register m2x_device", mdot_ret);
+        osDelay(2000);
+    }
+
+    lora_pl.clear();
+    lora_pl.push_back(20);
+    lora_pl.push_back(strlen(m2x_key));
+    lora_pl.insert(lora_pl.end(), m2x_key, m2x_key + strlen(m2x_key));
+    while ((mdot_ret = mdot_radio->send(lora_pl)) != mDot::MDOT_OK) {
+        log_error(mdot_radio, "Failed to register m2x_key", mdot_ret);
+        osDelay(2000);
+    }
+
     do {
         evbLCD->startUpdate();
         evbLCD->clearBuffer();
@@ -474,7 +513,7 @@
         sprintf(txtstr,"Alti=%ld.%03d m", num_whole, num_frac);
         evbLCD->writeText(0,5,font_6x8,txtstr,strlen(txtstr));
         num_whole = baro_data._temp / 16;		// 8 bit signed significant integer
-        num_frac = (baro_data._temp & 0x0F) * 625 / 100;		// 4 bit fractional .0625 per bit
+        num_frac = (baro_data._temp & 0x0F) * 625 / 10;		// 4 bit fractional .0625 per bit
         sprintf(txtstr,"Temp=%ld.%03d C", num_whole, num_frac);
         evbLCD->writeText(0,6,font_6x8,txtstr,strlen(txtstr));
 
@@ -484,36 +523,43 @@
         lux_data = evbAmbLight->getData();
         num_whole = lux_data * 24 / 100;		// 16000 lux full scale .24 lux per bit
         num_frac = lux_data * 24 % 100;
-        sprintf(txtstr, "Light=%ld.%02d lux", num_whole, num_frac );
+        sprintf(txtstr, "Light=%ld.%02d lux", num_whole, num_frac);
         evbLCD->writeText(0,7,font_6x8,txtstr,strlen(txtstr));
 
         evbLCD->endUpdate();
         printf("finished iteration %d\n\r",(++i));
 
         if (i % pckt_time == 0) { // check packet counter will send packet every 2-5-10 data collection loops
-            mdot_data.clear();
-            mdot_data.push_back(0x0E);			// key for Current Acceleration 3-Axis Value
-            converts.f_s = accel_data._x *4;		// shift data 2 bits while retaining sign
-            mdot_data.push_back(converts.t_u[1]);	// get 8 MSB of 14 bit value
-            converts.f_s = accel_data._y * 4;		// shift data 2 bits while retaining sign
-            mdot_data.push_back(converts.t_u[1]);	// get 8 MSB of 14 bit value
-            converts.f_s = accel_data._z * 4;		// shift data 2 bits while retaining sign
-            mdot_data.push_back(converts.t_u[1]);	// get 8 MSB of 14 bit value
-            mdot_data.push_back(0x08);			// key for Current Pressure Value
+            lora_pl.clear();
+            lora_pl.push_back(0x0E);			// key for Current Acceleration 3-Axis Value
+            lora_pl.push_back(6);
+            converts.f_s = accel_data._x;
+            lora_pl.push_back(converts.t_u[1]);
+            lora_pl.push_back(converts.t_u[0]);
+            converts.f_s = accel_data._y;
+            lora_pl.push_back(converts.t_u[1]);
+            lora_pl.push_back(converts.t_u[0]);
+            converts.f_s = accel_data._z;
+            lora_pl.push_back(converts.t_u[1]);
+            lora_pl.push_back(converts.t_u[0]);
+            lora_pl.push_back(0x08);			// key for Current Pressure Value
+            lora_pl.push_back(3);
             convertl.f_u = pressure;				// pressure data is 20 bits unsigned
-            mdot_data.push_back(convertl.t_u[2]);
-            mdot_data.push_back(convertl.t_u[1]);
-            mdot_data.push_back(convertl.t_u[0]);
-            mdot_data.push_back(0x05);			// key for Current Ambient Light Value
+            lora_pl.push_back(convertl.t_u[2]);
+            lora_pl.push_back(convertl.t_u[1]);
+            lora_pl.push_back(convertl.t_u[0]);
+            lora_pl.push_back(0x05);			// key for Current Ambient Light Value
+            lora_pl.push_back(2);
             converts.f_u = lux_data;				// data is 16 bits unsigned
-            mdot_data.push_back(converts.t_u[1]);
-            mdot_data.push_back(converts.t_u[0]);
-            mdot_data.push_back(0x0B);			// key for Current Temperature Value
+            lora_pl.push_back(converts.t_u[1]);
+            lora_pl.push_back(converts.t_u[0]);
+            lora_pl.push_back(0x0B);			// key for Current Temperature Value
+            lora_pl.push_back(2);
             converts.f_s = baro_data._temp;		// temperature is signed 12 bit
-            mdot_data.push_back(converts.t_u[1]);
-            mdot_data.push_back(converts.t_u[0]);
+            lora_pl.push_back(converts.t_u[1]);
+            lora_pl.push_back(converts.t_u[0]);
 
-            if ((mdot_ret = mdot_radio->send(mdot_data)) != mDot::MDOT_OK) {
+            if ((mdot_ret = mdot_radio->send(lora_pl)) != mDot::MDOT_OK) {
                 log_error(mdot_radio, "failed to send", mdot_ret);
             } else {
                 printf("successfully sent data to gateway\r\n");
@@ -627,16 +673,16 @@
  */
 void config_pkt_xmit (void const *args)
 {
-
-    std::vector<uint8_t> data;
+    std::vector<uint8_t> lora_pl;
 
     while (true) {
         Thread::signal_wait(0x10);		// wait for pb2ISR to signal send
-        data.clear();
-        data.push_back(0x0F);			// key for Configuration data (packet transmission timer)
-        data.push_back(pckt_time);
+        lora_pl.clear();
+        lora_pl.push_back(0x0F);			// key for Configuration data (packet transmission timer)
+        lora_pl.push_back(1);
+        lora_pl.push_back(pckt_time);
 
-        if ((mdot_ret = mdot_radio->send(data)) != mDot::MDOT_OK) {
+        if ((mdot_ret = mdot_radio->send(lora_pl)) != mDot::MDOT_OK) {
             log_error(mdot_radio, "failed to send config data", mdot_ret);
         } else {
             printf("sent config data to gateway\r\n");