module MYalgaar
~ module MYalgaar
~ # class methods
~ @@client=nil ~ @@retConnect=nil ~ def yalgaarClient(clientKey,isSecure,connectionCallback) ~ clientKey=clientKey+'/1' ~ puts clientKey ~ ~ thr = Thread.new do ~ @@client = MQTT::Client.connect(:host => '192.168.0.243', :port => 1883,:client_id => clientKey)do |retConnect| ~ @@retConnect=retConnect ~ @@retConnect.get do |topic,message| ~ puts “#{topic}: #{message}” ~ end ~ end ~ end ~ def subscribe(channel,subscribeReturnMessageCallback,errorMsgCallback) ~ print channel,':',subscribeReturnMessageCallback,':',errorMsgCallback,'n' ~ client.subscribe( 'ck-47046d75cf64402f/test' ) ~ end ~ ~ ~ end ~ end
Public Instance Methods
subscribe(channel,subscribeReturnMessageCallback,errorMsgCallback)
click to toggle source
# File YalgaarUserlist.rb, line 51 def subscribe(channel,subscribeReturnMessageCallback,errorMsgCallback) print channel,':',subscribeReturnMessageCallback,':',errorMsgCallback,'\n' @@client.subscribe( 'ck-47046d75cf64402f/test' ) end
yalgaarClient(clientKey,isSecure,connectionCallback)
click to toggle source
# File YalgaarUserlist.rb, line 33 def yalgaarClient(clientKey,isSecure,connectionCallback) clientKey=clientKey+'/1' puts clientKey begin @@client = MQTT::Client.connect(:host => '192.168.0.23', :port => 1883,:client_id => clientKey) rescue Errno::EHOSTUNREACH puts "error to connect" puts connectionCallback(6) exit(0) end puts "success to connect" hr = Thread.new do |client| @@client.get do |topic,message| puts "#{topic}: #{message}" end end end