From 4c06d2519634f95e5686aca74bf60ee608d770ee Mon Sep 17 00:00:00 2001 From: zhaojh329 Date: Thu, 8 Jun 2017 12:59:04 +0800 Subject: [PATCH] add command line option for client Signed-off-by: zhaojh329 --- openwrt/files/xterminal.config | 3 +++ openwrt/files/xterminal.init | 14 +++++++++++++- xterminal_device.lua | 4 +++- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 openwrt/files/xterminal.config mode change 100644 => 100755 openwrt/files/xterminal.init diff --git a/openwrt/files/xterminal.config b/openwrt/files/xterminal.config new file mode 100644 index 0000000..18e5496 --- /dev/null +++ b/openwrt/files/xterminal.config @@ -0,0 +1,3 @@ +config base + option mqtt_hostname 'jianhuizhao.f3322.net' + option mqtt_port '8883' diff --git a/openwrt/files/xterminal.init b/openwrt/files/xterminal.init old mode 100644 new mode 100755 index 5ca9fb9..096b2af --- a/openwrt/files/xterminal.init +++ b/openwrt/files/xterminal.init @@ -5,9 +5,21 @@ START=99 BIN=/usr/sbin/xterminal_device +mqtt_hostname= +mqtt_port= + +parse_conf() { + local cfg=$1 + config_get mqtt_hostname "$cfg" "mqtt_hostname" + config_get mqtt_port "$cfg" "mqtt_port" +} + start_service() { + config_load xterminal + config_foreach parse_conf base + procd_open_instance - procd_set_param command $BIN br-lan + procd_set_param command $BIN br-lan "$mqtt_hostname:$mqtt_port" procd_close_instance } diff --git a/xterminal_device.lua b/xterminal_device.lua index 744d4e9..2864fd5 100755 --- a/xterminal_device.lua +++ b/xterminal_device.lua @@ -9,6 +9,8 @@ local loop = ev.Loop.default local mgr = evmg.init() local ifname = arg[1] or "eth0" +local server = arg[2] or "localhost:1883" + local devid = nil local session = {} @@ -91,7 +93,7 @@ end print("devid:", devid) -mgr:connect("localhost:1883", ev_handle) +mgr:connect(server, ev_handle) ev.Signal.new(function(loop, sig, revents) loop:unloop()