[RESOLVED]LED (@ pin 23?) not working
Wildatheart
Posts: 195
Added AJAX "Hello World / LED" from Google downloads to HTML at http://72.208.99.227:5000
LED and Hello World both function on index page, and Hello World on LED.htm page returns to index page, but LED change indicator on LED.htm page doesn't change.
Reviewed tutorial but didn't find dispatcher at line 255 - but that's for HTTPserver. Anything new published for the W5100? I know that I need to get pin 23 in there somewhere.
LED and Hello World both function on index page, and Hello World on LED.htm page returns to index page, but LED change indicator on LED.htm page doesn't change.
Reviewed tutorial but didn't find dispatcher at line 255 - but that's for HTTPserver. Anything new published for the W5100? I know that I need to get pin 23 in there somewhere.
Comments
In my post above I mentioned that the controls on the LED page were consistently nonresponsive. In Chrome, all of the LED page controls snaped-to 100% of the time. This doesn't solve the necessary addition of the spin code to light the P23 LED that I need to do, but it certainly adds a new dimension to problematic page loading we've been discussing.
It looks like the Spinneret and Chrome are a match made in Google. Can there really be that much difference? or could that the problematic page loadings have been caused by my laptop? Whatever the case, it's worth a footnote somewhere.
I updated WebServer_W5100.spin on Google Code. The new code looks for pinstate.xml. If found, the server code will grab two querystring variable; led and value. the two values are used to set/read PIN I/O. The result of the request is an XML document returned to the caller. The caller must parse the XML returned and update the client using JavaScript.
This is a live example...
Set PIN 23 to 0 (off)
http://192.168.1.109:8080/pinstate.xml?led=23&value=0
Set PIN 23 to 1 (on)
http://192.168.1.109:8080/pinstate.xml?led=23&value=1
Read pin I/O value without setting state
http://192.168.1.109:8080/pinstate.xml?led=23&value=-1
What's left is to write the client JavaScript to update the DOM via AJAX.
It just displays the COGs in use and what code the COGs are executing.
Made code changes (best I understand) to Getting AJAX - attached.
<html>
<head>
<title>GETing AJAX</title>
<script language="javascript" type="application/javascript">
//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
} else {
alert("Your Browser does not support AJAX!\nIt's about time to upgrade don't you think?");
}
}
//XmlHttpRequest object
var req = getXmlHttpRequestObject();
var htmlTarget;
function getRequest(resource, elementId) {
// handle the case where a querystring is not detected
var char = "&";
if(resource.indexOf("?", 0) == -1) {
char = "?";
}
if (req.readyState == 4 || req.readyState == 0) {
req.open("GET", resource + char + 'ms=' + new Date().getTime(), true);
req.onreadystatechange = handleResponse;
htmlTarget = elementId;
req.send(null);
return false;
}
}
function handleResponse() {
if (req.readyState == 4) {
var str = req.responseText;
//alert(str);
var placeholder = document.getElementById(htmlTarget);
placeholder.innerHTML = str;
}
}
</script>
</head>
<body style="background-color:beige;">
<div style="width:600px;margin:auto;background-color:white;padding:10px;">
<h1 style="text-align:center;color:blue;">LED</h1>
<div style="text-align:center;"><a href="index.htm">Hello World</a> | <a href="led.htm">LED</a></div>
<h2>RESTful</h2>
<p>
<a href="led.htm" onClick="return getRequest('http://192.168.1:5000/led/23/on', 'placeholder');">LED On</a> ::
<a href="led.htm" onClick="return getRequest('http://192.168.1:5000/led/23/off', 'placeholder');">LED Off</a>
</p>
<p>LED: <span id="placeholder">State</span></p>
</div>
</body>
</html>
Manager attachment won't let me load the file. So...
It works perfectly and I'm sure this addition will open up a lot of doors and stimulate much creativity here.
Perhaps this is important enough for its own thread, but do you think there is a need to have any discussion pertaining to post #17 in the "My chickens have the internet..." thread?
Big deal! Thanks again for going the extra mile.