From 34196cc1f18f850f3eefe89479b5c5df04c5dbe3 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Sun, 6 Mar 2011 01:05:15 +0100 Subject: [PATCH] [fsync] generate a flukso.service file for avahi --- .../openwrt/package/flukso/luasrc/fsync.lua | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/mote/v2/openwrt/package/flukso/luasrc/fsync.lua b/mote/v2/openwrt/package/flukso/luasrc/fsync.lua index 0da4884..463b4c8 100755 --- a/mote/v2/openwrt/package/flukso/luasrc/fsync.lua +++ b/mote/v2/openwrt/package/flukso/luasrc/fsync.lua @@ -33,6 +33,7 @@ local CTRL_PATH_IN = CTRL_PATH .. '/in' local CTRL_PATH_OUT = CTRL_PATH .. '/out' local O_RDWR_NONBLOCK = nixio.open_flags('rdwr', 'nonblock') +local O_RDWR_CREAT = nixio.open_flags('rdwr', 'creat') local POLLIN = nixio.poll_flags('in') local POLL_TIMEOUT_MS = 1000 local MAX_TRIES = 5 @@ -115,6 +116,7 @@ local COMMIT = 'ct' local API_PATH = '/www/sensor/' local CGI_SCRIPT = '/usr/bin/restful' +local AVAHI_PATH = '/etc/avahi/services/flukso.service' -- check hardware version local hw_major, hw_minor = send(ctrl, GET_HW_VERSION):match(GET_HW_VERSION_R) @@ -248,4 +250,45 @@ for i = 1, MAX_SENSORS do end end +-- generate a new flukso.service for avahi +avahi = { head = {}, body = {}, tail = {} } + +avahi.head[1] = '' +avahi.head[2] = '' +avahi.head[3] = '' +avahi.head[4] = ' Flukso RESTful API on %h' +avahi.head[5] = ' ' +avahi.head[6] = ' _flukso._tcp' +avahi.head[7] = ' 8080' + +for i = 1, MAX_SENSORS do + if flukso[tostring(i)] ~= nil and flukso[tostring(i)].enable == '1' and flukso[tostring(i)].id then + avahi.body[#avahi.body + 1] = string.format(' id%d=%s' , i, flukso[tostring(i)].id) + end +end + +avahi.tail[1] = ' path=/sensor' +avahi.tail[2] = ' version=1.0' +avahi.tail[3] = ' ' +avahi.tail[4] = '' + +-- remove the old flukso.service +nixio.fs.unlink(AVAHI_PATH) + +-- generate the new one +fd = nixio.open(AVAHI_PATH, O_RDWR_CREAT) +print(string.format('generating a new %s', AVAHI_PATH)) + +for i = 1, #avahi.head do + fd:write(avahi.head[i] .. '\n') +end + +for i = 1, #avahi.body do + fd:write(avahi.body[i] .. '\n') +end + +for i = 1, #avahi.tail do + fd:write(avahi.tail[i] .. '\n') +end + print(arg[0] .. ' completed successfully. Bye!')