Windows based HTTP to Socket Relay App


(Patrick Stuart [@pstuart]) #1

Ok,

Sick of waiting for a response from Smartthings on supporting raw sockets from a local hubaction.

So I started developing a simple .NET application to relay the request via HTTP and then send it via a raw socket request and then return the response from the raw socket to the response to the hub.

Before I get too far, wanted to poll the community for need and some answers.

  1. Is .NET 4.0 acceptable to most people? It comes pre-installed on Windows 8.x now and is a quick download.

  2. Would you want an application running, or have it installed as a service?

  3. Do you want on screen logging, or a text file or xml file outputted? All?

  4. Will this request format work for most cases? http://ipofserver:port/?ip=xxx.xxx.xxx.xxx&port=xxxx&cmd=xxx&type=(udp/tcp)

What this .NET app will do is listen for web requests and split out the query string and then open a socket connection of type (udp/tcp) on port xxxx to ip xxx.xxx.xxx.xxx and send the cmd xxx and wait for a response for a few seconds and then close the connection.

It would then respond back to the request with any response from the socket or an error code. Either as a webpage, xml, or json.

  1. what error handling would you like to see returned, ie timeout, no response,

  2. how would you like to see the response, html, xml, json, other?

I already have the .NET app listening on a port / ip for a query string and have it echoing the request.

The next piece would be to relay the request to the raw socket and that requires a lot of devices to test.

I have the following devices I can test with:
-JVC Projector
-HTPC Remote Software (custom developed code to control mouse and keyboard commands)
-Pioneer AVR
-Sony AVR
-Sony TV
-HDMI Matrix Switch (using IP to serial adapter)
-Wattbox Power Strip
-Control4 16channel Amp

If anyone has any input, let me know. I’ll be unable to finish this project until next week, so this should give plenty of time to get thoughts.

Having socket relay would open the options to automate a lot of devices with smartthings and check the status of simple IP devices.

The one use case I have right now is I have a SONOS connect plugged into my 16 channel amp serving 8 rooms. I want to be able to turn that amp on, announce a Sonos action via Smartthings and then turn it back off.

It is as simple as sending to port 8080 on the IP of the amp, the raw command of a range of inputs and outputs and on or off. So to turn on room 3 to input 3 it is in3,out3 or to turn on all rooms to input 4 it is in3,out1-8. To turn off any output, its offX where X is the output.

Another example is I have a home theater and my kids occasionly leave the projector on. So I want to do a simple action to check for motion, check for projector status pwr on the ip of the projector and if pwr = on, then issue the command pwr off.

Hopefully Smartthings will implement socket support, but in the mean time this .NET app shouldn’t be too hard to implement, but I want to make sure I create something that is flexible enough to serve all the use cases.

Thanks!


(Geko) #2

I’d prefer Python or Node. It then could run on any low-end Linux system as well as Windoze.


(Mike Maxwell) #3

–.Net 4 is fine by me. (32bit at least), the *nix guys can run an emulator if need be…
–as a service please…, auto starting a console app, well just sucks…
–text logging, format doesn’t matter, would like the ability to disable completly
–the supplied format should would work in my intended use case (an Onkyo Pro pre/pro)
–sure timeout/no response + anything else that didn’t explicitly get trapped…
–json would be the best from my POV, but whatever’s easiest to integrate with smartApps.

Nice one man!


(Geko) #4

Actually, this can be easily implemented as a CGI script running on any web server. Just a thought… :smile:


(Mike Maxwell) #5

OK, go for it…


#6

Did you ever manage to complete this?

I a new to ST so please forgive me if this it technically rubbish, I have a Pioneer amp that I would like very basic control of, On/Off, Input and volume. I can currently control it via Telnet. I saw somewhere on the forum being able to send Raw data (albeit with no response) however I couldn’t seem to work it out. To turn it on its as simple as sending “PO”. Can I use sendHubCommand to do this, I don’t mind not having the state etc.

This gateway would mean a solution to my issue. I can’t seem to find a windows one, and don’t want another server in the house, suppose I could cram one onto my NAS

Thanks


(Patrick Stuart [@pstuart]) #7

I did not release this relay app. I was hoping for better support in hub v2. Which did not happen (yet?)

I have a pioneer AVR and I am pretty sure I got it working with a hub action, let me test something when I get back to the house and see if still works.


#8

Thanks Patrick, would really appreciate it, its the missing link in my Movie mode. I did read that it may arrive at some point, it seems to be a much requested feature.

In a device type I was trying the following for power on also confirmed that my deviceNetworkId is in hex and correct

new physicalgraph.device.HubAction("PO<CR>", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}")

I am pretty sure I have the command wrong and have been guessing away with no luck


(Mike Maxwell) #9

Yea, the

'<CR>'

will be evaluated as text you can substitute \r\n for that…


#10

Perfect, that did the trick thanks Mike

Now amp turning on and off.


#11

Did you ever happen to get this working? I’m new to ST and not a developer, so things have to be pretty basic and all managed in ST Hub for me to pick up some of the concepts needed to get this running. I was looking to get my Pioneer receiver setup in ST for IP control but the smartapp setup is a little daunting. Any help or guidance would be appreciated.

I do have quite a but setup for all of my A/V control in the house with iRule, iTach and other apps. The draw to ST was the integration with Amazon Echo. I’d love to be able to port everything to ST somehow so I can just tell Alexa to do all of the commands that I have in iRule and other apps.

Doing something simple to start with, like IP control, seems like it should be pretty straight forward to turn on/off, control volume, switch inputs, zones, etc. Then calling from Alexa would be awesome!


(Convinced ST will never be unbroken…) #12

If you have a Mac, check out HAM Bridge.