+++ /dev/null
-# Put your custom commands here that should be executed once
-# the system init finished. By default this file does nothing.
-
-I2C_BUS=0
-DS3221=68
-
-echo heartbeat > /sys/class/leds/linkit-smart-7688:orange\:wifi/trigger
-
-if [ ! -e /dev/lcdi2c ]; then
- insmod lcdi2c busno=0 address=0x27 cursor=0 blink=0 topo=1
-fi
-
-echo 1 > /sys/class/alphalcd/lcdi2c/clear
-echo \00\00 > /sys/class/alphalcd/lcdi2c/position
-
-if [ ! -e /dev/rtc0 ]; then
-
- modprobe rtc-ds1307
- echo ds1307 0x$DS3221 > /sys/class/i2c-dev/i2c-$I2C_BUS/device/new_device
- sleep 1
- if [ -e /dev/rtc0 ]; then
- ln -sf /dev/rtc0 /dev/rtc
- logger -t hardware RTC initialized
- fi
-
-fi
-
-if [ -e /dev/rtc0 ]; then
- /sbin/hwclock -u --rtc=/dev/rtc0 --hctosys
- echo "Hardware RTC OK" > /dev/lcdi2c
-else
- echo "Hardware RTC FAIL" > /dev/lcdi2c
-fi
#!/usr/bin/lua
local json = require("json")
-local socket = require("socket")
-
-local http = require("socket.http")
require "wm_util"
web_user = cur.get(config,"web","user")
web_timeout = cur.get(config,"web","timeout")
web_pass = cur.get(config,"web","password")
- web_devid = cur.get(config,"web","devid")
-
- web_iface = cur.get(config,"web","iface")
if not web_timeout then
web_timeout = 10
end
- if web_iface then
-
- command = '/sbin/ifconfig '..web_iface..' | grep \'\\<inet\\>\' | sed -n \'1p\' | tr -s \' \' | cut -d \' \' -f3 | cut -d \':\' -f2'
- f=io.popen(command,'r')
- ip_addr=f:read()
-
- end
-
- if not web_devid then
-
- if web_iface then
- io.input("/sys/class/net/"..web_iface.."/address")
- else
- io.input("/sys/class/net/eth0/address")
- end
-
- local mac = io.read("*line")
- mac = mac:gsub(":","")
- mac = mac:upper()
-
- web_devid = mac
-
- end
+ web_devid = get_devid(config)
logging = cur.get(config,"logging","enabled")
touch_file = cur.get(config,"logging","touch_file")
log_con:execute(string.format("INSERT INTO log(time_stamp,sensor_id,sensor,param,value) VALUES (datetime('now','localtime'),'%s','%s','%s',%f)",id,type,param,val))
end
- if touch_file then
- touch(touch_file)
- end
-
end
function storeRecord(id,sensor,param,value)
for k,v in pairs(sensor) do
storeRecord(sensor_id,sensor_type,k,v)
printLog("Type = "..sensor_type..", ID = "..sensor_id..", Param = "..k..", Value = \""..v.."\"")
- submitValue(sensor_type,sensor_id,k,v)
+ if web_url then
+ submitValue(sensor_type,sensor_id,k,v)
+ end
if mqtt_client then
mqtt_path=string.gsub(mqtt_topic,"{(.-)}",
function (name)
return '{'..name..'}'
end
end)
- mqtt_client:connect(mqtt_host,mqtt_port)
mqtt_client:publish(mqtt_path,v)
- mqtt_client:disconnect()
+ mqtt_client:loop()
end
end
else
for k,v in pairs(sensor) do
storeRecord(sensor_id,sensor_type,k,v)
printLog("Type = "..sensor_type..", ID = "..sensor_id..", Param = "..k..", Value = "..v)
- submitValue(sensor_type,sensor_id,k,v)
+ if web_url then
+ submitValue(sensor_type,sensor_id,k,v)
+ end
if mqtt_client then
mqtt_path=string.gsub(mqtt_topic,"{(.-)}",
function (name)
return '{'..name..'}'
end
end)
- mqtt_client:connect(mqtt_host,mqtt_port)
mqtt_client:publish(mqtt_path,v)
- mqtt_client:disconnect()
+ mqtt_client:loop()
end
end
else
return '{'..name..'}'
end
end)
- mqtt_client:connect(mqtt_host,mqtt_port)
mqtt_client:publish(mqtt_path,msg_body)
- mqtt_client:disconnect()
+ mqtt_client:loop()
end
if alarm_exec then
command=alarm_exec..
log_con:execute("CREATE INDEX log_idx ON log(sensor_id,sensor,param,time_stamp)")
end
+if web_url then
+ http = require("socket.http")
+ socket = require("socket")
+end
+
if mqtt_host then
MQTT = require "mosquitto"
mqtt_client = MQTT.new(mqtt_id)
if mqtt_user then
mqtt_client:login_set(mqtt_user, mqtt_passwd)
end
+ mqtt_client:connect(mqtt_host,mqtt_port)
end
if serial_port then
processLine(line)
end
+ if touch_file then
+ pcall(function ()
+ touch(touch_file)
+ end)
+ end
+
if dump_file then
- local f = io.open(dump_file,"w")
- io.output(f)
- io.write(json.encode(records))
- io.close(f)
+ pcall(function ()
+ local f = io.open(dump_file,"w")
+ io.output(f)
+ io.write(json.encode(records))
+ io.close(f)
+ end)
end
end)