[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OFF-TOPIC: HTML to send data out a certain port



Kent West wrote:
> We're thinking of building a Debian-based web-server that offers up
> a "remote control" interface ...

Using the web like that is a good way to go.  It is the way a lot of
people do things too.  A web browser has become the "universal"
interface to everything.

> In order to do this, we have to convert the web clicks into infrared
> signals going to the various IR-enabled devices, essentially
> replacing the remote controls that came with the devices.
> ...
> Global Cache (http://www.globalcache.com/products/itach/models2/)
> has devices that, as I understand it, will send out the various IR
> signals to the various devices, based on ASCII commands sent to it
> via a wireless connection.

I have no information on such devices.

One traditional problem is ensuring that it actually activates.  For
example for years VHS and later video recorders have often needed to
interface to proprietary cable boxes to change channels.  Often there
will be an IR remote proxy device to send the signal.  That /mostly/
works.  The problem is that it is all done in the blind with no
feedback.  So when it does not work there is no way for this to be
detected and no way for the signal to be sent again.  Using an actual
remote the human can see that it didn't work and will move around and
point the remote differently and repeat until it works.  But the
device can't do that without feedback and I know of none with
feedback.  I personally had such trouble with those on video recorder
to cable box adaptors that I gave up and stopped using them.  Other
people swear by them.  I swear at them.  YMMV.

> My problem is how to convert a click on a web page into the proper
> code to be sent over the wireless network to the Global Cache
> device.

Set up a "dynamic" web page.  Unless you found something that does
exactly what you want it to do, and I don't think it exists or you
would have found it, then you are going to need to write some code on
the backend to do what you want.  That is okay.  What you want is
fairly easy to do.  You should also be able to find a lot of
knowledgeable help for your topic.

The traditional simplest and easiest interface is CGI.  You may
already have several /usr/lib/cgi-bin/ scripts already.  The default
apache2 package configuration will set up a default /usr/lib/cgi-bin/
script directory automatically.  This is one of those long time
traditional methods.  If you have no other experience doing something
like then CGI would be a reasonable place to start.  You would learn
from it even if you decided to do something else afterward.  You would
want to use CGI with your favorite programming language.  Do you have
any programming experience?  In what language?  You can use it in a
CGI interface.  CGI is an interface and your choice of language behind
it is your choice.

The next most popular would probably be to use PHP.  PHP is a very
Perl-like language specialized for dealing with the web.  It isn't too
complicated but as a programming language neither is it completely
trivial.  This might be the place you end up second but then stay
there forever.

Next up the ladder would be a web framework of which there are very
many and if I were to mention one or another we would degrade into a
long discussion about which one is better.  And there is a grey scale
of features from mostly there with plugin modules to start with
nothing and write everything full custom.  Okay, I should mention
Wordpress as one of the 800lb gorillas in that space.  I will also
mention Drupal, Joomla, Rails, CakePHP, Symfony, just to give you
ideas to search out but note there are endless others too.

For something this simple you do not need a database.  If anyone tells
you otherwise be polite, nod, and ignore them.  You can think about a
database after you have something that needs it.  But almost certainly
there will be a handful of people who's only tool is a hammer and so
every problem looks like a nail.

> I don't have the Global Cache yet to play with, but I'm
> trying to get a feel for how to do things before we start spending
> money. The API documentation from their web site indicates it's a
> matter of just sending the correct ASCII sequence out the web
> server's TCP socket on Port 4998.

Sounds reasonable and likely.

> >get_NET,0:1↵

You should try this from the command line to get a feel for it first.
Then after understanding it there it will be easier for you to write
this into the back-end of a web page.

I like the 'connect' command for this type of thing.  Others like 'nc'
(aka netcat).  For netcat you will need to choose between either the
traditional one or the new openbsd one.  You can install it with APT.

  # apt-get install connect-proxy netcat-openbsd

Then call it like this:

  $ connect hostname.example.com 4998

At that point you are talking to your network device.  You can send it
commands interactively and see the response.

  $ connect hostname.example.com 4998
  get_NET,0:1

I would tend to use an echo or a here-document.

  $ echo "get_NET,0:1" | connect hostname.example.com 4998

Or

  $ connect hostname.example.com 4998 <<EOF
  get_NET,0:1
  EOF

> Better yet, can anyone also provide me a means of testing if I'm
> sending to that port without yet having the hardware in-hand? Like,
> if I manage to send data to port 4998, how do I know I sent it and
> what it looks like on the other side?

The above assumes that you have a real device.  But you don't yet.  So
how do you fake it?  You can use netcat to listen.  Open a second
terminal window and type in:

  $ nc -l -p 4998

That will listen on the same socket as your device would be
listening on port 4998.  Then connect to it from the first terminal.

  $ connect hostname.example.com 4998

Those two windows will be talking to each other.  If you send the
command get_NET,0:1 from one it will be received on the other.  You
can type a reply back and it will go back the other direction.

Play with that for a bit until you understand what is happening.  It
is simple but it will help you when it comes time to write your web
application.

> Can anyone provide me a snippet of HTML (and/or related, such as
> php, etc) code for sending an ASCII string (such as the above
> "net_NET,0:1 <CR>") to TCP socket Port 4998?

HTML is a page format not a programming language.  If someone else
doesn't propose something I could do so later.  No time at the moment.

> And is this called "raw socket programming", or what? If I knew what
> terms to google for, I might not need to bother y'all any more.

Raw socket programming is something you would probably do from a C
program.  That is where I most closely associate the two.  But as I
showed by using the command line tools 'connect' and 'nc' you don't
need to do C level programming in order to open network connections.
You might try searching for "php tcp open" and "tcp open perl" and
"cgi tcp open" and other combinations.

Bob

Attachment: signature.asc
Description: Digital signature


Reply to: