Hello,
I am using mdot as node. I can see in the TTN console:
*The join requests sent by the mdot
*The join ACCEPT sent by the gateway
But my node can’t receive it.
I used this code to test OTAA on my mdot:
#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]={...};
// AppKey
uint8_t AppKey[16]={....};
// Some defines for the LoRa configuration
/*
* EU868 Datarates
* ---------------
* DR0 - SF12BW125
* DR1 - SF11BW125
* DR2 - SF10BW125
* DR3 - SF9BW125
* DR4 - SF8BW125
* DR5 - SF7BW125
* DR6 - SF7BW250
*
* US915 Datarates
* ---------------
* DR0 - SF10BW125
* DR1 - SF9BW125
* DR2 - SF8BW125
* DR3 - SF7BW125
* DR4 - SF8BW500
*/
#define LORA_SF mDot::DR0
#define LORA_ACK 0
#define LORA_TXPOWER 14
// Ignoring sub band for EU modules.
static uint8_t config_frequency_sub_band = 1;
// Serial via USB for debugging only
Serial pc(USBTX,USBRX);
int main()
{
int32_t ret;
mDot* dot;
std::vector<uint8_t> send_data;
std::vector<uint8_t> recv_data;
std::vector<uint8_t> nwkId;
std::vector<uint8_t> nwkKey;
pc.baud(115200);
pc.printf("TTN OTAA mDot\n\r");
// get a mDot handle
dot = mDot::getInstance();
dot->setLogLevel(MTSLog::TRACE_LEVEL);
logInfo("Checking Config");
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++);
logInfo("Resetting Config");
// reset to default config so we know what state we're in
dot->resetConfig();
// Set Spreading Factor, higher is lower data rate, smaller packets but longer range
// Lower is higher data rate, larger packets and shorter range.
logInfo("Set SF");
if((ret = dot->setTxDataRate( LORA_SF )) != mDot::MDOT_OK) {
logError("Failed to set SF %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
}
logInfo("Set TxPower");
if((ret = dot->setTxPower( LORA_TXPOWER )) != mDot::MDOT_OK) {
logError("Failed to set Tx Power %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
}
logInfo("Set Public mode");
if((ret = dot->setPublicNetwork(true)) != mDot::MDOT_OK) {
logError("failed to set Public Mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
}
logInfo("Set AUTO_OTA Join mode");
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());
}
logInfo("Set Ack");
// 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());
}
// Library ignores the frequency sub band for 868MHz in EU
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("Set Network Id");
if ((ret = dot->setNetworkId(nwkId)) != mDot::MDOT_OK) {
logError("Failed to set Network Id %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
}
logInfo("Set Network Key");
if ((ret = dot->setNetworkKey(nwkKey)) != mDot::MDOT_OK) {
logError("Failed to set Network Id %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
}
logInfo("Saving Config");
// Save config
if (! dot->saveConfig()) {
logError("failed to save configuration");
}
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");
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");
}
and this is what I got in the debug:
[TRACE] Enable centi band
[TRACE] Initiating join...
[TRACE] Join Network - Auto OTA
[TRACE] Join attempt #4
[DEBUG] Send Join Packet with DR0
[TRACE] Number of enabled channels: 3 Mask: 00ff
[TRACE] Check freq: 0 - 868100000
[TRACE] Preparing frame
[TRACE] FRAME_TYPE_JOIN_REQ
[DEBUG] txPower: 14 AntG: 3 radioPower: 11
[INFO] TX Frequency: 868100000 SF: 12 BW: 125 kHz POW: 11 dBm
[DEBUG] Time on air: 23 bytes 1482 ms
[DEBUG] Time off air: 148200 ms duty-cycle: 1.0 %
[TRACE] Rx Window 1 - Frequency: 868100000 BW: 0 SF: 12
[TRACE] Rx Window 2 - Frequency: 869525000 BW: 0 SF: 12
[TRACE] Windows Expired
[ERROR] Failed to join network
[ERROR] failed to join network [-4][Join Error]
On the gateway, here is the JOIN_ACCEPT:
{
"gw_id": "...",
"payload": "IIahjicSMdDMqdc4EejLQxW+VZpnfJ8EOoXdrIw4lBT3",
"lora": {
"spreading_factor": 12,
"bandwidth": 125,
"air_time": 1810432000
},
"coding_rate": "4/5",
"timestamp": "2017-08-08T15:56:26.114Z",
"frequency": 869525000
}
Any idea what is wrong? or how can I debug the issue? is there any way to see logs in the kerlink?
Thanks!