LoRaWAN_FAE_Training

Dependencies:   X_NUCLEO_IKS01A2

Revision:
45:96fe99f19cd0
Parent:
26:f07f5febf97f
Child:
48:b02d43b5e90c
--- a/main.cpp	Mon Nov 19 08:00:29 2018 +0000
+++ b/main.cpp	Tue Mar 12 08:57:55 2019 +0000
@@ -25,6 +25,13 @@
 #include "trace_helper.h"
 #include "lora_radio_helper.h"
 
+// Sensors
+#include "Grove_temperature.h"
+#include "MMA7660.h"
+
+Grove_temperature temp(A1);
+MMA7660 accelemeter;
+
 using namespace events;
 
 // Max payload size can be LORAMAC_PHY_MAXPAYLOAD.
@@ -97,6 +104,9 @@
 
     // stores the status of a call to LoRaWAN protocol
     lorawan_status_t retcode;
+    
+    //Initialise accelerometer (if plugged)
+    accelemeter.init(); 
 
     // Initialize LoRaWAN stack
     if (lorawan.initialize(&ev_queue) != LORAWAN_STATUS_OK) {
@@ -150,9 +160,10 @@
  */
 static void send_message()
 {
-    uint16_t packet_len;
+    uint16_t packet_len, Temperature, axConverted, ayConverted, azConverted;
     int16_t retcode;
     float sensor_value;
+    float ax,ay,az;
 
     if (ds1820.begin()) {
         ds1820.startConversion();
@@ -166,9 +177,35 @@
 
     packet_len = sprintf((char*) tx_buffer, "Dummy Sensor Value is %3.1f",
                     sensor_value);
+   
+    /*  Grove Temperature Sensor */
+//    sensor_value = temp.getTemperature();                 
+//    printf("temperature = %2.2f\n", sensor_value);
+//    Temperature = (uint16_t)sensor_value * 100;
+//    tx_buffer[0]=0x01; //Temperature
+//    tx_buffer[1]=0x02; // Len
+//    tx_buffer[2]=Temperature & 0xFF; // Temp LSB
+//    tx_buffer[3]=(Temperature >> 16) & 0xFF; // Temp MSB 
+//    packet_len = 4; 
+    
+    /* Grove Accelerometer Sensor */    
+//    accelemeter.getAcceleration(&ax,&ay,&az);
+//    printf("Accleration of X=%2.2fg, Y=%2.2fg, Z=%2.2fg\n\r",ax,ay,az);
+//    tx_buffer[0]=0x02; //Acceleration
+//    tx_buffer[1]=0x06; // Len
+//    axConverted = ax * 100;
+//    tx_buffer[2]=(axConverted & 0xFF);          // x axe LSB
+//    tx_buffer[3]=((axConverted >> 16) & 0xFF);  // x axe MSB     
+//    ayConverted = ay * 100;
+//    tx_buffer[4]=(ayConverted & 0xFF);          // y axe LSB
+//    tx_buffer[5]=((ayConverted >> 16) & 0xFF);  // y axe MSB     
+//    azConverted = az * 100;
+//    tx_buffer[6]=(azConverted & 0xFF);          // x axe LSB
+//    tx_buffer[7]=((azConverted >> 16) & 0xFF);  // x axe MSB   
+//    packet_len = 8; 
 
     retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, tx_buffer, packet_len,
-                           MSG_CONFIRMED_FLAG);
+                           MSG_UNCONFIRMED_FLAG);
 
     if (retcode < 0) {
         retcode == LORAWAN_STATUS_WOULD_BLOCK ? printf("send - WOULD BLOCK\r\n")