Join Accept loop

Hello. I have a question regarding the status of my LoRa in TTN.

As of now, it loops on the accept join-request to forward join-accept message. I do not know what seems to be the problem. The gateway is near me. I am using an sx1276 transmitter connected to an Arduino pro mini.

Can anyone help me with this problem?

Here is a picture for reference.

Thanks.
image

what does the Arduino serial monitor display? upload as text not a screen image

how is the LoRaWAN module connected to the pro mini? the SPI looks OK as it initialises and attempts a JOIN but check the DIO0, DIO1 and DIO2 connections

upload the code? in particular check the setting of lmic_pins matches the pro mini connections, e.g.

// Pin mapping for Adafruit Feather 32u4 LoRa
const lmic_pinmap lmic_pins = {  
   .nss = 10,
   .rxtx = LMIC_UNUSED_PIN,
   .rst = LMIC_UNUSED_PIN,  
   .dio = {4, 5, 7}, //DIO0, DIO1 and DIO2 connected

Hi Horace.

Inputs DIO1, DIO1, and DIO2 are connected in digital pins 3,4,and 5 respectively. In addition, here is a picture of the serial monitor, which it also a loop of "EV_TXSTART."

image

Here is the code for reference:

#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
#include <DHT.h>
#include <DHT_U.h>


// This EUI must be in little-endian format, so least-significant-byte
// first. When copying an EUI from ttnctl output, this means to reverse
// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3,
// 0x70.
static const u1_t PROGMEM APPEUI[8]= { 0x34, 0x34, 0x34, 0x12, 0x12, 0x12, 0x12, 0x12 };
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}

// This should also be in little endian format, see above.
static const u1_t PROGMEM DEVEUI[8]= { 0xF0, 0x21, 0x00, 0xD8, 0x7E, 0xD5, 0xB3, 0x70 };
void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}

// This key should be in big endian format (or, since it is not really a
// number but a block of memory, endianness does not really apply). In
// practice, a key taken from the TTN console can be copied as-is.
static const u1_t PROGMEM APPKEY[16] = { 0x01, 0x7F, 0x12, 0x8B, 0xC8, 0x32, 0x73, 0x2D, 0x0F, 0xFC, 0x38, 0x0C, 0x98, 0x8B, 0xD4, 0x0D };
void os_getDevKey (u1_t* buf) {  memcpy_P(buf, APPKEY, 16);}

static uint8_t mydata[] = "Hello, world!";
static osjob_t sendjob;

// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 20;

// Pin mapping
//# error "Unknown target"
const lmic_pinmap lmic_pins = {
    .nss = 10, 
    .rxtx = LMIC_UNUSED_PIN,
    .rst = 9,
    .dio = {3,4,5}, 
    .rxtx_rx_active = 0,
    .rssi_cal = 0,              // LBT cal for in dB
    .spi_freq = 1000000
};

#define DHT_PIN 7
#define DHTTYPE DHT22
DHT dht(DHT_PIN, DHTTYPE);

