• Home
  • Resources
    • User Guides
    • Concepts Articles
    • API References
    • Client Libraries & SDKs
    • Product Updates
  • FAQs
    • General
    • IoTConnect
      • Device Rules
      • Devices
      • Settings
      • Device Commands
      • Device Templates
      • Device Firmware
      • Device Onboarding
    • Security
  • Contact Us
  • Home
  • Resources
    • User Guides
    • Concepts Articles
    • API References
    • Client Libraries & SDKs
    • Product Updates
  • FAQs
    • General
    • IoTConnect
      • Device Rules
      • Devices
      • Settings
      • Device Commands
      • Device Templates
      • Device Firmware
      • Device Onboarding
    • Security
  • Contact Us

Client Libraries & SDKs

home/Documentation/Client Libraries & SDKs
  • Device SDK Reference
    • Overview
    • Device Authentication Options
    • Data Flow
    • Public Methods
      • Device Connection
      • Send Telemetry
      • Get Attributes
      • Send acknowledgment
      • Update Twin
    • SDKs (Message version 1.0)
      • DOT NET (C#)
      • Node.js
      • Java
      • Python
      • iOS
      • Android
      • Embedded
      • C language
      • Build Your Own SDK
      • Node-RED
        • IoTConnect Node-red 1.0.9
        • IoTConnect Node-red 1.0.8
      • Node-RED Subflow
        • Single Device
        • Multiple Device
    • SDKs (Message version 2.1)
      • Python
      • DOT NET (C#)
      • C language
        • IoTConnect Generic C SDK
          • Linux Build Instructions
          • Windows Build Instructions
      • Python 1.1
    • Code Samples
      • Node.js
        • TPM 3.1
        • Standard SDK 3.0
        • Standard
        • TPM
        • Standard SDK 3.0.1
        • Standard 2.0
      • Java
        • Standard
        • Standard 2.0
        • Standard 3.0
      • Python
        • Standard 2.0
        • TPM 2.1
        • Standard 3.0.1
        • Standard
        • TPM
          • TPM 3.0.1
        • TPM 3.0
        • Standard 3.0.2
        • Standard 3.0.3
        • Standard 3.0.4
        • Python SDK
      • iOS
        • ios1.0.1
      • C Language
        • nRF9160 DK
        • STM32L4
        • ESP32
        • Standard 3.0
        • Standard 2.0
        • Standard 3.1
      • Android
        • Standard 3.0
        • Standard 2.0.6
        • Standard 2.0.0
      • DOT NET (C#)
        • Standard
        • Standard 2.0
        • Standard 3.0
    • Device Message 1.0
      • D2C (Device to Cloud)
        • IoTConnect SDK
        • Custom SDK
      • C2D (Cloud to Device)
        • IoTConnect SDK
        • Custom SDK
      • Troubleshooting & Response codes
      • Know Your Essentials
    • Device Message 2.1
    • AWS Device Message 2.1
    • SDK Deep-diving
Download PDF

ESP32

Card Image

C Language SDK

Version 2.2.0

Release On 11/21

ESP32/ ESP8266 Board – Sample Code of SDK

# Date Name Download
1 02/09/2020 ESP32/ESP8266 SDK 2.2.0 Download
2 02/09/2020 ESP32/ESP8266 Gateway SDK 2.2.0 Download

How to run a C sample code ESP32/ ESP8266 Board ?

Prerequisite tools:

  1. Arduino IDE 1.8.5 or higher (Download)
  2. ESP board installed
    • Open Arduino IDE and click on File > Preferences. In “Additional Boards Manager URLs”
      add below line and click on “OK”:
    • ESP32 device package link “https://dl.espressif.com/dl/package_esp32_index.json”
    • ESP8266 device package link
      “http://arduino.esp8266.com/stable/package_esp8266com_index.json”
  3. Now go to Tools > Board > Boards Manager
    • Enter “ESP32” and click on Install button “esp32 by Espressif System version 1.0.4 ” or
      higher version
    • Enter “ESP8266” and click on install button “esp8266 by ESP8266 community version
      2.4.2” or higher version
  4. Selection of board
    • ESP32 : Tools > Board > DOIT ESP32 DEVKITV1 (or else which you are using )
    • ESP8266 : Tools > Board > Nodemcu 1.0 (or else which you are using )
  5. Libraries installation : You can open Sketch > include library > manage libraries.. in Arduino IDE. When you
    install ESP board in IDE mortally all required libraries will install as per device. You need to install
    ArduinoJson version(6.13.0)

Installation:

  1. Download and Extract the “iotconnect-C-sdk-ESP-2.2.0.zip” file
  2. Using Arduino IDE goto respective ESP board folder.
    • iotconnect-C-sdk-ESP-2.2.0/ESP_SDK/ESP32SDK/ESP32
    • iotconnect-C-sdk-ESP-2.2.0/ESP_SDK/ESP8266SDK/ESP8266
  3. Configuration guide documentation for Arduino and ESP boards. On above path you can find the reference document
    which is as below:

    • ESP32-With-the-Arduino-IDE.doc
    • ESP8266-With-the-Arduino-IDE.doc
  4. You can take the firmware file from step #2 file path
    • ESP32 : ESP32.ino
    • ESP866 : ESP8266.ino
  5. Add prerequisite input data in above file as explained in the usage section as below. Also enter proper
    attribute/sensor name which has associated to the device.
  6. Ready to go with following step.
    • Using Arduino IDE click on “Upload” button or else press “ctrl + u”

Usage:

Prerequisite input data

String ENV        = "IoTConnectENV"; // IoTConnect platform Environment
String cpId       = "yourCpid";  // your CPID name can grab it from IoTConnect portal
String uniqueId   = "yourUniqueID";  // your UniqueID name can grab it from IoTConnect portal
char *ssid        = "yourNetwork";  // your network SSID (name)
char *pass        = "secretPassword";  // your network password (use for WPA, or use as key for WEP)

To get the device information and connect to the device

client.InitializationSDK(cpId, uniqueId, CallBack, TwinCallBack, ENV); 
    

To receive the command from Cloud to Device(C2D)

void CallBack(String &topic, String &payload) {        
    String cmd_ackID="";   String Cmd_value="";
    int Status = 0,mt=0;
    Serial.println("Cmd_msg >>  " + payload);    
    StaticJsonDocument<512> in_cmd;   
    deserializeJson(in_cmd, payload);
    cmd_ackID = in_cmd["ackId"].as();  
    Cmd_value = in_cmd["cmdType"].as();
    if(Cmd_value == "0x01" ){Status = 6; mt = 5;}
    else {Status = 7; mt = 11;}     
    StaticJsonDocument<400> Ack_Json; 
        Ack_Json["ackId"] = cmd_ackID;                                 
        Ack_Json["st"] = Status;
        Ack_Json["msg"] = "";
        Ack_Json["childId"] = "";
    String Ack_Json_Data;
    serializeJson(Ack_Json, Ack_Json_Data);
    
    // Sending ACk of command with Json(String), msg Type(int) and Current Time(String)  
    client.SendAck(Ack_Json_Data, GetTime(), mt);
    in_cmd.clear();    Ack_Json.clear();  
}

Data input format

DynamicJsonDocument  Attribute_json(2048);                                 
    JsonArray Device_data = Attribute_json.to();             
    JsonObject Device_01 = Device_data.createNestedObject();                 
    Device_01["uniqueId"] = uniqueId;                                          
    Device_01["time"] = GetTime();                                             
    JsonObject D01_Sensors=Device_01.createNestedObject("data");               
        D01_Sensors["Humidity"] = random(20, 80);                              
        D01_Sensors["Temperature"] = random(12, 32);                            
    JsonObject D01_SensorsV = D01_Sensors.createNestedObject("vibration");      
        D01_SensorsV["x"] = random(12,  50);                                    
        D01_SensorsV["y"] = random(-20, 30);                                    
        D01_SensorsV["z"] = random(10,  35);                                      
String Attribute_json_Data;                                                     
serializeJson(Attribute_json, Attribute_json_Data);

To send the data from Device To Cloud(D2C)

client.SendData(Attribute_json_Data); 

To receive the twin from Cloud to Device(C2D)

void TwinCallBack(String &topic, String &payload) {          
    Serial.println("Twin_msg >>  " +topic + " " + payload);       
    //TO update the twinproperty                              
    client.UpdateTwin(key,value);
}

Get all the Twin property from the cloud to your device.

client.getAllTwins();

Disconnects IoTConnect SDK using Dispose Method.

client.dispose();

Powered by Softweb – An Avnet Company.

Copyright ©2022 Avnet, Inc. All rights reserved.

Human Rights Privacy Terms of Use