Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Write full website to browser


  • Please log in to reply
No replies to this topic

#1 Wayneio

Wayneio

    Member

  • Members
  • PipPip
  • 24 posts

Posted 01 August 2013 - 06:02 PM

I'm using a web server to control devices in the house with the netduino. The code below writes a simple html page to the pc when typing in the netduinos ip address.

	    while (true)		    {			    Socket clientSocket = listenerSocket.Accept();			    bool dataReady = clientSocket.Poll(5000000, SelectMode.SelectRead);			    if (dataReady && clientSocket.Available > 0)			    {				    byte[] buffer = new byte[clientSocket.Available];				    int bytesRead = clientSocket.Receive(buffer);				    string request =				    new string(System.Text.Encoding.UTF8.GetChars(buffer));				    if (request.IndexOf("ON") >= 0)				    {					    outD7.Write(true);				    }				    else if (request.IndexOf("OFF") >= 0)				    {					    outD7.Write(false);				    }				    string statusText = "Light is " + (outD7.Read() ? "ON" : "OFF") + ".";				    string response = WebPage.startHTML(statusText, ip);				    clientSocket.Send(System.Text.Encoding.UTF8.GetBytes(response));			    }			    clientSocket.Close();		    }
public static string startHTML(string ledStatus, string ip)	    {		    string code = "<html><head><title>Netduino Home Automation</title></head><body> <div class="status"><p>" + ledStatus + " </p></div>        <div class="switch"><p><a href="http://" + ip + "/ON">On</a></p><p><a href="http://" + ip + "/OFF">Off</a></p></div></body></html>";		    return code;	    }

This works great, so I wrote a full jquery mobile website to use instead. But my problem is the jquery website only writes the html to the browser, with none of the JS/CSS files that are referenced in the HTML. How can I make sure the  browser reads all of these files?

 

The code I wrote to read the website from the SD is:

 private static string getWebsite()	    {		    try		    {			    using (StreamReader reader = new StreamReader(@"SDindex.html"))			    {				    text = reader.ReadToEnd();			    }		    }		    catch (Exception e)		    {			    throw new Exception("Failed to read " + e.Message);		    }		    return text;	    }





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.