Here it is ...
Dependencies: libxDot-mbed5 TSL2561
Fork of Dot-Examples by
Revision 39:0d4362063352, committed 2018-07-26
- Comitter:
- David Gutsch dgutsch@umail.iu.edu
- Date:
- Thu Jul 26 12:03:47 2018 -0400
- Parent:
- 38:401bd606d2dd
- Child:
- 40:314e6b1c289f
- Commit message:
- board configured for cellular gateway. added led flashes at startup. reconfigured to sleep hourly for 1 hour, and daily for 12 hours
Changed in this revision
--- a/TSL2561.lib Wed Jul 25 18:30:01 2018 +0000 +++ b/TSL2561.lib Thu Jul 26 12:03:47 2018 -0400 @@ -1,1 +1,1 @@ -http://os.mbed.com/users/anhnt2407/code/TSL2561/#ab906ac6e90b +https://os.mbed.com/users/kenjiArai/code/TSL2561/#05d322353720
--- a/examples/inc/dot_util.h Wed Jul 25 18:30:01 2018 +0000 +++ b/examples/inc/dot_util.h Thu Jul 26 12:03:47 2018 -0400 @@ -8,6 +8,7 @@ #include "MTSText.h" #include "example_config.h" #include <stdlib.h> +#include "TSL2561.h" extern mDot* dot; @@ -42,7 +43,7 @@ /** a function which gets light data(manufactures data as of now */ -uint8_t get_light_data(); +uint8_t get_light_data(TSL2561*, Serial*); void ascii_converter(char*, uint8_t, std::vector<uint8_t>*, Serial*);
--- a/examples/inc/dot_util.h~ Wed Jul 25 18:30:01 2018 +0000 +++ b/examples/inc/dot_util.h~ Thu Jul 26 12:03:47 2018 -0400 @@ -25,7 +25,7 @@ void join_network(Serial*); -void sleep_wake_rtc_only(bool deepsleep); +void sleep_wake_rtc_only(bool deepsleep, int, Serial*); void sleep_wake_interrupt_only(bool deepsleep);
--- a/examples/src/dot_util.cpp Wed Jul 25 18:30:01 2018 +0000 +++ b/examples/src/dot_util.cpp Thu Jul 26 12:03:47 2018 -0400 @@ -1,7 +1,7 @@ #include "dot_util.h" #if defined(TARGET_XDOT_L151CC) #include "xdot_low_power.h" -#include "TSL2561.h" + #endif #if defined(TARGET_MTS_MDOT_F411RE) @@ -731,8 +731,20 @@ } } -uint8_t get_light_data() { - return (uint8_t)(rand() % 100); +uint8_t get_light_data(TSL2561 *sensor, Serial *pc) { + + if(sensor->who_am_i()) + pc->printf("\r\nI'm a light sensor!\r\n"); + else + pc->printf("\r\nI'm not a light sensor.\r\n"); + + + float raw_data = sensor->lux(); + pc->printf("raw data: %f\r\n", raw_data); + + return (uint8_t)raw_data; + + //return (uint8_t)(rand() % 100); } void ascii_converter(char *ret, uint8_t numData, std::vector<uint8_t> *tx_data, Serial *pc) {
--- a/examples/src/dot_util.cpp~ Wed Jul 25 18:30:01 2018 +0000 +++ b/examples/src/dot_util.cpp~ Thu Jul 26 12:03:47 2018 -0400 @@ -1,6 +1,7 @@ #include "dot_util.h" #if defined(TARGET_XDOT_L151CC) #include "xdot_low_power.h" + #endif #if defined(TARGET_MTS_MDOT_F411RE) @@ -316,16 +317,17 @@ (*pc).printf("j_n(): network join SUCCESSFUL\r\n"); } -void sleep_wake_rtc_only(bool deepsleep) { +void sleep_wake_rtc_only(bool deepsleep, int delay, Serial *pc) { // in some frequency bands we need to wait until another channel is available before transmitting again // wait at least 10s between transmissions - uint32_t delay_s = dot->getNextTxMs() / 1000; - if (delay_s < 10) { + uint32_t delay_s;// = dot->getNextTxMs() / 1000; + /*if (delay_s < 10) { delay_s = 10; - } - - logInfo("%ssleeping %lus", deepsleep ? "deep" : "", delay_s); - logInfo("application will %s after waking up", deepsleep ? "execute from beginning" : "resume"); + }*/ + delay_s = delay; + + pc->printf("%ssleeping %lus ", deepsleep ? "deep " : " ", delay_s); + pc->printf("application will %s after waking up\r\n", deepsleep ? "execute from beginning" : "resume"); // lowest current consumption in sleep mode can only be achieved by configuring IOs as analog inputs with no pull resistors // the library handles all internal IOs automatically, but the external IOs are the application's responsibility @@ -729,8 +731,14 @@ } } -uint8_t get_light_data() { - return (uint8_t)(rand() % 100); +uint8_t get_light_data(TSL2561 *sensor, Serial *pc) { + + float raw_data = sensor->lux(); + pc->printf("raw data: %f\r\n", raw_data); + + return (uint8_t)raw_data; + + //return (uint8_t)(rand() % 100); } void ascii_converter(char *ret, uint8_t numData, std::vector<uint8_t> *tx_data, Serial *pc) {
--- a/examples/src/ota_example.cpp Wed Jul 25 18:30:01 2018 +0000 +++ b/examples/src/ota_example.cpp Thu Jul 26 12:03:47 2018 -0400 @@ -1,6 +1,7 @@ #include "dot_util.h" #include "RadioEvent.h" #include "TSL2561.h" + #if ACTIVE_EXAMPLE == OTA_EXAMPLE @@ -23,8 +24,16 @@ // * either the network name and passphrase can be used or // // the network ID (8 bytes) and KEY (16 bytes) // ///////////////////////////////////////////////////////////// -static std::string network_name = "MTCDT-19400691"; -static std::string network_passphrase = "MTCDT-19400691"; + +// wifi gateway +//static std::string network_name = "MTCDT-19400691"; +//static std::string network_passphrase = "MTCDT-19400691"; + +// cellular gateway +static std::string network_name = "iuiot-gw1"; +static std::string network_passphrase = "pivotiot"; + + 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 = 1; @@ -37,13 +46,16 @@ // in sleep mode, IO state is maintained, RAM is retained, and application will resume after waking up // in deepsleep mode, IOs float, RAM is lost, and application will start from beginning after waking up // if deep_sleep == true, device will enter deepsleep mode -static bool deep_sleep = true; +static bool deep_sleep = false; +static const uint16_t HOURLY_SLEEP_INTERVAL = 3600; // 1 hour +static const uint16_t DAILY_SLEEP_INTERVAL = 43200; // 12 hours mDot* dot = NULL; lora::ChannelPlan* plan = NULL; - +DigitalOut led1(LED1); Serial pc(PA_9, PA_10); +TSL2561 lightSensor(PB_9, PB_8); int main() { pc.baud(115200); @@ -51,7 +63,18 @@ // Custom event handler for automatically displaying RX data RadioEvent events; - + + ///////////////////////////// + // visual display + led1 = 0; + for(int i = 0; i < 5; i++) { + led1 = 1; + wait(1); + led1 = 0; + wait(1); + } + + mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); @@ -153,7 +176,7 @@ // hourly loop while( counter < 12) { - uint8_t light_data = get_light_data(); + uint8_t light_data = get_light_data(&lightSensor, &pc); //pc.printf("pseudo-light data: %d\r\n", light_data); pc.printf("\r\nhour: %d\r\n", ++counter); @@ -177,7 +200,7 @@ } // ONLY ONE of the three functions below should be uncommented depending on the desired wakeup method - sleep_wake_rtc_only(deep_sleep, 30, &pc); + sleep_wake_rtc_only(deep_sleep, HOURLY_SLEEP_INTERVAL, &pc); //sleep_wake_interrupt_only(deep_sleep); //sleep_wake_rtc_or_interrupt(deep_sleep); } @@ -191,8 +214,6 @@ pc.printf("\r\n"); pc.printf("capacity tx_data: %d\r\n", tx_data.capacity()); - //tx_data.reserve(tx_data.size()); - //pc.printf("cap resized: %d\r\n", tx_data.capacity()); pc.printf("sized tx_data: %d\r\n", tx_data.size()); //actually send the data pc.printf("sending data\r\n"); @@ -208,6 +229,9 @@ tx_data.erase(tx_data.begin(), tx_data.end()); counter = 0; pc.printf("deleted tx_data and reset counter\r\ncap: %d size: %d\r\n", tx_data.capacity(), tx_data.size()); + + // sleep for the day + sleep_wake_rtc_only(deep_sleep, DAILY_SLEEP_INTERVAL, &pc); }
--- a/examples/src/ota_example.cpp~ Wed Jul 25 18:30:01 2018 +0000 +++ b/examples/src/ota_example.cpp~ Thu Jul 26 12:03:47 2018 -0400 @@ -1,6 +1,6 @@ #include "dot_util.h" #include "RadioEvent.h" - +#include "TSL2561.h" #if ACTIVE_EXAMPLE == OTA_EXAMPLE @@ -37,7 +37,7 @@ // in sleep mode, IO state is maintained, RAM is retained, and application will resume after waking up // in deepsleep mode, IOs float, RAM is lost, and application will start from beginning after waking up // if deep_sleep == true, device will enter deepsleep mode -static bool deep_sleep = false; +static bool deep_sleep = true; mDot* dot = NULL; lora::ChannelPlan* plan = NULL;