control Renard with...
 
Notifications
Clear all

control Renard with PHP

38 Posts
13 Users
0 Reactions
13.2 K Views
jlowe
Posts: 952
(@jlowe)
Noble Member
Joined: 16 years ago

I'm thinking about running a Pirate Box with a Raspberry PI and a router. So, outside, the radio voiceovers will instruct people to use their smart phone to connect to the "Halloween" network (which will be broadcasting from the router). They connect to the raspberry which will run the webserver and the web interface. Then, have the user input sent to channels of a controller to control halloween props. This would let visitors try and "scare" others as they walked by or something. I don't know how to execute this, but I think this may be a starting point.

Can you help me out understanding what your test files actually do?

I understand that the slider runs a different test file based on the value on the slider. However, I don't really know what they are doing. So, could you break down the write statement? I get that fopen is opening com1 for writing, but I don't know what the write is doing... or how that interacts with a controller? Perhaps I need to do some renard protocol reading...

Edit:

Ok, that wasn't too hard. Maybe I should research before replying.

So, x7E starts the packet and x80 lets the controller know the data is for that controller, right?

So, it's the next two values that actually affect the channel?

So, x00, x00 = both channels off.
xff, x00 = chan1 on, chan2 off.
xff, xff = both channels on.

Do I have that right?

And, why is it that you can't send all 8 channels of data through a straight sequence of values like that?
How many can be sent directly in that way? In your first post you show three channels...


Reply
jaywalk101
Posts: 760
Topic starter
(@jaywalk101)
Prominent Member
Joined: 15 years ago

Hey jlowe,

You are correct about the channel addressing..... in my example I'm basically chasing 2 channels back and forth. I'm going to to be addressing an 8 channel arch eventually in my setup.. However with the way the Renard protocol works (from my understanding), you have to address all other channels that come before your last channel (hence all the different test php files)

So when I finish my script, my last test.php file will look like this: fwrite($fp, "\x7E\x80\x00\x00\x00\x00\x00\x00\x00\x00"); -- all 8 channels off when the user slides the pointer all the way to the right

Hope this helps with your project..... and please anyone share your ideas as mine may not be the best.... thanks!

jlowe wrote:

Can you help me out understanding what your test files actually do?

I understand that the slider runs a different test file based on the value on the slider. However, I don't really know what they are doing. So, could you break down the write statement? I get that fopen is opening com1 for writing, but I don't know what the write is doing... or how that interacts with a controller? Perhaps I need to do some renard protocol reading...

Edit:

Ok, that wasn't too hard. Maybe I should research before replying.

So, x7E starts the packet and x80 lets the controller know the data is for that controller, right?

So, it's the next two values that actually affect the channel?

So, x00, x00 = both channels off.
xff, x00 = chan1 on, chan2 off.
xff, xff = both channels on.

Do I have that right?

And, why is it that you can't send all 8 channels of data through a straight sequence of values like that?
How many can be sent directly in that way? In your first post you show three channels...


Reply
jlowe
Posts: 952
(@jlowe)
Noble Member
Joined: 16 years ago

Oh ok, I get it now. So, you want the user to be able to run their finger up and down the slider to chase lights up and down your display piece. So, you plan to create various functions for each position.

I think this could be more easily done via a single function. I'll work on this later today if I have a chance.


Reply
jaywalk101
Posts: 760
Topic starter
(@jaywalk101)
Prominent Member
Joined: 15 years ago

Let me know if you can get it working with a single function. I would like to have this as an option as well.. Thanks!

jlowe wrote:Oh ok, I get it now. So, you want the user to be able to run their finger up and down the slider to chase lights up and down your display piece. So, you plan to create various functions for each position.

I think this could be more easily done via a single function. I'll work on this later today if I have a chance.


Reply
jlowe
Posts: 952
(@jlowe)
Noble Member
Joined: 16 years ago

I had previously posted these files, but with errors. I added a little debug code and was able to figure out the problem. This will work for "chasing" lights up and down a set of channels through use of the slider posted earlier. I changed the slider so that, once activated, it could be set on zero (all lights off). Also removed all the if conditional statements.

