From 977f25cc48106af2e344ad151d4bafacc09b9673 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Mon, 18 Apr 2011 10:28:51 +0200 Subject: [PATCH] [fluksod] make fluksod settings configurable through uci file --- .../openwrt/package/flukso/config/flukso.uci | 8 ++++++ .../openwrt/package/flukso/luasrc/fluksod.lua | 25 +++++++++++-------- .../package/flukso/luasrc/heartbeat.lua | 10 +++++--- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/mote/v2/openwrt/package/flukso/config/flukso.uci b/mote/v2/openwrt/package/flukso/config/flukso.uci index 80d244f..401a164 100644 --- a/mote/v2/openwrt/package/flukso/config/flukso.uci +++ b/mote/v2/openwrt/package/flukso/config/flukso.uci @@ -7,6 +7,14 @@ config settings main option max_analog_sensors 3 option reset_counters 0 +config settings daemon + option logmask info + option enable_wan_branch 1 + option enable_lan_branch 1 + option wan_base_url https://api.flukso.net/ + option upgrade_url http://www.flukso.net/files/upgrade/ + option cacert /etc/ssl/certs/flukso.ca.crt + ### sensor config options # config sensor <1..6> # option id diff --git a/mote/v2/openwrt/package/flukso/luasrc/fluksod.lua b/mote/v2/openwrt/package/flukso/luasrc/fluksod.lua index 8b371d6..8291a50 100755 --- a/mote/v2/openwrt/package/flukso/luasrc/fluksod.lua +++ b/mote/v2/openwrt/package/flukso/luasrc/fluksod.lua @@ -29,10 +29,13 @@ local uci = require 'luci.model.uci'.cursor() local httpclient = require 'luci.httpclient' local data = require 'flukso.data' +-- parse and load /etc/config/flukso +local FLUKSO = uci:get_all('flukso') + local arg = arg or {} -- needed when this code is not loaded via the interpreter local DEBUG = (arg[1] == '-d') -local LOGMASK = 'debug' +local LOGMASK = FLUKSO.daemon.logmask or 'info' nixio.setlogmask(LOGMASK) local DAEMON = os.getenv('DAEMON') or 'fluksod' @@ -48,14 +51,13 @@ local O_RDWR_CREAT = nixio.open_flags('rdwr', 'creat') local POLLIN = nixio.poll_flags('in') --- parse and load /etc/config/flukso -local FLUKSO = uci:get_all('flukso') -local WAN_ENABLED = true -local WAN_INTERVAL = 300 -local LAN_ENABLED = true -local TIMESTAMP_MIN = 1234567890 - -- set WAN parameters +local WAN_ENABLED = true +if tonumber(FLUKSO.daemon.enable_wan_branch) == 0 then WAN_ENABLED = false end + +local TIMESTAMP_MIN = 1234567890 +local WAN_INTERVAL = 300 + local WAN_FILTER = { [1] = {}, [2] = {}, [3] = {} } WAN_FILTER[1].span = 60 WAN_FILTER[1].offset = 0 @@ -64,7 +66,7 @@ WAN_FILTER[2].offset = 7200 WAN_FILTER[3].span = 86400 WAN_FILTER[3].offset = 172800 -local WAN_BASE_URL = 'https://api.flukso.net/sensor/' +local WAN_BASE_URL = FLUKSO.daemon.wan_base_url .. 'sensor/' local WAN_KEY = '0123456789abcdef0123456789abcdef' uci:foreach('system', 'system', function(x) WAN_KEY = x.key end) -- quirky but it works @@ -73,9 +75,12 @@ local FLUKSO_VERSION = '000' uci:foreach('system', 'system', function(x) FLUKSO_VERSION = x.version end) -- quirky but it works, again local USER_AGENT = 'Fluksometer v' .. FLUKSO_VERSION -local CACERT = '/etc/ssl/certs/flukso.ca.crt' +local CACERT = FLUKSO.daemon.cacert -- set LAN parameters +local LAN_ENABLED = true +if tonumber(FLUKSO.daemon.enable_lan_branch) == 0 then LAN_ENABLED = false end + local LAN_POLISH_CUTOFF = 60 local LAN_PUBLISH_PATH = DAEMON_PATH .. '/sensor' diff --git a/mote/v2/openwrt/package/flukso/luasrc/heartbeat.lua b/mote/v2/openwrt/package/flukso/luasrc/heartbeat.lua index 8eeaf5b..8e6e7b8 100755 --- a/mote/v2/openwrt/package/flukso/luasrc/heartbeat.lua +++ b/mote/v2/openwrt/package/flukso/luasrc/heartbeat.lua @@ -36,22 +36,26 @@ luci.sys = require 'luci.sys' luci.json = require 'luci.json' local httpclient = require 'luci.httpclient' + +-- parse and load /etc/config/flukso +local FLUKSO = uci:get_all('flukso') + -- WAN settings -local WAN_BASE_URL = 'https://api.flukso.net/device/' +local WAN_BASE_URL = FLUKSO.daemon.wan_base_url .. 'device/' local WAN_KEY = '0123456789abcdef0123456789abcdef' uci:foreach('system', 'system', function(x) WAN_KEY = x.key end) -- quirky but it works local DEVICE = '0123456789abcdef0123456789abcdef' uci:foreach('system', 'system', function(x) DEVICE = x.device end) -local UPGRADE_URL = 'http://www.flukso.net/files/upgrade/' +local UPGRADE_URL = FLUKSO.daemon.upgrade_url -- https header helpers local FLUKSO_VERSION = '000' uci:foreach('system', 'system', function(x) FLUKSO_VERSION = x.version end) local USER_AGENT = 'Fluksometer v' .. FLUKSO_VERSION -local CACERT = '/etc/ssl/certs/flukso.ca.crt' +local CACERT = FLUKSO.daemon.cacert -- collect relevant monitoring points function collect_mp()