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'.

main.cpp

Committer:
mfiore
Date:
2015-06-26
Revision:
1:8295b8c0d802
Parent:
0:e17e5a07892d
Child:
2:aadbdfb6d517

File content as of revision 1:8295b8c0d802:

#include "mbed.h"
#include "mDot.h"
#include "MTSLog.h"
#include "MTSText.h"
#include <string>
#include <vector>

using namespace mts;

static std::string config_network_name = "<network name>";
static std::string config_network_pass = "<network key>";
static uint8_t config_frequency_sub_band = 1;

int main() {
    Serial debug(USBTX, USBRX);
    debug.baud(460800);
    
    int32_t ret;
    int32_t next_tx;
    mDot* dot;
    std::vector<uint8_t> send_data;
    std::vector<uint8_t> recv_data;
    uint8_t recv = 0;
    uint8_t recv_mismatch = 0;
    uint8_t send_failure = 0;
    uint8_t iterations = 50;
    
    send_data.push_back(0x00);
    send_data.push_back(0xFF);
    send_data.push_back(0xFF);
    send_data.push_back(0xFF);
    send_data.push_back(0xFF);
    send_data.push_back(0xFF);
    send_data.push_back(0xFF);
    send_data.push_back(0xFF);

    dot = mDot::getInstance();

    dot->resetConfig();
    
    dot->setLogLevel(MTSLog::TRACE_LEVEL);

    while ((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());
    }
    while ((ret = dot->setNetworkName(config_network_name)) != mDot::MDOT_OK) {
        logError("failed to set network name: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
    }
    while ((ret = dot->setNetworkPassphrase(config_network_pass)) != mDot::MDOT_OK) {
        logError("failed to set network password: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
    }

    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");

    for (uint8_t i = 0; i < iterations; i++) {
        send_data[0] = i;
        if ((ret = dot->send(send_data)) != mDot::MDOT_OK) {
            logError("failed to send: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
            send_failure++;
        } else {
            logInfo("send data: %s", Text::bin2hexString(send_data).c_str());
            if ((ret = dot->recv(recv_data)) != mDot::MDOT_OK) {
                logError("failed to recv: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
            } else {
                logInfo("recv data: %s", Text::bin2hexString(recv_data).c_str());
                if (recv_data == send_data) {
                    recv++;
                } else {
                    recv_mismatch++;
                }
            }
            recv_data.clear();
        }
        
        next_tx = dot->getNextTxMs() + 1;
        logInfo("waiting %ld ms to transmit again", next_tx);
        wait_ms(next_tx);
    }
    
    logInfo("Version: %s", dot->getId().c_str());
    logInfo("Recv: %d/%d", recv, iterations);
    logInfo("Recv Mismatch: %d/%d", recv_mismatch, iterations);
    logInfo("Send Failure: %d/%d", send_failure, iterations);
    logInfo("Dropped: %d/%d", iterations - (recv + recv_mismatch + send_failure), iterations);

    return 0;
}