I am learning Google Home Integration with IoT device. I have IoT device which reponds only TCP/WS protocol to get/update things in the device. I am running webhook in rails application. Rails web service can get request from google assistant and respond back. Now to fullfill the request received from google assistant, I have to make TCP/WS request to the device. I am running client web socket program in the device to get request. server web socket program is in server side. my problem (same) is how to forward received request from google assistant to the device using web socket and get response from device and forward to google assistant.
Here is sample controller code.
class WebhookController < ApplicationController
def create
value = params[:result][:parameters][:value].first
action = params[:result][:parameters]['action'].first
/*
Here I have to access the following web socket connection and send the request and need to get response back and update to google assistant.
*/
res = { 'speech' => "temperature #{value} successfully changed.", 'displayText' => 'success' }
render json: res
end
end
Sample web socket server which is already connected with client which is running in the device.
require 'em-websocket'
EM.run {
EM::WebSocket.run(:host => "0.0.0.0", :port => 8080) do |ws|
ws.onopen { |handshake|
puts "WebSocket connection open"
ws.send "Hello Client, you connected to #{handshake.path}"
}
ws.onclose { puts "Connection closed" }
ws.onmessage { |msg|
puts "Recieved message: #{msg}"
ws.send msg
/*
Here It should get msg from controller and forward to the client and get response from client and send to server controller.
*/
}
end
}