rak811 LoRa tracker board
The board
Links
- Getting Started with the RAK LoRa Tracker Board
- RAK811-TrackerBoard
- RAK811 > Hardware_Specification
- RAKWireless / RAK811_LoRaWAN_Arduino
- Wisblock RAK811 with TinyLoRa
- Examples for RAK811 with Core Arduino
- AS923 LoRa GPS Tracking with MatchX MatchBox Gateway and RAK811 LoRa GPS Tracker Board
- Coocox CoIDE and GCC Arm Embedded Toolchain Download Links
- STM32CubeProg
- Arduino core support for STM32 based boards
Steps for demo code
- Start VirtualBox with Windows
- Download the firmware from github: RAKWireless / RAK811_BreakBoard
- Download the Coocox IDE, toolchain and flasher: RAK811-TrackerBoard > Tools or from the mirror CooCox
- Or download the newer toolchain from GNU Arm Embedded Toolchain Downloads
- Open the CiIDE and select the toolchain in "Project -> Select Toolchain Path"
- Open the "ClassA" project in "Project -> Open Project..."
- Build the project in "Project -> Build". The bin file ends up under the "coIDE/classA/classA/Debug/bin" folder in the project.
- Set the jumper on the board to the outmost position for 'program mode'
- Install and run the "Flash Loader Demonstrator" (or the STM32CubeProgrammer that also runs under linux)
Target: STM32L1-Cat2-128K - Use the RAK Serial Port tool for setting the "at" commands
Steps for Arduino code
- Start the Arduino IDE
- Add the STM32 board json URL to "File -> Preferences -> Additional Boards Manager URLs" (https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json)
- Restart the IDE and install the STM32 board under "Tools -> Board -> Boards Manager..."
- Select the "LoRa boards" with "RAK811 LoRa Tracker (16kb RAM)". Could be that you have a 32kB version but this is the safe choice
- Install the "MCCI LoRaWAN LMIC library" through "Sketch -> Include Library -> Manage Libraries..."
Issues
- The code did not accept any received 'at' commands. I found that it needed a weird combination of 'r' and 'n' characters most often not sent by the terminal program
- STM32CubeProgrammer needs "Oracle JDK 1.8" because of JavaFX
Arduino antenna switching
Arduino code sends the JOIN request and the request is receoived by the LoRa gateway but the JOIN is never completed. It could have something to do with the "external antenna receiving and transmitting state switching". That is implemented in LMIC but this board needs two bits to be flipped.
Receiving:
pinMode(RADIO_RF_CRX_RX, OUTPUT); digitalWrite(RADIO_RF_CRX_RX, HIGH); //control LoRa work to receive pinMode(RADIO_RF_CTX_PA, OUTPUT); digitalWrite(RADIO_RF_CTX_PA, LOW);
Transmitting:
pinMode(RADIO_RF_CRX_RX, OUTPUT); digitalWrite(RADIO_RF_CRX_RX, LOW); pinMode(RADIO_RF_CTX_PA,OUTPUT); digitalWrite(RADIO_RF_CTX_PA, HIGH); //control LoRa send by PA_BOOST
See firmware source code in boards/RAK811BreakBoard/sx1276-board.c:
void SX1276SetAntSw( uint8_t opMode ) { switch( opMode ) { case RFLR_OPMODE_TRANSMITTER: GpioWrite( &AntCtxPa, 1 ); GpioWrite( &AntCbtHf, 0 ); GpioWrite( &AntCrxRx, 0 ); //printf("-Tx-rn"); break; case RFLR_OPMODE_RECEIVER: case RFLR_OPMODE_RECEIVER_SINGLE: case RFLR_OPMODE_CAD: default: GpioWrite( &AntCtxPa, 0 ); GpioWrite( &AntCbtHf, 0 ); GpioWrite( &AntCrxRx, 1 ); //printf("-Rx-rn"); break; } }
Not joining
OTAA does not function with the LMIC Arduino library. See Not Joining for additional info and suggestions on how to fix this.
Arduino demo code
#include #include <hal/hal.h> #include #define BUILTIN_LED LED2 // 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] = { xxx }; 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] = { xxx }; 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] = { xxx }; void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16); } static uint8_t lora_data[64]; uint32_t lora_count = 0; static osjob_t sendjob; typedef enum { LORA_UNCONFIRMED, LORA_CONFIRMED }; // Schedule TX every this many seconds (might become longer due to duty cycle limitations). const unsigned TX_INTERVAL = 10; // Pin mapping const lmic_pinmap lmic_pins = { .nss = RADIO_NSS, .rxtx = RADIO_RF_CRX_RX, .rst = RADIO_RESET, .dio = {RADIO_DIO_0, RADIO_DIO_1, RADIO_DIO_2}, }; void printHex2(unsigned v) { v &= 0xff; if (v < 16) Serial.print('0'); Serial.print(v, HEX); } void onEvent (ev_t ev) { long now = os_getTime(); Serial.printf("Time %lu: ", now); switch (ev) { case EV_SCAN_TIMEOUT: Serial.println("EV_SCAN_TIMEOUT"); break; case EV_BEACON_FOUND: Serial.println("EV_BEACON_FOUND"); break; case EV_BEACON_MISSED: Serial.println("EV_BEACON_MISSED"); break; case EV_BEACON_TRACKED: Serial.println("EV_BEACON_TRACKED"); break; case EV_JOINING: Serial.println("EV_JOINING"); break; case EV_JOINED: Serial.println("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) { Serial.print(" "); printHex2(artKey[i]); } Serial.println(""); Serial.print("NwkSKey:"); for (size_t i = 0; i < sizeof(nwkKey); ++i) { 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; case EV_RFU1: Serial.println("EV_RFU1"); break; case EV_JOIN_FAILED: Serial.println("EV_JOIN_FAILED"); break; case EV_REJOIN_FAILED: Serial.println("EV_REJOIN_FAILED"); break; case EV_TXCOMPLETE: Serial.println("EV_TXCOMPLETE"); digitalWrite(BUILTIN_LED, LOW); if (LMIC.txrxFlags & TXRX_ACK) { Serial.printf("rssi:%d, snr:%1dn", LMIC.rssi, LMIC.snr); Serial.println("Received ack"); } if (LMIC.dataLen) { Serial.printf("rssi:%d, snr:%1dn", LMIC.rssi, LMIC.snr); Serial.printf("Received %d", LMIC.dataLen); Serial.print("Data:"); for (size_t i = 0; i < LMIC.dataLen; i++) { Serial.print(" "); printHex2(LMIC.frame[i + LMIC.dataBeg]); } Serial.println(); } // Schedule next transmission os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(TX_INTERVAL), do_send); break; case EV_LOST_TSYNC: Serial.println("EV_LOST_TSYNC"); break; case EV_RESET: Serial.println("EV_RESET"); break; case EV_RXCOMPLETE: // data received in ping slot Serial.println("EV_RXCOMPLETE"); break; case EV_LINK_DEAD: Serial.println("EV_LINK_DEAD"); break; case EV_LINK_ALIVE: Serial.println("EV_LINK_ALIVE"); break; case EV_SCAN_FOUND: Serial.println("EV_SCAN_FOUND"); break; case EV_TXSTART: Serial.println("EV_TXSTART"); break; case EV_TXCANCELED: Serial.println("EV_TXCANCELED"); break; case EV_RXSTART: Serial.println("EV_RXSTART"); break; case EV_JOIN_TXCOMPLETE: Serial.println("EV_JOIN_TXCOMPLETE"); break; default: Serial.printf("Unknown event %udn", 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("OP_TXRXPEND, not sending"); } else { // Prepare upstream data transmission at the next possible time. sprintf((char *)lora_data, "Hello %d", lora_count++); LMIC_setTxData2(1, lora_data, strlen((char *)lora_data), LORA_UNCONFIRMED); Serial.println("Packet queued"); digitalWrite(BUILTIN_LED, HIGH); } // Next TX is scheduled after TX_COMPLETE event. } void setup() { Serial.begin(115200); while ( !Serial ) delay(10); Serial.println("n*******************************"); Serial.println("System Starting..."); Serial.println(""); Serial.println("Pins:"); Serial.printf(" NSS: %d, RXTX: %d, RST: %d, DIO0: %d, DIO1: %d, DIO2: %dn", RADIO_NSS, RADIO_RF_CRX_RX, RADIO_RESET, RADIO_DIO_0, RADIO_DIO_1, RADIO_DIO_2); Serial.println("");
// Enable the LoRa module pinMode(RADIO_XTAL_EN, OUTPUT); digitalWrite(RADIO_XTAL_EN, HIGH); // LMIC init os_init(); LMIC_reset(); // Reset the MAC state. Session and pending data transfers will be discarded. //LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100); //LMIC_setLinkCheckMode(0); // Disable link check validation //LMIC_setAdrMode(true); //LMIC_setDrTxpow(DR_SF7, 14); // Set data rate and transmit power (note: txpow seems to be ignored by the library) // Start job (sending automatically starts OTAA too) do_send(&sendjob); pinMode(BUILTIN_LED, OUTPUT); digitalWrite(BUILTIN_LED, LOW); pinMode(LED1, OUTPUT); } void loop() { os_runloop_once(); digitalWrite(LED1, HIGH); delay(500); digitalWrite(LED1, LOW); delay(500); }