How to use mDot 868 connect to TTN?

Home Forums mDot/xDot How to use mDot 868 connect to TTN?

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #14302
    Xiaotian Fei
    Participant

    Hi,
    I’m trying use mDot 868 connect to TTN in public network. When I type this:

        mDot* dot;
       
        // get a mDot handle
        dot = mDot::getInstance();
        dot->resetConfig();
    
        dot->setJoinMode(mDot::AUTO_OTA);
        dot->setPublicNetwork(true);
        dot->setFrequencyBand(FB_868);
        dot->setNetworkId(app_eui);
        dot->setNetworkKey(app_key);
    

    dot->setFrequencyBand(FB_868); this line can not pass the compile process.
    So, how can I choice the 868 frequency for mDot?
    Thanks!

    #14303
    Mike Fiore
    Blocked

    Hi Xiaotian,

    The mDots are configured at the factory for either the 915 band and then that configuration is locked in.

    It isn’t possible to change the frequency band with the mDot library.

    Cheers,

    Mike

    #14308
    Andrew Lindsay
    Participant

    You shouldnt need to set the band. Using TTN works.
    Example application is at https://developer.mbed.org/teams/Thing-Innovations/code/mDot_TTN_OTAA_Node/

    Andrew

    #14326
    Xiaotian Fei
    Participant

    Thanks guys, I will try it.

    #14327
    Xiaotian Fei
    Participant

    Hi, Mike
    I compile following code in the mbed online compiler, libmDot version is 14, mbed lib version is 119, mbed-rtos lib is 111.
    When I download the bin file into mDot 868, the program stop at:“mDot* dot = mDot::getInstance()”.
    When using the mDot 915 the programming can pass this line.

    Can you help me with this problem, thanks.

    
    #include "mbed.h"
    #include "mDot.h"
    #include "MTSLog.h"
    #include "MTSText.h"
    #include <string>
    #include <vector>
    
    using namespace mts;
    
    #define MIN(a,b) (((a)<(b))?(a):(b))
    #define MAX(a,b) (((a)>(b))?(a):(b))
    
    // AppEUI
    uint8_t AppEUI[8] = { 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x00, 0x06, 0x56 };
    // AppKey
    uint8_t AppKey[16] = { 0x7F, 0xA6, 0xF7, 0x50, 0x9F, 0xE5, 0x92, 0x28, 0xD5, 0xF8, 0x79, 0xC3, 0xAD, 0x39, 0x3E, 0xD9 };
    
    #define LORA_SF mDot::DR5
    #define LORA_ACK 0
    #define LORA_TXPOWER 14
    
    Serial pc(XBEE_DOUT,XBEE_DIN);//tx, rx
     
    
    int main() {
        int32_t ret;
        std::vector<uint8_t> send_data;
        std::vector<uint8_t> recv_data;
        std::vector<uint8_t> nwkId;
        std::vector<uint8_t> nwkKey;
    
        float temperature = 28.7;
       
        pc.baud(115200);
        pc.printf("TTN OTAA mDot LoRa sensor    \n\r");
    
        // get a mDot handle
        //
        //dot->setLogLevel(MTSLog::TRACE_LEVEL);
    
        pc.printf("Checking Config   ");
        // reset to default config so we know what state we're in
        mDot* dot = mDot::getInstance();
        
        pc.printf("Resetting Config    ");
    
        dot->resetConfig();
        
        uint8_t *it = AppEUI;
        for (uint8_t i = 0; i<8; i++)
            nwkId.push_back((uint8_t) *it++);
        
        it = AppKey;
        for (uint8_t i = 0; i<16; i++)
            nwkKey.push_back((uint8_t) *it++);
    
    /*****************  Config mDot *****************/
    
        // Set Spreading Factor, higher is lower data rate, smaller packets but longer range
        // Lower is higher data rate, larger packets and shorter range.
        pc.printf("Set SF\n\r");
        if((ret = dot->setTxDataRate( LORA_SF )) != mDot::MDOT_OK) {
            logError("Failed to set SF %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
        }
    
        pc.printf("Set TxPower\n\r");
        if((ret = dot->setTxPower( LORA_TXPOWER )) != mDot::MDOT_OK) {
            logError("Failed to set Tx Power %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
        }
    
        pc.printf("Set Public mode\n\r");
        if((ret = dot->setPublicNetwork(true)) != mDot::MDOT_OK) {
            logError("failed to set Public Mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
        }
    
        pc.printf("Set AUTO_OTA Join mode\n\r");
        if((ret = dot->setJoinMode(mDot::AUTO_OTA)) != mDot::MDOT_OK) {
            logError("Failed to set AUTO_OTA Join Mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
        }
    
        pc.printf("Set Ack\n\r");
        // 1 retries on Ack, 0 to disable
        if((ret = dot->setAck( LORA_ACK)) != mDot::MDOT_OK) {
            logError("Failed to set Ack %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
        }
        pc.printf("Set Network Id\n\r");
        if ((ret = dot->setNetworkId(nwkId)) != mDot::MDOT_OK) {
            logError("Failed to set Network Id %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
        }
        pc.printf("Set Network Key\n\r");
        if ((ret = dot->setNetworkKey(nwkKey)) != mDot::MDOT_OK) {
            logError("Failed to set Network Id %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
        }
    
        pc.printf("Saving Config\n\r");
        // Save config
        if (! dot->saveConfig()) {
            logError("failed to save configuration");
        }
    /*****************  print mDot configs *****************/
        pc.printf("Device ID {");
        std::vector<uint8_t> deviceId;
        deviceId = dot->getDeviceId();
        for (std::vector<uint8_t>::iterator it = deviceId.begin() ; it != deviceId.end(); ++it) {
            pc.printf("0x%2.2X",*it );
            pc.printf("%s", it != (deviceId.end() -1 ) ? ", " : " " );
        }
        pc.printf("}\r\n");
    
        std::vector<uint8_t> netId;
        pc.printf("Network Id/App EUI {");
        netId = dot->getNetworkId();
        for (std::vector<uint8_t>::iterator it = netId.begin() ; it != netId.end(); ++it) {
            pc.printf("0x%2.2X", *it );
            pc.printf("%s", it != (netId.end() -1 ) ? ", " : " " );
        }
        pc.printf("}\r\n");
    
        std::vector<uint8_t> netKey;
        pc.printf("Network Key/App Key {");
        netKey = dot->getNetworkKey();
        for (std::vector<uint8_t>::iterator it = netKey.begin() ; it != netKey.end(); ++it) {
            pc.printf("0x%2.2X", *it );
            pc.printf("%s", it != (netKey.end() -1 ) ? ", " : " " );
        }
        pc.printf("}\r\n");
    /***************** connect *****************/
        pc.printf("Joining Network\n\r");
    
        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");
    /***************** send data *****************/
        char dataBuf[50];
        while( 1 ) {
            temperature = 30.3;
            sprintf(dataBuf, "{\"t\":%3.1f}", temperature );
            pc.printf("%s\n\r",dataBuf);
            send_data.clear();
            // probably not the most efficent way to do this
            for( int i=0; i< strlen(dataBuf); i++ ) {
                send_data.push_back( dataBuf[i] );
            }
    
            if ((ret = dot->send(send_data)) != mDot::MDOT_OK) {
                 logError("failed to send: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
            } else {
               logInfo("send data: %s", Text::bin2hexString(send_data).c_str());
            }
    
            // Should  sleep here and wakeup after a set 5 minute interval.
            // 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;
    //wait_ms(2000);
            // go to sleep and wake up automatically sleep_time seconds later
            dot->sleep(sleep_time, mDot::RTC_ALARM, false);
        }
        return 0;
    }
    
    #14336
    Mike Fiore
    Blocked

    Xiaotian,

    I tested your app on my 868 mDot and it seemed to work fine. Here’s the debug output

    TTN OTAA mDot LoRa sensor
    Checking Config Resetting Config Set SF
    Set TxPower
    Set Public mode
    Set AUTO_OTA Join mode
    Set Ack
    Set Network Id
    Set Network Key
    Saving Config
    Device ID {0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43 }
    Network Id/App EUI {0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x00, 0x06, 0x56 }
    Network Key/App Key {0x7F, 0xA6, 0xF7, 0x50, 0x9F, 0xE5, 0x92, 0x28, 0xD5, 0xF8, 0x79, 0xC3, 0xAD, 0x39, 0x3E, 0xD9 }
    Joining Network
    TTN OTAA mDot LoRa sensor
    Checking Config Resetting Config Set SF
    Set TxPower
    Set Public mode
    Set AUTO_OTA Join mode
    Set Ack
    Set Network Id
    Set Network Key
    Saving Config
    Device ID {0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43 }
    Network Id/App EUI {0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x00, 0x06, 0x56 }
    Network Key/App Key {0x7F, 0xA6, 0xF7, 0x50, 0x9F, 0xE5, 0x92, 0x28, 0xD5, 0xF8, 0x79, 0xC3, 0xAD, 0x39, 0x3E, 0xD9 }
    Joining Network

    I suggest resetting your config to factory defaults and trying again. Also make sure your serial application (for viewing debug output) is running at 115200 since your app sets the mDot’s debug port to that speed.

    Cheers,

    Mike

    #14342
    Xiaotian Fei
    Participant

    I tried the same code again, it’s working now. Maybe I did something I have forgotten.

    Thanks for running this code for me.

    I have send the message {“t”:30.3} to TTN LoRa Server.

    
    Network Key
    
    Saving Config
    
    Device ID {0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0xB8, 0x53 }
    Network Id/App EUI {0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x00, 0x06, 0x56 }
    Network Key/App Key {0x7F, 0xA6, 0xF7, 0x50, 0x9F, 0xE5, 0x92, 0x28, 0xD5, 0xF8, 0x79, 0xC3, 0xAD, 0x39, 0x3E, 0xD9 }
    Joining Network
    
    {"t":30.3}
    
    {"t":30.3}
    
    #14347
    Mike Fiore
    Blocked

    Xiaotian,

    Happy to help! Please let us know if you have any other issues.

    Thanks for choosing MultiTech!

    Cheers,

    Mike

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.