Skip to content

1.4 Lab 4

gloveboxes edited this page Apr 10, 2015 · 1 revision

#LAB 4: CONNECTING TO AZURE

This lab connects the Netduino to a MQTT Service running on Azure. When you have successfully completed this lab your data will be displayed on the central Internet of Things dashboard.

You can also run the Internet of Things dashboard app from the PC you are using. It is pinned to the taskbar next to Visual Studio.

Ensure the Netduino is connected to the PC using the USB cable and the Ethernet cable is plugged in to the Netduino. Then follow these steps.

  1. Review the code below. On completion of this lab, your code should be the same

  2. If the program is still running from Lab 3, then click the stop button first. You will not be able to edit the Program.cs file while the code executes.

  3. Follow the notes in the Lab 4 and copy and paste the code in to Program.cs

  4. Replace “emul” with something unique such as your initials, use 3 to 5 characters.

  5. Ensure the network cable is plugged in to the Netduino and connected to the internet.

  6. Press F5 or the click the Start button from the toolbar to deploy the app to the Netduino

  7. The RGB LED blinks when a sensor is read (this can take up to 30 seconds to begin)

  8. Check the central Internet of Things dashboard; your data should be displayed. Try adjusting the light reading by covering the LDR. You’ll see the change reflected on the IoT Dashboard.

    using Coatsy.Netduino.NeoPixel.Jewel;
    using Glovebox.Adafruit.Mini8x8Matrix;
    using Glovebox.MicroFramework.Sensors;
    using Glovebox.Netduino.Actuators;
    using Glovebox.Netduino.Sensors;
    using Microsoft.SPOT;
    using SecretLabs.NETMF.Hardware.NetduinoPlus;
    using System.Threading;
    
    namespace MakerDen {
        public class Program : MakerBaseIoT {
    
            public static void Main() {
                // main code marker
    
                //Replace the "emul" which is the name of the device with a unique 3 to 5 character name
                //use your initials or something similar.  This code will be visible on the IoT Dashboard
                StartNetworkServices("emul", true);
    
                using (SensorTemp temp = new SensorTemp(Pins.GPIO_PIN_D8, 10000, "temp01"))
                using (SensorLight light = new SensorLight(AnalogChannels.ANALOG_PIN_A0, 1000, "light01"))
                using (rgb = new RgbLed(Pins.GPIO_PIN_D3, Pins.GPIO_PIN_D5, Pins.GPIO_PIN_D6, "rgb01")) {
                    temp.OnBeforeMeasurement += OnBeforeMeasure;
                    temp.OnAfterMeasurement += OnMeasureCompleted;
                    light.OnBeforeMeasurement += OnBeforeMeasure;
                    light.OnAfterMeasurement += OnMeasureCompleted;
                    Thread.Sleep(Timeout.Infinite);
                }
            }
        }
    }
    
Clone this wiki locally