A similar configuration will work with any router that lets you set a destination NAT.
First I configured a static IP for my Dash based on its MAC address (its not printed on the device or available online as far as I can tell, so I had to look for the most recent lease / it registered as 'WICED DHCP Client'). I configured it w/Amazon normally.
Then I add a destination-nat to force all outgoing tcp connections to hit my razberry:
Code: Select all
/ip firewall nat
add action=dst-nat chain=dstnat protocol=tcp src-address=192.168.1.65 to-addresses=192.168.1.2 to-ports=8081
I then run a ruby daemon that listens for connections and triggers a scene whenever the connection occurs; first logging in then triggering the scene.
Code: Select all
require 'socket'
require 'net/http'
server = TCPServer.new 8081
loop do
client = server.accept # Wait for a client to connect
uri=URI('http://192.168.1.2:8083/ZAutomation/api/v1/login')
req = Net::HTTP::Post.new(uri)
req.body = '{"form":true,"login":"admin","password":"YOURPASSWORD","keepme":false,"default_ui":1}'
req.set_content_type('application/json;charset=utf-8')
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
http.request(req)
end
cookie = res.response['set-cookie'].split('; ')[0]
urls = %w(/ZAutomation/api/v1/devices/ZWayVDev_zway_10-0-37/command/off)
urls.each do |url|
uri = URI("http://192.168.1.2:8083/#{url}")
req = Net::HTTP::Get.new(uri)
req['Cookie'] = cookie
res = Net::HTTP.start(uri.hostname, uri.port) {|http|
http.request(req)
}
end
client.close
end