void onEvent (ev_t ev) {
    Serial.print(os_getTime());
    Serial.print(": ");
    switch(ev) {
        case EV_SCAN_TIMEOUT:
            Serial.println(F("EV_SCAN_TIMEOUT"));
            break;
        case EV_BEACON_FOUND:
            Serial.println(F("EV_BEACON_FOUND"));
            break;
        case EV_BEACON_MISSED:
            Serial.println(F("EV_BEACON_MISSED"));
            break;
        case EV_BEACON_TRACKED:
            Serial.println(F("EV_BEACON_TRACKED"));
            break;
        case EV_JOINING:
            Serial.println(F("EV_JOINING"));
            break;
        case EV_JOINED:
            Serial.println(F("EV_JOINED"));
            {
              u4_t netid = 0;
              devaddr_t devaddr = 0;
              u1_t nwkKey[16];
              u1_t artKey[16];
              LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey);
              Serial.print("netid: ");
              Serial.println(netid, DEC);
              Serial.print("devaddr: ");
              Serial.println(devaddr, HEX);
              Serial.print("artKey: ");
              for (int i=0; i<sizeof(artKey); ++i) {
                if (i != 0)
                  Serial.print("-");
                Serial.print(artKey[i], HEX);
              }
              Serial.println("");
              Serial.print("nwkKey: ");
              for (int i=0; i<sizeof(nwkKey); ++i) {
                      if (i != 0)
                              Serial.print("-");
                      Serial.print(nwkKey[i], HEX);
              }
              Serial.println("");
            }
            // Disable link check validation (automatically enabled
            // during join, but because slow data rates change max TX
      // size, we don't use it in this example.
            LMIC_setLinkCheckMode(0);
            break;
        /*
        || This event is defined but not used in the code. No
        || point in wasting codespace on it.
        ||
        || case EV_RFU1:
        ||     Serial.println(F("EV_RFU1"));
        ||     break;
        */
        case EV_JOIN_FAILED:
            Serial.println(F("EV_JOIN_FAILED"));
            break;
        case EV_REJOIN_FAILED:
            Serial.println(F("EV_REJOIN_FAILED"));
            break;
            break;
        case EV_TXCOMPLETE:
            Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
            if (LMIC.txrxFlags & TXRX_ACK)
              Serial.println(F("Received ack"));
            if (LMIC.dataLen) {
              Serial.print(F("Received "));
              Serial.print(LMIC.dataLen);
              Serial.println(F(" bytes of payload"));
              Serial.print("Port: ");
              Serial.println(LMIC.frame[(LMIC.dataBeg-1)]);
              Serial.print("Data: ");
             // char rec_data = (LMIC.frame + LMIC.dataBeg);
              for (int i=0; i< LMIC.dataLen; ++i) {
                if (i != 0)
                  Serial.print(",");
                Serial.print(LMIC.frame[LMIC.dataBeg+i], HEX);
              }
              Serial.println();
            }
            // Schedule next transmission
            os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
            break;
        case EV_LOST_TSYNC:
            Serial.println(F("EV_LOST_TSYNC"));
            break;
        case EV_RESET:
            Serial.println(F("EV_RESET"));
            break;
        case EV_RXCOMPLETE:
            // data received in ping slot
            Serial.println(F("EV_RXCOMPLETE"));
            break;
        case EV_LINK_DEAD:
            Serial.println(F("EV_LINK_DEAD"));
            break;
        case EV_LINK_ALIVE:
            Serial.println(F("EV_LINK_ALIVE"));
            break;
        /*
        || This event is defined but not used in the code. No
        || point in wasting codespace on it.
        ||
        || case EV_SCAN_FOUND:
        ||    Serial.println(F("EV_SCAN_FOUND"));
        ||    break;
        */
        case EV_TXSTART:
            Serial.println(F("EV_TXSTART"));
            break;
        default:
            Serial.print(F("Unknown event: "));
            Serial.println((unsigned) ev);
            break;
    }
}

void do_send(osjob_t* j){
    // Check if there is not a current TX/RX job running
    if (LMIC.opmode & OP_TXRXPEND) {
        Serial.println(F("OP_TXRXPEND, not sending"));
    } else {
        uint32_t humidity = dht.readHumidity(false)*100;
        uint32_t temperature = dht.readTemperature(false) * 100;
        
        Serial.println("Humidity: " + String(humidity));
        Serial.println("Temperature: " + String(temperature));
        
        byte payload[4];
        payload[0] = highByte(humidity);
        payload[1] = lowByte(humidity);
        payload[2] = highByte(temperature);
        payload[3] = lowByte(temperature); 
      
        // Prepare upstream data transmission at the next possible time.
        LMIC_setTxData2(3, (xref2u1_t)(payload), sizeof(payload), 0);
        Serial.println(F("Packet queued"));
    }
    // Next TX is scheduled after TX_COMPLETE event.
}

