Getting Started with ESP32 IDF and Bytebeam Part 1 - Data Visualization

Getting Started with ESP32 IDF and Bytebeam Part 1 - Data Visualization
Learn about managing IoT devices and visualising device data using Bytebeam cloud

In this multi-part series of tutorials, We will deep dive into the Bytebeam SDK for ESP-IDF. We will get familiar with the concepts of the Bytebeam cloud console and go through different analytics tools provided by Bytebeam. In Part 1 of this tutorial, we will learn about the following:

  • Getting Started with Bytebeam cloud
  • Device provisioning on Bytebeam cloud.
  • Setting up Bytebeam SDK for ESP-IDF.
  • Data Visualization using ByteBeam cloud.

In this tutorial, We will use ESP32 to compile our example. ESP32 comes with capacitive touch GPIOs which can sense human touch. So, we will read and visualize touch sensor data using bytebeam dashboard.

Hardware Requirements

Getting Started with ByteBeam cloud

Firstly, you need to create an account on Bytebeam Cloud (cloud.bytebeam.io). In case you already have an account with Bytebeam Cloud then you can proceed further with this guide or else follow Getting started with Bytebeam cloud.

Creating a new project

  • Login to your Bytebeam account to access the cloud console.
  • Now create a New Project and give it a name. I have given it the name “esp32Demo
  • In the next screen, you will be asked to select the project. Select the newly created project and proceed further

Provisioning a new device

Click on Create Device button to provision a new device to Bytebeam cloud. And hit Submit.


  • As you hit submit in the prompt. A new JSON file will be downloaded which contains the authentication certificate, broker, device_id, and project id. You need to save this file in the ESP file system. We will talk about this in a later section. The JSON will look like this.
{
 "project_id": "****",
 "broker": "******",
 "port": 8883,
 "device_id": "**",
 "authentication": {
      "ca_certificate":*"*********",
      "device_certificate": "**********",
      "device_private_key": "***********"
      }
}
  • Now you can find the newly created device in the console. The provisioned device will have the following columns
    • id: This column shows the device id of the provisioned device.
    • Last Heartbeat: last online status of the device.
    • Device Shadow: latest data received from the remote device.
    • MetaData: Device Metadata, this gives information about device data like customer id, organization id, and others as desired by the user
    • Last Action: This column gives us information about the last action id, last action status, its progress and type.
    • Operations: From this column, we can download the device provision JSON file.

Configuring a Stream

  • Next, we need to configure the stream where we will define our data keys and their data types. For this go to Admin in the top right corner and select Streams. You will find the Table Name, Column Name, and Column Type in Streams. Add your data keys in Column Name and respective data types in Column Type. Here I have added state and touch keys with int8 and int16 as their respective data types and device_shadow as your Table Name. In this example we are using the following data keys:
    • sequence: this is a message counter for all the successful publish
    • timestamp: time of message publish
    • status: string message that gives us the status of led.
    • state: state of led.
    • touch: ESP32 touch sensor values.

Now we are all set to configure our hardware to push data to bytebeam cloud. Next, we will set up ESP Bytebeam SDK.

Setting up ByteBeam SDK for ESP-IDF

ByteBeam provides an SDK for ESP IoT Development Framework (IDF) to connect to the ByteBeam cloud platform.  This guide assumes that you have a fair understanding of ESP-IDF and that you had already set up ESP-IDF on your machine. In case you haven’t done this you should follow ESP Getting Started Guide before going further.

Clone Bytebeam ESP SDK

git clone https://github.com/bytebeamio/esp-bytebeam-sdk.git 
  • The Repository contains the following directories
    • components: This directory contains bytebeam_esp_sdk as a component that you can add to your ESP application
    • examples: examples directory contains a list of examples, some of the important ones are
      • touch: This is a capacitive touch example which we are demonstrating in this blog
    • provisioning: example to push device JSON got from bytebeam cloud to SPIFFS.
  • Follow Setting up bytebeam sdk guide to get more information about setting up WiFi configuration and partition table.

Provision ESP32 with device config data

Earlier in this guide, we had provisioned a new device in bytebeam cloud console and downloaded a JSON file. We need to flash this file to SPIFFS to connect our device to the cloud.

  • First, rename the downloaded file to device_config.json.
  • Now navigate to the provisioning example and create a new folder config_data inside it.
  • Put the device_config.json inside config_data.
  • Now open ESP-IDF terminal and navigate to the provisioning project.
  • Clear entire flash
idf.py erase-flash
  • Once the flash is erased, upload the provisioning example. This will flash the device_config.json file to the device
Idf.py -p PORT flash monitor

Getting ESP32 capacitive touch values

  • Navigate to touch -> main -> app_main.c.
  • include touch sensor driver
#include "driver/touch_pad.h"
  • inside app_main initialize the capacitive touchpad
void app_main(void){
    touch_pad_init()
    //set touch pad voltage
    touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5,      TOUCH_HVOLT_ATTEN_1V);
}
  • raw_touch_values() function read touch values
uint16_t raw_touch_values(){
    uint16_t touch_value;
     for (int i = 0; i < TOUCH_PAD_MAX; i++) {
       touch_pad_read(i, &touch_value);
     }
    return touch_value;
}
  • Add touch and led state values to payload JSON
state_json = cJSON_CreateNumber(led_state);
cJSON_AddItemToObject(device_shadow_json, "state", state_json);
touch_json = cJSON_CreateNumber(touch_value);
cJSON_AddItemToObject(device_shadow_json, "touch", touch_json);
  • Now flash and upload touch example
Idf.py -p PORT flash monitor
  • After flashing ESP32 with touch example. Go to bytebeam cloud console
  • In Device Management tab you can see updated Device Shadow and Last Heartbeat.

Creating a Dashboard

Now let’s create a dashboard to visualise our data. Click on Dashboards in bytebeam console. And then click on Create Dashboard.

  • Add a title to your dashboard like we have given a title ESP32touchDashboard. and leave other columns as defaults.
  • Now Navigate to the Dashboards tab. And click on the dashboard title.
  • Click on the Panel button to add visualizations.
  • Select from different panels available. Like we are choosing Line Chart.

  • Give a name to your panel in the Title. select table (device_shadow in our case) from the Table drop-down. select a column (touch in our case) from the Column dropdown. and select max from the third drop-down. now your graph will look like this.

  • Like this, you can create multiple visualizations at a user-defined refresh period for your dashboard. We are getting values every second from the device and we are updating the dashboard every 5s. So even sensitive information like touch can be plotted in a graph.

Conclusion

I hope you find this tutorial useful. We will come up with other interesting features offered by ByteBeam like OTA, remote debugging, actions and notifications, and more. In Part 2 of this multi-part series, we will be exploring the remote OTA option provided by ByteBeam. Stay in touch to get information on many other interesting IoT projects.