Communicating with dos via website

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
PaulK
-


Joined: 26 Apr 2006
Posts: 132
Location: London, UK

PostPosted: Sun May 28, 2006 12:09 pm    Post subject: Communicating with dos via website Reply with quote

HI There

I need some help with a project I am doing.

I have a ProLite moving message disaply that I would like to hook up to my website to allow people to type messages that will scoll on the sign in my living room (sad I know, but fun never the less).

To control the sign you simply echo the message to the com port with the correct formatting.

I also have a little dos program the takes care of the formatting where the output to the sign is controlled like: pwrite "hello world"

Is there a way using abyss and php that I can capture test from my website and squirt it to either the dos echo command or pwrite.exe util?

I appreciate this might require some complicated work, but any pointers would be very useful.

With thanks
Paul
Back to top View user's profile Send private message Visit poster's website
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Sun May 28, 2006 12:21 pm    Post subject: Reply with quote

http://www.php.net/manual/en/ref.exec.php
Code:
echo shell_exec("ver"); # Microsoft Windows XP [Version 5.1.2600]

_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
PaulK
-


Joined: 26 Apr 2006
Posts: 132
Location: London, UK

PostPosted: Sun May 28, 2006 12:44 pm    Post subject: Reply with quote

That's brilliant thank you so much!

my first code:

led.php
Code:
<?php
$output = shell_exec('echo ^<ID01^> Web Test > com1');
echo "<pre>$output</pre>";
?>


Had the desired result, my sign is now scrolling 'Web Test'

Code:
'echo ^<ID01^> Web Test > com1'

is the exact dos command to send the message ^<ID01^> being the code to select the first LED display

So I'm thinking that if I add a few more variables I could make this into slicker code to be included on a web page. I am new to php (onlt halfway thru teach yourself php in 10mins) so if you can help with my logic that would be great.

This is my thought progression, am I on the write track?
[setup]
$open = 'echo ^<ID01^>'
$message = **something captured from web**
$close = '> com1'

[send]
$output = shell_exec('$open' ' $message' '$close')

Thank you
Paul
Back to top View user's profile Send private message Visit poster's website
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Sun May 28, 2006 1:09 pm    Post subject: Reply with quote

You're on the right track.
Two problems:
For variables to get evaluated you have to use double quotes (""s). And you don't really need to use them in this case, you can just do $var.$var.
Secondly, to "join" to variables together you have to use periods. ("red".$green."blue".$yellow.$orange).

Also, you don't need to pad it out over multiple lines. (Although if it's easier then sure.)

Code:
if ($_GET['message'])
  $output = shell_exec('echo ^<ID01^>'.$_GET['message'].' > com1');
# Would print out "Jelly" upon accessing my.page.php?message=Jelly.

_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
PaulK
-


Joined: 26 Apr 2006
Posts: 132
Location: London, UK

PostPosted: Sun May 28, 2006 1:37 pm    Post subject: Reply with quote

Thanks MN that is working perfectly

Am I right in thinking I can set up a form to collect the value for $_GET, or should I replace $_GET with a new variable captured by the web form?

Sorry for the dumb questions but in 10 mins you have taught me more than reading this damn book in a week!

With gratitude
Paul
Back to top View user's profile Send private message Visit poster's website
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Sun May 28, 2006 1:52 pm    Post subject: Reply with quote

Well, there are two ways to pass values over with forms.
They both have obvious advantaeges and disadvantages over eachother. (Post being less visibile, get being easier to manipulate for the end user.)

To use the code above, you could try something like:
Code:
<form action='<?=$_SERVER['PHP_SELF']?>' method=get> (<?=stuff?> is the equivelant to <?php echo stuff ?>, $_SERVER['PHP_SELF'] is the relative path to the current script.)
<input name='message' value=''><br>
<input type='submit' value='Change Message'>
</form>
<?php
if ($_GET['message'])
  $output = shell_exec('echo ^<ID01^>'.$_GET['message'].' > com1');
?>


To change that to use the post method, just replace $_GET with $_POST (Note that capitolization isn't important.), and change the form's method to post.
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
PaulK
-


Joined: 26 Apr 2006
Posts: 132
Location: London, UK

PostPosted: Sun May 28, 2006 2:02 pm    Post subject: Reply with quote

A-ha! I think I know where I have gotten confused as I have learnt POST and low and behold the next topic in the book is GET - duh!

I'm gonna read ahead a few more chapters before I ask for more help. Essentially you have whipped up the exact code I am after, now people can post message to my scrolling LED display (I'll post a url soon).

I want to expand this further to pull info from MySQL and display the number of users on my website, the cpu load etc but I have a heck load more reading and learning before I get there yet.

I can't thank you enough for your help, it had been so valuable and saved me hours of head scratching, you rock!

Paul

UPDATE: Temp url to send me a message is: http://viahome.co.uk
Messages will display on the LED sign in my lounge not on the webpage

UPDATE2: Thanks, the messages are coming through!
Just think of all the strange messages people could send :D

UPDATE3: Cheers for the messages MonkeyNation / TRUSTabyss.com


Last edited by PaulK on Sun May 28, 2006 7:09 pm; edited 3 times in total
Back to top View user's profile Send private message Visit poster's website
PaulK
-


Joined: 26 Apr 2006
Posts: 132
Location: London, UK

PostPosted: Sun May 28, 2006 4:01 pm    Post subject: Reply with quote

Just like to thank everyone for the messages they are sending I am getting them all, some quite funny :)

Would anyone be interested in having a 'recent messages' displayed on the web or shall I keep it secret?
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group