Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #5612
    Adam
    Participant

    Hi, lovely board you’ve created, is there any examples to connect the Mini Ultra Pro (RFM95W) to the TTN with otaa? I’ve tried a few libraries but with no success.

    #6014
    LIM PHANG MOH
    Keymaster

    Hi Adam,
    Sorry if this comes a bit late. Was finalizing the V2 while this question came in. In the midst of writing a tutorial for this.
    But, here are the important points that get the example provided by Matthijs Kooijman’s LMIC library running correctly:

    • Both the Device EUI and Application EUI (both are the 8-bytes key) are displayed as MSB….LSB on the TTN dashboard. But, you must key in as LSB…MSB on the OTAA example.
    • Add LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100); after LMIC_reset();
    • Add #define Serial SerialUSB if you want to see the debug messages on the USB port.

    These are only 3 changes needed to get going.

    Some stuff I’ll be adding in the tutorial includes using the EUI64 identification and using the RTC to resides in low power mode while connected to the network. This will serve as a good skeleton firmware for low power application using OTAA to TTN.

    • This reply was modified 6 years, 10 months ago by LIM PHANG MOH.
    #6017
    LIM PHANG MOH
    Keymaster

    Forgot to mention that you will also need to have the DIO pins connection which I presume you already know, just in case. On V2 of the Mini Ultra Pro, it should look like this:

    // Pin mapping
    const lmic_pinmap lmic_pins = {
      .nss = 5,
      .rxtx = LMIC_UNUSED_PIN,
      .rst = 3,
      .dio = {2, 6, 7},
    };

    Of course, you can remove the D7 for DIO2 support if not using the FSK mode. On V1 of the Mini Ultra Pro, you can use any free pins (other than D2, D4 & D5) and connect the DIO pins up using wires.

    #6504
    matthiasnielsen
    Participant

    I am following your instructions trying to connect my Mini Ultra Pro V2 to TTN using Matthijs’ LCIM library. However, I am stuck at joining the TTN network.

    I’ve changed Matthijs’ ttn-otaa example in the following ways:
    – Added APPEUI from my TTN application page (made sure to reverse it)
    – Added DEVEUI from my TTN application page (made sure to reverse it)
    – Added APPKEY from my TTN application page (as is – i.e. not reversed)
    – Changed lmic_pins per your instructions above.
    – Added LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100); after LMIC_reset();
    – Added #define Serial SerialUSB for serial monitor output
    – Added while(!Serial); after Serial.begin(9600); (otherwise I get not output in the serial monitor)

    In the serial monitor I receive the following message and nothing more:

    Starting
    Packet queued
    321993: EV_JOINING

    Even if I leave it for minutes nothing happens. I am around 200 meters away from the nearest TTN access point, so I’m thinking rangewise I should be good (although this is my first experience with LoRa and/or TTN).

    Any suggestions as to what I can try to get it working?

    #6506
    matthiasnielsen
    Participant

    Quick update – I got it working with ABP, but still no luck with OTAA, which makes me think I might be setting up the TTN OTAA parameters wrong. However, I have no idea where to look for errors… Any suggestions would highly appreciated 🙂

    I’m going to leave it powered on overnight to see if it succeeds in joining…

    #6510
    LIM PHANG MOH
    Keymaster

    Hi Matthias,

    Check your TTN 8-byte DEV EUI. Mine didn’t connect until that gets corrected and same as on the device on OTAA join. Take note of it’s MSB-LSB sequence too. In fact, OTAA is easier (less things to make mistake on the dashboard except the above).

    #6512
    matthiasnielsen
    Participant

    Thanks for your reply!

    I think I might indeed be doing the DEV EUI part wrong. I have been using a EUI generated by TTN where I should be using the Ultra Pro Mini’s LoRa module’s EUI, right? However, I can’t seem to figure out how to retrieve the DEV EUI from the device – any suggestions?

    /Matthias

    #6514
    LIM PHANG MOH
    Keymaster

    Hi Matthias,
    I’m sorry but I should have put this up some time ago. My plan was to include the sleeping portion for a tutorial/guide before posting it up but it seems that I have to do it before this particular issue is solve. When it starts, the code prints out the 64-bit MAC address. Key those in as it is on the TTN dashboard.

    
    /*******************************************************************************
       Copyright (c) 2015 Thomas Telkamp and Matthijs Kooijman
    
       Permission is hereby granted, free of charge, to anyone
       obtaining a copy of this document and accompanying files,
       to do whatever they want with them without any restriction,
       including, but not limited to, copying, modification and redistribution.
       NO WARRANTY OF ANY KIND IS PROVIDED.
    
       This example sends a valid LoRaWAN packet with payload "Hello,
       world!", using frequency and encryption settings matching those of
       the The Things Network.
    
       This uses OTAA (Over-the-air activation), where where a DevEUI and
       application key is configured, which are used in an over-the-air
       activation procedure where a DevAddr and session keys are
       assigned/generated for use with all further communication.
    
       Note: LoRaWAN per sub-band duty-cycle limitation is enforced (1% in
       g1, 0.1% in g2), but not the TTN fair usage policy (which is probably
       violated by this sketch when left running for longer)!
    
       To use this sketch, first register your application and device with
       the things network, to set or generate an AppEUI, DevEUI and AppKey.
       Multiple devices can use the same AppEUI, but each device has its own
       DevEUI and AppKey.
    
       Do not forget to define the radio type correctly in config.h.
    
     *******************************************************************************/
    
    #include <lmic.h>
    #include <hal/hal.h>
    #include <SPI.h>
    #include <Wire.h>       
    #define EUI64_CHIP_ADDRESS 0x50
    #define EUI64_MAC_ADDRESS 0xF8
    #define EUI64_MAC_LENGTH 0x08
    #define Serial SerialUSB
    
    // 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] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
    void os_getArtEui (u1_t* buf) {
      memcpy_P(buf, APPEUI, 8);
    }
    
    // This should also be in little endian format, see above.
    u1_t DEVEUI[EUI64_MAC_LENGTH];
    void os_getDevEui (u1_t* buf) {
      memcpy(buf, DEVEUI, EUI64_MAC_LENGTH);
    }
    
    // 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 ttnctl can be copied as-is.
    // The key shown here is the semtech default key.
    static const u1_t PROGMEM APPKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
    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 = 60;
    
    // Pin mapping
    const lmic_pinmap lmic_pins = {
      .nss = 5,
      .rxtx = LMIC_UNUSED_PIN,
      .rst = 3,
      .dio = {2, 6, 7},
    };
    
    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"));
    
          // Disable link check validation (automatically enabled
          // during join, but not supported by TTN at this time).
          LMIC_setLinkCheckMode(0);
          break;
        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.println(F("Received "));
            Serial.println(LMIC.dataLen);
            Serial.println(F(" bytes of payload"));
          }
          // 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;
        default:
          Serial.println(F("Unknown event"));
          break;
      }
    }
    
    void do_send(osjob_t* j) {
      digitalWrite(13, HIGH);
      
      // Check if there is not a current TX/RX job running
      if (LMIC.opmode & OP_TXRXPEND) {
        Serial.println(F("OP_TXRXPEND, not sending"));
      } else {
        // Prepare upstream data transmission at the next possible time.
        LMIC_setTxData2(1, mydata, sizeof(mydata) - 1, 0);
        Serial.println(F("Packet queued"));
      }
      // Next TX is scheduled after TX_COMPLETE event.
      
      digitalWrite(13, LOW);
    }
    
    void setDevEui(unsigned char* buf)
    {
      Wire.begin();
      Wire.beginTransmission(EUI64_CHIP_ADDRESS);
      Wire.write(EUI64_MAC_ADDRESS);
      Wire.endTransmission();
      Wire.requestFrom(EUI64_CHIP_ADDRESS, EUI64_MAC_LENGTH);
       
      // Format needs to be little endian (LSB...MSB)
      while (Wire.available())
      {
        *buf-- = Wire.read();
      }
    }
    
    void setup() {
      unsigned char count;
      
      pinMode(4, OUTPUT);
      digitalWrite(4, HIGH);
      pinMode(13, OUTPUT);
      setDevEui(&DEVEUI[EUI64_MAC_LENGTH - 1]);
      while (!Serial) {};
      Serial.begin(115200);
      Serial.println(F("Starting"));
      Serial.print(F("DEVEUI: "));
      
      for (count = 0; count < EUI64_MAC_LENGTH; count++)
      {
        Serial.print("0x");
        if (DEVEUI[count] <= 0x0F) Serial.print("0");
        Serial.print(DEVEUI[count], HEX);
        Serial.print(" ");    
      }
      Serial.println();
    
    #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_setClockError(MAX_CLOCK_ERROR * 1 / 100);
    
      // Start job (sending automatically starts OTAA too)
      do_send(&sendjob);
    }
    
    void loop() {
      os_runloop_once();
    }
    
    #6583
    LIM PHANG MOH
    Keymaster

    Guys,
    You can now follow the guide here to connect to TTN through OTAA.

    #6706
    matthiasnielsen
    Participant

    Thanks for the link! It helped me getting both of mine working now 🙂

    A quick question – do I actually need to read out the Device ID of the Mini Ultra Pro and inserting it into the TTN dashboard?
    I mean, couldn’t I make up my own Device ID (or let TTN generate one) and insert that Device ID into the LCIM code that I upload to the Ultra Pro Mini? Or is the actual hardware Device ID necessary (if so, why)?

    #6711
    LIM PHANG MOH
    Keymaster

    Hi Matthias,

    A quick question – do I actually need to read out the Device ID of the Mini Ultra Pro and inserting it into the TTN dashboard?
    I mean, couldn’t I make up my own Device ID (or let TTN generate one) and insert that Device ID into the LCIM code that I upload to the Ultra Pro Mini? Or is the actual hardware Device ID necessary (if so, why)?

    You can used a random number during development, but in real LoRaWAN deployment, it is necessary to have a unique 64-bit ID. So, every single device is unique in the network. For example, every single RN2483/RN2903 module has an unique 64-bit ID too (same ID chip used on the Mini Ultra Pro V2). When doing an OTAA, basically you join the network through a process of exchanging some unique keys with the backend to enable the network to differentiate each devices globally (before assigning the dynamic DevAddr). You might want to read the importance of it here.

    #6720
    matthiasnielsen
    Participant

    Thanks for the reply!

    Helps me getting better grip on LoRa 🙂

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