initial version / sends time + 012345689
Dependencies: libmDot mbed-rtos mbed
Fork of wotiolora by
Revision 1:6b84fe382e27, committed 2015-10-30
- Comitter:
- tuddman
- Date:
- Fri Oct 30 13:35:16 2015 +0000
- Parent:
- 0:eea6446bc510
- Child:
- 2:8cf7270307e5
- Commit message:
- adds latest libraries
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Oct 28 22:04:20 2015 +0000
+++ b/main.cpp Fri Oct 30 13:35:16 2015 +0000
@@ -8,7 +8,7 @@
// these options must match the settings on your Conduit
// uncomment the following lines and edit their values to match your configuration
static std::string config_network_name = "wotioloranetwork";
-static std::string config_network_pass = "iotandbigdata";
+static std::string config_network_pass = "<INSERT PASSPHRASE>";
static uint8_t config_frequency_sub_band = 7;
@@ -28,7 +28,6 @@
}
-
int main() {
int32_t ret;
mDot* dot;
@@ -37,7 +36,7 @@
// configure the Ticker to blink the LED on 500ms interval
- tick.attach(&blink, 0.5);
+ tick.attach(&blink, 1.0);
// print the message on 2s interval
while (true) {
@@ -45,7 +44,6 @@
wait(2);
}
-
// get a mDot handle
dot = mDot::getInstance();
@@ -95,12 +93,6 @@
logError("failed to enable ACKs %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
}
- // set join mode to AUTO_OTA so the mDot doesn't have to rejoin after sleeping
- logInfo("setting join mode to AUTO_OTA");
- if ((ret = dot->setJoinMode(mDot::AUTO_OTA)) != mDot::MDOT_OK) {
- logError("failed to set join mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
- }
-
// save this configuration to the mDot's NVM
logInfo("saving config");
if (! dot->saveConfig()) {
@@ -110,36 +102,29 @@
// end of configuration
//*******************************************
+ // attempt to join the network
+ logInfo("joining network");
+ while ((ret = dot->joinNetwork()) != mDot::MDOT_OK) {
+ logError("failed to join network %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
+ // in the 868 (EU) frequency band, we need to wait until another channel is available before transmitting again
+ osDelay(std::max((uint32_t)1000, (uint32_t)dot->getNextTxMs()));
+ }
+
// format data for sending to the gateway
for (std::string::iterator it = data_str.begin(); it != data_str.end(); it++)
data.push_back((uint8_t) *it);
- // join the network if not joined
- if (!dot->getNetworkJoinStatus()) {
- logInfo("network not joined, joining network");
- if ((ret = dot->joinNetwork()) != mDot::MDOT_OK) {
- logError("failed to join network %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
- }
- }
- if (dot->getNetworkJoinStatus()) {
- // send the data
- // ACKs are enabled by default, so we're expecting to get one back
+ while (true) {
+ // send the data to the gateway
if ((ret = dot->send(data)) != mDot::MDOT_OK) {
- logError("failed to send %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
+ logError("failed to send", ret, mDot::getReturnCodeString(ret).c_str());
} else {
logInfo("successfully sent data to gateway");
}
+
+ // in the 868 (EU) frequency band, we need to wait until another channel is available before transmitting again
+ osDelay(std::max((uint32_t)5000, (uint32_t)dot->getNextTxMs()));
}
- // in the 868 (EU) frequency band, we need to wait until another channel is available before transmitting again
- uint32_t sleep_time = std::max((uint32_t)10000, (uint32_t)dot->getNextTxMs()) / 1000;
- logInfo("going to sleep...");
-
- // go to deepsleep and wake up automatically sleep_time seconds later
- dot->sleep(sleep_time, mDot::RTC_ALARM);
-
- // go to deepsleep and wake up on rising edge of WKUP pin (PA0/XBEE_CTS/XBEE_DIO7)
- // dot->sleep(0, mDot::INTERRUPT);
-
return 0;
}
