PineDio LoRa Gateway: Testing The Prototype

📝 11 Nov 2021

Previously we tested two new wireless gadgets by Pine64…

Both gadgets transmit and receive small data packets over incredible distances thanks to LoRa, the Long-Range Low-Bandwidth wireless network.

(Up to 5 km or 3 miles in urban areas… 15 km or 10 miles in rural areas!)

Today we test the third LoRa gadget by Pine64: PineDio LoRa Gateway

PineDio LoRa Gateway

What’s a LoRa Gateway? How does it differ from other LoRa gadgets?

PineDio Stack and PineDio USB are perfectly fine for Point-to-Point Wireless Communication.

But if we need to relay data packets to multiple devices or to the internet, we need a LoRa Gateway like PineDio Gateway.

(It’s like a WiFi Router, but for LoRa)

LoRa works over the internet?

Yes when we connect PineDio Gateway to The Things Network, the free-to-use public global network for LoRa gadgets.

(We’ll learn how in a while)

PineDio Gateway relays LoRa Packets to The Things Network

The Things Network is a public LoRa network. Why do we need PineDio Gateway?

Network Coverage for The Things Network is spotty in some regions.

Hopefully Pine64 will make PineDio Gateway highly affordable for Schools, Workplaces and Homes to install everywhere… And grow The Things Network!

(Coverage map for The Things Network)

The data packets received by The Things Network… What can we do with them?

We may configure The Things Network to…

What about other LoRa networks?

PineDio Gateway runs an open source LoRa Network Stack. (Based on Arm64 Linux)

We could possibly integrate PineDio Gateway with other LoRa Mesh Networks… Like Meshtastic (Data Mesh), QMesh (Voice Mesh) and Mycelium Mesh (Text Mesh).

Will PineDio Gateway support Helium Network?

Probably not. Our pre-production PineDio Gateway doesn’t have a Cryptographic Co-Processor.

(More about Cryptographic Co-Processors)

Can we run our LoRa Gateway on a local network, without connecting to the cloud?

Yep just install ChirpStack, the open source LoRaWAN Stack.

(LoRa Packets received by ChirpStack will be published to a Local MQTT Queue)

Inside PineDio Gateway

(Source)

§1 Inside PineDio Gateway

What’s inside PineDio Gateway?

Our pre-production PineDio Gateway has two boards inside…

What’s a LoRa Concentrator? How does it differ from a LoRa Transceiver?

LoRa Transceivers (like SX1262 in PineDio Stack and PineDio USB) are designed to talk to one LoRa device at a time.

LoRa Concentrators (like SX1302 in PineDio Gateway) can handle data packets from multiple LoRa devices across multiple frequencies at the same time.

That’s why LoRa Gateways have a LoRa Concentrator inside.

(And nope, we can’t build a proper LoRa Gateway with a plain LoRa Transceiver)

Back of PineDio Gateway

What ports and connectors are on PineDio Gateway?

In the pic above we see connectors for…

(All these need to be connected except HDMI, which is useful for troubleshooting)

The connectors not shown are microSD, USB 2.0, Audio Input / Output.

Note that we’re testing the pre-production PineDio Gateway, so some features may change…

Underside of PineDio Gateway

§2 Install PineDio Gateway

Let’s install our PineDio Gateway…

  1. Download RTP’s awesome all-in-one Armbian Image for PineDio Gateway…

    “Pinedio Mesh Gateway Image”

    (Remember to buy RTP a coffee! 👍)

  2. Flash the Armbian Image to a microSD Card (32 GB or bigger)

    (balenaEtcher works on Linux, macOS and Windows)

  3. On PineDio Gateway, connect the LoRa Antenna, GPS Antenna, Ethernet LAN and DC Power.

    (HDMI Output is optional)

    CAUTION: Always connect the Antenna before Powering On… Or the LoRa Module may get damaged!

  4. Insert the microSD Card

  5. Power on PineDio Gateway

If HDMI Output is connected: We should see PineDio Gateway starting the services for ChirpStack and The Things Network (Packet Forwarder)…

PineDio Gateway starts ChirpStack and Packet Forwarder for The Things Network

