Chapter 8. Connecting to the Internet
Reading values from sensors, flashing LEDs, and moving are all very useful and cool things to do. But connecting these up to the Internet opens up a world of possibilities.
You can create tweeting sensors, phone apps for your Netduino projects, and more.
Note
Connecting to the Internet is a big topic, which could take up a book of its own. And it does. Those up to speed with C# programming can learn more via O’Reilly’s book Getting Started with the Internet of Things. This book, written by Dr. Cuno Pfister, details how to link a world of sensors and actuators together over the Internet, generate reports from that data, work with router firewalls, and more.
To introduce this topic, you’ll create a Netduino app that simply turns on and off its onboard LED in response to a web page request. Yes—you can serve up web content from a Netduino!
For this sample, you’ll need a Netduino Plus (which includes integrated networking).
Coding the Server
Since you’re using the Netduino Plus’s built-in LED for this demo, there’s no need to wire up any components. This means you can move on to the code.
Create a new Netduino Plus app. Make sure that you select “Netduino Plus” instead of “Netduino,” so that the networking features are available to your app.
Inside your Main routine, start by typing in the following code:
// set up the LED and turn it off by default OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
As before, this configures the onboard LED. You’ll ...
Get Getting Started with Netduino now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.