Hi, this a note/solution if someone end up with the same problems I had.
If you are having problems doing AJAX call but you can see your web pages have a look at
cross-domain ajax guide . Important by doing this modification you create security holes ... please read more about XSS . Have fun,
Quick fix for me 'work with Firefox, Chrome, not working with IE and Opera... still searching', modify the HTTP header in
Request.cs by adding
Access-Control-Allow-Origin: *
string header = "HTTP/1.0 200 OK\r\nContent-Type: " + type + "; charset=utf-8\r\nContent-Length: "
+ response.Length.ToString()
+ "\r\nCache-Control: no-cache"
+ "\r\nAccess-Control-Allow-Origin: *"
+ "\r\nAccess-Control-Allow-Methods: GET"
+ "\r\nConnection: close\r\n";
Also if you want to make yourself a nice weather station have a look at those
nice gauge .
Example :
Client side
<script type="text/javascript">
var speedGauge;
jQuery(document).ready(function() {
speedGauge = new Speedometer("speedometer");
setInterval( "updateGauge()", 1000 );
}); //document.ready
function updateGauge() {
jQuery.get('http://192.168.222.110/analog0', function(data) {
if( data <= 100 && data >= 0 )
speedGauge.SetMPH(data);
else
speedGauge.SetMPH(0);
});
}
</script>
Netduino side
public class Program
{
const string WebFolder = "\\SD\\Web";
public static string trimpot = "0";
public static void Main()
{
OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
AnalogInput an0 = new AnalogInput(Pins.GPIO_PIN_A0);
an0.SetRange(0, 100);
trimpot = an0.Read().ToString();
Listener webServer = new Listener(RequestReceived);
while (true)
{
// Blink LED to show we're still responsive
led.Write(!led.Read());
trimpot = an0.Read().ToString();
Thread.Sleep(500);
}
}
private static void RequestReceived(Request request)
{
// Quick'n'dirty ajax call
if( request.URL == @"/analog0" )
request.SendResponse(trimpot);
else
request.Send404();
}
// ...
Screenshot
screenshot.jpg 120.15KB
87 downloads