Skip to content

Latest commit

 

History

History
61 lines (58 loc) · 5.01 KB

IoTHubCreation.md

File metadata and controls

61 lines (58 loc) · 5.01 KB

-------- Steps using IoT Hub only -----

  1. Setup your Azure IoT Hub.
  2. Go to the Azure Portal.
  3. Select the IoT Hub Service.
  4. Click on "Add".
  5. Enter the properties for your IoT Hub. 1. Enter a name for your hub. eg. TerrysFirstIoTHub 1. Choose the "Free" pricing tier. This will allow you up to 5,000 messages per day. 1. For the Free tier, the "IoT Hub units" will default to 1. 1. If you have more than 1 subscription, choose the one you wish to use. 1. Create a new Resource group for your hub. It can have the same name as the IoT Hub. 1. Select the "West US" Location. 1. Click the "Pin to dashboard" button. 1. Click the "Create" button.
  6. Wait for the hub to be created. You will be notified in the "Notifications" section when it is complete.

  7. Create (configure) your device in Azure IoT Hub.
  8. Click on your new IoT Hub in the Azure Portal Dashboard.
  9. Click on the "Shared access policies".
  10. Click on the "iothubowner" policy.
  11. Copy the primary key connection string. Save the primary key connection string for later.

  12. Open Device Explorer
  13. In the "Connection information" tab paste the primary key connection string into the "IoT Hub Connection String" text box.
  14. Click on "Update".
  15. Click on the "Management" tab.
  16. In the "Actions" section, select "Create".
  17. Enter a name for your device. Save the device name for later.

  18. Click "Create".
  19. Configure the Raspberry Pi to send messages to the IoT Hub.
  20. Copy the Python code from this HOL to a file. Save the file as SenseHat_IoTHub_Http.py and open it with a text editor such as Notepad. 1. Alternatively you can download the file directly to your Raspberry Pi using: git clone https://github.com/khilscher/IoTHubPiHackathon.git and edit the SenseHat_IoTHub_Http.py using a text editor such as Nano.
  21. Update the file with the primary key connection string. Look for connectionString = and paste in the primary key connection string you copied earlier. Then look for deviceId = and paste in the Device Name you created earlier.
  22. Copy SenseHat_IoTHub_Http.py to your Raspberry Pi using PuTTY. The pscp executable will be in your PuTTY directory.
    pscp SenseHat_IoTHub_Http.py userid@server_name:/path/SenseHat_IoTHub_Http.py
  23. Log into the Raspberry Pi using PuTTY.
  24. Verify that the file was transfered by listing the directory: ls -l
  25. Start sending messages by invoking the script in Python
    pi@raspberrypi:~ $ python SenseHat_IoTHub_Http.py
    
  26. On your laptop, open Device Explorer, click the Data tab, select your device from the Device ID list, and click Monitor. If you see messages arriving then Congratulations, your Raspberry Pi is now sending data to Azure IoT Hub.
  27. Referring to the Sense Hat API, update the code to send other telemetry to IoT Hub from the Sense HAT.
  28. Update the SenseHat_IoTHub_Http.py code to send multiple telemetry data points (e.g. Yaw, Pitch, Roll, or Temperature, Pressure, Humidity) in a single JSON-formatted message to IoT Hub. See [sample_payload.json] (sample_payload.json). Solution source code - Authorized MSFT personnel only SenseHat_IoTHub_Http_JSON.py.
  29. Update SenseHat_IoTHub_Http.py to display the HTTP response code from the IoT Hub message onto the Sense HAT LED display. Solution source code - Authorized MSFT personnel only SenseHat_IoTHub_Http_JSON_LED.py.
  30. To send messages from IoT Hub back to your Raspberry Pi:
  31. Copy the SenseHat_IoTHub_Http_C2D_LED.py file to your Raspberry Pi using pscp or download it directly using git clone.
  32. Update the file with the primary key connection string. Look for connectionString = and paste in the primary key connection string you copied earlier. Then look for deviceId = and paste in the Device Name you created earlier. Save the file.
  33. Run the file using pi@raspberrypi:~ $ python SenseHat_IoTHub_Http_C2D_LED.py
  34. On your laptop, open Device Explorer, click the Messages to Device tab, select your device from the Device ID list, type in a message into the Message textbox and click Send. You should see the message appear on the Sense HAT LED display.

Back to Main HOL Instructions