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.
Before proceeding, you should have the following ready:
-
MPLAB code configurator (Once you finish the installation of the previous items, open MPLAB X IDE, then click Tools > Plugin Download > search for MPLAB code configurator and install it)
-
Get the sample files from GitHub: Link to Eric's GitHub repo
-
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"
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"
Create a new device on your IoT Hub using this device as your device name.
- Update the Wi-Fi credentials and security
- On the left hand panel, look for Header files > platform > config > config_winc.h
- 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)
- 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=
- Once you have all the credentials set, you can upload the code to your device, by clicking on debug project.
- 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.
- On your device window on Azure, click Direct Method
- On the direct method window, type blink on the Method Name, type {"duration":3} on the payload, and click "Invoke method".
- You should see the red LED turning on for 3 seconds and then turning back off again.