Developing lightweight computation at the DSG edge

Commit 472e80fc authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[qmp-system] Fix device ID part for #474



The device_id field is now properly managed for both public and natted, and
appended ad lib.
Signed-off-by: default avatarRoger Pueyo Centelles <roger.pueyo@guifi.net>
parent 4f7ebe99
...@@ -33,6 +33,9 @@ config 'qmp' 'node' ...@@ -33,6 +33,9 @@ config 'qmp' 'node'
# The node id (2 hex digits). Leave blank to use crc16 from MAC address. # The node id (2 hex digits). Leave blank to use crc16 from MAC address.
option device_id '' option device_id ''
# Append device_id to device_name in the device hostname
option append_id '1'
# Temporay key file for session (autogenerated in each boot). # Temporay key file for session (autogenerated in each boot).
option key '/tmp/qmp_key' option key '/tmp/qmp_key'
...@@ -139,4 +142,3 @@ config 'qmp' 'wireless' ...@@ -139,4 +142,3 @@ config 'qmp' 'wireless'
option country 'US' option country 'US'
option bssid '02:CA:FF:EE:BA:BE' option bssid '02:CA:FF:EE:BA:BE'
option mrate '6000' option mrate '6000'
...@@ -14,21 +14,20 @@ qmp_configure_system() { ...@@ -14,21 +14,20 @@ qmp_configure_system() {
else else
local device_id=$(qmp_get_id_hostname) local device_id=$(qmp_get_id_hostname)
device_id="$(echo -n $device_id | tr -cd 'ABCDEFabcdef0123456789' | tail -c 4)" device_id="$(echo -n $device_id | tr -cd 'ABCDEFabcdef0123456789' | tail -c 4)"
[ $(echo -n $device_id | wc -c) -lt 4 ] && {
qmp_log "Warning, device_id not defined properly, using failsafe 0000"
device_id=0000
}
qmp_uci_set node.device_id $device_id qmp_uci_set node.device_id $device_id
fi fi
[ $(echo -n $device_id | wc -c) -lt 4 ] && {
qmp_log "Warning, device_id not defined properly, using failsafe 0000"
device_id=0000
}
local device_name="$(qmp_uci_get node.device_name)" local device_name="$(qmp_uci_get node.device_name)"
[ -z "$device_name" ] && device_name="qMp" && qmp_uci_set node.device_name $device_name [ -z "$device_name" ] && device_name="qMp" && qmp_uci_set node.device_name $device_name
# set hostname # set hostname
local ig_roaming="$(uci get qmp.roaming.ignore)" local append_id="$(uci get qmp.node.append_id)"
if [ $ig_roaming -eq 1 ]; then if [ $append_id -eq 0 ]; then
uci set system.@system[0].hostname="${device_name}" uci set system.@system[0].hostname="${device_name}"
echo "${device_name}" > /proc/sys/kernel/hostname echo "${device_name}" > /proc/sys/kernel/hostname
else else
......
...@@ -47,23 +47,36 @@ m = SimpleForm("qmp", translate("qMp easy setup"), translate("This page provides ...@@ -47,23 +47,36 @@ m = SimpleForm("qmp", translate("qMp easy setup"), translate("This page provides
local devicename_help local devicename_help
local devicename_help = m:field(DummyValue,"_devicename_help") local devicename_help = m:field(DummyValue,"_devicename_help")
devicename_help.rawhtml = true devicename_help.rawhtml = true
devicename_help.default = "<legend>"..translate("Device identification").."</legend>".."<br/> <br/>"..translate("Choose a name for this device. It will be used to identify it in the mesh network.").."<br/> <br/>" devicename_help.default = "<legend>"..translate("Device identification").."</legend>".."<br/> <br/>"..translate("Choose a name and a numeric ID for this device. It will be used to identify it in the mesh network:").."<br/> <br/>"
local devicename = m:field(Value, "_devicename", " ", translate("Use only alphanumeric characters, dots, dashes and underscores.")) local devicename = m:field(Value, "_devicename", translate("Device name"), translate("Use only alphanumeric characters, dots, dashes and underscores."))
devicename.datatype="hostname" devicename.datatype="hostname"
devicename.optional=false devicename.optional=false
devicename.default="MyMeshDevice" devicename.default="MyMeshDevice"
if uciout:get("qmp","node","device_name") ~= nil then if uciout:get("qmp","node","device_name") ~= nil then
devicename.default=uciout:get("qmp","node","device_name") devicename.default = uciout:get("qmp","node","device_name")
else
devicename.default = "qMp"
end end
-- Device ID device
local deviceid = m:field(Value, "_deviceid", translate("Device ID"), translate("Use hexadecimal characters only."))
deviceid:depends({_communityname = "Guifi.net"})
deviceid.datatype="string"
deviceid.optional = false
if uciout:get("qmp","node","device_id") ~= nil then
deviceid.default = uciout:get("qmp","node","device_id")
else
deviceid.default = "0000"
end
-- Community network name -- Community network name
local communityname_help local communityname_help
communityname_help = m:field(DummyValue,"_communityname_help") communityname_help = m:field(DummyValue,"_communityname_help")
communityname_help.rawhtml = true communityname_help.rawhtml = true
communityname_help.default = translate("Select the name of the community network this device belongs to.") .. "<br/> <br/>" communityname_help.default = translate("If the device is part of a community network, select it:") .. "<br/> <br/>"
local communityname = m:field(Value, "_communityname", " ", translate("Select a predefined community network from the list, type your own name or leave it blank.")) local communityname = m:field(Value, "_communityname", " ", translate("Select a predefined community network from the list, type your own name or leave it blank."))
communityname.datatype="string" communityname.datatype="string"
...@@ -98,15 +111,6 @@ if uciout:get("qmp","node","mesh_name") ~= nil then ...@@ -98,15 +111,6 @@ if uciout:get("qmp","node","mesh_name") ~= nil then
guifimeshname.default=uciout:get("qmp","node","mesh_name") guifimeshname.default=uciout:get("qmp","node","mesh_name")
end end
-- Guifi device
local guifideviceid = m:field(Value, "_guifideviceid", " ", translate("Device ID in Guifi.net's web site. Use numbers only."))
guifideviceid:depends({_communityname = "Guifi.net"})
guifideviceid.datatype="uinteger"
if uciout:get("qmp","node","device_id") ~= nil then
guifideviceid.default=uciout:get("qmp","node","device_id")
end
---------------------------------------- ----------------------------------------
-- Node mode and public IPv4 address -- -- Node mode and public IPv4 address --
...@@ -360,13 +364,12 @@ function nodemode.write(self, section, value) ...@@ -360,13 +364,12 @@ function nodemode.write(self, section, value)
local community_name = communityname:formvalue(section) local community_name = communityname:formvalue(section)
if community_name == "Guifi.net" then if community_name == "Guifi.net" then
local mesh_name = guifimeshname:formvalue(section) local mesh_name = guifimeshname:formvalue(section)
local device_id = guifideviceid:formvalue(section) local device_id = deviceid:formvalue(section)
uciout:set("qmp","node","mesh_name",mesh_name) uciout:set("qmp","node","mesh_name",mesh_name)
uciout:set("qmp","node","device_id",device_id) uciout:set("qmp","node","device_id",device_id)
end end
uciout:set("qmp","node","community_name",community_name) uciout:set("qmp","node","community_name",community_name)
if mode == "community" then if mode == "community" then
uciout:set("qmp","roaming","ignore","1") uciout:set("qmp","roaming","ignore","1")
uciout:set("qmp","networks","publish_lan","1") uciout:set("qmp","networks","publish_lan","1")
......
...@@ -24,6 +24,18 @@ local uci = luci.model.uci.cursor() ...@@ -24,6 +24,18 @@ local uci = luci.model.uci.cursor()
local qmpinfo = require "qmpinfo" local qmpinfo = require "qmpinfo"
local util = require "luci.util" local util = require "luci.util"
devices = qmpinfo.get_devices()
devname = uci:get("qmp","node","device_name")
devid = uci:get("qmp","node","device_id")
if (devname == nil or devname == '') then
devname = "qMp"
end
if (devid == nil or devid == '') then
devid = "0000"
end
m = Map("qmp", "qMp node settings", translate("This page allows to configure the basic node settings, like the device identification, location and contact details.") .. "<br/> <br/>" .. translate("You can check the on-line documentation at <a href=\"https://www.qmp.cat/Web_interface\">https://www.qmp.cat/Web_interface</a> for more information about the different options.")) m = Map("qmp", "qMp node settings", translate("This page allows to configure the basic node settings, like the device identification, location and contact details.") .. "<br/> <br/>" .. translate("You can check the on-line documentation at <a href=\"https://www.qmp.cat/Web_interface\">https://www.qmp.cat/Web_interface</a> for more information about the different options."))
...@@ -36,6 +48,18 @@ device_name.optional = false ...@@ -36,6 +48,18 @@ device_name.optional = false
device_name.rmempty = false device_name.rmempty = false
device_name.default = "qMp" device_name.default = "qMp"
device_id = device_section:option(Value,"device_id", translate("Device ID"), translate("The ID of this device in the mesh network (optional). Use hexadecimal characters only."))
device_id:depends("community_name","Guifi.net")
device_id.datatype = "string"
device_id.optional = false
device_id.rmempty = false
append_id = device_section:option(ListValue, "append_id", translate("Append ID"),translatef("Append the device ID to the device name (e.g., %s-%s)", devname, devid))
append_id:value("0", translate ("No"))
append_id:value("1", translate("Yes"))
append_id.default = "1"
append_id.optional = false
append_id.rmempty = false
community_name = device_section:option(Value, "community_name", translate ("Community Network name"), translate("Select a predefined community network from the list, type your own name or leave it blank.")) community_name = device_section:option(Value, "community_name", translate ("Community Network name"), translate("Select a predefined community network from the list, type your own name or leave it blank."))
community_name.datatype="string" community_name.datatype="string"
...@@ -59,14 +83,6 @@ guifimesh_name:value("Vallcarca", "Vallcarca (VKK)") ...@@ -59,14 +83,6 @@ guifimesh_name:value("Vallcarca", "Vallcarca (VKK)")
guifimesh_name:value("Herguijuela", "La Herguijuela (LHer)") guifimesh_name:value("Herguijuela", "La Herguijuela (LHer)")
guifimesh_name:value("CepedaLaMora", "Cepeda la Mora (CPD)") guifimesh_name:value("CepedaLaMora", "Cepeda la Mora (CPD)")
device_id = device_section:option(Value,"device_id", translate("Device ID"), translate("The ID of this device in the mesh network (optional). Use alphanumeric characters only, without spaces or symbols."))
device_id:depends("community_name","Guifi.net")
device_id.datatype = "string"
device_id.optional = true
device_id.rmempty = false
devices = qmpinfo.get_devices()
primary_device = device_section:option(Value,"primary_device", translate("Primary network interface"), translate("The name of the node's primary network interface. The last four digits of this device's MAC address will be appended to the node name.")) primary_device = device_section:option(Value,"primary_device", translate("Primary network interface"), translate("The name of the node's primary network interface. The last four digits of this device's MAC address will be appended to the node name."))
primary_device.datatype = "network" primary_device.datatype = "network"
primary_device.optional = false primary_device.optional = false
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment