Here it is ...
Dependencies: libxDot-mbed5 TSL2561
Fork of Dot-Examples by
Revision 37:4818522075f8, committed 2018-07-25
- Comitter:
- David Gutsch dgutsch@umail.iu.edu
- Date:
- Wed Jul 25 14:23:40 2018 -0400
- Parent:
- 36:5529d26e97e6
- Child:
- 38:401bd606d2dd
- Commit message:
- updated, with everything working (pseudo-data)
Changed in this revision
--- a/examples/inc/dot_util.h Wed Jul 25 10:39:56 2018 -0400 +++ b/examples/inc/dot_util.h Wed Jul 25 14:23:40 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/inc/dot_util.h~ Wed Jul 25 10:39:56 2018 -0400 +++ b/examples/inc/dot_util.h~ Wed Jul 25 14:23:40 2018 -0400 @@ -37,13 +37,13 @@ void sleep_restore_io(); -void send_data(std::vector<uint8_t> data, Serial *pc); +int send_data(std::vector<uint8_t> data, Serial *pc); /** a function which gets light data(manufactures data as of now */ uint8_t get_light_data(); -void ascii_converter(*char, uint8_t, std::vector<uint8_t>*, Serial*); +void ascii_converter(char*, uint8_t, std::vector<uint8_t>*, Serial*); #endif
--- a/examples/src/dot_util.cpp Wed Jul 25 10:39:56 2018 -0400 +++ b/examples/src/dot_util.cpp Wed Jul 25 14:23:40 2018 -0400 @@ -316,16 +316,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
--- a/examples/src/dot_util.cpp~ Wed Jul 25 10:39:56 2018 -0400 +++ b/examples/src/dot_util.cpp~ Wed Jul 25 14:23:40 2018 -0400 @@ -714,17 +714,36 @@ #endif } -void send_data(std::vector<uint8_t> data, Serial *pc) { +int send_data(std::vector<uint8_t> data, Serial *pc) { int32_t ret; ret = dot->send(data); if (ret != mDot::MDOT_OK) { (*pc).printf("s_d(): failed to send data to %s [%d][%s]\r\n", dot->getJoinMode() == mDot::PEER_TO_PEER ? "peer\r\n" : "gateway\r\n", ret, mDot::getReturnCodeString(ret).c_str()); + + return 1; } else { (*pc).printf("successfully sent data to %s", dot->getJoinMode() == mDot::PEER_TO_PEER ? "peer\r\n" : "gateway\r\n"); + + return 0; } } uint8_t get_light_data() { return (uint8_t)(rand() % 100); } + +void ascii_converter(char *ret, uint8_t numData, std::vector<uint8_t> *tx_data, Serial *pc) { + + sprintf(ret, "%d", numData); + //pc->printf("char buffer: %s\r\n", ret); + + int i = 0; + while(ret[i] != '\0' || ret[i] == 'X') { + //pc->printf("%c ", ret[i]); + tx_data->push_back(ret[i++]); + //pc->printf("%c", ret[i - 1]); + } + + //pc->printf("\r\n"); +}
--- a/examples/src/ota_example.cpp Wed Jul 25 10:39:56 2018 -0400 +++ b/examples/src/ota_example.cpp Wed Jul 25 14:23:40 2018 -0400 @@ -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; @@ -155,12 +155,11 @@ uint8_t light_data = get_light_data(); //pc.printf("pseudo-light data: %d\r\n", light_data); - pc.printf("hour: %d\r\n", ++counter); + pc.printf("\r\nhour: %d\r\n", ++counter); // clean out char buffer strcpy(buffer, "XXXX"); - // pc.printf("char buffer X: %s\r\n", buffer); // convert to ascii char && push to vector ascii_converter(buffer, light_data, &tx_data, &pc); @@ -169,12 +168,6 @@ if( counter < 12) tx_data.push_back(' '); - // set the data_rate (from forum) - //dot->setTxDataRate(lora::DR_2); - - //send_data(tx_data, &pc); - //pc.printf("size: %d\r\n", tx_data.size()); - //pc.printf("capacity: %d\r\n", tx_data.capacity()); // 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 @@ -184,7 +177,7 @@ } // ONLY ONE of the three functions below should be uncommented depending on the desired wakeup method - //sleep_wake_rtc_only(deep_sleep); + sleep_wake_rtc_only(deep_sleep, 30, &pc); //sleep_wake_interrupt_only(deep_sleep); //sleep_wake_rtc_or_interrupt(deep_sleep); } @@ -198,15 +191,15 @@ pc.printf("\r\n"); pc.printf("capacity tx_data: %d\r\n", tx_data.capacity()); - //tx_data.resize(tx_data.size()); - //tx_data.resize(); + //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"); // set the data_rate (from forum) - dot->setTxDataRate(lora::DR_2); + dot->setTxDataRate(lora::DR_1); int retVal = send_data(tx_data, &pc); //while(retVal == 1) //retVal = send_data(tx_data, &pc);
--- a/examples/src/ota_example.cpp~ Wed Jul 25 10:39:56 2018 -0400 +++ b/examples/src/ota_example.cpp~ Wed Jul 25 14:23:40 2018 -0400 @@ -148,29 +148,26 @@ pc.printf("joining lora network.\r\n"); join_network(&pc); } + // hourly loop while( counter < 12) { uint8_t light_data = get_light_data(); - pc.printf("pseudo-light data: %d\r\n", light_data); - pc.printf("hour: %d\r\n", ++counter); + //pc.printf("pseudo-light data: %d\r\n", light_data); + pc.printf("\r\nhour: %d\r\n", ++counter); // clean out char buffer strcpy(buffer, "XXXX"); - // pc.printf("char buffer X: %s\r\n", buffer); // convert to ascii char && push to vector ascii_converter(buffer, light_data, &tx_data, &pc); - pc.printf("char buffer converted: %s\r\n", buffer); + pc.printf("char buffer: %s\r\n", buffer); if( counter < 12) tx_data.push_back(' '); - send_data(tx_data, &pc); - pc.printf("size: %d\r\n", tx_data.size()); - pc.printf("capacity: %d\r\n", tx_data.capacity()); // 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 @@ -180,7 +177,7 @@ } // ONLY ONE of the three functions below should be uncommented depending on the desired wakeup method - //sleep_wake_rtc_only(deep_sleep); + sleep_wake_rtc_only(deep_sleep, 30, &pc); //sleep_wake_interrupt_only(deep_sleep); //sleep_wake_rtc_or_interrupt(deep_sleep); } @@ -194,12 +191,15 @@ pc.printf("\r\n"); pc.printf("capacity tx_data: %d\r\n", tx_data.capacity()); - //tx_data.resize(tx_data.size()); - //tx_data.resize(36); + //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"); + + // set the data_rate (from forum) + dot->setTxDataRate(lora::DR_1); int retVal = send_data(tx_data, &pc); //while(retVal == 1) //retVal = send_data(tx_data, &pc); @@ -207,7 +207,7 @@ // 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"); + pc.printf("deleted tx_data and reset counter\r\ncap: %d size: %d\r\n", tx_data.capacity(), tx_data.size()); }