The controllerWrite.php file takes in the value set on the slider. It then creates a controllerSequence variable containing the starting values, adds ON values from channel 1 through whatever the slider is set on, then adds OFF values for all remaining channels. Finally, it writes it to the selected com port. By changing the slider range size in the html file, and the allChannels variable in the php file, you can set the slider up to control as many channels as you wish. I see an easy way to add additional sliders to control different sets of channels as well, if interested.

slider.html:


<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width = device-width, height = device-height" />
<title>jQuery Mobile: Slider</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.css" />
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
</head>
<body>
 
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
$("#slider").change(function() {
    sVal = $(this).val();
	
  //Call the php function and pass the value of the slider.    
$.ajax({
  url: "controllerWrite.php",
  type: "post",
  data: ({'slider': sVal}),
  /*success: function(returnValue){ alert( "Data Saved" + returnValue); }*/ //Debug Line. Uncomment to use.
});


});
});//]]>  

</script>

</head>
<body>
  <div data-role="page" id="slider-test" data-theme="b"> 
    <div data-role="content">
        <div data-role="fieldcontain">
            <label for="slider"> 
                <img id="theImage" src="http://jquerymobile.com/demos/1.0b2/docs/toolbars/glyphish-icons/09-chat2.png" alt="slider images" />
            </label>
            <input type="range" name="slider" id="slider" value="0" min="0" max="10"  />
        </div>
        
    </div>
	</div>
  
</body>
</html>

controllerWrite.php:


<?php

//User-Configurable Variables:
	$comPort = "Com1";			//Set COM port to be used.
	$allChannels = 10;			//Set the number of channels to be controlled.
	$StartData = "\x70\x80";	//Start of Packet and Command/Address byte (these are renard defaults).


//Get variable from slider page
	$sliderValue = $_POST['slider'];

$fp =fopen($comPort, "w"); //Open COM Port for Write

$controllerSequence = $StartData;	//Start the sequence data with startdata.
$onChannels = $sliderValue;			//On channels are determined by the value on the slider.
$offChannels = $allChannels - $sliderValue; //Off channels are the channel count that remains.

//Add ON values to onChannels.
for($i=1;$i<=$onChannels;$i++)
	{
	$controllerSequence = $controllerSequence . "\xff";  //Add ON value
	}

//Add OFF values to remaining channels.
for($i=1;$i<=$offChannels;$i++)
	{
	$controllerSequence = $controllerSequence . "\x00";  //Add OFF value
	}

fwrite($fp, $controllerSequence);	//Send channel values out through the COM port.
fclose($fp); //Close COM Port


//Debug Code (Will print to the browser)
    /* Add two slashes "//" to the front of this line to activate debug.
	echo " On: " . $onChannels . ", Off: " . $offChannels . ", Data: " . $controllerSequence;
	// */
		
?>

Reply
jaywalk101
Posts: 760
Topic starter
(@jaywalk101)
Prominent Member
Joined: 15 years ago

Well I did some more testing tonight with my mobile phone. When I'm connected through 4Glte on my Samsung Note 2 with Verizon Wireless the lights don't respond good at all. The channels are misfiring and the output is terrible. But here's the funny part. My wife has an Iphone 4 with 3G on Verizon, and it works just fine. So I'm kind of confused here. One would think 4G would work much better.. well.. guess I need to do some more testing...........


Reply
jaywalk101
Posts: 760
Topic starter
(@jaywalk101)
Prominent Member
Joined: 15 years ago

added some code that fixed the misfiring of channels.. ended up being a cache issue. anyways.. here is a proof of concept video with 8 channels. its kind of a make shift arch.. This is working with 4GLTE and as you can see it's fairly responsive.


Reply
jaywalk101
Posts: 760
Topic starter
(@jaywalk101)
Prominent Member
Joined: 15 years ago
jlowe wrote: I see an easy way to add additional sliders to control different sets of channels as well, if interested.

Hey jlowe,

I sent you a PM, but wanted to reply here as well. Tested out your code tonight and it works great! Was wondering how it would be possible to achieve different effects for different sliders. Would you have to have multiple controllerWrite.php files with different set of variables for each slider?

Thanks!


Reply
Page 4 / 4
Share: