From 46f5784e3acb277aab44217e2521625ffe043d35 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 1 Nov 2015 16:17:40 +0100 Subject: o Cleaning up logging. --- diller/inter.lua | 14 +++++++------- diller/main.lua | 31 +++++++++++++++---------------- diller/manual_init.lua | 2 +- diller/mq.lua | 24 ++++++++++-------------- upload.sh | 2 +- 5 files changed, 34 insertions(+), 39 deletions(-) diff --git a/diller/inter.lua b/diller/inter.lua index 8820727..a0aee5b 100644 --- a/diller/inter.lua +++ b/diller/inter.lua @@ -1,7 +1,7 @@ local P = {} function P.parse(line) - -- print("inter_parse: line="..line) +-- info("inter_parse: line="..line) line = string.sub(line, 1, string.find(line, "\r")) line = line:gsub("^%s+", "") @@ -10,11 +10,11 @@ function P.parse(line) local args = {} local i = string.find(line, " ") if not i then --- print("inter_parse: invalid line: no command, line="..line) +-- info("inter_parse: invalid line: no command, line="..line) return string.len(line) > 0 and line or nil, args end local cmd = string.sub(line, 1, i - 1) - -- print("inter_parse: cmd="..cmd) + -- info("inter_parse: cmd="..cmd) local last = i + 1 while i do @@ -26,19 +26,19 @@ function P.parse(line) arg = arg:gsub("%s+", "") if #arg > 0 then --- print("inter_parse: arg: "..arg) +-- info("inter_parse: arg: "..arg) j = string.find(arg, "=") if not j then if #arg > 0 then key = arg args[key] = true --- print("inter_parse: key="..key.."=true") +-- info("inter_parse: key="..key.."=true") end else key = string.sub(arg, 1, j-1) value = string.sub(arg, j+1) args[key] = value --- print("inter_parse: key="..key..", value="..value) +-- info("inter_parse: key="..key..", value="..value) end end @@ -53,7 +53,7 @@ end local cb function inter_on_line(line) --- print("line:"..line) +-- info("line:"..line) local cmd, args = P.parse(line) if not cmd then diff --git a/diller/main.lua b/diller/main.lua index dc1032d..3450bec 100644 --- a/diller/main.lua +++ b/diller/main.lua @@ -4,6 +4,10 @@ function panic(reason) node.restart() end +info = function(msg) + print("info "..msg) +end + local P = {} local inter = require('inter') @@ -46,11 +50,11 @@ local function configure_wlan() local wlan_password = read_cfg("wlan-password", false) if not wlan_ssid or not wlan_password then - print("Missing SSID and/or password configuration, use 'wlan' to configure") + info("Missing SSID and/or password configuration, use 'wlan' to configure") return end - print("Connecting to SSID: "..wlan_ssid) + info("Connecting to SSID: "..wlan_ssid) wifi.setmode(wifi.STATION) wifi.sta.config(wlan_ssid, wlan_password) end @@ -60,9 +64,9 @@ local function on_cmd(cmd, args) return end - print("on_cmd: '"..cmd.."', #args="..tostring(table.getn(args))) + info("on_cmd: '"..cmd.."', #args="..tostring(table.getn(args))) for k, v in pairs(args) do - print(k.."="..tostring(v)) + info(k.."="..tostring(v)) end if cmd == "reset" then @@ -104,23 +108,23 @@ local function on_cmd(cmd, args) local description_path = "property/"..id.."/description" if not property then - print("new property: "..id) + info("new property: "..id) property = {} properties[id] = property - mq.subscribe(name_path, function() print('message on '..path) end) - mq.subscribe(description_path, function() print('message on '..path) end) + mq.subscribe(name_path, function() info('message on '..path) end) + mq.subscribe(description_path, function() info('message on '..path) end) end if args.value then mq.publish(value_path, args.value) end if args.name and property.name ~= args.name then - print("publishing name") + info("publishing name") mq.publish(name_path, args.name) property.name = args.name end if args.description and property.description ~= args.description then - print("publishing description") + info("publishing description") mq.publish(description_path, args.description) property.description = args.description end @@ -139,13 +143,8 @@ local function on_cmd(cmd, args) end local function print_status() - print("System Status") - print("Uptime : "..tmr.time()) - print("Heap left: "..node.heap()) ip, nm, gw = wifi.sta.getip() - print("IP : "..tostring(ip)) - print("Netmask : "..tostring(nm)) - print("Gateway : "..tostring(gw)) + print("status uptime="..tmr.time().." heap-left="..node.heap().." ip="..tostring(ip).." netmask="..tostring(nm).." gateway="..tostring(gw)) end -- uart.setup(id, baud, databits, parity, stopbits, echo) @@ -183,7 +182,7 @@ function P.main() -- payload = payload.."}" -- P.publish("firmware", payload) - print("init done") + info("init done") end return P diff --git a/diller/manual_init.lua b/diller/manual_init.lua index f9c77a0..2bf5c9e 100644 --- a/diller/manual_init.lua +++ b/diller/manual_init.lua @@ -1,6 +1,6 @@ node.compile('inter.lua'); node.compile('mq.lua'); -node.compile('main.lua'); +-- node.compile('main.lua'); print("network"); print("wlan"); diff --git a/diller/mq.lua b/diller/mq.lua index 66927e2..f3136d6 100644 --- a/diller/mq.lua +++ b/diller/mq.lua @@ -2,26 +2,22 @@ local P = {} local m, topic, cid local subscriptions = {} -local function p(msg) - print("# MQTT: "..msg) -end - local function mq_client_connected(con) - p("connected") + info("mqtt: connected") end local function subscribed() - p("subscribed") + info("mqtt: subscribed") end local function disconnect() - p("Lost wifi connection, disconnecting") + info("mqtt: Lost wifi connection, disconnecting") m:close() m = nil end local function on_message(client, topic, message) - -- p("on_message: topic="..topic..", message="..message) + -- p("mqtt: on_message: topic="..topic..", message="..message) local _, _, new_property_name = string.find(topic, '/property/([%a%d-]+)/name$') if new_property_name then @@ -38,13 +34,13 @@ end function mq_on_timer() -- This crashes the module: -- local status = wifi.sta.status() - -- p("checking status, status="..status) + -- p("mqtt: checking status, status="..status) local status = wifi.sta.getip() if status and status ~= "0.0.0.0" then if not m then - p("connecting") + info("mqtt: connecting") -- client id, keepalive, username, password m = mqtt.Client(cid, 120) @@ -73,11 +69,11 @@ end function P.subscribe(path) local subscription = subscriptions[path] if subscription then - print("subscription on "..path.." already registered, state="..tostring(subscription.state)) + info("mqtt: subscription on "..path.." already registered, state="..tostring(subscription.state)) return end - print("Registering subscription on "..path) + info("mqtt: Registering subscription on "..path) subscriptions[path] = true @@ -87,12 +83,12 @@ end function P.publish(path, payload) if not m then - print("Not connected, dropping message to "..path) + info("mqtt: Not connected, dropping message to "..path) return false, 'not connected' end path = topic.."/"..path - print("path="..path) + info("mqtt: path="..path) m:publish(path, payload, 0, 0) return true, 'ok' diff --git a/upload.sh b/upload.sh index 68d8ebd..65005bf 100755 --- a/upload.sh +++ b/upload.sh @@ -8,7 +8,7 @@ cookie=$(cd $dir; echo $(pwd)/.cookie) cmd=() paths=() -for path in $(ls "$dir"/cfg-* "$dir"/*.lua) +for path in $(ls "$dir"/cfg-* "$dir"/*.lua 2>/dev/null) do if [[ $path -nt "$cookie" ]] then -- cgit v1.2.3