Skip to content

danewalton/Microchip-PIC24-MCU16-AzureIoT

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PIC 16 - Azure IoT Embedded C SDK Sample Code

This page shows the steps needed to get started with the Microchip PIC 16 board and get it to work with the Azure IoT Embedded C SDK.

Prerequisites

Before proceeding, you should have the following ready:

code-configurator

Sample Instructions

Get the files

  1. Get the sample files from GitHub: Link to Eric's GitHub repo

  2. Open the project in MPLAB X: File > Open Project > [select the folder in which you just downloaded the files]. The MPLAB X project name is "myiot"

project

Get the Device ID

The device_ID on both IoT hub and the devie itself must match, so before creating a new device in Iot Hub, you must retrieve your device_ID. (If you're using DPS - device Provisioning Service, you don't need to worry with this step.)

  • You can find the device_id on the IoT_Sensor_Node_config.h file.
  • To find it, on the left hand panel, look for Header files > platform > config > IoT_Sensor_Node_config.h
  • Line 39 shows the #define DEVICE_ID "your_device_number"

sensor node

Create a new device on your IoT Hub using this device as your device name.

device_id

Update your credentials

  1. Update the Wi-Fi credentials and security
  • On the left hand panel, look for Header files > platform > config > config_winc.h

winc

  • Update your wi-fi SSID name: Line 25 shows #define CFG_MAIN_WLAN_SSID "your-ssid"
  • Update your wi-fi Password: Line 42 shows #define CFG_MAIN_WLAN_PSK "your-ssid-password"
  • Update your wi-fi security: Line 36 shows #define CFG_MAIN_WLAN_AUTH M2M_WIFI_SEC_WPA_PSK (most home routers use M2M_WIFI_SEC_WPA_PSK, If this is you case, there's no need for updating this line)
  1. Update the device_key and MQTT_Host
  • On the left hand panel, look for Header files > platform > config > IoT_Sensor_Node_config.h

  • Line 44 shows the DEVICE_KEY: replace it by the Primary Key you find at your device page on Azure Portal.

  • Still on this file, look at line 23 and update the CFG_MQTT_HOST information.

  • You'll need your device's primary connection string for that.

    Note: you don't need the whole connection string, you only need the host name. In the example connection string below, the highlighted is the part you need to update on line 23.

HostName=ps-demo-hub.azure-devices.net;DeviceId=Pic_test_2;SharedAccessKey=PaPq+m4gtXvYs=

Upload the Sample to the Device

  1. Once you have all the credentials set, you can upload the code to your device, by clicking on debug project.

debug_button

  1. If everything went well, you should see the onboard LEDs turning on. The blue and the green LEDs will be on all the time and the yellow one blinks every 5 seconds to confirm the telemetry has been sent to Azure.

Calling a direct method on the device

  1. On your device window on Azure, click Direct Method
  2. On the direct method window, type blink on the Method Name, type {"duration":3} on the payload, and click "Invoke method".
  3. You should see the red LED turning on for 3 seconds and then turning back off again.

direct_method

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 82.5%
  • Makefile 14.2%
  • C++ 3.2%
  • Shell 0.1%