Using Bluetooth to control Asterisk calls.
de61.old_status = get_status(de61.file) # found is either true or false
de61.old_location = get_location(de61.file) # location is either 'at home', 'gone to bed' or 'asleep'
while count < 1
puts 'old status : ' + de61.old_status.to_s
de61.new_status = check_device(de61.id, de61.name)
puts 'new_status: ' + de61.new_status.to_s
if de61.new_status and de61.old_status
if de61.old_status == false
puts 'connecting to the bluetooth device ...'
Thread.new{`rfcomm connect 0 #{de61.id}`}
sleep 12
end
de61.new_location = check_location(de61.id)
end
puts 'old_location: ' + de61.old_location.to_s
puts 'new_location: ' + de61.new_location.to_s
update_status(de61.project, de61.new_status, de61.new_location) if ((de61.old_status != de61.new_status.to_s) or (de61.old_location != de61.new_location))
mystatus = ''
if (not de61.old_status == de61.new_status) then
if (de61.new_status.to_s == 'true') then
mystatus = ' has entered the building'
callto('SIP/line1')
elsif (de61.new_status == false) then
mystatus = ' has left the building'
callto('SIP/07736668666@sipgate')
end
puts 'updating in or out the building'
ms = MyStatus.new(mystatus)
elsif (de61.old_location.to_s != de61.new_location.to_s)
if de61.old_location.match(/sleep/) and de61.new_location.match(/home|bed/) and not old_mystatus.match(/awoken/) then
mystatus = ' has awoken'
elsif (de61.old_location.match(/home|bed/)) and de61.new_location.match(/sleep/)
mystatus = ' has gone to sleep'
elsif (de61.old_location.match(/home/)) and de61.new_location.match(/bed/)
mystatus = ' has gone to bed'
elsif de61.old_location.match(/bed/) and de61.new_location.match(/home/)
mystatus = ' has got out of bed'
end
puts 'updating home location'
ms = MyStatus.new(mystatus) if mystatus != ''
end
de61.old_location = de61.new_location
de61.new_location = 'at home'
de61.old_status = de61.new_status
old_mystatus = mystatus
sleep 7
end
end
def callto(dialstring)
file = File.new('/etc/asterisk/ruby/call-to.txt','w')
file.puts 'Dial(' + dialstring + ')'
file.close
end
file: extensions.conf
exten => 5168666,n,ReadFile(dialplan1=/etc/asterisk/ruby/call-to.txt,130) exten => 5168666,n,Exec(${dialplan1})