Shop OBEX P1 Docs P2 Docs Learn Events
[RESOLVED]LED (@ pin 23?) not working — Parallax Forums

[RESOLVED]LED (@ pin 23?) not working

WildatheartWildatheart Posts: 195
edited 2013-01-29 22:15 in Accessories
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.

Comments

  • WildatheartWildatheart Posts: 195
    edited 2013-01-28 23:43
    The Spinneret LOVES Chrome! On a whim, I set up my desktop PC this afternoon and downloaded Chrome. My recent experience with the Spinneret has primarily been on my (not that old) laptop running IE. I also did followup testing on my iPhone running Safari on 3G. Mike assisted such that I have my Spinneret loading in IE at about 95%, but the pauses he suggested seemed to slow the loading a bit. Sometimes Safari worked and sometimes it didn't. But Chrome loaded at 100%, and... it was VERY FAST!!

    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.
  • Mike GMike G Posts: 2,702
    edited 2013-01-29 07:11
    It has occurred to me the tutorials and posted concepts are not working as well as I hoped. I'm answering the same type of questions over and over. It's a bit frustrating but obviously there is a problem with the concepts presented, the location of the examples, and/or documentation.

    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.
  • Mike GMike G Posts: 2,702
    edited 2013-01-29 11:30
    BTW, I added COG ID properties to all the source libraries except PST. So you'll need to get the latest base files; Spi5100CounterPasm, Socket, W5100, and the 3 SD files.

    It just displays the COGs in use and what code the COGs are executing.
  • WildatheartWildatheart Posts: 195
    edited 2013-01-29 20:20
    WOW! Paul has full control over his chicken coup already and I'm still struggling to get a light turned on.

    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...
  • Mike GMike G Posts: 2,702
    edited 2013-01-29 21:53
    The attached HTML file, pin.htm, goes with the new source. Just unzip and drop the file on the SD card.
  • WildatheartWildatheart Posts: 195
    edited 2013-01-29 22:15
    Thanks, Mike! I'm guessing you worked WAY overtime to accomplish this for us.

    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.
Sign In or Register to comment.