Support for LoRAWAN HAT using SX1302

Connecting the SX1302 LoRAWAN HAT

  1. Enable I2C, SPI and UART. Edit the file /boot/hw_intfc.conf by running command sudo nano /boot/hw_intfc.conf. And make the changes given below.

    intfc:i2c7=on
    intfc:spi1=on
    intfc:uart2=on 
    # Uncomment the line 
    intfc:dtoverlay=devspi1
    
  2. Disable the UART debug serial, by editing the file /boot/extlinux/extlinux.conf sudo nano /boot/extlinux/extlinux.conf. And removing console=ttyS2,1500000n8 from APPEND variable.

    The edited line should look like below

    APPEND earlycon=uart8250,mmio32,0xff1a0000 swiotlb=1 coherent_pool=1m earlyprintk init=/init
    
  3. Connect the SX1302 HAT to BrainyPi.

Compiling the SX1302 libraries

  1. Install pre-requisites

    sudo apt update
    sudo apt install git build-essential
    
  2. Clone the library from github

    git clone https://github.com/shunyaos/sx1302_hal.git
    
  3. Compile the library

    cd sx1302_hal
    make clean all
    make all
    
  4. Edit the file tools/reset_lgw.sh, and change the variables given below

    1. Original values
      SX1302_RESET_PIN=23     # SX1302 reset
      SX1302_POWER_EN_PIN=18  # SX1302 power enable
      SX1261_RESET_PIN=22     # SX1261 reset (LBT / Spectral Scan)
      AD5338R_RESET_PIN=13    # AD5338R reset (full-duplex CN490 reference design)
      
    2. Changed values
      SX1302_RESET_PIN=145     # SX1302 reset
      SX1302_POWER_EN_PIN=131  # SX1302 power enable
      SX1261_RESET_PIN=149     # SX1261 reset (LBT / Spectral Scan)
      AD5338R_RESET_PIN=76    # AD5338R reset (full-duplex CN490 reference design)
      

    Note: This is done to make the library compatible with BrainyPi.

  5. Copy the tools/reset_lgw.sh script to correct locations

    cp tools/reset_lgw.sh util_chip_id/
    cp tools/reset_lgw.sh packet_forwarder/
    
  6. That is it now the libraries are compiled and ready to use.

Connecting the LoRA concentrator to TTN

  1. TTN is free LoRAWAN network.

  2. To test if the SX1302 is working we connect to TTN and see if the data is being received.

  3. Connect BrainyPi to internet using steps given here - Rbian OS | BrainyPi

  4. First sign up on TTN and create an account.

  5. Then Go to Gateways and Register a Gateway.

  6. The register page asks for EUID of the SX1302 chip. To get the EUID we need to run command on BrainyPi.

    cd util_chip_id
    sudo ./chip_id
    

  7. Copy the EUI and put it in the TTN gateway register page.

  8. Download global_config.json.

  9. Copy the sample packet_forwarder config file global_conf.json.sx1250.XXXXX, Where XXXXX is the frequency plan. In this example the Frequency plan is EU868.

    cd packet_forwarder/
    cp global_conf.json.sx1250.EU868 test_conf
    
  10. Open the global_config.json in an editor.

  11. Copy the lines in the key gateway_conf

  12. Open the file packet_forwarder/test_conf nano test_conf.

  13. Paste the lines copied from the global_config.json to test_conf

  14. This will configure the LoRA concentrator to connect to TTN using the frequency plan.

  15. Now start the packet forwarder

    sudo ./lora_pkt_fwd -c test_conf
    

    Packet forwarder starts sending data to TTN.

  16. This data can also be seen in the TTN Live Data section

  17. Now your LoRA Gateway is running and is connected to TTN.

Troubleshooting

1. Running the command sudo ./lora_pkt_fwd -c test_conf gives error.

  1. This error is due to misconfigured RESET and POWER_EN GPIO pins in the file tools/reset_lgw.s
  2. Get the correct pinout from the HAT manufacturer.
  3. And correctly configure the file tools/reset_lgw.s

2. Command sudo ./lora_pkt_fwd -c test_conf runs but TTN shows disconnected.

  1. Make sure that the LoRA gateway EUI is registered.
  2. Make sure that the frequency plan configured in TTN and in the packet_forwarder library matches.