Book A Demo Now

Getting Started with ESP32 Arduino and ByteBeam Part 4 - Cloud Logging and Remote Debugging

Getting Started with ESP32 Arduino and ByteBeam Part 4 - Cloud Logging and Remote Debugging
Learn to publish and monitor logs on Bytebeam

In Earlier parts of this getting started guide, we understood some basic concepts of bytebeam cloud that can be very helpful for your IoT application.

  • In Part 1 we set up the bytebeam cloud console and Arduino SDK.
  • In Part 1 we also created a simple touch application  and created a dashboard in the bytebeam cloud
  • In Part 2 we created a bin for new firmware and performed over-the-air firmware updates on our ESP32 device.
  • In Part 3 we created an action on Bytebeam cloud to toggle the led on ESP32

Within this article, we will be focusing on remote debugging and cloud logging using the Bytebeam cloud.

logging and remote debugging using Bytebeam

Bytebeam offers this cool feature to monitor device logs. Next, we will guide you through the procedure to enable logging functionality and monitor device logs using the bytebeam cloud using the following simple steps.

  • Configuring Bytebeam logs on ESP32: We will go through configuring bytebeam logs on ESP32 and we will understand various logging APIs.
  • Configuring Log Stream on Bytebeam cloud: We will go through the process of creating a new stream for logs in bytebeam cloud.
  • Creating Dashboard to monitor logs: We will learn to create a dashboard and Log panel bytebeam cloud.

So let's get started.

Hardware Requirements

  • ESP 32 dev module

Configuring bytebeam logs in ESP32

  • Navigate to File->Examples->BytebeamArduino->CloudLogging.
  • First, to configure WiFi credentials navigate to arduino_secrets.h. and change your WiFi SSID and WIFi Password.
  • Then in CloudLogging.ino Define TAG for your logs.
const char* TAG = "BYTEBEAM_CLOUD_LOGGING_SKETCH";
  • In setup(), call setupWiFi() function to connect to your provided WiFi credentials
void setupWifi() {
  // set the wifi to station mode to connect to a access point
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID , WIFI_PASSWORD);

  Serial.println();
  Serial.print("Connecting to " + String(WIFI_SSID));

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(250);
  }

  Serial.print("Connected to " + String(WIFI_SSID) + ", Got IP address : ");
  Serial.println(WiFi.localIP());
}
  • Next call syncTimeFromNtp() to sync time with NTP.
void syncTimeFromNtp() {
  // sync the time from ntp server
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
  struct tm timeinfo;

  // get the current time
  if(!getLocalTime(&timeinfo)) {
    Serial.println("Failed to obtain time");
    return;
  }

  // log the time info to serial :)
  Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
  Serial.println();
}
  • call Bytebeam.begin() to begin Bytebeam client.
  • Bytebeam provides logging APIs to send logs to the cloud. isCloudLoggingEnabled() API checks whether the logging functionality is enabled or not.
// check if cloud logging is enabled or disabled for your device
  bool cloudLoggingStatus = Bytebeam.isCloudLoggingEnabled();
  • enableCloudLogging() API enables cloud logging feature.
Bytebeam.enableCloudLogging() // enables cloud logging
  • disableCloudLogging() API disables the cloud logging feature
Bytebeam.disableCloudLogging(); //disable cloud logging
  • getLogLevel() API gets the current log level
int current_log_level = Bytebeam.getLogLevel();
  • setLogLevel() API sets the log level.
  • Each log message can be associated with the following log level
    • BYTEBEAM_LOG_LEVEL_NONE
    • BYTEBEAM_LOG_LEVEL_ERROR
    • BYTEBEAM_LOG_LEVEL_WARN
    • BYTEBEAM_LOG_LEVEL_INFO
    • BYTEBEAM_LOG_LEVEL_DEBUG
    • BYTEBEAM_LOG_LEVEL_VERBOSE
  • The default log level is set to INFO. To set the log level to let's say DEBUG, call setLogLevel(log_level)
Bytebeam.setLogLevel(BYTEBEAM_LOG_LEVEL_DEBUG)
  • We can publish logs to Bytebeam cloud using the following API
Bytebeam.logErrorln(TAG, "Error Log");		// to send error logs
Bytebeam.logWarnln(TAG, "Warn log");		// to send warn logs
Bytebeam.logInfoln(TAG, "Info Log");		// to send info logs
Bytebeam.logDebugln(TAG, "Debug Log");      // to send debug logs       Bytebeam.logVerboseln(TAG, "Verbose Log");  // to send verbose logs
  • Now upload your example

In the next section, we will configure the logs stream and will monitor logs on the Bytebeam dashboard.

Configuring Log Stream on Bytebeam cloud

  • 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, Add tag, level and message keys with string as their respective data types and logs as your Table Name. In this example, we are using the following data keys:
    • tag: TAG for your logs.
    • level: Log Level
    • message: log message.

Creating a Dashboard

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

  • Add a title to your dashboard like we have given the title ESP32logDashboard. Select Device Dashboard from the Dashboard Type dropdown and leave other columns as defaults.
  • Now Navigate to the Dashboards tab. Click on the dashboard title and then click on the Select button to select the device.
  • Click on the Panel button to add visualizations.
  • Select from different panels available. Like we are choosing logs.
  • Give a name to your panel in the Title. select the table (logs in our case) from the Table drop-down.  now your log table will look like this. Click on the Show search bar toggle button to show the search bar. and Hit Submit.
  • Now go back to your dashboard and click on the Save icon to save your changes. Here you will find the log panel. In the log panel, you can monitor your logs for your respective device id.

Conclusion

I hope you find this tutorial useful. Check out our other guides on Data visualization, OTA, and Handling actions as well. In Part 5 of this multi-part series, we will be exploring the update configuration option provided by ByteBeam.

I hope you gained valuable insights from this comparison summary. As we continue to come up with more interesting tutorials and maker content, we invite you to explore Bytebeam further and see how our platform can empower your projects.