Shop OBEX P1 Docs P2 Docs Learn Events
[Contest Entry] Multi-Socket Server - Page 3 — Parallax Forums

[Contest Entry] Multi-Socket Server

13

Comments

  • william chanwilliam chan Posts: 1,326
    edited 2011-09-11 00:41
    Since the problem is most likely a latency problem, could you try increasing the timeouts in the HTTPServer code?
  • Mike GMike G Posts: 2,702
    edited 2011-09-11 10:02
    Since the problem is most likely a latency problem, could you try increasing the timeouts in the HTTPServer code?

    I increased the timeout to from 10ms to 300ms. So we're on the same page, timeout is the amount of time the Spinneret will wait for data on the Socket(id) Rx buffer while the socket is open. Sockets are opened by a client request therefore the request has to make it to the Spinneret.

    I also implemented a 30 minute cache on all content-types except text/html.
  • skynuggetskynugget Posts: 172
    edited 2011-09-12 08:50
    hey mike,
    first off, thank you so much for the code/documentation.

    I've been trying to parse the new xml response for led state on the restful led.html demo html, i commented and added the following code, but i must admit im not to hot with ajax/javascript, so im flying kinda blind.
    led.htm
    
    function handleResponse() {
    	 if (req.readyState == 4) {
    
    		 //var str = req.responseText;
    		 //alert(str);
    		 
    		 var str = req.responseXML;
    		 alert("response: " + str);
    		 
    		 var placeholder = document.getElementById(htmlTarget);
    		 placeholder.innerHTML = str;
    	 }
     }
    

    all i get in return is " [Object Document] "
    any suggestions?
  • Mike GMike G Posts: 2,702
    edited 2011-09-12 08:56
    skynugget, please see Returning XML (tutorial) for information on parsing return XML. Basically, you need to drill into an XML node or convert the response to a string.

    Let me know if you have any questions.
  • skynuggetskynugget Posts: 172
    edited 2011-09-12 09:01
    thanks for the nudge mike, i dunno how i passed that over! im all good now :)
  • william chanwilliam chan Posts: 1,326
    edited 2011-09-12 20:04
    Now it seems to be stuck on one page only and keeps getting General Error File Not Found? when you click various links.
  • Mike GMike G Posts: 2,702
    edited 2011-09-12 21:40
    Now it seems to be stuck on one page only and keeps getting General Error File Not Found?
    The server has been up and running all day. The error page General Error File Not Found? is sent when the requested resource does not exist. Sounds like you can render pages though. Especially since you can see the menu and the error page.
  • skynuggetskynugget Posts: 172
    edited 2011-09-13 19:54
    i have been hitting it pretty hard the past couple days, and the only problem i see, is occasionally the style sheet does not load.
  • Mike GMike G Posts: 2,702
    edited 2011-09-13 20:18
    Thanks skynugget,

    I thought this was interesting. Here are two snapshots of unique Spinneret requests and their locations.
    7 GMT to 9 GMT
    IP			City		State		Country	
    -----------------------------------------------------------------------		
    124.179.240.173		Lucaston 	Australia	Tasmania
    130.75.115.106		Hanover		Niedersachsen	Germany
    213.161.40.97		Unknown		Unknown		Finland
    81.0.158.201		Oslo		Oslo		Norway
    134.134.137.75		Portland	Oregon		United States
    118.102.133.26		Madras		Tamil Nadu	India
    113.210.96.234		Kuala Lumpur	Kuala Lumpur	Malaysia
    99.192.81.5		Halifax		Nova Scotia	Canada
    98.118.76.250		Orange		Massachusetts	United States
    79.196.100.234		Nalbach		Saarland	Germany
    

    18 GMT to 19:24 GMT
    IP			City		State		Country	
    -----------------------------------------------------------------------		
    206.83.251.2	 	Frederick	Maryland	United States
    75.148.49.70		Beaverton	Oregon		United States
    75.152.110.212		Sherwood Park	Alberta		Canada
    204.17.31.126		Phoenix		Arizona		United States
    68.49.21.20		Frederick	Maryland	United States
    12.130.117.131		Decatur		Georgia		United States
    66.173.23.122		Madison		Wisconsin	United States
    64.119.240.2		Summersville	West Virginia	United States
    146.217.200.214		Minneapolis	Minnesota	United States
    72.185.51.122		St Petersburg	Florida		United States
    
  • Phil.BPhil.B Posts: 12
    edited 2011-09-20 16:21
    I was just checking out your really great project and it is either down or you must be doing some work. I just see Afh5yg==vwAQMg==192.168.001.122 when trying to load up the server. I'll be looking forward to it coming back online, so I can finish up my spinneret testing. Thanks for writing such a useful piece of code for this sweet little webserver.
  • Mike GMike G Posts: 2,702
    edited 2011-09-20 18:26
    Sorry Phil.B; I was demonstrating an Spinneret based security door device. The string Afh5yg== is a base64 encoded RFID tag serial number. Anyway, the site is back up.
  • Phil.BPhil.B Posts: 12
    edited 2011-09-20 18:48
    The nerve of you taking your project offline for another use! :P

    Thanks for the quick reply and putting it back up, it has saved me soooo much time in messing around with my spinneret and xbee project. I have gotten it to light LEDs and send strings of text back and forth from a pair of series 2 xbee modems with ease via the website interface. We all know that once you can successfully turn on an LED you can jump right to launching nukes and such! Goofing aside thanks again for the hard work that makes people like me not pull their hair out when trying to build semi simple projects.
  • malmeidapmalmeidap Posts: 11
    edited 2011-09-21 17:55
    Hi Mike, the tutorial said that i can use javascript on my web page, but this portion of code doesnt execute on my web browser. Can u help me ?

    <script type="text/javascript">
    document.write("Hello World!")
    </script>
  • Mike GMike G Posts: 2,702
    edited 2011-09-21 19:09
    malmeidap, Welcome to the forum.

    It's hard to pin point the problem without seeing the entire rendered html and associated SPIN code.

    This works if rendered properly.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Hello World</title>
    </head>
    <body>
    <script type="text/javascript">
    	document.write("Hello World!")
    </script> 
    </body>
    </html>
    

    However, document.write() is not the best method for writing content. It promotes spaghetti code and does not work with popular JavaScript libraries. A better method is to target the DOM.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Hello World</title>
    </head>
    <body>
    <div id="hello">test</div>
    <script type="text/javascript">
    	var div = document.getElementById("hello");
    	div.innerHTML = "Hello World!";
    </script>
    </body>
    </html>
    
    
  • malmeidapmalmeidap Posts: 11
    edited 2011-09-22 04:50
    Thank u Mike, im going to test ur code. Ur project is awesome and it gives me some ideas to work with the spinneret :D Great effort !!!
  • Phil.BPhil.B Posts: 12
    edited 2011-09-22 19:52
    Sorry to bug you again Mike, but I had a question regarding the xmltime tutorial. I have the example code working perfectly and it refreshes the current time on a click of the link just fine. I am trying to figure out a way to refresh the time automatically to give the appearance of a live clock and seem to be falling flat on my face with the AJAX code. I have never messed with AJAX code until this project and seem to be drowning just a tiny bit... My first attempt was to use the google API jquery.min.js which I read about in another forum. It is a pretty simple bit of code that lets you load the content of a file in the current page at a defined refresh rate. It works fine if I test it local, but as soon as I load it up on the spinneret it bombs and I get a 404 error on the PST debug, but the page never loads. I assume the server chokes on the jquery.min.js because I am trying to kill a fly with a shotgun based on my lack of AJAX skills. I know there must be an easier way than reloading the time.htm example code page or a txt file of the current time I am writing to the SD card via and iframe or something. I apologize for my noob questions and it really seemed like a simple task until I spent 2 hours beating my head on the desk :)

    If you could please share a snip of code that would auto refresh the value of xmltime on the page or point me in a better direction than I am currently heading in that would be great. The time value is useful, but I have plans to use this code to read from all my sensors in my project and output the values in near real time on a webpage.

    Thanks in advance for any help :)
  • Mike GMike G Posts: 2,702
    edited 2011-09-22 21:12
    Invoke the setInterval method to execute a function every x milliseconds. This code will execute the xmltime service every 2 seconds.
    setInterval("getRequest('xmltime', 'placeholder')", 2000);
    

    If you are using the demo code as is then the time response is written to the span tag (innerHTML). The nice thing... the whole page doesn't refresh only the DOM object.
    <span id="placeholder"></span>
    


    More info on setInterval...
    http://www.w3schools.com/jsref/met_win_setinterval.asp
  • Phil.BPhil.B Posts: 12
    edited 2011-09-22 22:10
    Yet again I am humbled by the speed and helpfulness of this form. Thanks for the fast response Mike and setInterval did the job perfectly in the time example page allowing the time to work just as I need it. I did still have one issue when trying to use the code from the services and AJAX tutorial on the same page a this time code. I assume it has to do with the two scripts stepping on each others toes because they are just about exactly the same aside from the function handleResponse() parts. It being past 1am here I am going to sleep on this problem and look at it with a fresh set of eyes to see if it is just something simple I am over looking. Thanks again for the help :)
  • Mike GMike G Posts: 2,702
    edited 2011-09-23 08:59
    You can have multiple AJAX handlers. Once you go with setInterval, it is very difficult to share a single AJAX object as you don't know when the method is invoked. It is best to create a separate AJAX request and handler for the setInterval() method.
  • Phil.BPhil.B Posts: 12
    edited 2011-09-23 11:54
    Please forgive my epic amount of failing with the AJAX code. I have both features working fine on their own separate pages with the time updating perfectly and the status messages of if something is On or Off. However, when I attempt to merge the time and controlling code into the same page the server seems to just give up part way and display a 404.

    I have included the code I am running as well as the rendered page to show just where it dies out with the 404. It also displays a 404 error in the pst debug window which confuses me because the file is there and it partially loads.

    I'm sure it is my butchery of the AJAX code confusing the server. I tried to use multiple AJAX handlers as you said, but I may be going about it wrong. I am having MUCH better luck with my spin code and am able to log all my result to a SD card file just fine, it's just this AJAX that is whooping me. What I'm trying to do here is about the extent of my project where I just need a page that displays values of variables and allows for things to be turned on and off.


    Code I am using that 404's part way through:
    <html>
    <head>
    <title>RF Remote Control</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 handleResponsetime() {
         if (req.readyState == 4) {
            parseState(req.responseXML);
         }
    } 
    
    function parseState(xDoc) {
        var target = document.getElementById(htmlTarget);
        target.innerHTML = xDoc.getElementsByTagName("time")[0].childNodes[0].nodeValue;
    }
     
     
     function handleResponse() {
         if (req.readyState == 4) {
    
             var str = req.responseText;
             //alert(str);
    
             var chan0stat = document.getElementById(htmlTarget);
             chan0stat.innerHTML = str;
             
             var chan1stat = document.getElementById(htmlTarget);
             chan1stat.innerHTML = str;
             
             var chan2stat = document.getElementById(htmlTarget);
             chan2stat.innerHTML = str;
             
             var chan3stat = document.getElementById(htmlTarget);
             chan3stat.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;">RF Remote Channels</h1>
      
    <p>&nbsp;</p>
    
    <p><span id="tplaceholder"></span></p>
    
        <script language='javascript' type='text/javascript'>
            setInterval("getRequest('xmltime', 'tplaceholder')", 1000);
        </script>
    
    <p>&nbsp;</p>
    
    <p>
          <a href="rfstat.htm" onClick="return getRequest('achan0.htm?chan0=on', 'chan0stat');">Channel 0 On </a> :: 
          <a href="rfstat.htm" onClick="return getRequest('achan0.htm?chan0=off', 'chan0stat');">Channel 0 Off</a>
      </p>
      <p>Channel 0: <span id="chan0stat">State</span></p>
      <p>
          <a href="rfstat.htm" onClick="return getRequest('achan1.htm?chan1=on', 'chan1stat');">Channel 1 On </a> :: 
          <a href="rfstat.htm" onClick="return getRequest('achan1.htm?chan1=off', 'chan1stat');">Channel 1 Off</a>
      </p>
      <p>Channel 1: <span id="chan1stat">State</span></p>
      <p>
          <a href="rfstat.htm" onClick="return getRequest('achan2.htm?chan2=on', 'chan2stat');">Channel 2 On </a> :: 
          <a href="rfstat.htm" onClick="return getRequest('achan2.htm?chan2=off', 'chan2stat');">Channel 2 Off</a>
      </p>
      <p>Channel 2: <span id="chan2stat">State</span>  </p>
      <p>
          <a href="rfstat.htm" onClick="return getRequest('achan3.htm?chan3=on', 'chan3stat');">Channel 3 On </a> :: 
          <a href="rfstat.htm" onClick="return getRequest('achan3.htm?chan3=off', 'chan3stat');">Channel 3 Off</a>
      </p>
      <p>Channel 3: <span id="chan3stat">State</span></p>
     
    
    
    Rendered Code from firefox:
    
    
    <html>
    <head>
    <title>RF Remote Control</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 handleResponsetime() {
         if (req.readyState == 4) {
            parseState(req.responseXML);
         }
    } 
    
    function parseState(xDoc) {
        var target = document.getElementById(htmlTarget);
        target.innerHTML = xDoc.getElementsByTagName("time")[0].childNodes[0].nodeValue;
    }
     
     
     function handleResponse() {
         if (req.readyState == 4) {
    
             var str = req.responseText;
             //alert(str);
    
             var chan0stat = document.getElementById(htmlTarget);
             chan0stat.HTTP/1.1 404 Not Found
    Content-Type: text/html
    Server: Spinneret/2.1
    Cache-Control: public
    Expires: Wed, 04 Jan 1999 04:30:18 GMT
    
    <html><head><title>Error</title></head><body><h1>Error</h1></body></html>
    
    
    
  • Mike GMike G Posts: 2,702
    edited 2011-09-23 14:47
    You can't reuse the req object unless you have some kind of traffic cop. When you invoke getRequest(), you're starting an asynchronous call and assigning a call back handler. The problem comes in when the setInterval method has fired and is waiting for the response and you click a link. Plus the code has some issues.

    You'll have to debug the code but I think this should give you the idea.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>RF Remote Control</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 chan0stat = document.getElementById(htmlTarget);
             chan0stat.innerHTML = str;
             
             var chan1stat = document.getElementById(htmlTarget);
             chan1stat.innerHTML = str;
             
             var chan2stat = document.getElementById(htmlTarget);
             chan2stat.innerHTML = str;
             
             var chan3stat = document.getElementById(htmlTarget);
             chan3stat.innerHTML = str;
         }
     }
     
     
     // Timed AJAX
     //////////////////////////////////////////////
     var setIntReq = getXmlHttpRequestObject();
     var setIntTarget;
    
     function getTimedRequest(resource, elementId) {
         
        // handle the case where a querystring is not detected
        var char = "&";
         if(resource.indexOf("?", 0) == -1) {
            char = "?";
        }
            
         if (setIntReq.readyState == 4 || setIntReq.readyState == 0) {
             setIntReq.open("GET", resource + char + 'ms=' + new Date().getTime(), true);
             setIntReq.onreadystatechange = handleTimedResponse;
             setIntTarget = elementId;
             setIntReq.send(null);
             return false;
         }
     }
     
     function handleTimedResponse() {
         if (setIntReq.readyState == 4) {
            parseTimedState(setIntReq.responseXML);
         }
    } 
    
    
    function parseTimedState(xDoc) {
        var target = document.getElementById(setIntTarget);
        target.innerHTML = xDoc.getElementsByTagName("time")[0].childNodes[0].nodeValue;
    }
    
    </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;">RF Remote Channels</h1>
    <p>&nbsp;</p>
    <p><span id="tplaceholder"></span></p>
    <script language='javascript' type='text/javascript'>
            setInterval("getTimedRequest('xmltime', 'tplaceholder')", 1000);
        </script>
    <p>&nbsp;</p>
    <p> <a href="rfstat.htm" onClick="return getRequest('achan0.htm?chan0=on', 'chan0stat');">Channel 0 On </a> :: <a href="rfstat.htm" onClick="return getRequest('achan0.htm?chan0=off', 'chan0stat');">Channel 0 Off</a> </p>
    <p>Channel 0: <span id="chan0stat">State</span></p>
    <p> <a href="rfstat.htm" onClick="return getRequest('achan1.htm?chan1=on', 'chan1stat');">Channel 1 On </a> :: <a href="rfstat.htm" onClick="return getRequest('achan1.htm?chan1=off', 'chan1stat');">Channel 1 Off</a> </p>
    <p>Channel 1: <span id="chan1stat">State</span></p>
    <p> <a href="rfstat.htm" onClick="return getRequest('achan2.htm?chan2=on', 'chan2stat');">Channel 2 On </a> :: <a href="rfstat.htm" onClick="return getRequest('achan2.htm?chan2=off', 'chan2stat');">Channel 2 Off</a> </p>
    <p>Channel 2: <span id="chan2stat">State</span> </p>
    <p> <a href="rfstat.htm" onClick="return getRequest('achan3.htm?chan3=on', 'chan3stat');">Channel 3 On </a> :: <a href="rfstat.htm" onClick="return getRequest('achan3.htm?chan3=off', 'chan3stat');">Channel 3 Off</a> </p>
    <p>Channel 3: <span id="chan3stat">State</span></p>
    
    
  • Phil.BPhil.B Posts: 12
    edited 2011-09-23 18:52
    I took a swing and a miss with the code you posted. I tried to debug it with firebug and oddly enough it spits out no errors other than the 404 which still boggles me because javascript is client side. I would assume it should render all of the html and not just stop at a blank screen with a 404 mid head tag.

    I had a friend of mine look over all the code I had and what you posted to try and help me out. Below is a copy of what he came up with based on your information. It still loads a blank screen and stops writing html midway through the head tag. We checked for errors with firebug and the chrome debug tool with nothing coming up other than the html stopping dead in it's tracks.

    Do you have any ideas what could cause this? I have formatted the SD card and triple checked the file on my card reader with no signs of corruption. I am really starting to think it is not a code issue and more of a filesystem issue because it spits out the 404 in the PST debug, but a blank screen in the browser. I am just all sorts of lost with this current issue :(
    <!DOCTYPE html>
    <html>
    <head>
    <title>RF Remote Control</title>
    <script language="javascript" type="application/javascript">
    var req = new XMLHttpRequest();
    var htmlTarget;
    req.onreadystatechange = getRequest_handler;
    
    function getRequest(resource, elementId) {
        if (req.readyState == 4 || req.readyState == 0) {
            // handle the case where a querystring is not detected
            var char = "&";
            if (resource.indexOf("?", 0) == -1) {
                char = "?";
            }
            
            htmlTarget = elementId;
            req.open("GET", resource + char + 'ms=' + new Date().getTime(), true);
            req.send();
        }
    }
    function getRequest_handler() {
        if (req.readyState == 4) {
            var str = req.responseText;
            //alert(str);
    
            var chan0stat = document.getElementById(htmlTarget);
            chan0stat.innerHTML = str;
             
            var chan1stat = document.getElementById(htmlTarget);
            chan1stat.innerHTML = str;
             
            var chan2stat = document.getElementById(htmlTarget);
            chan2stat.innerHTML = str;
             
            var chan3stat = document.getElementById(htmlTarget);
            chan3stat.innerHTML = str;
        }
    }
      
    var setIntReq = new XMLHttpRequest();
    var setIntTarget;
    setIntReq.onreadystatechange = getTime_handler;
    
    // Get time
    function getTimedRequest(resource, elementId) {
        if (setIntReq.readyState == 4 || setIntReq.readyState == 0) {
            // handle the case where a querystring is not detected
            var char = "&";
            if (resource.indexOf("?", 0) == -1) {
                char = "?";
            }
            
            setIntTarget = elementId;
            setIntReq.open("GET", resource + char + 'ms=' + new Date().getTime(), true);
            setIntReq.send();
        }
    }
    function getTime_handler() {
        if (setIntReq.readyState == 4) {
            var xDoc;
            xDoc = setIntReq.responseXML;
            var target = document.getElementById(setIntTarget);
            target.innerHTML = xDoc.getElementsByTagName("time")[0].childNodes[0].nodeValue;
        }
    }
    
    setInterval(function(){ getTimedRequest('xmltime', 'tplaceholder'); }, 1000);
    </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;">RF Remote Channels</h1>
    
    <br /><br />
    
    <div id="tplaceholder"></div>
    
    <br /><br />
    
    <a href="#" onClick="getRequest('achan0.htm?chan0=on', 'chan0stat');">Channel 0 On </a> :: <a href="#" onClick="getRequest('achan0.htm?chan0=off', 'chan0stat');">Channel 0 Off</a> <br />
    Channel 0: <span id="chan0stat">State</span> <br /><br />
    <a href="#" onClick="getRequest('achan1.htm?chan1=on', 'chan1stat');">Channel 1 On </a> :: <a href="#" onClick="getRequest('achan1.htm?chan1=off', 'chan1stat');">Channel 1 Off</a> <br />
    Channel 1: <span id="chan1stat">State</span> <br /><br />
    <a href="#" onClick="getRequest('achan2.htm?chan2=on', 'chan2stat');">Channel 2 On </a> :: <a href="#" onClick="getRequest('achan2.htm?chan2=off', 'chan2stat');">Channel 2 Off</a> <br />
    Channel 2: <span id="chan2stat">State</span> <br /><br />
    <a href="#" onClick="getRequest('achan3.htm?chan3=on', 'chan3stat');">Channel 3 On </a> :: <a href="#" onClick="getRequest('achan3.htm?chan3=off', 'chan3stat');">Channel 3 Off</a> <br />
    Channel 3: <span id="chan3stat">State</span> <br /><br />
    
    </body>
    </html>
    
    
  • Mike GMike G Posts: 2,702
    edited 2011-09-23 20:54
    No idea, how about attaching all your code.

    Edit: I think your problem is elsewhere. A 404 pops up when a resource does not exist. The 404 is rendered from the server.
    I tried to debug it with firebug and oddly enough it spits out no errors other than the 404 which still boggles me because javascript is client side.
    You're making an HTTP request with JavaScript so I'm not sure what you mean or expect. Plus, it looks like you're calling an entire htm page? I'd think you;re requests would look more like, \ch\0\1 or ch\0\0; [Channel 0 on] and [Channel 0 off]

    Also does achan0.htm, achan1.htm, achan2.htm, and achan3.htm exist on the SD card and in the root? If not, did you set a return in the Dispatcher so so the server does not try to render the mentioned static htm pages?
  • Phil.BPhil.B Posts: 12
    edited 2011-09-24 11:43
    I have worked in IT for 13+ years and have seen computers/electronics do some very odd things... but this is one for the books. Last night at like 1:30am I was packaging up the code to send over for you to take a look at and wanted to load it up one last time to be sure the parts they I knew worked still worked. So, I mount my SD card and put fresh copies of the code I was working one then unmounted the card and loaded up the spinneret. I checked the RF channel page, that worked with the status messages and everything as it should. I then checked the time.htm and that loaded the time just like It should, but just for kicks I loaded up the code I posted to you.... IT LOADED! Now at this point I am beyond boggled. I honestly went to sleep after seeing it work to make sure it still worked in the morning and I was not dreaming this stuff up... It still works fine as I am typing this reply.

    Now I would like to blame dark magic and gremlins because the code on the SD card was a bit primitive, but fully working and the Spin code works like a champ. Still the only possible logical thing I can come up with is my SD card is somewhat damaged to the point were the spinneret is sensitive enough to fail at reading the files sometimes while the usb reader works fine. I know it is a bit of a reach, but I have triple checked the code and even having a friend remote into the computer and verify the correct code was on the SD card I am honestly at my wits end. I am going to replace the SD card and see if this fluke goes away. This is a proper head scratcher for sure...

    Sorry for pulling the fire alarm on something that I hope to be a failing SD card. If I do ever 100% nail down what caused the spinneret to get confused I will share it for sure. Thanks again for all the fast responses, help and suggestions.
  • Mike GMike G Posts: 2,702
    edited 2011-09-24 12:32
    Regarding SD cards and the FAT driver... I found that adding and updating files caused some unexpected results.

    My standard SD card web site update consists of a delete all files and copy. As a matter of fact, I created a batch file to do this quickly. If anything quirky happens, I'll format the SD card and re-copy.
  • Phil.BPhil.B Posts: 12
    edited 2011-09-24 13:59
    You may have hit the nail on the head! I have always edited my code directly from the card in the past and then when it magically seemed to work was when I deleted and copied everything. I will adopt this delete everything and copy fresh from now on and with some luck all my drama will end.
  • Mike GMike G Posts: 2,702
    edited 2011-09-24 14:12
    Sorry; probably should have mentioned the SD card issue before now. Thing is, I came up with a process and didn't look back. Anyway, I believe something happens to the FAT while editing on a PC that S35390A_SD-MMC_FATEngine.spin does not like or expect.
  • ColeyColey Posts: 1,110
    edited 2011-09-26 04:10
    @Mike,

    I tried this over the weekend and it's great!

    I have an application that needs dynamic updating is there any way to achieve this with this server?

    My app is basically a table that needs updating in real time, colour of text changes in relation to the device status.

    Any help/pointers will be appreciated.

    Regards,

    Coley
  • Mike GMike G Posts: 2,702
    edited 2011-09-26 05:15
    Sounds like you want to monitor a process and view the state of the process dynamically.
    • Create logic that monitors the device
    • Store the device state in an XML document
    • Build a method that watches for a device state request (Dispatcher)
    • Build a method that sends the XML document in a response
    • Setup the client to request the XML document at some frequency
    • Build code to parse the XML and update the client view

    The Returning XML tutorial section explains how to request and parse XML from the server using JavaScript.

    My suggestion is to get started. If you get stuck, create a new thread with details of the problem. Please do not add to this thread unless it is related to the [Contest Entry] Multi-Socket Server.
  • BillDerBillDer Posts: 33
    edited 2011-10-09 09:21
    Mike what an absolutely fabulous project and resource for us newbies.
    Thanks!
    I just spent the morning reading your tutorials and this thread, it was very helpful. However, I don't know HTML and I want to do exactly what you did with the web camera and controlling pins. I did not see how you are able to simultaneously send the image to the page as the led's turned on and off so very cool!!! Any help would be greatly appreciated
    Bill
Sign In or Register to comment.