Skip to content

Adding AU915 V1.0.2rB Support #1011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ElectronicallyE
Copy link

Hi @terrillmoore,

This is follow-on from #1010.

As mentioned in my issues post, I have created this branch with the changes needed to support AU915 V1.0.2rB. I have updated README.md to reflect this change.

The only other change I have made is the addition of LMIC_selectSubBand(1) in ttn-otaa.ino to align with the other examples.

I have tested this code using both The Things Network and Chirpstack and am confident it works.

Your feedback and willingness to merge into the "master" would be appreciated.

@Pranau-R
Copy link

Hi @ElectronicallyE ,

Thank you for bringing up this Dwell time issue to our attention.
We have reviewed your code changes and are trying to build and test it from the branch Adding-AU915-1.0.2-Support, but we were facing the following build issue:

Using previously compiled file: C:\Users\Pranau\AppData\Local\Temp\arduino\sketches\56F930A92C46CBD0986C6AB7E0C640A7\libraries\arduino-lmic\lmic\lmic_us915.c.o
c:\Users\Pranau\Documents\Arduino\libraries\arduino-lmic\src\lmic\lmic_au915.c:307:9: error: expected identifier or '(' before 'if'
         if (dwellDelay > globalDutyDelay) {
         ^~
c:\Users\Pranau\Documents\Arduino\libraries\arduino-lmic\src\lmic\lmic_au915.c:310:9: error: expected identifier or '(' before 'if'
         if (globalDutyDelay != 0) {
         ^~
c:\Users\Pranau\Documents\Arduino\libraries\arduino-lmic\src\lmic\lmic_au915.c:313:1: error: expected identifier or '(' before '}' token
 }
 ^

by removing the parentheses from the line 304 of lmic_au915.c, this build issue can be fixed.

We will test the changes and let you know how it works; meanwhile, you can do the necessary code changes and update the pull request.

Thank you.

Added { to line 302 to fix issue on line 304
@ElectronicallyE
Copy link
Author

ElectronicallyE commented Jun 24, 2025

Hi @Pranau-R,

Thanks for the reply. Quick fix on my end! I added a "{" to line 302.

I believe this has updated the pull request automatically.

Do let me know if there is anything else you need me to do.

@ElectronicallyE
Copy link
Author

Hi @Pranau-R,

Hope you are well. Just checking in to see if there are any further changes required.

It would be great to see this merged soon!

@Pranau-R
Copy link

Pranau-R commented Jul 1, 2025

Hi @ElectronicallyE,

Thank you for the reminder.

The build issue has been resolved, and we have started testing the changes using the example sketch ttn-otaa.ino. Our setup includes a gateway configured for the AU915 region and an end device registered on TTN app for the same region.

However, the device is currently unable to join the network. We have updated the sketch to include LMIC_selectSubBand(1) before do_send, as suggested in issue #1010, and are continuing to investigate.

Please let us know if there’s anything we might be overlooking. Once the changes are tested and verified, we will proceed with merging.

Thank you!

@ElectronicallyE
Copy link
Author

ElectronicallyE commented Jul 2, 2025

Hi @Pranau-R,

Thanks for the reply. If you are testing with a TTGO LoRa32 V1, you might need to downgrade the esp32 by Espressif Systems board library to 2.0.17. This is because the board has a 26 MHz crystal instead of the more common 40 MHz crystal which results in the clock not running at real-time and means the RX delay is incorrect. You would know this is an issue if you had to select a baud rate different to that specified in the code.

More information is available here:
jgromes/RadioLib#1471 (comment)

I'll try the code this evening and let you know how I get on.

Also make sure that the board is unplugged and plugged back in when trying to reconnect, instead of trying to use the "RST" button as I have found that this does not reset the device correctly.

@ElectronicallyE
Copy link
Author

ElectronicallyE commented Jul 3, 2025

Hi @Pranau-R,

This evening I have tested the code.

I downloaded my modified branch and removed the existing library I had installed.

The only changes I made in addition to my branch are:

lmic_project_config.h
I uncommented the following lines:

#define CFG_au915 1
#define CFG_sx1276_radio 1
#define LMIC_LORAWAN_SPEC_VERSION   LMIC_LORAWAN_SPEC_VERSION_1_0_2

ttn-otaa.ino
I added my APPEUI (LSB), DEVEUI (LSB) and APPKEY (MSB) from the TTN Console.

I changed const unsigned TX_INTERVAL = 60; to const unsigned TX_INTERVAL = 20; for testing.

I changed my "pin mapping" from...

const lmic_pinmap lmic_pins = {
     .nss = 6,
     .rxtx = LMIC_UNUSED_PIN,
     .rst = 5,
     .dio = {2, 3, 4},
};

to the following to match my board, being a TTGO LoRa32 V1 SX1276:

const lmic_pinmap lmic_pins = {
    .nss = 18,
    .rxtx = LMIC_UNUSED_PIN,
    .rst = 14,
    .dio = {26, 33, 32}
};

You will also see I have also modified lmic_bandplan_au915.h to set the JoinReq DR to DR0 for 1.0.2 instead of DR2 for 1.0.3 as per my comment back near the start of my issue post:
#1010 (comment)

I uploaded the code and the board connected first time. I power cycled the board several times without issue:
image

image image

Please note that I do have "Resets join nonces" enabled as there isn't any persistence (memory) written into the code.
image

@Pranau-R
Copy link

Pranau-R commented Jul 3, 2025

Hi @ElectronicallyE,

Thank you for sharing the detailed test results.
We have pulled your updated code and will begin testing shortly. We will share our feedback based on the results.
For reference, we're using the Catena 4610 board in our test setup.
Thanks again!

@Pranau-R
Copy link

Pranau-R commented Jul 4, 2025

Hi @ElectronicallyE ,

As mentioned earlier, we have successfully pulled the latest changes from your Adding-AU915-1.0.2-Support branch and we followed the same steps you have outlined.

As per the previous discussion:

In lmic_project_config.h, we uncommented the following:

#define CFG_au915 1
#define CFG_sx1276_radio 1
#define LMIC_LORAWAN_SPEC_VERSION   LMIC_LORAWAN_SPEC_VERSION_1_0_2

In ttn-otaa.ino, we:

  • Added our end device APPEUI (LSB), DEVEUI (LSB), and APPKEY (MSB) from the TTN Console.
  • Set const unsigned TX_INTERVAL = 10; for quicker testing.
  • Updated the pin mapping to support the Catena4610 board.
  • Added LMIC_selectSubBand(1) before the do_send() call.

The device is now able to join the network without any issues. However, it consistently joins using DR2, SF10, as shown in the TTN console screenshot below:
image

Next, we plan to test using the compliance-otaa-halconfig.ino sketch for more detailed debug output.
Please let us know if there’s anything we might have missed or if you have any further suggestions.

Thanks again!

@ElectronicallyE
Copy link
Author

ElectronicallyE commented Jul 5, 2025

Hi @Pranau-R,

Checked again this morning by reinstalling my branch, using the ttn-otaa.ino from scratch, making the exact same changes as I described above and it worked without an issue, sending the join request on DR0. I also created a new device in the TTN Console.

Did you make sure that your version of the library included the changes I made to lmic_bandplan_au915.h a couple of days ago to change the DR depending on the LoRaWAN Regional Parameter version (see 6de5bee)? I had missed adding this in my original merge request.

image

Here is my ttn-otaa.ino:

/*******************************************************************************
 * Copyright (c) 2015 Thomas Telkamp and Matthijs Kooijman
 * Copyright (c) 2018 Terry Moore, MCCI
 *
 * 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
 * arduino-lmic/project_config/lmic_project_config.h or from your BOARDS.txt.
 *
 *******************************************************************************/

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

//
// For normal use, we require that you edit the sketch to replace FILLMEIN
// with values assigned by the TTN console. However, for regression tests,
// we want to be able to compile these scripts. The regression tests define
// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non-
// working but innocuous value.
//
#ifdef COMPILE_REGRESSION_TEST
# define FILLMEIN 0
#else
# warning "You must replace the values marked FILLMEIN with real values from the TTN control panel!"
# define FILLMEIN (#dont edit this, edit the lines that use FILLMEIN)
#endif

// 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.
static const u1_t PROGMEM DEVEUI[8]={0x26, 0x1D, 0x07, 0xD0, 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 ttnctl can be copied as-is.
static const u1_t PROGMEM APPKEY[16] = {0x73, 0xB9, 0x97, 0xEA, 0x62, 0xA5, 0x20, 0x8A, 0xB2, 0xEB, 0x81, 0xF8, 0xED, 0x95, 0x58, 0x70};
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
// const lmic_pinmap lmic_pins = {
//     .nss = 6,
//     .rxtx = LMIC_UNUSED_PIN,
//     .rst = 5,
//     .dio = {2, 3, 4},
// };

const lmic_pinmap lmic_pins = {
    .nss = 18,
    .rxtx = LMIC_UNUSED_PIN,
    .rst = 14,
    .dio = {26, 33, 32}
};

void printHex2(unsigned v) {
    v &= 0xff;
    if (v < 16)
        Serial.print('0');
    Serial.print(v, HEX);
}

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("AppSKey: ");
              for (size_t i=0; i<sizeof(artKey); ++i) {
                if (i != 0)
                  Serial.print("-");
                printHex2(artKey[i]);
              }
              Serial.println("");
              Serial.print("NwkSKey: ");
              for (size_t i=0; i<sizeof(nwkKey); ++i) {
                      if (i != 0)
                              Serial.print("-");
                      printHex2(nwkKey[i]);
              }
              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;
        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"));
            }
            // 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;
        case EV_TXCANCELED:
            Serial.println(F("EV_TXCANCELED"));
            break;
        case EV_RXSTART:
            /* do not print anything -- it wrecks timing */
            break;
        case EV_JOIN_TXCOMPLETE:
            Serial.println(F("EV_JOIN_TXCOMPLETE: no JoinAccept"));
            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 {
        // 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.
}

void setup() {
    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();

    // TTN uses the 2nd sub-band (channels 8-15) (sub-band 1 when counting from 0).
    LMIC_selectSubBand(1);
    
    // Start job (sending automatically starts OTAA too)
    do_send(&sendjob);
}

void loop() {
    os_runloop_once();
}

Here is my lmic_project_config.h:

// project-specific definitions
//#define CFG_eu868 1
//#define CFG_us915 1
#define CFG_au915 1
//#define CFG_as923 1
//#define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP      /* for as923-JP; also define CFG_as923 */
//#define CFG_kr920 1
//#define CFG_in866 1
#define CFG_sx1276_radio 1
//#define CFG_sx1261_radio 1
//#define CFG_sx1262_radio 1
//#define ARDUINO_heltec_wifi_lora_32_V3
//#define LMIC_USE_INTERRUPTS
#define LMIC_LORAWAN_SPEC_VERSION   LMIC_LORAWAN_SPEC_VERSION_1_0_2
//#define LMIC_LORAWAN_SPEC_VERSION   LMIC_LORAWAN_SPEC_VERSION_1_0_3
//#define LMIC_DEBUG_LEVEL 1
//#define LMIC_DEBUG_LEVEL 2

There are no other files that I have changed as part of my testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants