Proximity Sensor Plugin - Help !

[center]Welcome to the Proximity Plugin.
This is a work in progress.
[/center]

I’ve been thinking of a way to create a simple proximity sensor, and just to be clear the goal is to try and create a plugin that can look for ‘identifiers’ that are in range and then notify you when they are not.

I have two main goals for this, one is to monitor the movement of the kids (a recent news item in the UK is of a girl who was kidnapped from her front garden) and the other is for an elderly relative who has a habit of wondering off. The plugin would be a simple motion sensor (green when in range and red when out etc.

* The plugin has other uses, such as being can used to notify you should a particular device have not been updated for a period on time too

I’ve already been using the current IP ping sensor to identify me and the misses, but that can be hit or miss when it works as the phone has to be on. I have also tried to look into a key fob but I’ve decided the sensing should be in the background and require no involvement of the person you want to track.

I’ve already kicked off some initial work using the rfxrtx433 plugin, which looks for the location of a temperature sensor in that it will check for any gaps in the sensors updates. [url=http://forum.micasaverde.com/index.php/topic,12037.0.html]http://forum.micasaverde.com/index.php/topic,12037.0.html[/url]

I’ve seen Bluetooth ones that work with iPhone apps and there are a number of ‘anti lost’ devices on the market. So I am optimistic that with this forums help I can get something to work, but it’s difficult to know which technology to back? E.g could z-wave be used e.g (Fibaro Universal Sensor?)

So in summary.

  • The plugin should work as a motion sensor in the Vera UI
  • It should require no involvement from the individual being tracked
  • The sensor should ideally be small, and not cumbersome to carry around. (e.g Wrist band, pocket)
  • The sensor should transmit at regular intervals (max 30 secs)
  • Needs to cover a wide area e.g 1-20 meters (so no NFID)

There have been a few posts on this previously, but only really as a supplementary discussion point - so all thoughts/comments on this as a stand alone app from this forum would be greatly appreciated …

–oo00oo–

16th Oct 2012 - Version 0.1 - This version is UNTESTED - Released for code review and feedback by others
17th Oct 2012 - Version 0.2 - Tested but with errors - still Lua issues I think, expertise and code review still sought.
21st Oct 2012 - Version 0.3 - Removed Ping ‘address’ references - Error = Proximity Sensor[76] Lua Engine Failed To Load
25th Oct 2012 - Version 0.4/5 - Posted in the forum but continues to have problems

–oo00oo–

29th Oct 2012 - Version 0.6 - New approach to be taken. ping sensor not converting well. So starting from scratch

–oo00oo–

31st Dec 2012 - Version 1 - Due to my own inability to create a plugin, this is now running as a scene with a dummy motion sensor device.

All input ideas comment most welcome…

these wireless tags (which were discussed in some other thread) could come in handy. http://www.wirelesstag.net

Hi Capjay,

Thanks for responding, I agree they do look nice :wink:

The challenge I have with those ones is that the RFXrtx i have already acts as a rudimentary version of that device. With the only major difference (i think) being the size and scope of their sensors, otherwise Vera looks like it can do much the same when you have certain add-ons installed.

In the link above to my post running in the RFXrtx plugin’s child board, I’m trying to write code to convert an oregon scientific temperature sensor to be a proximity sensor, but as I’ve never coded before it makes the gap between my vision and its reality, such a long one :).

If you have time to look at the code I’d really appreciate any help to work that idea through to some sort of conclusion, while this one looks for technologies like those you suggested.

It surprises me that there’s not a z-wave proximity sensor benefiting from the z-wave network, as it does not need to be a complex design, it would simple work on a ‘can you see me, or not’ set up.

One idea for a z-wave proximity sensor is as follows…

  • A Fibaro Universal Sensor
  • A 9v Battery

(You could even add a temp sensor to it as well)

That way I guess Vera could poll it and let you know if it is out of range. Any thoughts/comments?

Hi

I’m continuing to look at ways to create a motion sensor device that looks for a specified battery operated device, I have a stream running against the RFXrtx plugin for help on doing some test code against a temp sensor , but it could also look for a zwave device so i’m itching to create a motion sensor that can be set up to look for a specified device and then notify me when it is out of range (no longer transmitting/so the sensor is tripped)

I obviously need a device file D_…XML
I assume I need to write an I_…XML and a L_…XML

You probably don’t need to develop a plugin just for less than 10 lines of code.
Put your code in a scene and plan the execution of that scene for example every 15 seconds.
Just my humble opinion…

Thanks lolodomo, I know you’re right about it being simpler, but as I would like it to work for multiple things, it would be great to have such visibility on the dashboard. One for the car, one for the wife, one for the dog etc.

I am currently trying to rework the Ping Sensor plugin, so you can set it to look for a device of your choice. (Basically just change the ping function to something more suitable).

I am completely out of my depth, but enjoying the challenge ;). So to have someone like you, Guessed, Chris, futzle etc on this forum is reassuring when you can help.

