HTML/Javascript code and Pink
I'm writing a web interface for a robot with a PINK module as the server. I want to graphically show the status of the IRPD sensors.
showing an image of a LED thats off when nothing is in front of the sensor but show a picture of a LED that on when the sensor detects something. I know how to have it display a value but I don't know how to change a picture based on the value of a variable.
so basically
If Nb_var01 = "1" then show on LED picture
If NB_var01 = "0" then show Off LED picture
I plan on having the "sensor status" page in it's own frame which automatically reloads every few seconds, unless someone knows a better way to have more real time status of the sensors.
Thanks
Added:
how about changing the background color of a cell using a variable?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A complex design is the sign of an inferior designer. - Jamie Hyneman, Myth Buster
Post Edited (Dgswaner) : 7/9/2007 5:52:34 AM GMT
showing an image of a LED thats off when nothing is in front of the sensor but show a picture of a LED that on when the sensor detects something. I know how to have it display a value but I don't know how to change a picture based on the value of a variable.
so basically
If Nb_var01 = "1" then show on LED picture
If NB_var01 = "0" then show Off LED picture
I plan on having the "sensor status" page in it's own frame which automatically reloads every few seconds, unless someone knows a better way to have more real time status of the sensors.
Thanks
Added:
how about changing the background color of a cell using a variable?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A complex design is the sign of an inferior designer. - Jamie Hyneman, Myth Buster
Post Edited (Dgswaner) : 7/9/2007 5:52:34 AM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
the manual.... it's virtually non existent. There is only one simple example of how to display a variable. There are plenty of websites for example code I just need to know what to look for.
With as many pinks that have gone out I'm actually surprised of how few sites there are.
Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A complex design is the sign of an inferior designer. - Jamie Hyneman, Myth Buster
<html>
<body>
<script type="text/javascript">
var name = "<Nb_var06>"
if (name == 1)
{
document.write('<img src="images/Image1.jpg">')
}
else
{
document.write('<img src="images/Image2.jpg">')
}
</script>
</body>
</html>
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A complex design is the sign of an inferior designer. - Jamie Hyneman, Myth Buster
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A complex design is the sign of an inferior designer. - Jamie Hyneman, Myth Buster
<HTML>
<BODY>
<img src="images\<Nb_var01>.jpg">
</BODY>
</HTML>
Just name the images according to the states.·· (1.jpg for connected 0.jpg for not.)
That way depending on the value the correct icon would be loaded into the page.
SkyLight refreshing the web page at set intervals is quite simple, I don't have the code with me at work but google javascript automatic reload or metatag automatic reload and you'll find it.
I'm going through all of my sensors and making them viewable via a web page, then I'll make a custom page for each robot containing the specific sensors to that bot. I'll be posting the code for each sensor as I complete them.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A complex design is the sign of an inferior designer. - Jamie Hyneman, Myth Buster
Actually becomes this line:
if you view the source of the html.
I learn something everyday.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A complex design is the sign of an inferior designer. - Jamie Hyneman, Myth Buster
1. I haven't found a way to manipulate a value before posting it to the PINK module. If the user enters a value in an INPUT box you can't do anything except post it to the Nb_varXX variable. So if Box 1 is "3" and Input Box 2 is "7" you can't add them and stick them in a variable in Javascript. So in effect there seems to be no way to validate user inputs before running submit(). I'm still working on this so if I find something I will post it.
2. I talked to Parallax support yesterday and there is·no way to·save variables into the FLASH memory. So once you turn off the PINK module everything goes away.·
I don't have the pink in front of me but there is 10 or 20 variables that can be written into flash ram. it surprises me that they say it can't be done. maybe I'm not understanding what you after. have you looked at the source for the Default "Modify variables" page. so you should be able to take that code and rather than have it on I'll look into it. this weekend's project is going to be getting my Pink's "base Station" with RF link online. so I'll check on it if I have time.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A complex design is the sign of an inferior designer. - Jamie Hyneman, Myth Buster
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A complex design is the sign of an inferior designer. - Jamie Hyneman, Myth Buster
·
dg
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A complex design is the sign of an inferior designer. - Jamie Hyneman, Myth Buster
3 Files are needed.
1. A webpage with a named Span (See Below)
2. A Javascript File to handle the ajax calls (Ajax.js)
3. a Data file to load into the page. (Sensor.dat) This file can be called anything as long as the same name is used in the javascript file.
Copy all 3 to the netburner and you should have a page that updates every 2 seconds. without a refresh.
A quick note about the Sensor.dat file.·· This file would need to have all of your netburner tags in it. For example in the Sensor.dat file attached the cotent is <H1><NB_var01></H1>.· If variable 1 is set to "100" the file when accessed returns <H1>100</H1>.· I hope this sparks the minds of people to come up with more complex ajax calls.··
Please note that i haven't tested this on a netburner but on a workstation.· Once i get into work i will try this on a pink and update the code as needed.· If anyone get's a chance before that please let me know if it works.
Hope this helps the Stamp/Pink Community.
Code for AjaxPink.html
<HTML>
<HEAD>
<script src="Ajax.js" type="text/javascript"></SCRIPT>
<TITLE>Pink AJAX Example</TITLE>
</HEAD>
<BODY onload=InitTimer()>
<Table border=1>
<TR Height= 75px>
<TD>
<Span id="AjaxImg" />
</TD>
</TR>
<TR>
<TD>
variable 01
</TD>
</TR>
<Table>
</BODY>
On the side note, it may be easier if you use one of the many free javascript ajax frameworks out there. I personally hate having to check cross browser and security compliance so I just use pre made ajax frameworks. I'll have to find which one I used to use before I switched to using asp.net ajax.
Only Change is the Ajax.js file.
The sensor file also needs to be called Sensor.txt.
the webpage is the same.
Code for AjaxPink.html
<HTML>
<HEAD>
<script src="Ajax.js" type="text/javascript"></SCRIPT>
<TITLE>Pink AJAX Example</TITLE>
</HEAD>
<BODY onload=InitTimer()>
<Table border=1>
<TR Height= 75px>
<TD>
<Span id="AjaxImg" />
</TD>
</TR>
<TR>
<TD>
variable 01
</TD>
</TR>
<Table>
</BODY>
The only thing that needs to be developed is a basic program to update the netburner and you have an dynamicly updated(Ajax) Webpage running off of a Pink.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A complex design is the sign of an inferior designer. - Jamie Hyneman, Myth Buster
thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A complex design is the sign of an inferior designer. - Jamie Hyneman, Myth Buster
Post Edited (Dgswaner) : 10/10/2007 7:45:21 PM GMT
Thanks
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A complex design is the sign of an inferior designer. - Jamie Hyneman, Myth Buster