X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;ds=sidebyside;f=sensor_graph%2Fsample_sensor.lua;h=d5be01d84d7f74168195c2729667767ec905ebd1;hb=01d1e843ebefd15eede53ec06381f8aa483558bd;hp=ad3550df961c052847fde5f99dc08471c672a146;hpb=514a0e3aa78b091b9a5ed6e8f1ca68d5cdad144a;p=svn42.git diff --git a/sensor_graph/sample_sensor.lua b/sensor_graph/sample_sensor.lua old mode 100644 new mode 100755 index ad3550d..d5be01d --- a/sensor_graph/sample_sensor.lua +++ b/sensor_graph/sample_sensor.lua @@ -1,3 +1,4 @@ +#!/usr/bin/lua require('os') require('string') @@ -13,47 +14,53 @@ end function parse_value(str) if string.find(str,"Temp C:") then - last_temp = tonumber(string.sub(str,8)) + last_temp = tonumber(string.sub(str,11)) --print(string.format("t: %f Grad Celsius",last_temp)) end if string.find(str,"Photo:") then - last_light = tonumber(string.sub(str,7)) + last_light = tonumber(string.sub(str,10)) --print(string.format("p: %d",last_light)) end if string.find(str,"movement") then last_movement=1 --print "something moved" end - end - - local socket = require("socket") -local client = assert(socket.connect("127.0.0.1",2010)) ---socket.unix = require("socket.unix") ---local socket = assert(socket.unix()) ---local client = assert(socket:connect("/var/run/power_sensor.socket")) -client:settimeout(10) - - - while 1 do - local line, err = client:receive() - if not err then - parse_value(line) - end - client:send("T") - line, err = client:receive() - if not err then - parse_value(line) - end - client:send("P") - line, err = client:receive() - if not err then - parse_value(line) + local client = socket.connect("127.0.0.1",2010) + --socket.unix = require("socket.unix") + --local socket = assert(socket.unix()) + --local client = assert(socket:connect("/var/run/power_sensor.socket")) + if client then + client:settimeout(30) + while 1 do + local line, err = client:receive() + if not err then + parse_value(line) + elseif err ~= "timeout" then + break + end + client:send("T") + line, err = client:receive() + if not err then + parse_value(line) + elseif err ~= "timeout" then + break + end + client:send("P") + line, err = client:receive() + if not err then + parse_value(line) + elseif err ~= "timeout" then + break + end + save_values() + end + client:shutdown("both") end - save_values() + socket.select(nil, nil, 10) end