Shoalhaven Water / Mbed OS Cloudtracker

Dependencies:   libmDot-mbed5 ISL29011

Files at this revision

API Documentation at this revision

Comitter:
Evan Hosseini
Date:
Mon Apr 30 14:46:28 2018 -0500
Parent:
29:9e2c0d990ace
Child:
31:b1d5811e3d5d
Commit message:
Add ambient light sensor code back for xDot

Changed in this revision

examples/inc/dot_util.h Show annotated file Show diff for this revision Revisions of this file
examples/lib/ISL29011.lib Show annotated file Show diff for this revision Revisions of this file
examples/src/auto_ota_example.cpp Show annotated file Show diff for this revision Revisions of this file
examples/src/class_c_example.cpp Show annotated file Show diff for this revision Revisions of this file
examples/src/dot_util.cpp Show annotated file Show diff for this revision Revisions of this file
examples/src/manual_example.cpp Show annotated file Show diff for this revision Revisions of this file
examples/src/ota_example.cpp Show annotated file Show diff for this revision Revisions of this file
examples/src/peer_to_peer_example.cpp Show annotated file Show diff for this revision Revisions of this file
setup.sh Show annotated file Show diff for this revision Revisions of this file
--- a/examples/inc/dot_util.h	Fri Apr 20 14:42:46 2018 -0500
+++ b/examples/inc/dot_util.h	Mon Apr 30 14:46:28 2018 -0500
@@ -6,13 +6,14 @@
 #include "ChannelPlans.h"
 #include "MTSLog.h"
 #include "MTSText.h"
+#include "ISL29011.h"
 #include "example_config.h"
 
 extern mDot* dot;
 
 void display_config();
 
-void update_ota_config_name_phrase(std::string network_name, std::string network_passphrase, uint8_t frequency_sub_band, uint8_t ack);
+void update_ota_config_name_phrase(std::string network_name, std::string network_passphrase, uint8_t frequency_sub_band, bool public_network, uint8_t ack);
 
 void update_ota_config_id_key(uint8_t *network_id, uint8_t *network_key, uint8_t frequency_sub_band, bool public_network, uint8_t ack);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/lib/ISL29011.lib	Mon Apr 30 14:46:28 2018 -0500
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/Multi-Hackers/code/ISL29011/#953adca17438
--- a/examples/src/auto_ota_example.cpp	Fri Apr 20 14:42:46 2018 -0500
+++ b/examples/src/auto_ota_example.cpp	Mon Apr 30 14:46:28 2018 -0500
@@ -27,6 +27,7 @@
 static uint8_t network_id[] = { 0x6C, 0x4E, 0xEF, 0x66, 0xF4, 0x79, 0x86, 0xA6 };
 static uint8_t network_key[] = { 0x1F, 0x33, 0xA1, 0x70, 0xA5, 0xF1, 0xFD, 0xA0, 0xAB, 0x69, 0x7A, 0xAE, 0x2B, 0x95, 0x91, 0x6B };
 static uint8_t frequency_sub_band = 0;
+static bool public_network = true;
 static uint8_t join_delay = 5;
 static uint8_t ack = 0;
 static bool adr = true;
@@ -42,12 +43,23 @@
 
 Serial pc(USBTX, USBRX);
 
+#if defined(TARGET_XDOT_L151CC)
+I2C i2c(I2C_SDA, I2C_SCL);
+ISL29011 lux(i2c);
+#else
+AnalogIn lux(XBEE_AD0);
+#endif
+
 int main() {
     // Custom event handler for automatically displaying RX data
     RadioEvent events;
 
     pc.baud(115200);
 
+#if defined(TARGET_XDOT_L151CC)
+    i2c.frequency(400000);
+#endif
+
     mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL);
     
 #if CHANNEL_PLAN == CP_US915
@@ -96,7 +108,7 @@
         // only one method or the other should be used!
         // network ID = crc64(network name)
         // network KEY = cmac(network passphrase)
-        update_ota_config_name_phrase(network_name, network_passphrase, frequency_sub_band, ack);
+        update_ota_config_name_phrase(network_name, network_passphrase, frequency_sub_band, public_network, ack);
         //update_ota_config_id_key(network_id, network_key, frequency_sub_band, public_network, ack);
     
         // configure network link checks
