wiki:iot

Version 4 (modified by Ryan Erbstoesser, 13 days ago) (diff)

add collapse

Gateworks Internet of Things (IoT)

Gateworks is a hardware company that designs and manufactures single board computers and radios that can be used for IoT systems, most typically Gateways and Edge devices. Gateworks can custom create sensors as well for high volume projects.

IoT Radio Technologies

Long Range

  • LoRA
  • Sub 1GHz
  • Sigfox
  • Cellular
  • Satellite

Medium Range

  • WiFi?
  • Bluetooth 5.0 (BLE)

Short Range

  • RFID

IoT Clouds

  • Microsoft Azure
  • Amazon AWS
  • Google
  • The Things Network (TTN)(LoRa?)

IoT Software Solutions

LoRa & Azure Demo

Requirements

  1. Node / Device
    1. SparkLAN WLRS-591EVB
    2. Make sure antenna is connected
    3. Connect to desktop/laptop via CuteCom terminal program
    4. Set freq
    5. Mac join abp, etc
  2. Gateworks SBC
    1. Install Ubuntu Bionic (Ventana) Instructions
    2. Insert RAK2247 Mini-PCIe card with antenna installed into adapter (Because the card by default does not support active low reset which is what the Gateworks SBC uses. Contact RAK to have a RAK2247 modified to use a active low reset)
    3. Software pieces:
      1. Github rak_common_for_gateway https://github.com/RAKWireless/rak_common_for_gateway
        1. git clone https://github.com/RAKWireless/rak_common_for_gateway
        2. This talks to the actual radio card.
        3. Careful to set config file global_conf.json for frequency, and gateway to local host for this example (or The Things Network (TTN) if not using azure)
        4. /root/rak_common_for_gateway/lora/rak2247/packet_forwarder/lora_pkt_fwd/lora_pkt_fwd
      2. .deb package lora-gateway-bridge (must be v3.3 or higher)(now called chirpstack because of licensing issues)
        1. The bridge is required because the packet forwarder cannot talk to Azure direct. It only speaks Lora Protocol. Azure needs something like MQTT, etc. So the bridge converts from Lora to MQTT.
        2. https://www.chirpstack.io
        3. Download here: https://artifacts.chirpstack.io/downloads/lora-gateway-bridge/
        4. lora-gateway-bridge -c /etc/lora-gateway-bridge/lora-gateway-bridge.toml
          1. This is used
          2. Config file must specify the proper device ID thats set in Azure cloud, however, I felt the bridge was not listening to my config file and picked the eth0 MAC address as the device ID, so then I created a device in the cloud to match this MAC.
  3. Azure Cloud
    1. Use pre-done remote monitoring solution accelerator (https://docs.microsoft.com/en-us/azure/iot-accelerators/iot-accelerators-remote-monitoring-sample-walkthrough)
      1. Must get shared key device string like example:
        1. HostName=gateworksremotemonitor-s2pc7.azurewebsites.net;DeviceId=GateworksTest1;SharedAccessKey=R9hjZNOvtfferesrsHzFGScSgc3EUxc004pjMg=
          
        2. Must create a device with a specific device ID. This device ID must be used by the MQTT lora-gateway-bridge

Steps to take

  1. Make sure node is up and running and connected to with terminal program on laptop/desktop
  2. Start SBC and make sure packet forward is running first
  3. Then start the gateway bridge
  4. Then check for connected device on Azure
  5. Send packet from node and view on Azure

Sample Logs & files

lora-gateway-bridge Configuration File

Lora-gateway-bridge

root@bionic-armhf:~# cat /etc/lora-gateway-bridge/lora-gateway-bridge.toml
# This configuration provides a Semtech UDP packet-forwarder backend and
# integrates with a MQTT broker. Many options and defaults have been omitted
# for simplicity.
#
# See https://www.loraserver.io/lora-gateway-bridge/install/config/ for a full
# configuration example and documentation.

[general]
# debug=5, info=4, warning=3, error=2, fatal=1, panic=0
log_level = 5

# Gateway backend configuration.
[backend]
# Backend type.
type="semtech_udp"

  # Semtech UDP packet-forwarder backend.
  [backend.semtech_udp]

  # ip:port to bind the UDP listener to
  #
  # Example: 0.0.0.0:1700 to listen on port 1700 for all network interfaces.
  # This is the listeren to which the packet-forwarder forwards its data
  # so make sure the 'serv_port_up' and 'serv_port_down' from your
  # packet-forwarder matches this port.
  udp_bind = "0.0.0.0:1700"


# Integration configuration.
[integration]
# Payload marshaler.
#
# This defines how the MQTT payloads are encoded. Valid options are:
# * protobuf:  Protobuf encoding (this will become the LoRa Gateway Bridge v3 default)
# * json:      JSON encoding (easier for debugging, but less compact than 'protobuf')
marshaler="json"

  # MQTT integration configuration.
  [integration.mqtt]
  # Event topic template.
  event_topic_template="gateway/{{ .GatewayID }}/event/{{ .EventType }}"

  # Command topic template.
  command_topic_template="gateway/{{ .GatewayID }}/command/#"

  # MQTT authentication.
  [integration.mqtt.auth]
  # Type defines the MQTT authentication type to use.
  #
  # Set this to the name of one of the sections below.
  #type="generic"
  type="azure_iot_hub"

    # Generic MQTT authentication.
    [integration.mqtt.auth.generic]
    # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws)
    server="tcp://127.0.0.1:1883"

    # Connect with the given username (optional)
    username=""

    # Connect with the given password (optional)
    password=""

    # Azure IoT Hub
    #
    # This setting will preset uplink and downlink topics that will only
    # work with Azure IoT Hub service.
    [integration.mqtt.auth.azure_iot_hub]

    # Device connection string (symmetric key authentication).
    #
    # This connection string can be retrieved from the Azure IoT Hub device
    # details when using the symmetric key authentication type.
    device_connection_string="HostName=iothub-s2pc7.azure-devices.net;DeviceId=00d012fffee1f102;SharedAccessKey=hWY7XLZuFOYlgIzvSGEbvzDpJ5H2sVGWGq1M6cUoiNc="

    # Token expiration (symmetric key authentication).
    #
    # ChirpStack Gateway Bridge will generate a SAS token with the given expiration.
    # After the token has expired, it will generate a new one and trigger a
    # re-connect (only for symmetric key authentication).
    sas_token_expiration="24h0m0s"

    # Device ID (X.509 authentication).
    #
    # This will be automatically set when a device connection string is given.
    # It must be set for X.509 authentication.
    device_id=""

    # IoT Hub hostname (X.509 authentication).
    #
    # This will be automatically set when a device connection string is given.
    # It must be set for X.509 authentication.
    # Example: iot-hub-name.azure-devices.net
    hostname=""

    # Client certificates (X.509 authentication).
    #
    # Configure the tls_cert (certificate file) and tls_key (private-key file)
    # when the device is configured with X.509 authentication.
    tls_cert=""
    tls_key=""

lora packet forwarder configuration file

Packet forwarder config:

root@bionic-armhf:~/rak_common_for_gateway/lora/rak2247/packet_forwarder/lora_pkt_fwd# cat global_conf.json 
{
    "SX1301_conf": {
        "lorawan_public": true,
        "clksrc": 1,
        "antenna_gain": 0,
        "radio_0": {
            "enable": true,
            "type": "SX1257",
	    "freq": 902600000,
            "rssi_offset": -166.0,
            "tx_enable": true,
            "tx_freq_min": 902000000,
            "tx_freq_max": 928000000
        },
        "radio_1": {
            "enable": true,
            "type": "SX1257",
	    "freq": 903400000,
            "rssi_offset": -166.0,
            "tx_enable": false
        },
        "chan_multiSF_0": {
            "enable": true,
            "radio": 0,
            "if": -400000
        },
        "chan_multiSF_1": {
            "enable": true,
            "radio": 0,
            "if": -200000
        },
        "chan_multiSF_2": {
            "enable": true,
            "radio": 0,
            "if": 0
        },
        "chan_multiSF_3": {
            "enable": true,
            "radio": 0,
            "if": 200000
        },
        "chan_multiSF_4": {
            "enable": true,
            "radio": 1,
            "if": -300000
        },
        "chan_multiSF_5": {
            "enable": true,
            "radio": 1,
            "if": -100000
        },
        "chan_multiSF_6": {
            "enable": true,
            "radio": 1,
            "if": 100000
        },
        "chan_multiSF_7": {
            "enable": true,
            "radio": 1,
            "if": 300000
        },
        "chan_Lora_std": {
            "enable": true,
            "radio": 0,
            "if": 300000,
            "bandwidth": 500000,
            "spread_factor": 8
        },
        "chan_FSK": {
            "enable": false,
            "radio": 0,
            "if": 300000,
            "bandwidth": 250000,
            "datarate": 100000
        },
	"tx_lut_0": {
		"desc": "TX gain table, index 0",
		"pa_gain": 0,
		"mix_gain": 8,
		"rf_power": -6,
		"dig_gain": 0
	},
	"tx_lut_1": {
		"desc": "TX gain table, index 1",
		"pa_gain": 0,
		"mix_gain": 10,
		"rf_power": -3,
		"dig_gain": 0
	},
	"tx_lut_2": {
		"desc": "TX gain table, index 2",
		"pa_gain": 0,
		"mix_gain": 12,
		"rf_power": 0,
		"dig_gain": 0
	},
	"tx_lut_3": {
		"desc": "TX gain table, index 3",
		"pa_gain": 1,
		"mix_gain": 8,
		"rf_power": 3,
		"dig_gain": 0
	},
	"tx_lut_4": {
		"desc": "TX gain table, index 4",
		"pa_gain": 1,
		"mix_gain": 10,
		"rf_power": 6,
		"dig_gain": 0
	},
	"tx_lut_5": {
		"desc": "TX gain table, index 5",
		"pa_gain": 1,
		"mix_gain": 12,
		"rf_power": 10,
		"dig_gain": 0
	},
	"tx_lut_6": {
		"desc": "TX gain table, index 6",
		"pa_gain": 1,
		"mix_gain": 13,
		"rf_power": 11,
		"dig_gain": 0
	},
	"tx_lut_7": {
		"desc": "TX gain table, index 7",
		"pa_gain": 2,
		"mix_gain": 9,
		"rf_power": 12,
		"dig_gain": 0
	},
	"tx_lut_8": {
		"desc": "TX gain table, index 8",
		"pa_gain": 1,
		"mix_gain": 15,
		"rf_power": 13,
		"dig_gain": 0
	},
	"tx_lut_9": {
		"desc": "TX gain table, index 9",
		"pa_gain": 2,
		"mix_gain": 10,
		"rf_power": 14,
		"dig_gain": 0
	},
	"tx_lut_10": {
		"desc": "TX gain table, index 10",
		"pa_gain": 2,
		"mix_gain": 11,
		"rf_power": 16,
		"dig_gain": 0
	},
	"tx_lut_11": {
		"desc": "TX gain table, index 11",
		"pa_gain": 3,
		"mix_gain": 9,
		"rf_power": 20,
		"dig_gain": 0
	},
	"tx_lut_12": {
		"desc": "TX gain table, index 12",
		"pa_gain": 3,
		"mix_gain": 10,
		"rf_power": 23,
		"dig_gain": 0
	},
	"tx_lut_13": {
		"desc": "TX gain table, index 13",
		"pa_gain": 3,
		"mix_gain": 11,
		"rf_power": 25,
		"dig_gain": 0
	},
	"tx_lut_14": {
		"desc": "TX gain table, index 14",
		"pa_gain": 3,
		"mix_gain": 12,
		"rf_power": 26,
		"dig_gain": 0
	},
	"tx_lut_15": {
		"desc": "TX gain table, index 15",
		"pa_gain": 3,
		"mix_gain": 14,
		"rf_power": 27,
		"dig_gain": 0
	}
    },
    "gateway_conf": {
	"gateway_ID": "00D012FFFEE1F102",
	/* change with default server address/ports, or overwrite in local_conf.json */
	"server_address": "localhost",
	"serv_port_up": 1700,
	"serv_port_down": 1700,
	/* adjust the following parameters for your network */
	"keepalive_interval": 10,
	"stat_interval": 30,
	"push_timeout_ms": 100,
	/* forward only valid packets */
	"forward_crc_valid": true,
	"forward_crc_error": true,
	"forward_crc_disabled": false,
	"autoquit_threshold": 6
    }
}

lora packet forwarder example output

Example packet forward application running output:

root@bionic-armhf:~/rak_common_for_gateway/lora/rak2247/packet_forwarder/lora_pkt_fwd# ./lora_pkt_fwd 
*** Beacon Packet Forwarder for Lora Gateway ***
Version: 4.0.1
*** Lora concentrator HAL library version info ***
Version: 5.0.1;
***
INFO: Little endian host
INFO: found global configuration file global_conf.json, parsing it
INFO: global_conf.json does contain a JSON object named SX1301_conf, parsing SX1301 parameters
INFO: lorawan_public 1, clksrc 1
INFO: no configuration for LBT
INFO: antenna_gain 0 dBi
INFO: Configuring TX LUT with 16 indexes
INFO: radio 0 enabled (type SX1257), center frequency 902600000, RSSI offset -166.000000, tx enabled 1, tx_notch_freq 0
INFO: radio 1 enabled (type SX1257), center frequency 903400000, RSSI offset -166.000000, tx enabled 0, tx_notch_freq 0
INFO: Lora multi-SF channel 0>  radio 0, IF -400000 Hz, 125 kHz bw, SF 7 to 12
INFO: Lora multi-SF channel 1>  radio 0, IF -200000 Hz, 125 kHz bw, SF 7 to 12
INFO: Lora multi-SF channel 2>  radio 0, IF 0 Hz, 125 kHz bw, SF 7 to 12
INFO: Lora multi-SF channel 3>  radio 0, IF 200000 Hz, 125 kHz bw, SF 7 to 12
INFO: Lora multi-SF channel 4>  radio 1, IF -300000 Hz, 125 kHz bw, SF 7 to 12
INFO: Lora multi-SF channel 5>  radio 1, IF -100000 Hz, 125 kHz bw, SF 7 to 12
INFO: Lora multi-SF channel 6>  radio 1, IF 100000 Hz, 125 kHz bw, SF 7 to 12
INFO: Lora multi-SF channel 7>  radio 1, IF 300000 Hz, 125 kHz bw, SF 7 to 12
INFO: Lora std channel> radio 0, IF 300000 Hz, 500000 Hz bw, SF 8
INFO: FSK channel 8 disabled
INFO: global_conf.json does contain a JSON object named gateway_conf, parsing gateway parameters
INFO: gateway MAC address is configured to 00D012FFFEE1F102
INFO: server hostname or IP address is configured to "localhost"
INFO: upstream port is configured to "1700"
INFO: downstream port is configured to "1700"
INFO: downstream keep-alive interval is configured to 10 seconds
INFO: statistics display interval is configured to 30 seconds
INFO: upstream PUSH_DATA time-out is configured to 100 ms
INFO: packets received with a valid CRC will be forwarded
INFO: packets received with a CRC error will be forwarded
INFO: packets received with no CRC will NOT be forwarded
INFO: Auto-quit after 6 non-acknowledged PULL_DATA
INFO: found local configuration file local_conf.json, parsing it
INFO: redefined parameters will overwrite global parameters
INFO: local_conf.json does not contain a JSON object named SX1301_conf
INFO: local_conf.json does contain a JSON object named gateway_conf, parsing gateway parameters
INFO: gateway MAC address is configured to 00D012FFFEE1F102
INFO: packets received with a valid CRC will be forwarded
INFO: packets received with a CRC error will be forwarded
INFO: packets received with no CRC will NOT be forwarded
INFO: [main] concentrator started, packet can now be received

INFO: Disabling GPS mode for concentrator's counter...
INFO: host/sx1301 time offset=(1573244036s:715596µs) - drift=1811158092µs
INFO: Enabling GPS mode for concentrator's counter.


INFO: Received pkt from mote: 12345678 (fcnt=77)

JSON up: {"rxpk":[{"tmst":12244828,"chan":6,"rfch":1,"freq":903.500000,"stat":1,"modu":"LORA","datr":"SF10BW125","codr":"4/5","lsnr":10.8,"rssi":-39,"size":17,"data":"QHhWNBKATQAPR52Q+oKvi8I="}]}
INFO: [down] PULL_ACK received in 4 ms

INFO: Received pkt from mote: 12345678 (fcnt=78)

JSON up: {"rxpk":[{"tmst":27958804,"chan":4,"rfch":1,"freq":903.100000,"stat":1,"modu":"LORA","datr":"SF10BW125","codr":"4/5","lsnr":10.2,"rssi":-39,"size":17,"data":"QHhWNBKATgAPZnN8WUUi2U8="}]}
INFO: [up] PUSH_ACK received in 7 ms

##### 2019-11-08 20:14:29 GMT #####
### [UPSTREAM] ###
# RF packets received by concentrator: 2
# CRC_OK: 100.00%, CRC_FAIL: 0.00%, NO_CRC: 0.00%
# RF packets forwarded: 2 (34 bytes)
# PUSH_DATA datagrams sent: 2 (396 bytes)
# PUSH_DATA acknowledged: 50.00%
### [DOWNSTREAM] ###
# PULL_DATA sent: 3 (33.33% acknowledged)
# PULL_RESP(onse) datagrams received: 0 (0 bytes)
# RF packets sent to concentrator: 0 (0 bytes)
# TX errors: 0
# BEACON queued: 0
# BEACON sent so far: 0
# BEACON rejected: 0
### [JIT] ###
# SX1301 time (PPS): 2835751
src/jitqueue.c:448:jit_print_queue(): INFO: [jit] queue is empty
### [GPS] ###
# GPS sync is disabled
##### END #####

JSON up: {"stat":{"time":"2019-11-08 20:14:29 GMT","rxnb":2,"rxok":2,"rxfw":2,"ackr":50.0,"dwnb":0,"txnb":0}}
INFO: [up] PUSH_ACK received in 2 ms
INFO: [down] PULL_ACK received in 2 ms
INFO: [down] PULL_ACK received in 3 ms

lora-gateway-bridge example output

Example lora-gateway-bridge output

root@bionic-armhf:~# lora-gateway-bridge -c /etc/lora-gateway-bridge/lora-gateway-bridge.toml 
INFO[0000] starting LoRa Gateway Bridge                  docs="https://www.loraserver.io/lora-gateway-bridge/" version=3.3.0
INFO[0000] backend/semtechudp: starting gateway udp listener  addr="0.0.0.0:1700"
DEBU[0000] backend/semtechudp: cleanup gateway registry 
INFO[0000] integration/mqtt: connected to mqtt broker   
DEBU[0001] backend/semtechudp: received udp packet from gateway  addr="127.0.0.1:53877" protocol_version=2 type=PullData
DEBU[0001] backend/semtechudp: sending udp packet to gateway  addr="127.0.0.1:53877" protocol_version=2 type=PullACK
INFO[0001] integration/mqtt: subscribing to topic        qos=0 topic="devices/00d012fffee1f102/messages/devicebound/#"
DEBU[0006] backend/semtechudp: received udp packet from gateway  addr="127.0.0.1:50657" protocol_version=2 type=PushData
DEBU[0006] backend/semtechudp: sending udp packet to gateway  addr="127.0.0.1:50657" protocol_version=2 type=PushACK
INFO[0006] integration/mqtt: publishing event            event=up qos=0 topic=devices/00d012fffee1f102/messages/events/up uplink_id=d0e63fa3-ede2-4850-b981-e239820a8434
DEBU[0011] backend/semtechudp: received udp packet from gateway  addr="127.0.0.1:50657" protocol_version=2 type=PushData
DEBU[0011] backend/semtechudp: sending udp packet to gateway  addr="127.0.0.1:50657" protocol_version=2 type=PushACK
INFO[0011] integration/mqtt: publishing event            event=stats qos=0 stats_id=1af685eb-3e6d-4a1f-bf18-103c7619c7d1 topic=devices/00d012fffee1f102/messages/events/stats
DEBU[0011] backend/semtechudp: received udp packet from gateway  addr="127.0.0.1:53877" protocol_version=2 type=PullData
DEBU[0011] backend/semtechudp: sending udp packet to gateway  addr="127.0.0.1:53877" protocol_version=2 type=PullACK
DEBU[0021] backend/semtechudp: received udp packet from gateway  addr="127.0.0.1:53877" protocol_version=2 type=PullData
DEBU[0021] backend/semtechudp: sending udp packet to gateway  addr="127.0.0.1:53877" protocol_version=2 type=PullACK
DEBU[0032] backend/semtechudp: received udp packet from gateway  addr="127.0.0.1:53877" protocol_version=2 type=PullData
DEBU[0032] backend/semtechudp: sending udp packet to gateway  addr="127.0.0.1:53877" protocol_version=2 type=PullACK
DEBU[0041] backend/semtechudp: received udp packet from gateway  addr="127.0.0.1:50657" protocol_version=2 type=PushData
DEBU[0041] backend/semtechudp: sending udp packet to gateway  addr="127.0.0.1:50657" protocol_version=2 type=PushACK
INFO[0041] integration/mqtt: publishing event            event=stats qos=0 stats_id=9926a236-5ef0-41f5-968b-83eb80af1836 topic=devices/00d012fffee1f102/messages/events/stats
DEBU[0042] backend/semtechudp: received udp packet from gateway  addr="127.0.0.1:53877" protocol_version=2 type=PullData
DEBU[0042] backend/semtechudp: sending udp packet to gateway  addr="127.0.0.1:53877" protocol_version=2 type=PullACK

Sample status on Azure platform for a sample packet: Bridge log:

INFO[5322] integration/mqtt: publishing event            event=stats qos=0 stats_id=5c6c1e4f-ae87-4bf9-a18d-8b2c27646dbb topic=devices/00d012fffee1f102/messages/events/stats

Azure receive:

{
  "data": {
    "gatewayId": "ANAS//7h8QI=",
    "ip": "172.24.24.194",
    "time": "2019-11-08T21:37:30Z",
    "location": null,
    "configVersion": null,
    "rxPacketsReceived": 0,
    "rxPacketsReceivedOk": 0,
    "txPacketsReceived": 0,
    "txPacketsEmitted": 0,
    "statsId": "Mf/IdLFxTe6ZVlUYcQvlZw==",
    "stats": null
  },
  "deviceId": "00d012fffee1f102",
  "time": "2019-11-08T21:37:30+00:00"
}

Sample data up on Azure for sample up packet:

Bridge log:

INFO[5193] integration/mqtt: publishing event            event=up qos=0 topic=devices/00d012fffee1f102/messages/events/up uplink_id=7a36347f-e7f5-4d9e-b75c-d54adf68e9d2

Azure packet log

{
  "data": {
    "phyPayload": "QHhWNBKAVwAPo+J5m001Lok=",
    "txInfoFrequency": 903100000,
    "txInfoModulation": "LORA",
    "txInfoLoRaModulationInfoBandwidth": 125,
    "txInfoLoRaModulationInfoSpreadingFactor": 10,
    "txInfoLoRaModulationInfoCodeRate": "4/5",
    "txInfoLoRaModulationInfoPolarizationInversion": false,
    "rxInfoGatewayId": "ANAS//7h8QI=",
    "rxInfoTime": null,
    "rxInfoTimeSinceGpsEpoch": null,
    "rxInfoRssi": -35,
    "rxInfoLoRaSnr": 11.5,
    "rxInfoChannel": 4,
    "rxInfoRfChain": 1,
    "rxInfoBoard": 0,
    "rxInfoAntenna": 0,
    "rxInfoLocation": null,
    "rxInfoFineTimestampType": "NONE",
    "rxInfoContext": "NtnEjA==",
    "rxInfoUplinkId": "ejY0f+f1TZ63XNVK32jp0g==",
    "up": null
  },
  "deviceId": "00d012fffee1f102",
  "time": "2019-11-08T21:40:52+00:00"
}

Attachments (7)

Download all attachments as: .zip