Developing lightweight computation at the DSG edge

Commit 6b0a9bef authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[qmp-system] Add mesh name to hostname (finish #474)

Now the CN mesh name can be prepended ad lib to the hostname.
Signed-off-by: default avatarRoger Pueyo Centelles <>
parent 472e80fc
......@@ -37,6 +37,9 @@ config 'qmp' 'node'
# Append device_id to device_name in the device hostname
option append_id '1'
# Prepend mesh_name to device_name in the device hostname,
option prepend_cnm '1'
# Temporay key file for session (autogenerated in each boot).
option key '/tmp/qmp_key'
......@@ -14,28 +14,46 @@ qmp_configure_system() {
local device_id=$(qmp_get_id_hostname)
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"
[ $(echo -n $device_id | wc -c) -lt 4 ] && {
qmp_log "Warning, device_id not defined properly, using failsafe 0000"
qmp_uci_set node.device_id $device_id
if [ -n "$(qmp_uci_get node.mesh_name)" ]; then
local mesh_name=$(qmp_uci_get node.mesh_name)
local mesh_name=""
local device_name="$(qmp_uci_get node.device_name)"
[ -z "$device_name" ] && device_name="qMp" && qmp_uci_set node.device_name $device_name
# set hostname
local append_id="$(uci get qmp.node.append_id)"
if [ $append_id -eq 0 ]; then
uci set system.@system[0].hostname="${device_name}"
echo "${device_name}" > /proc/sys/kernel/hostname
uci set system.@system[0].hostname="${device_name}-${device_id}"
echo "${device_name}-${device_id}" > /proc/sys/kernel/hostname
local append_id=0
if [ -n "$(qmp_uci_get node.append_id)" ]; then
append_id="$(uci get qmp.node.append_id)"
uci commit system
local prepend_cnm=0
if [ -n "$(qmp_uci_get node.prepend_cnm)" ]; then
prepend_cnm="$(uci get qmp.node.prepend_cnm)"
if [ $append_id -eq 1 ]; then
if [ $prepend_cnm -eq 1 ] && [ -n "${mesh_name}" ]; then
uci set system.@system[0].hostname="${device_name}"
echo "${device_name}" > /proc/sys/kernel/hostname
uci commit system
uci set uhttpd.main.listen_http="80"
uci set uhttpd.main.listen_https="443"
......@@ -95,17 +95,17 @@ local guifimeshname = m:field(Value, "_guifimeshname", " ", translate("Select a
guifimeshname:value("GuifiBaix", "Baix Llobregat (GuifiBaix)")
guifimeshname:value("Bellvitge", "Bellvitge (HW)")
guifimeshname:value("GraciaSenseFils", "Gràcia Sense Fils (GSF)")
guifimeshname:value("PoblenouSenseFils", "Poblenou Sense Fils (P9SF)")
guifimeshname:value("Quesa", "Quesa (QUESA)")
guifimeshname:value("Raval", "Raval (RAV)")
guifimeshname:value("GuifiSants", "Sants-Les Corts-UPC (GS)")
guifimeshname:value("SantAndreu", "Sant Andreu (SAND)")
guifimeshname:value("Vallcarca", "Vallcarca (VKK)")
guifimeshname:value("Herguijuela", "La Herguijuela (LHer)")
guifimeshname:value("CepedaLaMora", "Cepeda la Mora (CPD)")
guifimeshname:value("GB", "Baix Llobregat - GuifiBaix (GB)")
guifimeshname:value("HW", "Bellvitge (HW)")
guifimeshname:value("GSF", "Gràcia Sense Fils (GSF)")
guifimeshname:value("P9SF", "Poblenou Sense Fils (P9SF)")
guifimeshname:value("QS", "Quesa (QS)")
guifimeshname:value("RAV", "Raval (RAV)")
guifimeshname:value("GS", "Sants-Les Corts-UPC (GS)")
guifimeshname:value("SAND", "Sant Andreu (SAND)")
guifimeshname:value("VKK", "Vallcarca (VKK)")
guifimeshname:value("LHER", "La Herguijuela (LHER)")
guifimeshname:value("CPD", "Cepeda la Mora (CPD)")
if uciout:get("qmp","node","mesh_name") ~= nil then
......@@ -28,6 +28,7 @@ devices = qmpinfo.get_devices()
devname = uci:get("qmp","node","device_name")
devid = uci:get("qmp","node","device_id")
meshname = uci:get("qmp","node","mesh_name")
if (devname == nil or devname == '') then
devname = "qMp"
......@@ -37,6 +38,10 @@ if (devid == nil or devid == '') then
devid = "0000"
if (meshname == nil or meshname == '') then
meshname = "GS"
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=\"\"></a> for more information about the different options."))
device_section = m:section(NamedSection, "node", "qmp", translate("Device identification"), translate("The following settings are used to identify the device all over the mesh network."))
......@@ -54,10 +59,8 @@ 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 = device_section:option(Flag, "append_id", translate("Append ID"),translatef("Append the device ID to the device name (e.g., %s-%s)", devname, devid))
append_id.default = 1
append_id.optional = false
append_id.rmempty = false
......@@ -71,17 +74,23 @@ community_name:value("NYCMesh","NYC Mesh")
guifimesh_name = device_section:option(Value, "mesh_name", translate ("Mesh Network name"), translate("Select a predefined community subnetwork or type your own name (optional)."))
guifimesh_name:value("GuifiBaix", "Baix Llobregat (GuifiBaix)")
guifimesh_name:value("Bellvitge", "Bellvitge (HW)")
guifimesh_name:value("GraciaSenseFils", "Gràcia Sense Fils (GSF)")
guifimesh_name:value("PoblenouSenseFils", "Poblenou Sense Fils (P9SF)")
guifimesh_name:value("Quesa", "Quesa (QUESA)")
guifimesh_name:value("Raval", "Raval (RAV)")
guifimesh_name:value("GuifiSants", "Sants-Les Corts-UPC (GS)")
guifimesh_name:value("SantAndreu", "Sant Andreu (SAND)")
guifimesh_name:value("Vallcarca", "Vallcarca (VKK)")
guifimesh_name:value("Herguijuela", "La Herguijuela (LHer)")
guifimesh_name:value("CepedaLaMora", "Cepeda la Mora (CPD)")
guifimesh_name:value("GB", "Baix Llobregat - GuifiBaix (GB)")
guifimesh_name:value("HW", "Bellvitge (HW)")
guifimesh_name:value("GSF", "Gràcia Sense Fils (GSF)")
guifimesh_name:value("P9SF", "Poblenou Sense Fils (P9SF)")
guifimesh_name:value("QS", "Quesa (QS)")
guifimesh_name:value("RAV", "Raval (RAV)")
guifimesh_name:value("GS", "Sants-Les Corts-UPC (GS)")
guifimesh_name:value("SAND", "Sant Andreu (SAND)")
guifimesh_name:value("VV", "Vallcarca (VKK)")
guifimesh_name:value("LHER", "La Herguijuela (LHER)")
guifimesh_name:value("CPD", "Cepeda la Mora (CPD)")
prepend_cnm = device_section:option(Flag, "prepend_cnm", translate("Prepend mesh ID"),translatef("Prepend the mesh network ID to the device name (e.g., %s-%s-%s)", meshname, devname, devid))
prepend_cnm.default = 1
prepend_cnm.optional = false
prepend_cnm.rmempty = false
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"
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