Hi All,

After looking into the code of the Ping Sensor, it has the following lines that look like the place where the check is done to return either a “1” or a “0” (Tripped or Not)

[code]local function executePing(address)
local returnCode = os.execute("ping -c 1 " … address)

  if (returnCode == 0) then
    -- everything is fine, we reached the host
    return "1"
  else
    -- something went wrong here
    -- log("abnormal exit while ping execution. ErrorCode: " .. tostring(returnCode))
    return "0"
  end
end[/code]

Now considering the above, it’s therefore my hope that i can change this check so that rather than looking up an IP address value, it instead does a check against any date/time variable of any registered battery operated device you want to specify. [size=1em]Please Note: there’s already a variable called ‘Period’ that specifies how frequent this should run.[/size]

OK, now to do this i was looking to change the current IP ‘address’ variable to be ‘DEVICE_ID’ and add another two called ‘SERVICE_NAME’ and ‘VARIABLE_NAME’ so that the user can then set up the plugin to look for any specific device date/time variable.

Therefore if I want to trip the sensor when a specify device is out of range (i.e has not been updated) could I use the following code?

local function executePing(address) local returnCode = luup.variable_get(SERVICE_NAME, VARIABLE_NAME, DEVICE_ID) if (os.time() - returnCode >= Period) then -- not good, the device has not reported in -- log("abnormal exit while proximity check execution. ErrorCode: " .. tostring(returnCode)) return "1" else -- relax the device still looks to be reporting in. return "0" end end

I’ve started creating new services etc. in my revamped version of the PingSensor, so all comments, suggestions would be greatly appreciated.

Hi All

Using the logic of the ping sensor (an no programming skills at all) I have had a go at creating a Proximity Plugin, which in it’s current form will look for any device (date/time) variable you specific to see if it’s been updated within a certain period of time. If not it will ‘Trip’ the device.

An example of how this plugin could be used is as follows

  • Place a battery operated device in my car and it will alert me when the car is in or out of the drive
  • Put a battery operated device on your person, or in your bag/handbag and it will notify you when you’re in or out of range.

Currently I’ve found the Oregon Scientific devices (used via the RFXrtx433 plugin) to be the best as these regularly transmit information every 10 seconds and update the 'Battery Date ’ value each time. There is also scope for z-wave devices too, by looking at the ‘Last Updated’ date.

PLEASE NOTE - The following is UNTESTED but I would hugely appreciate if someone can have a look at this and provide me with some feedback

PS - I’ve left the Ping sensors ‘address’ values in there for the moment, as a guide but I hope to remove them eventually

Even not by yourself ?!

Hi lolodomo

I have tested bits of the code but I’m afraid certain aspects did not work, which was why I made the earlier posts above seeking help to try to fix bits of it

Also I’ve never done anything like this before, writing code, creating/adding variables etc. so I was looking for anyone (ideally like you) with far more experience than I to help out, and just have a look at the code to let me know if it looks largely OK and where I might have gone wrong etc.

I also wanted to stress to others that it was ‘untested’ as I’m not a programmer, therefore people’s expectation of it working ‘out of the box’ should be set to low.