(ChirpStack is the open source LoRaWAN Stack, we won’t use it today)

PineDio Gateway is ready to be configured over SSH!

SSH to PineDio Gateway

§2.1 SSH to PineDio Gateway

Let’s connect to PineDio Gateway over SSH

  1. On our computer, enter this…

    ssh pinedio@rak-gateway
    

    Password is…

    SoPinePass!!!
    

    (Source)

  2. Check the Packet Forwarder Log for The Things Network…

    sudo tail /var/log/daemon.log
    

    PineDio Gateway should have started the LoRa Concentrator

    Note: chip version is 0x10 (v1.0)
    INFO: using legacy timestamp
    INFO: LoRa Service modem: configuring preamble size to 8 symbols
    ARB: dual demodulation disabled for all SF
    INFO: found temperature sensor on port 0x39
    INFO: [main] concentrator started, packet can now be received
    INFO: concentrator EUI: ...
    WARNING: [gps] GPS out of sync, keeping previous time reference
    INFO: [modify_os_time] local_time=1636244956, gps_time=1636244955
    

    (See pic above)

  3. To change the password

    passwd
    
  4. To change the hostname (“rak-gateway”)…

    sudo nano /etc/hostname
    sudo nano /etc/hosts
    sudo reboot
    

    Rename “rak-gateway” to our desired hostname.

§2.2 Set LoRa Frequency

Next we set the LoRa Frequency that PineDio Gateway shall use for our region…

  1. On PineDio Gateway, run this…

    sudo gateway-config
    

    We should see…

    Gateway Config

  2. Select “Setup RAK Gateway Channel Plan”

    We should see…

    Gateway Config: RAK Gateway Channel Plan

  3. Select “Server Is TTN”

    We should see…

    Gateway Config: LoRa Frequency

  4. Select the LoRa Frequency for our region based on this…

    “Frequency Plans by Country”

  5. Select Quit to exit

§2.3 Get Gateway ID

Finally we fetch the unique factory-installed Gateway ID from PineDio Gateway.

On PineDio Gateway, run this…

gateway-version

We should see…

SoPine with baseboard, OS "11 (bullseye)", 5.10.60-sunxi64.
RAKWireless gateway RAK7248 no LTE version 4.2.7R install from source code.
Gateway ID: YOUR_GATEWAY_ID

Copy the Gateway ID. We’ll use it in the next section.

Getting Gateway ID

§3 Connect to The Things Network

We’re ready to connect PineDio Gateway to The Things Network!

  1. Create a free account on The Things Network…

    “The Things Network: Sign Up”

  2. Log in and select the nearest region

    (Either US, Europe or Australia)

  3. Click Gateways and Add Gateway

    Add Gateway

  4. Fill in these fields…

    Gateway ID needs to be globally unique. (Choose wisely!)

    Gateway EUI (Extended Unique Identifier) is the Gateway ID from the previous section.

    Frequency Plan should match the LoRa Frequency from the previous section.

  5. Click “Create Gateway”

§3.1 Configure Gateway

