You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ToggleLED.ino example doesn't work both in Arduino IDE and Platformio.
It simple because there is no explanation on the examples given. I recommend adding comment on each line of the code.
The code is fairly simple but no explanation or comment, so the Bytebeam.begin() function doesn't work and I don't to pass as argument.
Arduino-ESP32 Version
ESP32 WROOM 32E
Bytebeam Arduino SDK Version
bytebeamio/BytebeamArduino@^1.0.1
IDE Name
Both Arduino IDE and Platformio
Operating System
Win10
Problem Description
No explanation on how to use the code.
Sketch
#include<time.h>
#include<WiFi.h>
#include<BytebeamArduino.h>
#include"arduino_secrets.h"// on board led pin number
#defineBOARD_LED15// led state variableint ledState = 0;
// wifi credentialsconstchar* WIFI_SSID = SECRET_SSID;
constchar* WIFI_PASSWORD = SECRET_PASS;
// sntp credentialsconstlong gmtOffset_sec = 28800; // GMT + 5:30hconstint daylightOffset_sec = 0;
constchar* ntpServer = "pool.ntp.org";
// function to setup the wifi with predefined credentialsvoidsetupWifi() {
// 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));
// wait till chip is being connected to wifi (Blocking Mode)while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(250);
}
// now it is connected to the access point just print the ip assigned to chip
Serial.println();
Serial.print("Connected to " + String(WIFI_SSID) + ", Got IP address : ");
Serial.println(WiFi.localIP());
}
// function to sync time from ntp server with predefined credentialsvoidsyncTimeFromNtp() {
// sync the time from ntp serverconfigTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
structtm timeinfo;
// get the current timeif(!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();
}
// function to setup the predefined ledvoidsetupLED() {
pinMode(BOARD_LED, OUTPUT);
digitalWrite(BOARD_LED, ledState);
}
// function to toggle the predefined ledvoidtoggleLED() {
ledState = !ledState;
digitalWrite(BOARD_LED, ledState);
}
// function to get the time unsignedlonglonggetEpochMillis() {
time_t now;
structtm timeinfo;
// get the current time i.e make sure the device is in sync with the ntp serverif (!getLocalTime(&timeinfo)) {
Serial.println("failed to obtain time");
return0;
}
// get the epoch timetime(&now);
// generate the epoch millisunsignedlonglong timeMillis = ((unsignedlonglong)now * 1000) + (millis() % 1000);
return timeMillis;
}
// function to publish payload to device shadowboolpublishToDeviceShadow() {
staticint sequence = 0;
unsignedlonglong milliseconds = 0;
char ledStatus[200] = "";
char deviceShadowStream[] = "device_shadow";
constchar* payload = "";
String deviceShadowStr = "";
StaticJsonDocument<1024> doc;
// get the current epoch millis
milliseconds = getEpochMillis();
// make sure you got the millisif(milliseconds == 0) {
Serial.println("failed to get epoch millis");
returnfalse;
}
// increment the sequence counter
sequence++;
// generate the led status message stringsprintf(ledStatus, "LED is %s !", ledState == true? "ON" : "OFF");
JsonArray deviceShadowJsonArray = doc.to<JsonArray>();
JsonObject deviceShadowJsonObj_1 = deviceShadowJsonArray.createNestedObject();
deviceShadowJsonObj_1["timestamp"] = milliseconds;
deviceShadowJsonObj_1["sequence"] = sequence;
deviceShadowJsonObj_1["Status"] = ledStatus;
serializeJson(deviceShadowJsonArray, deviceShadowStr);
payload = deviceShadowStr.c_str();
Serial.printf("publishing %s to %s\n", payload, deviceShadowStream);
return Bytebeam.publishToStream(deviceShadowStream, payload);
}
// handler for ToggleLED actionintToggleLED_Hanlder(char* args, char* actionId) {
Serial.println("ToggleLED Action Received !");
Serial.printf("<--- args : %s, actionId : %s --->\n", args, actionId);
// toggle the ledtoggleLED();
// publish led state to device shadowif(!publishToDeviceShadow()) {
// publish action failed statusif(!Bytebeam.publishActionFailed(actionId, "Publish led state to device shadow Failed")) {
Serial.println("Failed to publish action failed response for Toggle LED action");
}
Serial.println("Failed to publish led state to device shadow");
return -1;
}
// publish action completed statusif(!Bytebeam.publishActionCompleted(actionId)) {
Serial.println("Failed to publish action completed response for Toggle LED action");
return -1;
}
return0;
}
voidsetup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println();
setupWifi();
syncTimeFromNtp();
// setup the gpio ledsetupLED();
// setting up the device info i.e to be seen in the device shadow
Bytebeam.status = "Device is Up!";
Bytebeam.softwareType = "toggle-led-ino";
Bytebeam.softwareVersion = "1.0.0";
Bytebeam.hardwareType = "ESP32 Dev Module";
Bytebeam.hardwareVersion = "rev1";
// begin the bytebeam clientif(!Bytebeam.begin()) {
Serial.println("Bytebeam Client Initialization Failed.");
} else {
Serial.println("Bytebeam Client is Initialized Successfully.");
}
// add the handler for toggle led action
Bytebeam.addActionHandler(ToggleLED_Hanlder, "ToggleLED");
}
voidloop() {
// put your main code here, to run repeatedly:// bytebeam client loop
Bytebeam.loop();
// hold on the execution for some timedelay(5000);
}
Debug Message
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
BytebeamLogger::LOG_ERROR (BytebeamArduino) loop : Bytebeam Client is not Initialized.
BytebeamLogger::LOG_ERROR (BytebeamArduino) loop : Bytebeam Client is not Initialized.
BytebeamLogger::LOG_ERROR (BytebeamArduino) loop : Bytebeam Client is not Initialized.
BytebeamLogger::LOG_ERROR (BytebeamArduino) loop : Bytebeam Client is not Initialized.
BytebeamLogger::LOG_ERROR (BytebeamArduino) loop : Bytebeam Client is not Initialized.
BytebeamLogger::LOG_ERROR (BytebeamArduino) loop : Bytebeam Client is not Initialized.
BytebeamLogger::LOG_ERROR (BytebeamArduino) loop : Bytebeam Client is not Initialized.
BytebeamLogger::LOG_ERROR (BytebeamArduino) loop : Bytebeam Client is not Initialized.
More Information
Give a short comment on each function and their parameters in the example.
Before even someone try to use the code, it should have a description of the what the code does and how to use it.
The text was updated successfully, but these errors were encountered:
Board
ESP32 DEV Board in plaformio
Device Description
The ToggleLED.ino example doesn't work both in Arduino IDE and Platformio.
It simple because there is no explanation on the examples given. I recommend adding comment on each line of the code.
The code is fairly simple but no explanation or comment, so the Bytebeam.begin() function doesn't work and I don't to pass as argument.
Arduino-ESP32 Version
ESP32 WROOM 32E
Bytebeam Arduino SDK Version
bytebeamio/BytebeamArduino@^1.0.1
IDE Name
Both Arduino IDE and Platformio
Operating System
Win10
Problem Description
No explanation on how to use the code.
Sketch
Debug Message
More Information
Give a short comment on each function and their parameters in the example.
Before even someone try to use the code, it should have a description of the what the code does and how to use it.
The text was updated successfully, but these errors were encountered: