This section provides step by step instructions on how to set up and start using BytebeamArduino

This guide assumes that you are using ESP32 development board for this integration and the same instructions will work for ESP8266.

Step 1. Getting the SDK

You can install the SDK via Arduino Library Manager. We recommend installing the latest version of the SDK for this integration. Follow the below steps to install the SDK

Open the Arduino Library Manager and search for the bytebeam keyword. The BytebeamArduino SDK will pop up. Go ahead select the latest version (say 1.0.1) and hit the install button.

Now you should be able to see the SDK in the Arduino IDE. See Sketch > Include Library > BytebeamArduino within the Arduino IDE.

You can also look for example sketches that comes along with the SDK. See File > Examples > BytebeamArduino within the Arduino IDE.

Step 2. Device Provisioning

Provision device with device config data

Before you get started with the BytebeamArduino you need to provision your device. Each device has its own config file which needs to be flashed into its file system. When you call the begin method our SDK will look for this device config data and use that in order to establish the secure connection with the remote device at the cloud end.

For this integration we will go with the default configurations. If you want to change the configuration, check out the Advanced SDK Configurations guide.

Note: On ESP32 we use SPIFFS by default but if you are using ESP8266 you should use LITTLEFS by default

Before getting ahead make sure you have the SPIFFS file system partition. For this you can select the partition table setting under Tools section. See Tools > Partition Scheme within the Arduino IDE.

Follow the below steps to provision your device:

  1. Download the device configuration JSON file from Bytebeam cloud by following the Provisioning a Device guide.
  2. After downloading the config file, open it in your favourite text editor and format the json document. Once done copy the formatted json document to the clipboard.
  3. Open SPIFFS Provisioning example sketch as per your choice of file system. See File > Examples > BytebeamArduino > Provisioning > SPIFFSProvisioning within the Arduino IDE.
  4. Paste the copied content to the deviceConfigWriteStr char array, Refer below code snippet to do so.
  5. Setup the ESP32 board configurations and Hit the Upload button.
  6. Watch out the Serial logs for the provisioning status.
char deviceConfigWriteStr[DEVICE_CONFIG_STR_LENGTH] = R"(
{
    "project_id": "espbytebeamsdktest",
    "broker": "cloud.bytebeam.io",
    "port": 8883,
    "device_id": "1",
    "authentication": {
        "ca_certificate": "-----BEGIN CERTIFICATE-----\nMIIFrDCCA5SgAwIBAgICB+\naWExETAPBgNVBAgTCEthcm5hdGFrMRIwEAYDVQQHEwlCYW5nYWxvcmUx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GnnqRt+wjjuzci0rDvFdH\ntaUbjlb4kKStssQPTTmG726Zd1f32eKzBnCY8YqWdMMM1HXak20rPo8CgYEA6PN8\nYIcIrRkFzyvam8m5pCeoHylBgSNjN2j8dGC8b6SGMG6y4+rUiuxfhC/Oq7UtOvf+\njYQQgeMjB22dhcvJa6rjuuKXXpbcgNnzcemnySohUr7Nm1bXHwRfoqMAmeh3pkcL\nL+K4Mf6Gd1i2hiYd4Dd59m5/p3W+QUyKa4iaRP0CgYAf2/UZHyOijSDfW4hJZIs9\n2ypTtuGmi160Vqg33gJj/3M9UmobJcB3BQ6UjXnvRF4R2nMxsYuDVglqn32QEr7M\n6VjS67i2FSc8aKqtQmnpy8NPs/elHAdtq+wlFIRcovnHKj2K8hm8z6CsXqTc4y9+\nI6MNmgRl8kKGNs+iA5ggeQKBgBKLN25zsWQeJtE8G3XlVArWQVLhtN4z0/UYPWiC\nPt3gSfJXDZSJIAxDDsN2DsyqaoRUM4ZOagX878/qkOySsWEJxIEfAo+8EKeNMgzy\nXbHs0aRFnhZsjklgzsAim6ykzcmFxEU2lhUcvtWHUVhSdnRf1iyg1Taeb9vA3Q/8\nWtN9AoGBAN+rik+pvcdPAexngqmsUgoW8Abvv7dyBmt99KfnyRDfbt6EM68CZI90\naOlNE9P7XZyOyfQdzOlJWv8B78dwrbwMiwkhGyb6ms11GGB5J90f8oON4tMjEzdW\nKFI0T+ZOXN99GcKLHeg5GfGqHcHlEhXP9BtRyTJVz914alvOIaiY\n-----END RSA PRIVATE KEY-----\n"
    }
}
)";

Step 3. Initialize and Start Bytebeam Client

The next step is to initialize and start bytebeam client. Refer below code snippet to do so:

// Add this include to your sketch
#include <BytebeamArduino.h>

//
// By including the above header you got the access to the gloabl object named Bytebeam
// Use Bytebeam global object to perform the required operations
//

void setup() {
  // put your setup code here, to run once:

  //
  //  Your application setup stuff goes here
  //

  // Make sure you initialize the wifi and ntp before stepping ahead
  // If you want logging via Serial Monitor, consider initializing the Serial as well
  
  // setting up the device info i.e to be seen in the device shadow
  Bytebeam.status          = "Device is Up!";
  Bytebeam.softwareType    = "setup-wifi-client-ino";
  Bytebeam.softwareVersion = "1.0.0";
  Bytebeam.hardwareType    = "ESP32 Dev Module";
  Bytebeam.hardwareVersion = "rev1";
  
  // This function will initialize and start the bytebeam client
  // You can over-ride the default file system and file name options, if needed
  // eg. Bytebeam.begin(BytebeamArduino::LITTLEFS_FILE_SYSTEM,"/my_device_config.json")
  if(!Bytebeam.begin()) {
    Serial.println("Bytebeam Client Initialization Failed.");
  } else {
    Serial.println("Bytebeam Client is Initialized Successfully.");
  }

  //
  // If above call is successfull then your bytebeam client is now configured for the
  // use. You can always check for the logs in serial monitor for the status of the 
  // above call
  //

  // check if bytebeam client is connected or disconnected
  bool connectionStatus = Bytebeam.isConnected();

  if(!connectionStatus) {
    Serial.println("Bytebeam Client is Disconnected.");
  } else {
    Serial.println("Bytebeam Client is Connected.");
  }

  // Call the end method to stop and de-initialize the bytebeam client at any point of 
  // time in the code
  // Bytebeam.end();
}

void loop() {
  // put your main code here, to run repeatedly:

  //
  //  Your application regular stuff goes here
  //

  // This function will let you maintain the connection with the bytebeam cloud
  // In case the connection is lost, it will attempt to reconnect to the bytebeam cloud
  Bytebeam.loop();

  // software delay, you can customize it as per your application needs
  delay(5000);
}

Look at the SetupClient example sketch for reference. See File > Examples > BytebeamArduino > ESP32 > SetupClient within the Arduino IDE.

Step 4. Build and Flash Application

You can build and flash your application as usual with the Arduino IDE, just setup your board configurations and hit the upload button within the Arduino IDE.