The one we are talking about here is a simple net-connected application that will query the web API, collect information about it and would pin it over a map. The hardware components to be used in this project include Raspberry Pi 2 Model B, 56Ω resistor, a generic breadboard, Adafruit female/male jumper wires, and Adafruit LED. In this project,you are required to use the Adafruit Starter Pack meant for WIndows 10 IoT Core on Raspberry Pi 2 parts that will help in creating a project that blinks an LED light in response to any web based API call.
The hardware setup for this one will need to connect the Raspberry Pi 2 with the breadboard and other parts according to the Fritzing diagram given on the bottom of this page. The code can always be downloaded from https://github.com/ms-iot/adafruitsample. To begin, you need to open up “Lesson_201StartSolutionLesson_201.sin” and open up the MainPage.xaml.csfile.
In order to define the pin to be used for controlling the LED, you will have to define that is to be used on Pi2. You can always use the following lines on the top of MainPage class in order to accomplish that:
Once you are done with it, you can then add code in OnNavigatedTo method that will create a new InternetLed object and then make a web API call in order to pin it on the maker map. It will also initialize the object and would call the webapi for getting the delay value. You will have to loop it a hundred times along with the returned delay that will blink the led every pass. In case, you do not wish to add the pin on the map, just remove MalePinWebAPICall(); look at the following picture:
Post this, you will have to add a new class file that will include performance of maximum work. For this purpose, go to main menu and select Project and Add Class to it. Then add new item dialog that will open and get defualt to Visual C# Class. Enter InternetLed.cs for file name and then click on Add tab. The class file be created as well as opened up for you.
When you are done entering the code, you can always build the solution and execute the code over your Pi2. if you need, just review the instructions once again on connecting and running code on PI. On visual studio, open the Output tab and if it is required on main menu you can always use Debug -> Window -> Output. You will see Debug.WriteLine commands from here. Find the messages beginning with “Response strong:”, these will then be followed by the response from the web API surrounded from “” kind of brackets.
Once this step is complete, you will be able to see blinking LED on and off per second based upon the time string value that is being returned from web API.
Filed Under: Reviews