hostname = os.getenv("COLLECTD_HOSTNAME") if hostname==nil then hostname="undefined-hostname" end interval = os.getenv("COLLECTD_INTERVAL") if interval==nil then interval=10 end rserial=io.open("/dev/ttyACM0","r") wserial=io.open("/dev/ttyACM0","w") rserial:flush() while true do wserial:write(".") tstart = os.time() repeat line=rserial:read() line=string.gsub(line,"\r$","") temp = nil humidity = nil temp, humidity = string.match(line, 'DHT%s+([%.,%d]+)%s+([%.,%d]+)') if temp ~= nil and humidity ~= nil then print("PUTVAL "..hostname.."/dht/temperature-temperature interval="..interval.." N:"..temp) print("PUTVAL "..hostname.."/dht/humidity-humidity interval="..interval.." N:"..humidity) line="" end romid = nil temp = nil romid, temp = string.match(line, '(%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x)%s+([%.,%d]+)') if romid ~= nil and temp ~= nil then print("PUTVAL "..hostname.."/onewire/"..romid.."-temperature interval="..interval.." N:"..temp) end until line=="EOF" towait = interval - os.difftime(os.time(),tstart) if towait>0 then os.execute("sleep "..tonumber(towait)) end end