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:
- 35:b51d482e9731
--- 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 @@ -28,7 +28,7 @@ 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; static lora::NetworkType public_network;// = lora::PUBLIC_LORAWAN; -static uint8_t join_delay = 5; +static uint8_t join_delay = 1; static uint8_t ack = 0; static bool adr = true; @@ -101,8 +101,8 @@ // 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, public_network, ack);// use the line below - update_ota_config_id_key(network_id, network_key, frequency_sub_band, public_network, 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 // network link checks are a good alternative to requiring the gateway to ACK every packet and should allow a single gateway to handle more Dots @@ -136,37 +136,56 @@ uint8_t counter = 0; while (true) { - pc.printf("starting network join process\r\n"); - + pc.printf("top of loop\r\n"); std::vector<uint8_t> tx_data; + pc.printf("we got tx_data again\r\n"); // join network if not joined if (!dot->getNetworkJoinStatus()) { pc.printf("joining\r\n"); join_network(&pc); pc.printf("post join\r\n"); - } else { - pc.printf("Network has been joined\r\n"); + } + + // 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); + pc.printf("end of loop %d \r\n", counter); } - - tx_data.push_back(++counter); + + //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"); + //actually send the data logInfo("sending uplink with data = %d", counter); pc.printf("sending data\r\n"); send_data(tx_data); - pc.printf("data send\r\n"); + pc.printf("data sent\r\n"); + + + // erase vector data + tx_data.erase(tx_data.begin(), tx_data.end()); + counter = 0; + pc.printf("deleted tx_data and reset counter\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(); - } - - // 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;