a Hello world to connect to The Things Network

Dependencies:   libmDot mbed-rtos mbed

Fork of mDot_LoRa_Connect_Example by MultiTech

Revision:
6:8f7276e7d206
Parent:
4:36e214ebfa56
Child:
7:609e7bb06486
--- a/main.cpp	Sat Oct 24 22:54:25 2015 +0000
+++ b/main.cpp	Thu Nov 19 20:10:43 2015 +0000
@@ -4,53 +4,35 @@
 #include <string>
 #include <vector>
 #include <algorithm>
-
 // 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 = "<lora network id>";
-//static std::string config_network_pass = "<lora network key>";
-//static uint8_t config_frequency_sub_band = 1;
+static const uint8_t netowork_session_key_array[] = {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};
+static const uint8_t data_session_key_array[] = {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};
+static const uint8_t network_address_array[] = {0x02, 0x01, 0xBA, 0x01};
+static std::vector<uint8_t> netowork_session_key (netowork_session_key_array, netowork_session_key_array + sizeof(netowork_session_key_array) / sizeof(uint8_t));
+static std::vector<uint8_t> data_session_key (data_session_key_array, data_session_key_array + sizeof(data_session_key_array) / sizeof(uint8_t));
+static std::vector<uint8_t> network_address (network_address_array, network_address_array + sizeof(network_address_array) / sizeof(uint8_t));
+static uint8_t config_frequency_sub_band = 4;
 
 int main() {
     int32_t ret;
     mDot* dot;
     std::vector<uint8_t> data;
-    std::string data_str = "hello!";
+    std::string data_str = "hello ropu!";
     
     // get a mDot handle
     dot = mDot::getInstance();
-    
-    // print library version information
-    logInfo("version: %s", dot->getId().c_str());
+
+    dot->resetConfig();
 
-    //*******************************************
-    // configuration
-    //*******************************************
-    // reset to default config so we know what state we're in
-    dot->resetConfig();
-    
+    dot->setJoinMode(mDot::MANUAL);
+    dot->setPublicNetwork(true);
     dot->setLogLevel(mts::MTSLog::INFO_LEVEL);
-
-    // set up the mDot with our network information: frequency sub band, network name, and network password
-    // these can all be saved in NVM so they don't need to be set every time - see mDot::saveConfig()
+    dot->setFrequencySubBand(config_frequency_sub_band);
+    dot->setNetworkSessionKey(netowork_session_key);
+    dot->setDataSessionKey(data_session_key);
+    dot->setNetworkAddress(network_address);
     
-    // frequency sub band is only applicable in the 915 (US) frequency band
-    // if using a MultiTech Conduit gateway, use the same sub band as your Conduit (1-8) - the mDot will use the 8 channels in that sub band
-    // if using a gateway that supports all 64 channels, use sub band 0 - the mDot will use all 64 channels
-    logInfo("setting frequency sub band");
-    if ((ret = dot->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) {
-        logError("failed to set frequency sub band %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
-    }
-    
-    logInfo("setting network name");
-    if ((ret = dot->setNetworkName(config_network_name)) != mDot::MDOT_OK) {
-        logError("failed to set network name %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
-    }
-    
-    logInfo("setting network password");
-    if ((ret = dot->setNetworkPassphrase(config_network_pass)) != mDot::MDOT_OK) {
-        logError("failed to set network password %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
-    }
     
     // a higher spreading factor allows for longer range but lower throughput
     // in the 915 (US) frequency band, spreading factors 7 - 10 are available
@@ -60,9 +42,11 @@
         logError("failed to set TX datarate %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
     }
     
+    
+    
     // request receive confirmation of packets from the gateway
     logInfo("enabling ACKs");
-    if ((ret = dot->setAck(1)) != mDot::MDOT_OK) {
+    if ((ret = dot->setAck(0)) != mDot::MDOT_OK) {
         logError("failed to enable ACKs %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
     }