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; }