mDot project for Multitech and Explora worhshop

Dependencies:   mDot_X_NUCLEO_IKS01A1 libmDot-dev-mbed5-deprecated

Fork of mDot-IKS01A1 by Peter Ferland

Files at this revision

API Documentation at this revision

Comitter:
MDR
Date:
Mon Jun 26 17:22:52 2017 +0000
Parent:
11:1425f2e65663
Commit message:
Add support to connect to Explora server

Changed in this revision

RadioEvent.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 1425f2e65663 -r 3466445b1ac6 RadioEvent.h
--- a/RadioEvent.h	Tue Feb 14 20:36:21 2017 +0000
+++ b/RadioEvent.h	Mon Jun 26 17:22:52 2017 +0000
@@ -1,9 +1,9 @@
 #ifndef __RADIO_EVENT_H__
 #define __RADIO_EVENT_H__
-
+#include "mbed.h"
 #include "dot_util.h"
 #include "mDotEvent.h"
-
+extern DigitalOut MyLed;
 class RadioEvent : public mDotEvent
 {
  
@@ -69,6 +69,15 @@
                 // print RX data as string
                 std::string rx((const char*)info->RxBuffer, info->RxBufferSize);
                 printf("Rx data: %s\r\n", rx.c_str());
+                if(strcmp(rx.c_str(),"on")==0)
+                {
+                    printf("Turning Led ON\r\n");
+                    MyLed = 0;
+                }else
+                {
+                    printf("Turning Led OFF\r\n");
+                    MyLed = 1;
+                }
             }
         }
     }
diff -r 1425f2e65663 -r 3466445b1ac6 main.cpp
--- a/main.cpp	Tue Feb 14 20:36:21 2017 +0000
+++ b/main.cpp	Mon Jun 26 17:22:52 2017 +0000
@@ -5,13 +5,17 @@
 #include "RadioEvent.h"
 #include <cmath>
 
+// Add support to connect to Explora server
+
+DigitalOut MyLed(D7,1);
+
 // 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 SENET
 #ifdef ACTILITY
 // Network Id for Senet public network
 static uint8_t network_id[] = {0xF0, 0x3D, 0x29,0xAC,0x71,0x00,0x00, 0x00};
@@ -37,7 +41,7 @@
 // 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 = false;
+static bool public_network = true; // false;
 #endif
 static uint8_t ack = 0;
 static uint8_t tx_datarate = mDot::SF_7;
@@ -69,6 +73,32 @@
     RadioEvent events;
     pc.baud(115200);
 
+
+#if defined(SENET) || defined(ACTILITY)
+#if defined(SENET)
+    printf("Connect to SENET network\r\n");
+#else
+    printf("Connect to ACTILITY network\r\n");
+#endif
+#else
+    printf("Connect to MultiConnect, network_name:%s, network_passphrase:%s\r\n", network_name,network_passphrase);
+#endif
+
+//    LedD7 = 0;
+//    printf("Led ON\r\n");
+//    osDelay(2000);
+//    LedD7 = 1;
+//    printf("Led OFF\r\n");
+//    osDelay(2000);
+//    LedD7 = 0;
+//    printf("Led ON\r\n");
+//    osDelay(2000);
+//    LedD7 = 1;
+//    printf("Led OFF\r\n");
+//    osDelay(2000);
+//    LedD7 = 0;
+//    printf("Led ON\r\n");
+    
     /* Initialize mDot */
     dot = mDot::getInstance();
 
@@ -201,7 +231,7 @@
         tx_data.push_back(uint8_t(1)); // data id
         tx_data.push_back(uint8_t(0x67)); // data type - temp
         int16_t temp = floor(value1*10 + 0.5f);
-        logInfo("Temp payload: %d", temp);
+        //logInfo("Temp payload: %d", temp);
         tx_data.push_back(uint8_t( 0xFF & (temp >> 8)));
         tx_data.push_back(uint8_t(0xFF & temp));
         
@@ -211,14 +241,14 @@
         temp = floor(value2 * 2.0f + 0.5f);
         tx_data.push_back(uint8_t(0xFF & temp ));
 
-        logInfo("Temperature data %f", value1);
+        logInfo("\r\n\r\nTemperature data %f", value1);
         logInfo("Humidity data: %f", value2);
         
         pressure_sensor->GetPressure(&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);
+        //temp = floor(value1 * 100.0f + 0.5f);
         tx_data.push_back(uint8_t(3)); // data id
         tx_data.push_back(uint8_t(0x73)); // data type - pressure
         temp = floor(value1 / 0.1f + 0.5f);
@@ -230,17 +260,19 @@
         int32_t accel_vector[3];
         // returns in mG
         accelerometer->Get_X_Axes(accel_vector);
-        logInfo("Acclerometer Z axis: %d", accel_vector[2]);
+        logInfo("Acclerometer: %d,%d,%d", accel_vector[0], accel_vector[1], accel_vector[2]);
         
         tx_data.push_back(uint8_t(4)); // data id
         tx_data.push_back(uint8_t(0x71)); // data type - accelerometer
         for(int i=0; i<3; i++){
-            tx_data.push_back(uint8_t(0xFF & accel_vector[i]) >> 8);
+            tx_data.push_back(uint8_t(0xFF & (accel_vector[i] >> 8)));
             tx_data.push_back(uint8_t(0xFF & accel_vector[i]));
+            //logInfo("Acc: %d,%d,0x%02X, 0x%02X", i, accel_vector[i], accel_vector[2]);
         }
         
         // Get gyro data
         gyroscope->Get_G_Axes(accel_vector);
+        logInfo("Gyroscope: %d,%d,%d", accel_vector[0], accel_vector[1], accel_vector[2]);
         // 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
@@ -250,7 +282,12 @@
             tx_data.push_back(uint8_t(0xFF & accel_vector[i]));
         }
         
-        
+        // print Raw Data
+        //logInfo("Temp raw: 0x%02X, 0x%02X, 0x%02X, 0x%02X",tx_data[0], tx_data[1], tx_data[2], tx_data[3]);
+        //logInfo("Hum raw: 0x%02X, 0x%02X, 0x%02X",tx_data[4], tx_data[5], tx_data[6]);
+        //logInfo("Pres raw: 0x%02X, 0x%02X, 0x%02X, 0x%02X",tx_data[7], tx_data[8], tx_data[9], tx_data[10]);
+        //logInfo("Acc raw: 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X",tx_data[11], tx_data[12], tx_data[13], tx_data[14], tx_data[15], tx_data[16], tx_data[17], tx_data[18]);
+        //logInfo("Gir raw: 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X",tx_data[19], tx_data[20], tx_data[21], tx_data[22], tx_data[23], tx_data[24], tx_data[25], tx_data[26]);
         send_data(tx_data);
         
         if(deep_sleep){
@@ -262,10 +299,19 @@
         
 
         // ONLY ONE of the three functions below should be uncommented depending on the desired wakeup method
-        sleep_wake_rtc_only(deep_sleep);
+        // mdr sleep_wake_rtc_only(deep_sleep);
         //sleep_wake_interrupt_only(deep_sleep);
         //sleep_wake_rtc_or_interrupt(deep_sleep);
         
+        uint32_t delay_s = dot->getNextTxMs() / 1000;
+        if (delay_s < 5) {
+            delay_s = 5;
+        }
+        
+        logInfo("waiting %d", delay_s);
+        osDelay(delay_s*1000);
+        logInfo("application resume", deepsleep ? "execute from beginning" : "resume");
+
     }
 
     return 0;