@@ -122,8 +134,8 @@
         display_config();
     }
 
-    uint8_t counter = 0;
     while (true) {
+        uint16_t light;
         std::vector<uint8_t> tx_data;
 
         // join network if not joined
@@ -131,10 +143,30 @@
             join_network();
         }
 
-        tx_data.push_back(++counter);
-        logInfo("sending uplink with data = %d", counter);
+#if defined(TARGET_XDOT_L151CC)
+        // configure the ISL29011 sensor on the xDot-DK for continuous ambient light sampling, 16 bit conversion, and maximum range
+        lux.setMode(ISL29011::ALS_CONT);
+        lux.setResolution(ISL29011::ADC_16BIT);
+        lux.setRange(ISL29011::RNG_64000);
+
+        // get the latest light sample and send it to the gateway
+        light = lux.getData();
+        tx_data.push_back((light >> 8) & 0xFF);
+        tx_data.push_back(light & 0xFF);
+        logInfo("light: %lu [0x%04X]", light, light);
         send_data(tx_data);
 
+        // put the LSL29011 ambient light sensor into a low power state
+        lux.setMode(ISL29011::PWR_DOWN);
+#else 
+        // get some dummy data and send it to the gateway
+        light = lux.read_u16();
+        tx_data.push_back((light >> 8) & 0xFF);
+        tx_data.push_back(light & 0xFF);
+        logInfo("light: %lu [0x%04X]", light, light);
+        send_data(tx_data);
+#endif
+
         // ONLY ONE of the three functions below should be uncommented depending on the desired wakeup method
         //sleep_wake_rtc_only(deep_sleep);
         //sleep_wake_interrupt_only(deep_sleep);
--- a/examples/src/class_c_example.cpp	Fri Apr 20 14:42:46 2018 -0500
+++ b/examples/src/class_c_example.cpp	Mon Apr 30 14:46:28 2018 -0500
@@ -27,6 +27,7 @@
 static uint8_t network_id[] = { 0x6C, 0x4E, 0xEF, 0x66, 0xF4, 0x79, 0x86, 0xA6 };
 static uint8_t network_key[] = { 0x1F, 0x33, 0xA1, 0x70, 0xA5, 0xF1, 0xFD, 0xA0, 0xAB, 0x69, 0x7A, 0xAE, 0x2B, 0x95, 0x91, 0x6B };
 static uint8_t frequency_sub_band = 0;
+static bool public_network = true;
 static uint8_t join_delay = 5;
 static uint8_t ack = 1;
 static bool adr = true;
@@ -36,12 +37,23 @@
 
 Serial pc(USBTX, USBRX);
 
+#if defined(TARGET_XDOT_L151CC)
+I2C i2c(I2C_SDA, I2C_SCL);
+ISL29011 lux(i2c);
+#else
+AnalogIn lux(XBEE_AD0);
+#endif
+
 int main() {
     // Custom event handler for automatically displaying RX data
     RadioEvent events;
 
     pc.baud(115200);
 
+#if defined(TARGET_XDOT_L151CC)
+    i2c.frequency(400000);
+#endif
+
     mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL);
     
 #if CHANNEL_PLAN == CP_US915
@@ -88,7 +100,7 @@
     // only one method or the other should be used!
     // network ID = crc64(network name)
     // network KEY = cmac(network passphrase)
-    update_ota_config_name_phrase(network_name, network_passphrase, frequency_sub_band, ack);
+    update_ota_config_name_phrase(network_name, network_passphrase, frequency_sub_band, public_network, ack);
     //update_ota_config_id_key(network_id, network_key, frequency_sub_band, public_network, ack);
 
     // configure the Dot for class C operation
@@ -115,8 +127,8 @@
     // display configuration
     display_config();
 
-    uint8_t counter = 0;
     while (true) {
+        uint16_t light;
         std::vector<uint8_t> tx_data;
 
         // join network if not joined
@@ -124,10 +136,30 @@
             join_network();
         }
 
