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.

gyre's Content

There have been 1 items by gyre (Search limited from 28-April 23)


By content type

See this member's

Sort by                Order  

#54424 Newb fails to combine PUT and GET code samples from Gsiot book

Posted by gyre on 03 December 2013 - 02:12 AM in Netduino Plus 2 (and Netduino Plus 1)

Hi all,

 

I'm working through Cuno Pfister's book Getting Started with the Internet of Things.  The sample codes in the book all work for me.  So I decided to try to combine Example 11-1 (VoltageMonitor) and Example 12-1 (LedController): I wanted to write a program that would use different RequestRoutings via Yaler to both show me the current voltage of a potentiometer AND to allow me to turn the onboard LED on and off. Basically I inserted chunks of Example 11-1 into Example 12-1, made sure all references are intact, etc.  It compiles and deploys fine, and switching the LED on and off (the PUT request) works when I access try.yaler.net/my-domain/led/target.html, but reading the voltage (the GET request) yields only a blank page when I access try.yaler.net/my-domain/voltage/actual.html.

 

Any ideas?  I've pasted my code below (with Yaler credentials X'd out).  Any help greatly appreciated.  I'm very new to programming (2/10 at C#, 0/10 at JavaScript) so probably just making a simple mistake.

 

Thanks!!

 

 

using Gsiot.Server; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware.NetduinoPlus; public class LedControllerHtml {   public static void Main()   {   var ledActuator = new DigitalActuator   {   OutputPin = Pins.ONBOARD_LED   };   var lowPort = new OutputPort(Pins.GPIO_PIN_A0, false);         var highPort = new OutputPort(Pins.GPIO_PIN_A2, true);         var voltageSensor = new AnalogSensor         {             InputPin = Pins.GPIO_PIN_A1,             MinValue = 0.0,             MaxValue = 3.3         };   var webServer = new HttpServer     {   RelayDomain = "XXXXXXXX",   RelaySecretKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",   RequestRouting =   {   {   "PUT /led/target",   new ManipulatedVariable   {   FromHttpRequest =   CSharpRepresentation.TryDeserializeBool,   ToActuator = ledActuator.HandlePut   }.HandleRequest   },   {   "GET /led/target.html",   HandleLedTargetHtml   },   {                     "GET /voltage/actual.html",                     new MeasuredVariable                     {                         FromSensor = voltageSensor.HandleGet                     }.HandleRequest         }   }   };   webServer.Run();   }   static void HandleLedTargetHtml(RequestHandlerContext context)   {   string requestUri = context.BuildRequestUri("/led/target");   var script =   @"<html>   <head>   <script type=""text/javascript"">   var r;   try {   r = new XMLHttpRequest();   } catch (e) {   r = new ActiveXObject('Microsoft.XMLHTTP');   }   function put (content) {   r.open('PUT', '" + requestUri + @"');   r.setRequestHeader('Content-Type', 'text/plain');   r.send(content);   }   </script>   </head>   <body>   <p>   <input type=""button"" value=""Switch LED on""     onclick=""put('true')""/>   <input type=""button"" value=""Switch LED off""   onclick=""put('false')""/>   <input type=""button"" value=""Bah""   onclick=""put('bah')""/>   </p>   </body> </html>";   context.SetResponse(script, "text/html");   } }  





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.