From de6d4ed72d828e9c963747d1438e0dc1b75cd325 Mon Sep 17 00:00:00 2001 From: Stefan Eichenberger Date: Fri, 2 Dec 2016 14:25:56 +0100 Subject: [PATCH] lora: add systemd service file and config files --- .../lora/lora-gateway_1.7.0mts.bb | 2 +- .../lora-packet-forwarder/global_conf.json | 199 ++++++++++++++++++ .../lora-packet-forwarder/local_conf.json | 17 +- .../lora/lora-packet-forwarder/lora.service | 10 + .../lora/lora-packet-forwarder/start-lora.sh | 31 +++ .../lora/lora-packet-forwarder_1.4.1.bb | 16 +- 6 files changed, 267 insertions(+), 8 deletions(-) create mode 100644 recipes-connectivity/lora/lora-packet-forwarder/global_conf.json create mode 100644 recipes-connectivity/lora/lora-packet-forwarder/lora.service create mode 100644 recipes-connectivity/lora/lora-packet-forwarder/start-lora.sh diff --git a/recipes-connectivity/lora/lora-gateway_1.7.0mts.bb b/recipes-connectivity/lora/lora-gateway_1.7.0mts.bb index 13cffd8..9b1aae2 100644 --- a/recipes-connectivity/lora/lora-gateway_1.7.0mts.bb +++ b/recipes-connectivity/lora/lora-gateway_1.7.0mts.bb @@ -47,7 +47,7 @@ do_install() { PACKAGES += "${PN}-utils ${PN}-utils-dbg" -FILES_${PN}-utils = "/opt/lora/*" +FILES_${PN}-utils = "/opt/lora/* /lib" FILES_${PN}-utils-dbg = "/opt/lora/.debug" FILES_${PN}-dev = "${includedir}/lora ${libdir}/lora/library.cfg" FILES_${PN}-staticdev = "${libdir}/lora/libloragw.a" diff --git a/recipes-connectivity/lora/lora-packet-forwarder/global_conf.json b/recipes-connectivity/lora/lora-packet-forwarder/global_conf.json new file mode 100644 index 0000000..3f120d2 --- /dev/null +++ b/recipes-connectivity/lora/lora-packet-forwarder/global_conf.json @@ -0,0 +1,199 @@ +{ + "SX1301_conf": { + "lorawan_public": true, + "clksrc": 0, + "clksrc_desc": "radio_0 provides clock to concentrator", + "radio_0": { + "enable": true, + "type": "SX1257", + "freq": 867500000, + "rssi_offset": -166, + "tx_enable": true + }, + "radio_1": { + "enable": true, + "type": "SX1257", + "freq": 868500000, + "rssi_offset": -166, + "tx_enable": false + }, + "chan_multiSF_0": { + "desc": "Lora MAC, 125kHz, all SF, 868.1 MHz", + "enable": true, + "radio": 1, + "if": -400000 + }, + "chan_multiSF_1": { + "desc": "Lora MAC, 125kHz, all SF, 868.3 MHz", + "enable": true, + "radio": 1, + "if": -200000 + }, + "chan_multiSF_2": { + "desc": "Lora MAC, 125kHz, all SF, 868.5 MHz", + "enable": true, + "radio": 1, + "if": 0 + }, + "chan_multiSF_3": { + "desc": "Lora MAC, 125kHz, all SF, 867.1 MHz", + "enable": true, + "radio": 0, + "if": -400000 + }, + "chan_multiSF_4": { + "desc": "Lora MAC, 125k Hz, all SF, 867.3 MHz ", + "enable": true, + "radio": 0, + "if": -200000 + }, + "chan_multiSF_5": { + "desc": "Lora MAC", + "enable": true, + "radio": 0, + "if": 0 + }, + "chan_multiSF_6": { + "desc": "Lora MAC, 125kHz, all SF, 867.7 MHz", + "enable": true, + "radio": 0, + "if": 200000 + }, + "chan_multiSF_7": { + "desc": "Lora MAC, 125kHz, all SF, 867.9 MHz", + "enable": true, + "radio": 0, + "if": 400000 + }, + "chan_Lora_std": { + "desc": "Lora MAC, 250kHz, SF7, 868.3 MHz", + "enable": true, + "radio": 1, + "if": -200000, + "bandwidth": 250000, + "spread_factor": 7 + }, + "chan_FSK": { + "desc": "FSK 50kbps, 868.8 MHz", + "enable": true, + "radio": 1, + "if": 300000, + "bandwidth": 125000, + "datarate": 50000 + }, + "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": 10, + "rf_power": 20, + "dig_gain": 0 + }, + "tx_lut_12": { + "desc": "TX gain table, index 12", + "pa_gain": 3, + "mix_gain": 11, + "rf_power": 23, + "dig_gain": 0 + }, + "tx_lut_13": { + "desc": "TX gain table, index 13", + "pa_gain": 3, + "mix_gain": 12, + "rf_power": 24, + "dig_gain": 0 + }, + "tx_lut_14": { + "desc": "TX gain table, index 14", + "pa_gain": 3, + "mix_gain": 13, + "rf_power": 25, + "dig_gain": 0 + }, + "tx_lut_15": { + "desc": "TX gain table, index 15", + "pa_gain": 3, + "mix_gain": 15, + "rf_power": 26, + "dig_gain": 0 + } + } +} + diff --git a/recipes-connectivity/lora/lora-packet-forwarder/local_conf.json b/recipes-connectivity/lora/lora-packet-forwarder/local_conf.json index 3c2af80..925a010 100644 --- a/recipes-connectivity/lora/lora-packet-forwarder/local_conf.json +++ b/recipes-connectivity/lora/lora-packet-forwarder/local_conf.json @@ -1,7 +1,14 @@ { - "gateway_conf": { - "server_address": "localhost", - "serv_port_up": 1780, - "serv_port_down": 1782 - } + "gateway_conf": { + "server_address": "192.168.1.2", + "serv_port_up": 1700, + "serv_port_down": 1700, + "serv_enabled": true, + "fake_gps": true, + "ref_latitude": 47.142879, + "ref_longitude": 7.244233, + "ref_altitude": 481, + "contact_email": "mail@example.net", + "description": "NetModule LoRaWAN Gateway #1" + } } diff --git a/recipes-connectivity/lora/lora-packet-forwarder/lora.service b/recipes-connectivity/lora/lora-packet-forwarder/lora.service new file mode 100644 index 0000000..382b669 --- /dev/null +++ b/recipes-connectivity/lora/lora-packet-forwarder/lora.service @@ -0,0 +1,10 @@ +[Unit] +Description=Start lora paket forwarder +After=network.target + +[Service] +Type=simple +ExecStart=/opt/lora/start-lora.sh + +[Install] +WantedBy=multi-user.target diff --git a/recipes-connectivity/lora/lora-packet-forwarder/start-lora.sh b/recipes-connectivity/lora/lora-packet-forwarder/start-lora.sh new file mode 100644 index 0000000..0d2c807 --- /dev/null +++ b/recipes-connectivity/lora/lora-packet-forwarder/start-lora.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set_gpio() { + if [ ! -d "/sys/class/gpio/gpio$1" ]; then + echo $1 > /sys/class/gpio/export + fi + + echo out > /sys/class/gpio/gpio$1/direction + echo $2 > /sys/class/gpio/gpio$1/value +} + +set_gpio 14 1 +set_gpio 15 1 +set_gpio 27 1 + +if ! grep -q gateway_ID /opt/lora/local_conf.json; then + mac=$(ip link show eth0 | grep link | awk '{print $2 };' | sed 's/://g') + sed -i "3i\ \"gateway_ID\": \"${mac^^}\"," /opt/lora/local_conf.json +fi + +cd /opt/lora + +# Wait until power on +sleep 2 + +while [ $(route -n | wc -l) -lt 3 ]; do + sleep 5 +done + +# Fire up the forwarder. +/opt/lora/gps_pkt_fwd diff --git a/recipes-connectivity/lora/lora-packet-forwarder_1.4.1.bb b/recipes-connectivity/lora/lora-packet-forwarder_1.4.1.bb index 62e6f4c..c27f6a3 100644 --- a/recipes-connectivity/lora/lora-packet-forwarder_1.4.1.bb +++ b/recipes-connectivity/lora/lora-packet-forwarder_1.4.1.bb @@ -8,6 +8,11 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=22af7693d7b76ef0fc76161c4be76c45" DEPENDS = "lora-gateway" PR = "r10" +inherit systemd + +SYSTEMD_SERVICE_${PN} = "lora.service" +SYSTEMD_AUTO_ENABLE ?= "enable" + # tag v1.4.1 SRCREV = "0011a60759a7d81656a5393e97089daab1ff1a81" @@ -19,6 +24,10 @@ SRC_URI = "git://github.com/Lora-net/packet_forwarder.git;protocol=git \ file://lora-packet-forwarder-mts-enhancements.patch \ file://lora-packet-forwarder-synch-word.patch \ file://lora-packet-forwarder-add-queue.patch \ + file://global_conf.json \ + file://local_conf.json \ + file://start-lora.sh \ + file://lora.service\ file://README.md \ " @@ -44,9 +53,12 @@ do_install() { install -m 755 util_ack/util_ack ${D}${LORA_DIR}/ install -m 755 ${WORKDIR}/README.md ${D}${LORA_DIR}/ + install -d ${D}${systemd_unitdir}/system + install -m 0644 ${WORKDIR}/global_conf.json ${D}/opt/lora/ + install -m 0644 ${WORKDIR}/local_conf.json ${D}/opt/lora/ + install -m 0644 ${WORKDIR}/lora.service ${D}${systemd_unitdir}/system -# skip util_tx_test since it conflicts with one in lora-gateway -# install -m 755 util_tx_test/util_tx_test ${D}${LORA_DIR}/ + install -m 0755 ${WORKDIR}/start-lora.sh ${D}/opt/lora/ } FILES_${PN} += "${LORA_DIR}"