TCP to Serial forwarder

Community contributed apps
Post Reply
smande00
Posts: 13
Joined: Mon Mar 10, 2014 2:10 pm

TCP to Serial forwarder

Post by smande00 »

So forgive me if this is something that's already available or not needed - I'm just excited I got it working so easily :)

I hacked together a very quick and dirty app that will accept traffic on TCP port 2000 and forward it to the COM3 port. The long and the short of it is I'm able to use the Android app to control my Reef Angel (including setting relay states) without the Wifi module (I just have the RA connected via the USB->TTL cord to my pc running the app I wrote).

Is there a need for something like this in the community? If so I'd be happy to clean this up a bit for use by others. Just a caveat, it's developed in .NET so this would be a windows only solution.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: TCP to Serial forwarder

Post by rimai »

That would be really cool!!!
I would also like to request 2 things.
1. Host the source code on both github.
2. Permission to post your work in the contribution section of the website.
Roberto.
smande00
Posts: 13
Joined: Mon Mar 10, 2014 2:10 pm

Re: TCP to Serial forwarder

Post by smande00 »

Awesome, I have no problem with either of those. I'll put what I have on github tonight and post the link back on this thread.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: TCP to Serial forwarder

Post by lnevo »

You could probably do the same on the mac or linux by using nc (netcat) in a few lines as well. Just so we can cover all OSs
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: TCP to Serial forwarder

Post by lnevo »

Found this

http://playwithmyled.com/internet-to-serial-proxy/

And a whole page of options including netcat but its page was empty..

http://playground.arduino.cc/Interfacin ... yTl8S-9LCQ
smande00
Posts: 13
Joined: Mon Mar 10, 2014 2:10 pm

Re: TCP to Serial forwarder

Post by smande00 »

lnevo - I agree there's really nothing to these things so I'd be surprised if there's not already multiple options out there on other OSes (or windows for that matter). It certainly shouldn't be hard to put something together if they're not.

At any rate - https://github.com/smande00/ReefAngelTcpToSerialRelay is the link to what hacked together (with some help from http://www.codeproject.com/Articles/463 ... -in-Csharp)

I'm git challenged so the solution file didn't make it up to git, but it's not really important. I'll move this to a windows service and include an installer as my next steps. In the interim you can run this as a console app - just update the config if your usb->ttl cable is not running on COM3 or you're not using port 2000 for the wifi module.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: TCP to Serial forwarder

Post by rimai »

May I ask for the installable version too?
Just so people can just download and install.
Roberto.
smande00
Posts: 13
Joined: Mon Mar 10, 2014 2:10 pm

Re: TCP to Serial forwarder

Post by smande00 »

Sure - I have to actually write the installer still though :)

I should be able to get that put together tonight or tomorrow at the latest (along with moving the application to a service).

There's also some hardening of the code that needs to get done before I'd recommend anyone actually rely on this - things like gracefully handling errors (rather than ignoring them), reopening the serial port as necessary, etc.

I'll keep the thread updated as things progress.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: TCP to Serial forwarder

Post by lnevo »

For the record, I was not trying to belittle your contribution. On the contrary, this will be very helpful for many people.

I finally managed to get some syntax for netcat to read/write from the serial port. This should work on MacOS and on Linux

Code: Select all

nc -l 2000 > /dev/ttyS0 < /dev/ttyS0
This should open up a tcp port listener for port 2000 on the computer and read/write the IO to /dev/ttyS0. You'd need to change this to whatever serial device your RA comes up as. You may also need to use stty or setserial to set the speed/modes for the serial port. I'm looking into the syntax for those as well, but the command above is the meat of the process.

This should be pretty helpful to those without a wifi adapter who can have a machine permenantly connected. In addition if you kill this off, you shoudl be able to upload new code and then restart the redirection again remotely :)
smande00
Posts: 13
Joined: Mon Mar 10, 2014 2:10 pm

Re: TCP to Serial forwarder

Post by smande00 »

Hah! No worries, that's not at all how I took it. I'm all for options, and I'm glad to see such a simple built in solution is available on the mac & linux platforms. Something tells me there's probably something similar floating around for windows as well.
smande00
Posts: 13
Joined: Mon Mar 10, 2014 2:10 pm

Re: TCP to Serial forwarder

Post by smande00 »

I've added the solution file to git. I've also updated the application to run as a windows service and included an installer/uninstaller.

The link below will take you directly to the compiled binaries. Simply double click the install.bat file to get up and running.

https://github.com/smande00/ReefAngelTc ... r/Binaries


You'll also want to allow port 2000 through the windows firewall (as well as your router if you want to access this externally over the Internet).
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: TCP to Serial forwarder

Post by lnevo »

So this allows incoming connection what happens to outgoing for portal updates?
smande00
Posts: 13
Joined: Mon Mar 10, 2014 2:10 pm

Re: TCP to Serial forwarder

Post by smande00 »

lnevo wrote:So this allows incoming connection what happens to outgoing for portal updates?
Errr... sorry, obviously haven't checked the forums in awhile. I haven't really messed with the portal to see what it does for updating. I do know it allows Reeftronics to read the controller state and update it's logs for whatever that's worth.
Post Reply