I’ve zipped up everything I’ve done so far and shared it here in the hope it can (collectively) be improved.

Thanks…

Hi All

Sadly, still no joy in getting this to work:-(

I did notice a couple of things that ‘looked’ wrong, which I’ve now changed, however after installing the files, restating Luup etc. I’m still unable to get any of the new variables options to appear on the UI.

Latest V2 Code & Files attached below- but please note this is not currently a functional plugin - it’s very much a work in progress…

I’m still looking for help, if anyone has the time…

Hi

Current Status - After anther luup restart, the device is now looking like the intended motion sensor and the variable options i’d coded are now visible - however - I have a message in the info window of UI5 telling me Proximity Sensor : Please Restart Luup to initialise this plug in

No matter how many Luup restarts I do the message keeps coming back :frowning:

The device i’ve created on the dashboard also has a red light on and a message saying Lua Startup Failure Lua Failure

Oh and if i try to arm it I get a pop up telling me “Device not Ready”

If we could plug a bluetooth USB dongle into the Vera and scan for devices, we could simply use a small device that we carry with us regularly anyway like a bluetooth ear-piece. The trick then would only be to keep it charged all the time.
Is that a good idea to follow up on?

Hi, thanks for the input.

This plugin (when complete) could theoretically look for any device you have registered on Vera. So if you could get a Bluetooth transceiver working, and devices constantly talking to it - it should work.

The challenge with Bluetooth I seem to recall is the range, I think it’s designed to run over short distances.

The current Ping Sensor plugin, already looks for network IP devices, however when you’re using a mobile device (i.e a phone), it always has to be switched on and registered on the network for it to work properly.

Sadly, I continue to feel out of my depth on how to fix these errors :frowning:

If anyone is able to help and advise on where I went wrong, I would really appreciate it.

Many Thanks

Had another go at the code today, I removed some of the old Ping ‘address’ references just in case they were causing me the problems, the device itself no longer shows “Lua Start Up Failure Lua Failure” but sadly it is still no joy…

The info bar at the top of the UI5 screen is showing an error = Proximity Sensor[76] Lua Engine Failed To Load and if I try to Arm the device is gives me a pop up window saying Device Not Ready

Please can someone help - the latest code is on the first post (V3)?

This error means the failure occurs in the startup function.
Check the logs to know what is the error and at wbich line it fails.

Also take note that the error line may not be exactly where the error is due to the comments in the xml file. If you can post the error messages we can try and help.

  • Garrett

Thanks for assisting -

Looking in the (verbose) logs all i can seem to find is as follows…

10	10/22/12 20:47:21.153	AlarmManager::AddRelativeAlarm current time 1350935241 delay 3 type 5 <0x2b71a000>
10	10/22/12 20:47:21.153	AlarmManager::AddAbsoluteAlarm alarm 0xba22e0 entry 0x110dcd8 id 29 type 5 param=0xcbcc60 entry->when: 1350935244 time: 1350935241 bCancelFirst 0=0 <0x2b71a000>
31	10/22/12 20:47:21.154	AlarmManager::Run 0xba22e0 notified of a change entry 0xcc7ab0 id 20 deleted 0 <0x2be4d680>
31	10/22/12 20:47:21.154	AlarmManager::Run 0xba22e0 notified of a change entry 0xdb1f08 id 8 deleted 0 <0x2c04d680>
25	10/22/12 20:47:21.155	LuaInterface::LuaInterface 0x1112dc8 device 76 Proximity Sensor <0x2b71a000>
10	10/22/12 20:47:21.155	AlarmManager::AlarmManager 0x1114990 <0x2b71a000>
10	10/22/12 20:47:21.156	AlarmManager::Stop 0 <0x2b71a000>
10	10/22/12 20:47:21.156	AlarmManager::Stop done <0x2b71a000>
35	10/22/12 20:47:21.158	PIDLOG 13541 start AlarmThread <0x2e84d680>
25	10/22/12 20:47:21.170	LuaInterface::LuaInterface build device id's 0x1112dc8 device 76 Proximity Sensor <0x2b71a000>
25	10/22/12 20:47:21.171	LuaInterface::LuaInterface done 0x1112dc8 device 76 Proximity Sensor <0x2b71a000>
25	10/22/12 20:47:21.172	Device_Interface::CreateLuaInterface created 0x1112dc8 for device 76: 
 
    local PROX_ID = "urn:demo-node-central:serviceId:ProximitySensor1"

The rest looks to be the code in the I_ProximitySensor.xml file

And then when I try to Arm the device in the hope that it will then look for the device ever x seconds - it gives me a Device Not Ready Error and the following in the logs

10	10/22/12 21:39:14.295	GlobalLog: PIDLOG mongoose worker thread s: d:13541 <0x300a8680>
10	10/22/12 21:39:14.295	mg_callback from IP:127.0.0.1:36661 /port_3480/data_request start id: 765 <0x300a8680>
12	10/22/12 21:39:14.296	luvd_get_info_data_request starting /data_request?id=lu_action&output_format=json&DeviceNum=76&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&action=SetArmed&newArmedValue=1&rand=0.7555420021526515 pMem 0x1478000/21463040 diff: 9269248 <0x300a8680>
10	10/22/12 21:39:14.297	JobHandler_LuaUPnP::HandleRequest id lu_action request pMem 0x1478000/21463040 diff: 9269248 <0x300a8680>
10	10/22/12 21:39:14.297	sbrk JobHandler_LuaUPnP::HandleActionRequest from IP:0.0.0.0 pMem 0x1478000/21463040 diff: 9269248 <0x300a8680>
08	10/22/12 21:39:14.298	JobHandler_LuaUPnP::HandleActionRequest device: 76 service: urn:micasaverde-com:serviceId:SecuritySensor1 action: e[36;1mSetArmede[0m <0x300a8680>
08	10/22/12 21:39:14.298	JobHandler_LuaUPnP::HandleActionRequest argument DeviceNum=76 <0x300a8680>
08	10/22/12 21:39:14.298	JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:micasaverde-com:serviceId:SecuritySensor1 <0x300a8680>
08	10/22/12 21:39:14.299	JobHandler_LuaUPnP::HandleActionRequest argument action=SetArmed <0x300a8680>
08	10/22/12 21:39:14.299	JobHandler_LuaUPnP::HandleActionRequest argument newArmedValue=1 <0x300a8680>
08	10/22/12 21:39:14.299	JobHandler_LuaUPnP::HandleActionRequest argument rand=0.7555420021526515 <0x300a8680>
02	10/22/12 21:39:14.300	e[33;1mDevice_LuaUPnP::HandleActionRequest 76 not ready 0xcc4170e[0m <0x300a8680>
02	10/22/12 21:39:14.300	e[33;1mJobHandler_LuaUPnP::RunAction device 76 action urn:micasaverde-com:serviceId:SecuritySensor1/SetArmed failed with -911/Device not readye[0m <0x300a8680>
10	10/22/12 21:39:14.300	luvd_get_info_data_request creating file buffer /data_request?id=lu_action&output_format=json&DeviceNum=76&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&action=SetArmed&newArmedValue=1&rand=0.7555420021526515 pMem 0x1478000/21463040 diff: 9269248 <0x300a8680>
10	10/22/12 21:39:14.302	luvd_get_info_data_request done /data_request?id=lu_action&output_format=json&DeviceNum=76&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&action=SetArmed&newArmedValue=1&rand=0.7555420021526515 ret 0 size 23 pMem 0x1478000/21463040 diff: 9269248 took 0 info (nil) <0x300a8680>
10	10/22/12 21:39:14.303	mg_callback /data_request stop id: 765 <0x300a8680>
10	10/22/12 21:39:14.324	UPnPCallbackEventHandler 4 start PIDLOG2 13541 <0x2f28e680>

I hope that helps you, to help me… (keep in mind I am very very new to all this) and my goal was just to learn how to tweak the original Ping Sensor so it look for registered Vera devices, rather than Ping for certain IP addresses.