Demonstration TTN OTAA node
Dependencies: BME280 DS1820 libmDot mbed-rtos mbed
This is an example application for the MultiTech mDot and connects to The Things Network using Over The Air Activation (OTAA). It sends data from a Dallas Semiconductors DS18B20 OneWire temperature sensor.
Register a device and generate a random AppKey for the currently used application Id: (You need to use your own device IDs, the ones shown here are examples only)
./ttnctl devices register 0080000000000000 INFO Generating random AppKey... INFO Registered device AppKey=000102030405060708090A0B0C0D0E0F DevEUI=0080000000000000
or to specify the same AppKey for a new device or to reregister the same device again:
./ttnctl devices register 0080000000000000 000102030405060708090A0B0C0D0E0F
./ttnctl devices info 0080000000000000 Dynamic device:
AppEUI: 70B3D50000000000 {0x70, 0xB3, 0xD5, 0x00, 0x00, 0x00, 0x00, 0x00}
DevEUI: 0080000000000000 {0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
AppKey: 000102030405060708090A0B0C0D0E0F {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}
Copy the AppEUI and AppKey values provided in hex array notation above to the AppEUI and AppKey parameters below.
Diff: main.cpp
- Revision:
- 4:f649ab1b61d1
- Parent:
- 3:367aa95f9771
- Child:
- 5:48eb9245a914
--- a/main.cpp Tue Sep 22 13:58:59 2015 +0000 +++ b/main.cpp Thu Oct 15 20:34:52 2015 +0000 @@ -1,5 +1,5 @@ /** mDot_DS18B20 - Simple mDot temperature sensor using Dallas Semiconductors DS18B20 OneWire temperature sensor. - * It used the OTA_AUTO join mode using saved parameters. If the config is to be reset then pin A2 on the + * It used the OTA_AUTO join mode using saved parameters. If the config is to be reset then pin A2 on the * dev board must be held low during a reset or power up. * * Uses MultiTech mDot developer board http://www.multitech.com/models/94558010LF @@ -24,10 +24,13 @@ using namespace mts; +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MAX(a,b) (((a)>(b))?(a):(b)) + // these options must match the settings on your Conduit in // /var/config/lora/lora-network-server.conf -static std::string config_network_name = "<network name>"; -static std::string config_network_pass = "<network password>"; +static std::string config_network_name = "ThingInnovations"; +static std::string config_network_pass = "donkey123"; // Ignoring sub band for EU modules. //static uint8_t config_frequency_sub_band = 1; @@ -71,8 +74,8 @@ // get a mDot handle dot = mDot::getInstance(); - dot->setLogLevel(MTSLog::WARNING_LEVEL); -// dot->setLogLevel(MTSLog::TRACE_LEVEL); +// dot->setLogLevel(MTSLog::WARNING_LEVEL); + dot->setLogLevel(MTSLog::TRACE_LEVEL); logInfo("Checking Config"); @@ -139,11 +142,15 @@ logInfo("Using existing Config"); } + logInfo("Joining Network"); + while ((ret = dot->joinNetwork()) != mDot::MDOT_OK) { logError("failed to join network [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str()); wait_ms(dot->getNextTxMs() + 1); } + logInfo("Joined Network"); + probe.setResolution(9); char dataBuf[50]; @@ -167,7 +174,7 @@ } // Should sleep here and wakeup after a set interval. - uint32_t sleep_time = (dot->getNextTxMs() / 1000) + 60; + uint32_t sleep_time = MAX((dot->getNextTxMs() / 1000), 60); logInfo("going to sleep for %d seconds", sleep_time); // go to sleep and wake up automatically sleep_time seconds later