From d715b3325c695a96bb34763e3d60b89e56496eb9 Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Mon, 8 Mar 2010 16:20:46 +0000 Subject: [PATCH] sample sensor reconnect --- rf433ctl/rf433ctl.pde | 5 ++-- sensor_graph/sample_sensor.lua | 56 ++++++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/rf433ctl/rf433ctl.pde b/rf433ctl/rf433ctl.pde index 6f5ae7d..f404110 100644 --- a/rf433ctl/rf433ctl.pde +++ b/rf433ctl/rf433ctl.pde @@ -22,6 +22,7 @@ OneWire onewire(ONE_WIRE_PIN); DallasTemperature dallas_sensors(&onewire); DeviceAddress onShieldTemp = { 0x10, 0xE7, 0x77, 0xD3, 0x01, 0x08, 0x00, 0x3F }; +#define TEMPC_OFFSET typedef struct { byte offset; @@ -204,7 +205,7 @@ void printTemperature(DeviceAddress deviceAddress) dallas_sensors.requestTemperatures(); float tempC = dallas_sensors.getTempC(deviceAddress); Serial.print("Temp C: "); - Serial.println(tempC); + Serial.println(tempC TEMPC_OFFSET); //Serial.print(" Temp F: "); //Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit } @@ -333,7 +334,7 @@ void loop() { pb_postth_state=1; Serial.println("PanicButton"); - flash_led(7); + flash_led(4); } else if (!pb_state) pb_postth_state=0; diff --git a/sensor_graph/sample_sensor.lua b/sensor_graph/sample_sensor.lua index 9ff02a2..bcd6ec3 100644 --- a/sensor_graph/sample_sensor.lua +++ b/sensor_graph/sample_sensor.lua @@ -24,36 +24,42 @@ function parse_value(str) 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(30) - - - 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 -- 1.7.10.4