void setup() {
    delay(5000);
    while (! Serial)
        ;
    Serial.begin(9600);
    Serial.println(F("Starting"));

    #ifdef VCC_ENABLE
    // For Pinoccio Scout boards
    pinMode(VCC_ENABLE, OUTPUT);
    digitalWrite(VCC_ENABLE, HIGH);
    delay(1000);
    #endif

    // LMIC init
    os_init();
    // Reset the MAC state. Session and pending data transfers will be discarded.
    LMIC_reset();

    LMIC_setLinkCheckMode(0);
    LMIC_setDrTxpow(DR_SF7,14);

    // Start job (sending automatically starts OTAA too)
    do_send(&sendjob);
}

void loop() {
    os_runloop_once();
}

check you have the APPEUI DEVEUI etc correct
I think the last bytes of the APPEUI should be 0xD5, 0xB3, 0x70.

if the join fails it should say something like

15018: EV_JOINING
330902: EV_TXSTART
724820: EV_JOIN_TXCOMPLETE: no JoinAccept

if it joins it should say

315110: EV_JOINING
767674: EV_TXSTART
1090567: EV_JOINED
etc etc

I have issued the AppEUI, but the TTN issued the DevEUI and APPKey. I have tried also in other locations using the gateway, and it somehow worked. Does it mean that the place is relevant to the transmission of data?

if it sometimes joins and sometimes not the distance from the gateway could be a problem
the gateway probably receives the join request but the LoRa device is too far from the Gateway to receive the join accept
what antenna do you have on the LoRa module?

I am using this SX1276: China Low Price SX1276 SX1276 XL1276 LORA Wireless Spread Spectrum Module 868 M 915 M - Quotation - GNS COMPONENTS

Is the problem more or less on the gateway?

you need to attach an antenna to the ANT pin
have a look at LoRa antenna-length-for-868-and-433-mhz
how did you connect the SX1276 to the Pro Mini, e.g. via a PCB, soldered wires direct to the SX1276, etc
show us a photo?

I have used this site for my reference: OTAA-based LoRaWAN Node with Arduino & LoRa SX1276

The connections are directly from the pro mini to the transmitter.

In addition, I have attached the included antenna to the ant pin.

connections look correct
one thing to try is setting the relative clock error after the call to LMIC_reset()

  LMIC_reset();
  LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100);

without this my Feather 32u4 will not join

which LMIC library are you using?
I use MCCI_LoRaWAN_LMIC_library
and code based on File>Examples>MCCI LoRaWAN LMIC library>ttn-otaa

I am using the same code and library.

Will check on this.

This worked for me. Thank you!

Hi again. Would like to ask if how to set the device to transmit every minute? It seems that it stops transmitting once it has sent a payload.

it should transmit every TX_INTERVAL, e.g. in the onEvent() function on EV_TXCOMPLETE event

case EV_TXCOMPLETE:
            Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
 ............
            // Schedule next transmission
            os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
            break;

do you see "EV_TXCOMPLETE (includes waiting for RX windows)" on the serial monitor

what appears on your serial monitor?

can you schedule a Downlink from the TTN server? if so does the LoRa module receive it OK?

Yes, it is visible as seen in the picture below.

I tested this earlier, and every 30 seconds it transmits. However, as of the moment, it stops once it has found a payload.

Is there a limit as to how many payloads/downlinks/uplinks TTN can receive?

Here are some pictures for reference.

image

The picture below shows a payload every 30 seconds.

I've also noticed that the uplink and downlink meter in TTN became N/A.

no idea why you are getting FAILURE! message when the TTN server indicates you are receiving uplinks every 30 seconds

my TX_INTERVAL is set to 1 minute

// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 60;

the serial monitor output is

Starting
CFG_eu868
Packet queued
315074: EV_JOINING
612857: EV_TXSTART
935750: EV_JOINED
netid: 19
devaddr: ttttttt
AppSKey: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
NwkSKey: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
937194: EV_TXSTART
1319584: EV_TXCOMPLETE (includes waiting for RX windows)
5070781: EV_TXSTART
Packet queued
5453173: EV_TXCOMPLETE (includes waiting for RX windows)
9204204: EV_TXSTART
Packet queued
9525758: EV_TXCOMPLETE (includes waiting for RX windows)
Received 8 bytes of payload
 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88

you can see a three uplink transmissions and one downlink
the TTN server looks like