-        tx_data.push_back(++counter);
-        logInfo("sending uplink with data = %d", counter);
+#if defined(TARGET_XDOT_L151CC)
+        // configure the ISL29011 sensor on the xDot-DK for continuous ambient light sampling, 16 bit conversion, and maximum range
+        lux.setMode(ISL29011::ALS_CONT);
+        lux.setResolution(ISL29011::ADC_16BIT);
+        lux.setRange(ISL29011::RNG_64000);
+
+        // get the latest light sample and send it to the gateway
+        light = lux.getData();
+        tx_data.push_back((light >> 8) & 0xFF);
+        tx_data.push_back(light & 0xFF);
+        logInfo("light: %lu [0x%04X]", light, light);
         send_data(tx_data);
 
+        // put the LSL29011 ambient light sensor into a low power state
+        lux.setMode(ISL29011::PWR_DOWN);
+#else 
+        // get some dummy data and send it to the gateway
+        light = lux.read_u16();
+        tx_data.push_back((light >> 8) & 0xFF);
+        tx_data.push_back(light & 0xFF);
+        logInfo("light: %lu [0x%04X]", light, light);
+        send_data(tx_data);
+#endif
+
         // the Dot can't sleep in class C mode
         // it must be waiting for data from the gateway
         // send data every 30s
--- a/examples/src/dot_util.cpp	Fri Apr 20 14:42:46 2018 -0500
+++ b/examples/src/dot_util.cpp	Mon Apr 30 14:46:28 2018 -0500
@@ -24,7 +24,7 @@
     if (lora::ChannelPlan::IsPlanFixed(dot->getFrequencyBand())) {
         logInfo("frequency sub band ------- %u", dot->getFrequencySubBand());
     }
-   
+    logInfo("public network ----------- %s", dot->getPublicNetwork() ? "on" : "off");   
     logInfo("=========================");
     logInfo("credentials configuration");
     logInfo("=========================");
@@ -58,11 +58,11 @@
     }
 }
 
-void update_ota_config_name_phrase(std::string network_name, std::string network_passphrase, uint8_t frequency_sub_band, uint8_t ack) {
+void update_ota_config_name_phrase(std::string network_name, std::string network_passphrase, uint8_t frequency_sub_band, bool public_network, uint8_t ack) {
     std::string current_network_name = dot->getNetworkName();
     std::string current_network_passphrase = dot->getNetworkPassphrase();
     uint8_t current_frequency_sub_band = dot->getFrequencySubBand();
-    uint8_t current_network_type = dot->getPublicNetwork();
+    bool current_public_network = dot->getPublicNetwork();
     uint8_t current_ack = dot->getAck();
     
     if (current_network_name != network_name) {
@@ -87,7 +87,14 @@
 	    }
 	}
     }
