Testing basic mdot with external Interrupt

Dependencies:   libmDot mbed-rtos mbed-src

Fork of mDot_test_rx by Mike Fiore

LoRaWAN Network Configuration

For DevEUI, AppEUI, AppKey configuration to specific network, please see lines 10 to 18.

If using with an 8 channel gateway define config_frequency_sub_band at line 16. Setting config_frequency_sub_band to '1' will limit the device to using just the first eight (8) channels starting at 902.3 MHz.

Free Running vs Interrupt

At line 117 you can change the program from waiting for external interrupts to free-running by changing msg_rdy to be equal to 'true'.

Committer:
mfiore
Date:
Fri Jul 10 18:44:02 2015 +0000
Revision:
2:aadbdfb6d517
Parent:
1:8295b8c0d802
Child:
3:7cc5dfd22b54
update libraries, add extra wait between packets

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mfiore 0:e17e5a07892d 1 #include "mbed.h"
mfiore 0:e17e5a07892d 2 #include "mDot.h"
mfiore 0:e17e5a07892d 3 #include "MTSLog.h"
mfiore 0:e17e5a07892d 4 #include "MTSText.h"
mfiore 0:e17e5a07892d 5 #include <string>
mfiore 0:e17e5a07892d 6 #include <vector>
mfiore 0:e17e5a07892d 7
mfiore 0:e17e5a07892d 8 using namespace mts;
mfiore 0:e17e5a07892d 9
mfiore 2:aadbdfb6d517 10 static std::string config_network_name = "";
mfiore 2:aadbdfb6d517 11 static std::string config_network_pass = "";
mfiore 0:e17e5a07892d 12 static uint8_t config_frequency_sub_band = 1;
mfiore 0:e17e5a07892d 13
mfiore 0:e17e5a07892d 14 int main() {
mfiore 0:e17e5a07892d 15 Serial debug(USBTX, USBRX);
mfiore 0:e17e5a07892d 16 debug.baud(460800);
mfiore 0:e17e5a07892d 17
mfiore 0:e17e5a07892d 18 int32_t ret;
mfiore 0:e17e5a07892d 19 int32_t next_tx;
mfiore 2:aadbdfb6d517 20 int32_t wait_time = 2;
mfiore 0:e17e5a07892d 21 mDot* dot;
mfiore 0:e17e5a07892d 22 std::vector<uint8_t> send_data;
mfiore 0:e17e5a07892d 23 std::vector<uint8_t> recv_data;
mfiore 0:e17e5a07892d 24 uint8_t recv = 0;
mfiore 0:e17e5a07892d 25 uint8_t recv_mismatch = 0;
mfiore 0:e17e5a07892d 26 uint8_t send_failure = 0;
mfiore 0:e17e5a07892d 27 uint8_t iterations = 50;
mfiore 0:e17e5a07892d 28
mfiore 0:e17e5a07892d 29 send_data.push_back(0x00);
mfiore 0:e17e5a07892d 30 send_data.push_back(0xFF);
mfiore 0:e17e5a07892d 31 send_data.push_back(0xFF);
mfiore 0:e17e5a07892d 32 send_data.push_back(0xFF);
mfiore 0:e17e5a07892d 33 send_data.push_back(0xFF);
mfiore 0:e17e5a07892d 34 send_data.push_back(0xFF);
mfiore 0:e17e5a07892d 35 send_data.push_back(0xFF);
mfiore 0:e17e5a07892d 36 send_data.push_back(0xFF);
mfiore 0:e17e5a07892d 37
mfiore 0:e17e5a07892d 38 dot = mDot::getInstance();
mfiore 0:e17e5a07892d 39
mfiore 0:e17e5a07892d 40 dot->resetConfig();
mfiore 1:8295b8c0d802 41
mfiore 1:8295b8c0d802 42 dot->setLogLevel(MTSLog::TRACE_LEVEL);
mfiore 0:e17e5a07892d 43
mfiore 0:e17e5a07892d 44 while ((ret = dot->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) {
mfiore 0:e17e5a07892d 45 logError("failed to set frequency sub band: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
mfiore 0:e17e5a07892d 46 }
mfiore 0:e17e5a07892d 47 while ((ret = dot->setNetworkName(config_network_name)) != mDot::MDOT_OK) {
mfiore 0:e17e5a07892d 48 logError("failed to set network name: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
mfiore 0:e17e5a07892d 49 }
mfiore 0:e17e5a07892d 50 while ((ret = dot->setNetworkPassphrase(config_network_pass)) != mDot::MDOT_OK) {
mfiore 0:e17e5a07892d 51 logError("failed to set network password: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
mfiore 0:e17e5a07892d 52 }
mfiore 0:e17e5a07892d 53
mfiore 2:aadbdfb6d517 54 logInfo("enabling activity LED");
mfiore 2:aadbdfb6d517 55 dot->setActivityLedEnable(true);
mfiore 2:aadbdfb6d517 56
mfiore 0:e17e5a07892d 57 logInfo("joining network");
mfiore 0:e17e5a07892d 58 while ((ret = dot->joinNetwork()) != mDot::MDOT_OK) {
mfiore 0:e17e5a07892d 59 logError("failed to join network: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
mfiore 0:e17e5a07892d 60 wait_ms(dot->getNextTxMs() + 1);
mfiore 0:e17e5a07892d 61 }
mfiore 0:e17e5a07892d 62 logInfo("joined");
mfiore 0:e17e5a07892d 63
mfiore 0:e17e5a07892d 64 for (uint8_t i = 0; i < iterations; i++) {
mfiore 0:e17e5a07892d 65 send_data[0] = i;
mfiore 0:e17e5a07892d 66 if ((ret = dot->send(send_data)) != mDot::MDOT_OK) {
mfiore 0:e17e5a07892d 67 logError("failed to send: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
mfiore 0:e17e5a07892d 68 send_failure++;
mfiore 0:e17e5a07892d 69 } else {
mfiore 0:e17e5a07892d 70 logInfo("send data: %s", Text::bin2hexString(send_data).c_str());
mfiore 0:e17e5a07892d 71 if ((ret = dot->recv(recv_data)) != mDot::MDOT_OK) {
mfiore 0:e17e5a07892d 72 logError("failed to recv: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
mfiore 0:e17e5a07892d 73 } else {
mfiore 0:e17e5a07892d 74 logInfo("recv data: %s", Text::bin2hexString(recv_data).c_str());
mfiore 0:e17e5a07892d 75 if (recv_data == send_data) {
mfiore 0:e17e5a07892d 76 recv++;
mfiore 0:e17e5a07892d 77 } else {
mfiore 0:e17e5a07892d 78 recv_mismatch++;
mfiore 0:e17e5a07892d 79 }
mfiore 0:e17e5a07892d 80 }
mfiore 0:e17e5a07892d 81 recv_data.clear();
mfiore 0:e17e5a07892d 82 }
mfiore 0:e17e5a07892d 83
mfiore 0:e17e5a07892d 84 next_tx = dot->getNextTxMs() + 1;
mfiore 0:e17e5a07892d 85 logInfo("waiting %ld ms to transmit again", next_tx);
mfiore 0:e17e5a07892d 86 wait_ms(next_tx);
mfiore 2:aadbdfb6d517 87 logInfo("waiting another %d seconds", wait_time);
mfiore 2:aadbdfb6d517 88 wait(wait_time);
mfiore 0:e17e5a07892d 89 }
mfiore 0:e17e5a07892d 90
mfiore 0:e17e5a07892d 91 logInfo("Version: %s", dot->getId().c_str());
mfiore 0:e17e5a07892d 92 logInfo("Recv: %d/%d", recv, iterations);
mfiore 0:e17e5a07892d 93 logInfo("Recv Mismatch: %d/%d", recv_mismatch, iterations);
mfiore 0:e17e5a07892d 94 logInfo("Send Failure: %d/%d", send_failure, iterations);
mfiore 0:e17e5a07892d 95 logInfo("Dropped: %d/%d", iterations - (recv + recv_mismatch + send_failure), iterations);
mfiore 0:e17e5a07892d 96
mfiore 0:e17e5a07892d 97 return 0;
mfiore 0:e17e5a07892d 98 }