NRF9160 SDK 3.1
nRF9160 SDK
Version 3.1
Updated on 24 January 2024
# | Date | Name | Download |
---|---|---|---|
1 | 29/01/2024 | Nordic nRF9160 SDK 3.1 | Download |
How to run a C sample code nRF9160 Board?
Prerequisite
- Install for nRF9160 nRF SDK with 2.5.0 version will come along with modem firmware version 1.3.5 and complete Getting Started with nRF9160 DK.
– Reference link to install - Install the latest Visual Studio code along with nrf connect extensions to run the application.
Installation
- For making new application, create a folder in nrf-sample folder and name is “IoTConnect” where you installed nRFConnet SDK.
- Path to create folder : e.g.(C:\nordic\v2.5.0\nrf\samples\).
- Now unzip the “iotconnect-C-sdk-nRF-3.1.zip” SDK which you have downloaded from our IoTConnect help portal.
- We have “IoTConnect_config.h” file in nRF9160-DK\src with “main.c”(You can download this firmware file from above sample code).
- You need to input “uniqueId”, “CPID” and “env” in IoTConnect_config.h file. You can see more in below section title with “Prerequisite input data”
- You need to input “uniqueId”, “CPID” and “env” in IoTConnect_config.h file. You can see more in below section title with “Prerequisite input data”
- In the other folder “nRF9160-DK\IoTConnect\cert” we have a “certificate.h” in here you have to put your device certificate
#define CLOUD_CLIENT_PRIVATE_KEY \ "-----BEGIN RSA PRIVATE KEY-----\n" ---------------------------------- ---------------------------------- "-----END RSA PRIVATE KEY-----\n" #define CLOUD_CLIENT_PUBLIC_CERTIFICATE \ "-----BEGIN CERTIFICATE-----\n" ---------------------------------- ---------------------------------- "-----END CERTIFICATE-----\n" #define CLOUD_CA_CERTIFICATE \ "-----BEGIN CERTIFICATE-----\n" \ ---------------------------------- ---------------------------------- "-----END CERTIFICATE-----\n"
Usage:
To initialize the SDK object need to import below sdk package
#include "IoTConnect_Config.h" #include "main.h"
Prerequisite input data
#define IOTCONNECT_DEVICE_CP_ID "yourCpid" #define IOTCONNECT_DEVICE_UNIQUE_ID "yourUniqueID" #define IOTCONNECT_DEVICE_ENV IoTConnectENV"
- IOTCONNECT_DEVICE_UNIQUE_ID : Its device ID which register on IotConnect platform and also its status has Active and Acquired.
- IOTCONNECT_DEVICE_CP_ID : It is the company code. It gets from the IoTConnect UI portal “Settings->Key Vault”.
- IOTCONNECT_DEVICE_ENV : It is the UI platform environment. It gets from the IoTConnect UI portal “Settings->Key Vault”.
To Initialize the SDK object and connect to the cloud
IoTConnect_init(IOTCONNECT_DEVICE_CP_ID, IOTCONNECT_DEVICE_UNIQUE_ID, IOTCONNECT_DEVICE_ENV, Device_CallBack, Twin_CallBack);
To Connect mqtt client with IoTConnect
IoTConnect_connect();
To receive the command from Cloud to Device(C2D)
void DeviceCallback(char *payload){ printk("\n Cmd_msg >> %s",payload); if(payload.cmdType == "0x01") // Device Command if(payload.cmdType == "0x02") // Firmware Command if(payload.cmdType == "0x16") // Device connection status }
This is the standard data input format for non Gateway device to send the data on IoTConnect cloud(D2C)
// Example For Non Gateway Device String Attribute_json_Data = [{ "uniqueId": "<< Device UniqueId >>", "time" : "<< date >>", "data": {} }]; SendData(Attribute_json_Data);
- time : Date format should be as defined # “2021-01-24T10:06:17.857Z”
- data : JSON data type format # {“temperature”: 15.55, “gyroscope” : { ‘x’ : -1.2 }}
To send the command acknowledgment from device to cloud.
Ack_Json=cJSON_CreateObject(); cJSON_AddStringToObject(Ack_Json, "ackId", cmd_ackID); cJSON_AddStringToObject(Ack_Json, "msg", ""); cJSON_AddNumberToObject(Ack_Json, "st", Status); char *Ack_Json_Data = cJSON_Print(Ack_Json); int msgType = ""; // 5 ("0x01" device command), 11 ("0x02" Firmware OTA command) SendAck(Ack_Json_Data, msgType);
- ackId(*) : Command Acknowledgment GUID which will receive from command payload
(data.ackId) - st(*) : Acknowledgment status sent to cloud
4 = Fail
6 = Device command[0x01]
7 = Firmware OTA command[0x02]) - msg : It is used to send your custom message
- msgType : Message type
5 = Device command[0x01]
11 = Firmware OTA command[0x02]
To receive the twin from Cloud to Device(C2D)
void Twin_CallBack(char *payload){ printk("\n Twin_msg payload is >> %s", payload); }
To update the Twins reported property
UpdateTwin(key,value);
- key : Desired property key received from Twin callback message
- value : Value of the respective desired property
Get all the Twin property from the cloud to your device.
GetAllTwins();
To disconnect the device from IoTConnect cloud
IoTConnect_abort();