-       
+
+    if (current_public_network != public_network) {
+        logInfo("changing public network from %s to %s", current_public_network ? "on" : "off", public_network ? "on" : "off");
+        if (dot->setPublicNetwork(public_network) != mDot::MDOT_OK) {
+            logError("failed to set public network to %s", public_network ? "on" : "off");
+        }
+    }
+
     if (current_ack != ack) {
         logInfo("changing acks from %u to %u", current_ack, ack);
         if (dot->setAck(ack) != mDot::MDOT_OK) {
--- a/examples/src/manual_example.cpp	Fri Apr 20 14:42:46 2018 -0500
+++ b/examples/src/manual_example.cpp	Mon Apr 30 14:46:28 2018 -0500
@@ -24,6 +24,7 @@
 static uint8_t network_session_key[] = { 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04 };
 static uint8_t data_session_key[] = { 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04 };
 static uint8_t frequency_sub_band = 6;
+static bool public_network = true;
 static uint8_t join_delay = 5;
 static uint8_t ack = 1;
 static bool adr = true;
@@ -39,12 +40,23 @@
 
 Serial pc(USBTX, USBRX);
 
+#if defined(TARGET_XDOT_L151CC)
+I2C i2c(I2C_SDA, I2C_SCL);
+ISL29011 lux(i2c);
+#else
+AnalogIn lux(XBEE_AD0);
+#endif
+
 int main() {
     // Custom event handler for automatically displaying RX data
     RadioEvent events;
 
     pc.baud(115200);
 
+#if defined(TARGET_XDOT_L151CC)
+    i2c.frequency(400000);
+#endif
+
     mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL);
     
 #if CHANNEL_PLAN == CP_US915
@@ -99,7 +111,7 @@
         //      lora-query -a 01020304 A 0102030401020304 <your Dot's device ID> 01020304010203040102030401020304 01020304010203040102030401020304
         //   * if you change the network address, network session key, or data session key, make sure you update them on the gateway
         // to provision your Dot with a 3rd party gateway, see the gateway or network provider documentation
-        update_manual_config(network_address, network_session_key, data_session_key, frequency_sub_band, ack);
+        update_manual_config(network_address, network_session_key, data_session_key, frequency_sub_band, public_network, ack);
 
         // enable or disable Adaptive Data Rate
         dot->setAdr(adr);
@@ -122,15 +134,34 @@
         dot->restoreNetworkSession();
     }
     
-
-    uint8_t counter = 0;
     while (true) {
+        uint16_t light;
         std::vector<uint8_t> tx_data;
 
-        tx_data.push_back(++counter);
-        logInfo("sending uplink with data = %d", counter);
+#if defined(TARGET_XDOT_L151CC)
+        // configure the ISL29011 sensor on the xDot-DK for continuous ambient light sampling, 16 bit conversion, and maximum range
+        lux.setMode(ISL29011::ALS_CONT);
+        lux.setResolution(ISL29011::ADC_16BIT);
+        lux.setRange(ISL29011::RNG_64000);
+
+        // get the latest light sample and send it to the gateway
+        light = lux.getData();
+        tx_data.push_back((light >> 8) & 0xFF);
+        tx_data.push_back(light & 0xFF);
+        logInfo("light: %lu [0x%04X]", light, light);
         send_data(tx_data);
 
+        // put the LSL29011 ambient light sensor into a low power state
+        lux.setMode(ISL29011::PWR_DOWN);
+#else 
+        // get some dummy data and send it to the gateway
+        light = lux.read_u16();
+        tx_data.push_back((light >> 8) & 0xFF);
+        tx_data.push_back(light & 0xFF);
+        logInfo("light: %lu [0x%04X]", light, light);
+        send_data(tx_data);
+#endif
+
         // if going into deepsleep mode, save the session so we don't need to join again after waking up
         // not necessary if going into sleep mode since RAM is retained
         if (deep_sleep) {
--- a/examples/src/ota_example.cpp	Fri Apr 20 14:42:46 2018 -0500
+++ b/examples/src/ota_example.cpp	Mon Apr 30 14:46:28 2018 -0500
@@ -27,6 +27,7 @@
 static uint8_t network_id[] = { 0x6C, 0x4E, 0xEF, 0x66, 0xF4, 0x79, 0x86, 0xA6 };
 static uint8_t network_key[] = { 0x1F, 0x33, 0xA1, 0x70, 0xA5, 0xF1, 0xFD, 0xA0, 0xAB, 0x69, 0x7A, 0xAE, 0x2B, 0x95, 0x91, 0x6B };
 static uint8_t frequency_sub_band = 0;
+static bool public_network = true;
 static uint8_t join_delay = 5;
 static uint8_t ack = 0;
 static bool adr = true;
@@ -42,12 +43,23 @@
 
 Serial pc(USBTX, USBRX);
 
+#if defined(TARGET_XDOT_L151CC)
+I2C i2c(I2C_SDA, I2C_SCL);
+ISL29011 lux(i2c);
+#else
+AnalogIn lux(XBEE_AD0);
+#endif
+
 int main() {
     // Custom event handler for automatically displaying RX data
     RadioEvent events;
 
     pc.baud(115200);
 
+#if defined(TARGET_XDOT_L151CC)
+    i2c.frequency(400000);
+#endif
+
     mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL);
     
 #if CHANNEL_PLAN == CP_US915
@@ -95,7 +107,7 @@
         // only one method or the other should be used!
         // network ID = crc64(network name)
         // network KEY = cmac(network passphrase)
-        update_ota_config_name_phrase(network_name, network_passphrase, frequency_sub_band, ack);
+        update_ota_config_name_phrase(network_name, network_passphrase, frequency_sub_band, public_network, ack);
         //update_ota_config_id_key(network_id, network_key, frequency_sub_band, public_network, ack);
 
         // configure network link checks
@@ -126,8 +138,8 @@
         dot->restoreNetworkSession();
     }
 
-    uint8_t counter = 0;
     while (true) {
+        uint16_t light;
         std::vector<uint8_t> tx_data;
 
         // join network if not joined
@@ -135,10 +147,30 @@
             join_network();
         }
 
-        tx_data.push_back(++counter);
-        logInfo("sending uplink with data = %d", counter);
+#if defined(TARGET_XDOT_L151CC)
+        // configure the ISL29011 sensor on the xDot-DK for continuous ambient light sampling, 16 bit conversion, and maximum range
+        lux.setMode(ISL29011::ALS_CONT);
+        lux.setResolution(ISL29011::ADC_16BIT);
+        lux.setRange(ISL29011::RNG_64000);
+
+        // get the latest light sample and send it to the gateway
+        light = lux.getData();
+        tx_data.push_back((light >> 8) & 0xFF);
+        tx_data.push_back(light & 0xFF);
+        logInfo("light: %lu [0x%04X]", light, light);
         send_data(tx_data);
 
+        // put the LSL29011 ambient light sensor into a low power state
+        lux.setMode(ISL29011::PWR_DOWN);
+#else 
+        // get some dummy data and send it to the gateway
+        light = lux.read_u16();
+        tx_data.push_back((light >> 8) & 0xFF);
+        tx_data.push_back(light & 0xFF);
+        logInfo("light: %lu [0x%04X]", light, light);
+        send_data(tx_data);
+#endif
+
         // if going into deepsleep mode, save the session so we don't need to join again after waking up
         // not necessary if going into sleep mode since RAM is retained
         if (deep_sleep) {
--- a/examples/src/peer_to_peer_example.cpp	Fri Apr 20 14:42:46 2018 -0500
+++ b/examples/src/peer_to_peer_example.cpp	Mon Apr 30 14:46:28 2018 -0500
@@ -28,6 +28,13 @@
 
 Serial pc(USBTX, USBRX);
 
+#if defined(TARGET_XDOT_L151CC)
+I2C i2c(I2C_SDA, I2C_SCL);
+ISL29011 lux(i2c);
+#else
+AnalogIn lux(XBEE_AD0);
+#endif
+
 int main() {
     // Custom event handler for automatically displaying RX data
     RadioEvent events;
@@ -38,6 +45,10 @@
 
     pc.baud(115200);
 
+#if defined(TARGET_XDOT_L151CC)
+    i2c.frequency(400000);
+#endif
+
     mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL);
     
 #if CHANNEL_PLAN == CP_US915
@@ -147,8 +158,8 @@
     // display configuration
     display_config();
 
-    uint8_t counter = 0;
     while (true) {
+        uint16_t light;
         std::vector<uint8_t> tx_data;
 
         // join network if not joined
@@ -156,10 +167,30 @@
             join_network();
         }
 
-        tx_data.push_back(++counter);
-        logInfo("sending uplink with data = %d", counter);
+#if defined(TARGET_XDOT_L151CC)
+        // configure the ISL29011 sensor on the xDot-DK for continuous ambient light sampling, 16 bit conversion, and maximum range
+        lux.setMode(ISL29011::ALS_CONT);
+        lux.setResolution(ISL29011::ADC_16BIT);
+        lux.setRange(ISL29011::RNG_64000);
+
+        // get the latest light sample and send it to the gateway
+        light = lux.getData();
+        tx_data.push_back((light >> 8) & 0xFF);
+        tx_data.push_back(light & 0xFF);
+        logInfo("light: %lu [0x%04X]", light, light);
         send_data(tx_data);
 
+        // put the LSL29011 ambient light sensor into a low power state
+        lux.setMode(ISL29011::PWR_DOWN);
+#else 
+        // get some dummy data and send it to the gateway
+        light = lux.read_u16();
+        tx_data.push_back((light >> 8) & 0xFF);
+        tx_data.push_back(light & 0xFF);
+        logInfo("light: %lu [0x%04X]", light, light);
+        send_data(tx_data);
+#endif
+
         // the Dot can't sleep in PEER_TO_PEER mode
         // it must be waiting for data from the other Dot
         // send data every 5 seconds
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/setup.sh	Mon Apr 30 14:46:28 2018 -0500
@@ -0,0 +1,3 @@
+if [ ! -d ISL29011 ]; then
+    hg clone https://developer.mbed.org/teams/Multi-Hackers/code/ISL29011/
+fi