Using Bluetooth to control Asterisk calls.
1 2 de61.old_status = get_status(de61.file) # found is either true or false 3 de61.old_location = get_location(de61.file) # location is either 'at home', 'gone to bed' or 'asleep' 4 5 while count < 1 6 7 puts 'old status : ' + de61.old_status.to_s 8 de61.new_status = check_device(de61.id, de61.name) 9 puts 'new_status: ' + de61.new_status.to_s 10 11 12 if de61.new_status and de61.old_status 13 if de61.old_status == false 14 puts 'connecting to the bluetooth device ...' 15 Thread.new{`rfcomm connect 0 #{de61.id}`} 16 sleep 12 17 end 18 de61.new_location = check_location(de61.id) 19 end 20 21 puts 'old_location: ' + de61.old_location.to_s 22 puts 'new_location: ' + de61.new_location.to_s 23 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)) 24 25 mystatus = '' 26 27 if (not de61.old_status == de61.new_status) then 28 if (de61.new_status.to_s == 'true') then 29 mystatus = ' has entered the building' 30 callto('SIP/line1') 31 elsif (de61.new_status == false) then 32 mystatus = ' has left the building' 33 callto('SIP/07736668666@sipgate') 34 end 35 puts 'updating in or out the building' 36 ms = MyStatus.new(mystatus) 37 elsif (de61.old_location.to_s != de61.new_location.to_s) 38 if de61.old_location.match(/sleep/) and de61.new_location.match(/home|bed/) and not old_mystatus.match(/awoken/) then 39 mystatus = ' has awoken' 40 elsif (de61.old_location.match(/home|bed/)) and de61.new_location.match(/sleep/) 41 mystatus = ' has gone to sleep' 42 elsif (de61.old_location.match(/home/)) and de61.new_location.match(/bed/) 43 mystatus = ' has gone to bed' 44 elsif de61.old_location.match(/bed/) and de61.new_location.match(/home/) 45 mystatus = ' has got out of bed' 46 end 47 puts 'updating home location' 48 ms = MyStatus.new(mystatus) if mystatus != '' 49 end 50 51 52 de61.old_location = de61.new_location 53 de61.new_location = 'at home' 54 de61.old_status = de61.new_status 55 old_mystatus = mystatus 56 sleep 7 57 end 58 end 59 60 def callto(dialstring) 61 file = File.new('/etc/asterisk/ruby/call-to.txt','w') 62 file.puts 'Dial(' + dialstring + ')' 63 file.close 64 end
file: extensions.conf
1 2 exten => 5168666,n,ReadFile(dialplan1=/etc/asterisk/ruby/call-to.txt,130) 3 exten => 5168666,n,Exec(${dialplan1})