Here it is ...
Dependencies: libxDot-mbed5 TSL2561
Fork of Dot-Examples by
Diff: examples/src/ota_example.cpp
- Revision:
- 33:79e4c812d91d
- Parent:
- 32:cc05a2e80969
- Child:
- 34:fbdd22159585
--- a/examples/src/ota_example.cpp Thu Jul 12 12:54:47 2018 -0400 +++ b/examples/src/ota_example.cpp Thu Jul 19 10:48:47 2018 -0400 @@ -74,7 +74,7 @@ dot = mDot::getInstance(plan); assert(dot); - pc.printf("mdot instance asserted \r\n"); + // attach the custom events handler dot->setEvents(&events); @@ -86,6 +86,9 @@ logInfo("defaulting Dot configuration"); dot->resetConfig(); dot->resetNetworkSession(); + + // set the data_rate + (*dot).setTxDataRate(lora::DR_1); // make sure library logging is turned on dot->setLogLevel(mts::MTSLog::INFO_LEVEL); @@ -136,37 +139,52 @@ uint8_t counter = 0; while (true) { - pc.printf("starting network join process\r\n"); std::vector<uint8_t> tx_data; + // join network if not joined if (!dot->getNetworkJoinStatus()) { - pc.printf("joining\r\n"); + pc.printf("joining lora network.\r\n"); join_network(&pc); - pc.printf("post join\r\n"); - } else { - pc.printf("Network has been joined\r\n"); - } - - tx_data.push_back(++counter); - logInfo("sending uplink with data = %d", counter); - pc.printf("sending data\r\n"); - send_data(tx_data); - pc.printf("data send\r\n"); + } - // 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) { - logInfo("saving network session to NVM"); - dot->saveNetworkSession(); + // hourly loop + while( counter < 12) { + uint8_t light_data = get_light_data(); + tx_data.push_back(light_data); + pc.printf("pseudo-light data: %d\r\n", light_data); + pc.printf("hour: %d\r\n", ++counter); + + // 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) { + logInfo("saving network session to NVM"); + dot->saveNetworkSession(); + } + + // 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); + sleep_wake_rtc_or_interrupt(deep_sleep); } + + //print vector data + pc.printf("vector data:"); + for(std::vector<uint8_t>::const_iterator iter = tx_data.begin(); iter != tx_data.end(); ++iter) { + pc.printf(" %d",*iter); + } + pc.printf("\r\n"); + pc.printf("size of tx_data: %d\r\n", sizeof(tx_data)); + //actually send the data + pc.printf("sending data\r\n"); + send_data(tx_data, &pc); + + // erase vector data & reset counter + tx_data.erase(tx_data.begin(), tx_data.end()); + counter = 0; + pc.printf("deleted tx_data and reset counter\r\n"); - // 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); - sleep_wake_rtc_or_interrupt(deep_sleep); - pc.printf("end of loop %d \r\n", counter); } return 0;