Next we copy the Gatway Settings from The Things Network to PineDio Gateway…

  1. Browse to the Gateway that we have added

  2. Click “Download global_conf.json”

    Our Gateway in The Things Network

  3. Open the Downloaded global_conf.json with a text editor.

    It should look like this…

    Gateway Config

  4. On our PineDio Gateway, run this…

    sudo gateway-config
    
  5. Select “Edit Packet Forwarder Config”

  6. Look for the gateway_conf section…

    Edit Packet Forwarder Config

  7. Replace these values from the Downloaded global_conf.json

    "gateway_conf": {
      "gateway_ID":     ...,
      "server_address": ...,
      "serv_port_up":   ...,
      "serv_port_down": ...,
    
  8. Scroll down and look for the end of the gateway_conf section (just after beacon_power)…

    Edit Packet Forwarder Config

  9. Insert the entire servers section from the Downloaded global_conf.json

    "servers": [ {
      "gateway_ID":     ...,
      "server_address": ...,
      "serv_port_up":   ...,
      "serv_port_down": ...,
    } ]
    

    (Check the trailing commas, especially after beacon_power!)

  10. Our updated file should look like this…

    Packet Forwarded Config

  11. Save the file.

    Select “Restart Packet Forwarder”

(More about Packet Forwarder in the Appendix)

§3.2 Gateway Is Up!

How will we know if our Gateway is connected?

In The Things Network, browse to our Gateway and click “Live Data” (in the left bar)

We should see the Heartbeat Messages (Gateway Status) received from our Gateway…

Gateway Live Data

Now if we’re lucky, we might see Uplink Messages

Uplink Messages

What are the Uplink Messages?

These are LoRa Messages from nearby devices that our Gateway has helpfully relayed to The Things Network.

Yep we’re officially a contributor to the globally-connected The Things Network!

In case of problems, check the Packet Forwarder Log on our Gateway…

sudo tail /var/log/daemon.log

(Check the Appendix for the sample log)

PineDio Stack BL604 RISC-V Board

(Source)

§4 Test with PineDio Stack

PineDio Gateway works with all LoRa gadgets right?

Yep! Assuming that our LoRa gadget runs LoRaWAN Firmware.

Today we shall test PineDio Gateway with PineDio Stack BL604, the 32-bit RISC-V Board with a LoRa Transceiver inside. (Pic above)

This is how we transmit Sensor Data (Temperature) from PineDio Stack to The Things Network via PineDio Gateway…

PineDio Gateway relays LoRa Packets to The Things Network

  1. Log on to The Things Network Console

  2. Create an Application and add a Device

    “Add Device to The Things Network”

  3. Configure the CBOR Payload Formatter so that we will see the decoded temperature…

    “Configure Payload Formatter”

  4. On PineDio Stack: Build, flash and run the LoRaWAN Firmware

    “Build and Run LoRaWAN Firmware”

  5. Start the LoRaWAN Firmware on PineDio Stack…

    “Run the LoRaWAN Firmware”

  6. At the PineDio Stack Command Prompt, enter this command…

    las_app_tx_tsen 2 0 4000 10 60
    

    This transmits PineDio Stack’s Internal Temperature every 60 seconds. (For the next 10 minutes)

  7. Switch back to The Things Network Console.

    Click Applications → (Your Application) → Live Data

  8. Our Decoded Sensor Data should appear in the Live Data Table like so…

    Payload: { l: 4000, t: 4836 }
    

    Decoded Sensor Data in the Live Data Table

  9. Click on a message in the Live Data Table.

    We should see the decoded_payload field containing our Decoded Sensor Data…

    {
      ...
      "uplink_message": {
        ...
        "decoded_payload": {
          "l": 4000,
          "t": 4836
        }    
    

    These are the Light Sensor (“l”) and Temperature Sensor (“t”) values transmitted by PineDio Stack to The Things Network via PineDio Gateway.

    Yep PineDio Gateway works great with PineDio Stack!

    (Our Temperature Values are scaled up 100 times… 4836 means 48.36 ºC)

Here’s something interesting we might spot in the Live Data…

Two gateways in a single message

Why are there two (or more) Gateways in a single message?

Remember The Things Network is a Public Wireless Network with Gateways contributed by the community.

Thus it’s perfectly OK for multiple Gateways to receive our message.

(The Things Network will helpfully merge the duplicate messages into one)

Which is super awesome because it means we have (some) Wireless Redundancy in The Things Network!

RAKwireless WisGate D4H Gateway (RAK7248) and PineDio Gateway

RAKwireless WisGate D4H Gateway (above) and PineDio Gateway (below)

§5 Benchmark with RAKwireless WisGate

How does PineDio Gateway compare with other LoRa Gateways?

Let’s benchmark PineDio Gateway with RAKwireless WisGate D4H Gateway (RAK7248). (Pic above)

WisGate D4H is based on the same RAKwireless RAK2287 + Semtech SX1302 Concentrator as PineDio Gateway.

Thus we would expect the wireless performance of the two LoRa Gateways to be highly similar.

§5.1 Compare LoRa Reception

How shall we benchmark the two gateways for receiving LoRa packets?

We log on to The Things Network, browse to the two Gateways and view the Live Data

Compare PineDio Gateway with WisGate D4H: Single packet

For a single received packet, we see that the Received Signal Strength (RSSI) recorded by PineDio Gateway is slightly weaker than WisGate D4H…

(Higher numbers are better… -103 is better than -108)

Compare PineDio Gateway with WisGate D4H: Multiple packets

Across multiple packets (pic above), we see that the Received Signal Strength recorded by PineDio Gateway (left) is generally slightly weaker than WisGate D4H (right)…

This suggests that WisGate D4H might receive slightly more packets than PineDio Gateway. Especially if the packets were transmitted far from the Gateway.

(We’re talking packets in the -110 dBm to -120 dBm range… Close to the reception limit of LoRa Gateways)

Compare PineDio Gateway with WisGate D4H: Nearby packet

What about packets transmitted from nearby devices?

For a packet transmitted near the Gateways (pic above), the Received Signal Strength for PineDio Gateway is still slightly weaker than WisGate D4H…

But this shouldn’t be a problem… Due to the higher Signal Strength, PineDio Gateway will receive the same packets as WisGate D4H.

WisGate Antenna (left) vs PineDio Gateway Antenna (right)

WisGate Antenna (left) vs PineDio Gateway Antenna (right)

§5.2 Compare Antennas

Both LoRa Gateways are based on the same LoRa Concentrator. Why the difference in LoRa Reception?

The WisGate and PineDio Gateways have different antennas.

This might affect the LoRa Reception for the gateways.

Unfortunately we can’t swap the two antennas and test… The Antenna Connectors don’t match. (Pic above)

WisGate Antenna (above) vs PineDio Gateway Antenna (below)

I see a pattern… Why is one antenna twice the length of the other?

That’s because LoRa Antennas are typically “λ / 2” or “λ / 4” long.

Let’s do the math…

Which matches our Antenna Lengths!

PineDio LoRa Family: PineDio Gateway, PinePhone Backplate and PineDio USB Adapter

PineDio LoRa Family: PineDio Gateway, PinePhone Backplate and PineDio USB Adapter

§6 What’s Next

This article concludes our testing of the entire PineDio Family of LoRa Gadgets by Pine64!

  1. PineDio Stack BL604

  2. PineDio USB Adapter

  3. PineDio Gateway

  4. PinePhone LoRa Backplate

I hope Pine64 will make these awesome LoRa Gadgets available to the community real soon!

(I’m stuck at PinePhone Backplate though… Lemme know if you can help! 🙏)

UPDATE: See these excellent articles by JF…

Many Thanks to my GitHub Sponsors for supporting my work! This article wouldn’t have been possible without your support.

Got a question, comment or suggestion? Create an Issue or submit a Pull Request here…

lupyuen.github.io/src/gateway.md

§7 Notes

  1. This article is the expanded version of this Twitter Thread

  2. How was the Armbian image created for PineDio Gateway? See this…

    “Pinedio Project: Notes Sharing/Log”

  3. Check out these excellent articles on PineDio Gateway by JF and Ben V. Brown…

    “Discovering the Pine64 LoRa gateway”

    “Setting up the PineDIO LoRaWAN Gateway”

§8 Appendix: Packet Forwarder Service

Packet Forwarder is the Background Service on PineDio Gateway that relays received LoRa Packets to The Things Network.

(Yep it’s super critical to keep this service running on PineDio Gateway!)

To check if the Packet Forwarder Service is running

systemctl status ttn-gateway

We should see…

ttn-gateway.service - The Things Network Gateway
Loaded: loaded (/lib/systemd/system/ttn-gateway.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2021-11-06 20:29:12 EDT; 1min 22s ago
Main PID: 7679 (start.sh)
Tasks: 7 (limit: 2219)
Memory: 844.0K
CPU: 2.152s
CGroup: /system.slice/ttn-gateway.service
├─7679 /bin/bash /opt/ttn-gateway/packet_forwarder/lora_pkt_fwd/start.sh
└─7688 ./lora_pkt_fwd

Note: chip version is 0x10 (v1.0)
INFO: using legacy timestamp
INFO: LoRa Service modem: configuring preamble size to 8 symbols
ARB: dual demodulation disabled for all SF
INFO: found temperature sensor on port 0x39
INFO: [main] concentrator started, packet can now be received
INFO: concentrator EUI: ...
WARNING: [gps] GPS out of sync, keeping previous time reference
WARNING: [gps] GPS out of sync, keeping previous time reference
INFO: [modify_os_time] local_time=1636244956, gps_time=1636244955

To stop the Packet Forwarder Service

systemctl stop ttn-gateway

To disable the Packet Forwarder Service

systemctl disable ttn-gateway

To configure the Packet Forwarder Service

sudo gateway-config

The above command also configures the LoRa Concentrator to forward LoRa Packets to the Packet Forwarder Service or to ChirpStack. (See this)

Check the next section for the Packet Forwarder Log.

(Source)

§9 Appendix: Packet Forwarder Log

Here’s a sample Packet Forwarder Log for PineDio Gateway located at…

/var/log/daemon.log

(Log messages below are explained in this article)

§9.1 Startup

*** Packet Forwarder ***
Version: 2.0.1
*** SX1302 HAL library version info ***
Version: 2.0.1;
***
Little endian host
found configuration file global_conf.json, parsing it
global_conf.json does contain a JSON object named SX130x_conf, parsing SX1302 parameters
com_type SPI, com_path /dev/spidev0.0, lorawan_public 1, clksrc 0, full_duplex 0
antenna_gain 0 dBi
Configuring legacy timestamp
no configuration for SX1261
Configuring Tx Gain LUT for rf_chain 0 with 16 indexes for sx1250
radio 0 enabled (type SX1250), center frequency 923000000, RSSI offset -215.399994, tx enabled 1, single input mode 0
radio 1 enabled (type SX1250), center frequency 922000000, RSSI offset -215.399994, tx enabled 0, single input mode 0
Lora multi-SF channel 0>  radio 0, IF 200000 Hz, 125 kHz bw, SF 5 to 12
Lora multi-SF channel 1>  radio 0, IF 400000 Hz, 125 kHz bw, SF 5 to 12
Lora multi-SF channel 2>  radio 1, IF 200000 Hz, 125 kHz bw, SF 5 to 12
Lora multi-SF channel 3>  radio 1, IF 400000 Hz, 125 kHz bw, SF 5 to 12
Lora multi-SF channel 4>  radio 0, IF -400000 Hz, 125 kHz bw, SF 5 to 12
Lora multi-SF channel 5>  radio 0, IF -200000 Hz, 125 kHz bw, SF 5 to 12
Lora multi-SF channel 6>  radio 1, IF 0 Hz, 125 kHz bw, SF 5 to 12
Lora multi-SF channel 7>  radio 0, IF 0 Hz, 125 kHz bw, SF 5 to 12
Lora std channel> radio 1, IF 100000 Hz, 250000 Hz bw, SF 7, Explicit header
FSK channel> radio 1, IF -200000 Hz, 125000 Hz bw, 50000 bps datarate
global_conf.json does contain a JSON object named gateway_conf, parsing gateway parameters
gateway MAC address is configured to ...
server hostname or IP address is configured to "au1.cloud.thethings.network"
upstream port is configured to "1700"
downstream port is configured to "1700"
downstream keep-alive interval is configured to 10 seconds
statistics display interval is configured to 30 seconds
upstream PUSH_DATA time-out is configured to 100 ms
packets received with a valid CRC will be forwarded
packets received with a CRC error will NOT be forwarded
packets received with no CRC will NOT be forwarded
GPS serial port path is configured to "/dev/ttyS2"
Reference latitude is configured to 0.000000 deg
Reference longitude is configured to 0.000000 deg
Reference altitude is configured to 0 meters
Beaconing period is configured to 0 seconds
Beaconing signal will be emitted at 923400000 Hz
Beaconing channel number is set to 1
Beaconing channel frequency step is set to 0Hz
Beaconing datarate is set to SF9
Beaconing modulation bandwidth is set to 125000Hz
Beaconing TX power is set to 27dBm
global_conf.json does contain a JSON object named debug_conf, parsing debug parameters
got 2 debug reference payload
reference payload ID 0 is 0xCAFE1234
reference payload ID 1 is 0xCAFE2345
setting debug log file name to loragw_hal.log
found configuration file local_conf.json, parsing it
local_conf.json does contain a JSON object named gateway_conf, parsing gateway parameters
gateway MAC address is configured to ...
packets received with a valid CRC will be forwarded
packets received with a CRC error will NOT be forwarded
packets received with no CRC will NOT be forwarded
[main] TTY port /dev/ttyS2 open for GPS synchronization
Opening SPI communication interface
Note: chip version is 0x10 (v1.0)
using legacy timestamp
LoRa Service modem: configuring preamble size to 8 symbols
ARB: dual demodulation disabled for all SF
found temperature sensor on port 0x39
[main] concentrator started, packet can now be received
concentrator EUI: ...
WARNING: [gps] GPS out of sync, keeping previous time reference
[modify_os_time] local_time=1636450022, gps_time=1636450020

§9.2 Receive Packet

[modify_os_time] The difference between the system time(1636450022) and the GPS time(1636450020) is less than 10 seconds. Use the system time.
[down] PULL_ACK received in 93 ms
[down] PULL_ACK received in 92 ms
Received pkt from mote: 01E4BBF0 (fcnt=9969)
JSON up: 
{
  "rxpk": [
    {
      "jver": 1,
      "tmst": 19882284,
      "time": "2021-11-09T09:27:19.736572Z",
      "tmms": 1320485258736,
      "chan": 6,
      "rfch": 1,
      "freq": 922.000000,
      "mid": 8,
      "stat": 1,
      "modu": "LORA",
      "datr": "SF9BW125",
      "codr": "4/5",
      "rssis": -115,
      "lsnr": -9.0,
      "foff": 5178,
      "rssi": -107,
      "size": 32,
      "data": "QPC75AEA8SYrWsCiRKAGSBCQ6JnHQQFcntfm26fK1nk="
    }
  ]
}
[up] PUSH_ACK received in 94 ms
WARNING: [gps] GPS out of sync, keeping previous time reference
[down] PULL_ACK received in 92 ms

§9.3 Packet Received

#### [UPSTREAM] ###
RF packets received by concentrator: 1
CRC_OK: 100.00%, CRC_FAIL: 0.00%, NO_CRC: 0.00%
RF packets forwarded: 1 (32 bytes)
PUSH_DATA datagrams sent: 1 (319 bytes)
PUSH_DATA acknowledged: 100.00%

#### [DOWNSTREAM] ###
PULL_DATA sent: 3 (100.00% acknowledged)
PULL_RESP(onse) datagrams received: 0 (0 bytes)
RF packets sent to concentrator: 0 (0 bytes)
TX errors: 0

#### SX1302 Status ###
SX1302 counter (INST): 30753811
SX1302 counter (PPS):  26145712
BEACON queued: 0
BEACON sent so far: 0
BEACON rejected: 0

#### [JIT] ###
src/jitqueue.c:440:jit_print_queue(): [jit] queue is empty
--------
src/jitqueue.c:440:jit_print_queue(): [jit] queue is empty

#### [GPS] ###
Valid time reference (age: 0 sec)
GPS coordinates: latitude 1.2..., longitude 103.8..., altitude 17 m
##### END #####

JSON up:
{
  "stat": {
    "time": "2021-11-09 09:27:31 GMT",
    "lati": 1.2...,
    "long": 103.8...,
    "alti": 17,
    "rxnb": 1,
    "rxok": 1,
    "rxfw": 1,
    "ackr": 100.0,
    "dwnb": 0,
    "txnb": 0,
    "temp": 0.0
  }
}

[up] PUSH_ACK received in 92 ms
[down] PULL_ACK received in 92 ms
[down] PULL_ACK received in 92 ms
[down] PULL_ACK received in 92 ms

PineDio Gateway and WisGate Gateway on The Things Network

PineDio Gateway and WisGate Gateway on The Things Network