forked from openwrt/packages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds the `lora_pkt_fwd` which is widely used by all kinds of LoRa gateways to forward packages to a LoRaWAN broker. Signed-off-by: Xue Liu <[email protected]> [rebase, fix commit subject & message] Signed-off-by: Paul Spooren <[email protected]>
- Loading branch information
Showing
7 changed files
with
875 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# | ||
# Copyright (C) 2019 Xue Liu <liuxuenetmail@gmail> | ||
# | ||
# This is free software, licensed under the GNU General Public License v2. | ||
# See /LICENSE for more information. | ||
# | ||
|
||
include $(TOPDIR)/rules.mk | ||
|
||
PKG_NAME:=lora-packet-forwarder | ||
PKG_VERSION:=4.0.1 | ||
PKG_RELEASE:=1 | ||
|
||
PKG_SOURCE_URL:=https://codeload.github.com/Lora-net/packet_forwarder/tar.gz/v$(PKG_VERSION)? | ||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz | ||
PKG_HASH:=e68fadf6f1d2e5e7b601e504d5efb48b0a8f374c2c29c0476ab2fe9db68d33ae | ||
PKG_MAINTAINER:=Xue Liu <[email protected]> | ||
PKG_LICENSE_FILES:=LICENSE | ||
PKG_BUILD_DIR:=$(BUILD_DIR)/packet_forwarder-$(PKG_VERSION) | ||
|
||
include $(INCLUDE_DIR)/package.mk | ||
include $(INCLUDE_DIR)/cmake.mk | ||
|
||
define Package/lora-packet-forwarder | ||
SECTION:=net | ||
CATEGORY:=Network | ||
SUBMENU:=LoRaWAN | ||
TITLE:=Semtech packet-forwarder program | ||
DEPENDS:=+libloragw +libubox-lua +libuci-lua +dkjson | ||
endef | ||
|
||
define Package/lora-packet-forwarder/description | ||
A LoRa packet forwarder is a program running on the host of a LoRa gateway | ||
that forwards RF packets receive by the concentrator to a server through a | ||
IP/UDP link, and emits RF packets that are sent by the server. | ||
endef | ||
|
||
define Package/lora-packet-forwarder-utils | ||
SECTION:=net | ||
CATEGORY:=Network | ||
SUBMENU:=LoRaWAN | ||
TITLE:=Utilities for lora pakcet forwarder | ||
DEPENDS:=+libloragw | ||
endef | ||
|
||
define Package/lora-packet-forwarder/install | ||
$(INSTALL_DIR) $(1)/usr/sbin | ||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/lora_pkt_fwd/lora_pkt_fwd $(1)/usr/sbin | ||
$(INSTALL_BIN) ./files/gen_lora_global_conf $(1)/usr/sbin | ||
$(INSTALL_DIR) $(1)/etc/init.d | ||
$(INSTALL_BIN) ./files/lora_pkt_fwd.init $(1)/etc/init.d/lora_pkt_fwd | ||
$(INSTALL_DIR) $(1)/etc/config | ||
$(INSTALL_DATA) ./files/lora-global.config $(1)/etc/config/lora-global | ||
endef | ||
|
||
define Package/lora-packet-forwarder-utils/install | ||
$(INSTALL_DIR) $(1)/usr/sbin | ||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bin/util_ack $(1)/usr/sbin | ||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bin/util_sink $(1)/usr/sbin | ||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bin/util_tx_test $(1)/usr/sbin | ||
endef | ||
|
||
$(eval $(call BuildPackage,lora-packet-forwarder)) | ||
$(eval $(call BuildPackage,lora-packet-forwarder-utils)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
-- SPDX-License-Identifier: GPL-2.0 | ||
-- | ||
-- Copyright (c) 2019 Xue Liu <[email protected]> | ||
-- | ||
|
||
#!/usr/bin/env lua | ||
|
||
require("uloop") | ||
require("ubus") | ||
local json = require("dkjson") | ||
local uci = require("uci") | ||
|
||
x = uci.cursor() | ||
|
||
uloop.init() | ||
|
||
local conn = ubus.connect() | ||
if not conn then | ||
error("Failed to connect to ubus") | ||
end | ||
|
||
local lora_global_ubus = conn:call("uci", "get", {config = "lora-global"}) | ||
|
||
local lora_global_table = lora_global_ubus["values"] | ||
|
||
local lora_global = {} | ||
local gateway_conf = {} | ||
local sx1301_conf = {} | ||
local radio_0 = {} | ||
local radio_1 = {} | ||
|
||
-- | ||
-- chan_x | ||
-- | ||
for key, val in pairs(lora_global_table) do | ||
if string.match(key, 'chan_[%a]*', 1) then | ||
local chan = {} | ||
for k, v in pairs(val) do | ||
if string.match(k, '%.[%a]*', 1) == nil then | ||
if tonumber(v) then | ||
chan[k] = tonumber(v) | ||
elseif v == "true" then | ||
chan[k] = true | ||
elseif v == "false" then | ||
chan[k] = false | ||
else | ||
chan[k] = v | ||
end | ||
end | ||
end | ||
sx1301_conf[key] = chan | ||
end | ||
end | ||
|
||
-- | ||
-- tx_lut_x | ||
-- | ||
for key, val in pairs(lora_global_table) do | ||
if string.match(key, 'tx_lut_[%d]?', 1) then | ||
local tx_lut = {} | ||
for k, v in pairs(val) do | ||
if string.match(k, '%.[%a]*', 1) == nil then | ||
if tonumber(v) then | ||
tx_lut[k] = tonumber(v) | ||
elseif v == "true" then | ||
tx_lut[k] = true | ||
elseif v == "false" then | ||
tx_lut[k] = false | ||
else | ||
tx_lut[k] = v | ||
end | ||
end | ||
end | ||
sx1301_conf[key] = tx_lut | ||
end | ||
end | ||
|
||
-- | ||
-- radio_0 | ||
-- | ||
if lora_global_table["radio_0"] then | ||
for k, v in pairs(lora_global_table["radio_0"]) do | ||
if string.match(k, '%.[%a]*', 1) == nil then | ||
if tonumber(v) then | ||
radio_0[k] = tonumber(v) | ||
elseif v == "true" then | ||
radio_0[k] = true | ||
elseif v == "false" then | ||
radio_0[k] = false | ||
else | ||
radio_0[k] = v | ||
end | ||
end | ||
end | ||
else | ||
error("UCI configuration has no item radio_0, Please check your configuration") | ||
end | ||
|
||
-- | ||
-- radio_1 | ||
-- | ||
if lora_global_table["radio_1"] then | ||
for k, v in pairs(lora_global_table["radio_1"]) do | ||
if string.match(k, '%.[%a]*', 1) == nil then | ||
if tonumber(v) then | ||
radio_1[k] = tonumber(v) | ||
elseif v == "true" then | ||
radio_1[k] = true | ||
elseif v == "false" then | ||
radio_1[k] = false | ||
else | ||
radio_1[k] = v | ||
end | ||
end | ||
end | ||
else | ||
error("UCI configuration has no item radio_1, Please check your configuration") | ||
end | ||
|
||
-- | ||
-- gateway_conf | ||
-- | ||
if lora_global_table["gateway_conf"] then | ||
for k, v in pairs(lora_global_table["gateway_conf"]) do | ||
-- filter out internal uci options | ||
if string.match(k, '%.[%a]*', 1) == nil then | ||
if tonumber(v) then | ||
gateway_conf[k] = tonumber(v) | ||
elseif v == "true" then | ||
gateway_conf[k] = true | ||
elseif v == "false" then | ||
gateway_conf[k] = false | ||
else | ||
gateway_conf[k] = v | ||
end | ||
end | ||
end | ||
else | ||
error("UCI configuration has no item gateway_conf, Please check your configuration") | ||
end | ||
|
||
-- | ||
-- SX1301_conf | ||
-- | ||
if lora_global_table["SX1301_conf"] then | ||
for k, v in pairs(lora_global_table["SX1301_conf"]) do | ||
if string.match(k, '%.[%a]*', 1) == nil then | ||
if tonumber(v) then | ||
sx1301_conf[k] = tonumber(v) | ||
elseif v == "true" then | ||
sx1301_conf[k] = true | ||
elseif v == "false" then | ||
sx1301_conf[k] = false | ||
else | ||
sx1301_conf[k] = v | ||
end | ||
end | ||
end | ||
else | ||
error("UCI configuration has no item SX1301_conf, Please check your configuration") | ||
end | ||
|
||
sx1301_conf["radio_0"] = radio_0 | ||
sx1301_conf["radio_1"] = radio_1 | ||
lora_global["gateway_conf"] = gateway_conf | ||
lora_global["SX1301_conf"] = sx1301_conf | ||
|
||
local lora_global_text = json.encode(lora_global, { indent = true }) | ||
|
||
print(lora_global_text) |
Oops, something went wrong.