This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

iPhone presence detection
#15
(26.08.2016, 06:14)edgars Wrote: Here is Bluetooth device presence script which changes value of respective grp addresses based on Bluetooth device appearance.

Code:
require('ble')

-- enable ble
ble.up()

list = {}

-- mac -> group address mapping
known = {
 ['88:0F:10:10:F2:8A'] = '1/1/1',
 ['88:0F:10:4A:2C:36'] = '1/1/2',
}

ctime = os.time()

function callback(addr)
 local now, delta

 now = os.time()
 delta = now - ctime

 if addr then
   if not list[ addr ] then
     log('BLE found ' .. addr)

     if known[ addr ] then
       grp.write(known[ addr ], true, dt.bool)
     end
   end

   list[ addr ] = now
 end

 -- check for missing devices each 5 seconds
 if delta < 0 or delta > 5 then
   for addr, time in pairs(list) do
     delta = now - time

     if delta < 0 or delta > 60 then
       log('BLE missing ' .. addr)
       list[ addr ] = nil

       if known[ addr ] then
         grp.write(known[ addr ], false, dt.bool)
       end
     end
   end

   ctime = now
 end
end

ble.scan(callback)



Where should i put that code? In Common Functions or in Resident script?
This code is executed once or like resident script?
Reply


Messages In This Thread
iPhone presence detection - by npinguin - 25.08.2016, 18:29
RE: iPhone presence detection - by edgars - 26.08.2016, 06:14
RE: iPhone presence detection - by DGrandes - 07.08.2018, 11:46
RE: iPhone presence detection - by admin - 29.08.2016, 16:37
RE: iPhone presence detection - by DGrandes - 05.07.2018, 13:05
RE: iPhone presence detection - by npinguin - 29.08.2016, 21:04
RE: iPhone presence detection - by rocfusion - 04.09.2016, 19:46
RE: iPhone presence detection - by admin - 05.09.2016, 06:00
RE: iPhone presence detection - by adiaz - 09.07.2018, 07:17
RE: iPhone presence detection - by admin - 09.07.2018, 08:19
RE: iPhone presence detection - by Daniel - 09.07.2018, 08:25
RE: iPhone presence detection - by DGrandes - 11.07.2018, 10:58
RE: iPhone presence detection - by Daniel - 07.08.2018, 12:18
RE: iPhone presence detection - by DGrandes - 07.08.2018, 14:21
RE: iPhone presence detection - by Daniel - 07.08.2018, 14:37
RE: iPhone presence detection - by DGrandes - 07.08.2018, 14:55
RE: iPhone presence detection - by Daniel - 07.08.2018, 16:09
RE: iPhone presence detection - by DGrandes - 09.08.2018, 12:27
RE: iPhone presence detection - by FatMax - 09.08.2018, 14:52
RE: iPhone presence detection - by Daniel - 09.08.2018, 16:16
RE: iPhone presence detection - by DGrandes - 10.08.2018, 09:44

Forum Jump: