Control an ESP32 With Sensora Cloud

by PavloA1 in Circuits > Microcontrollers

98 Views, 0 Favorites, 0 Comments

Control an ESP32 With Sensora Cloud

Tutorial: Control ESP32 LED with Sensora Cloud

Control the built-in LED light of a Lolin C3 mini using Sensora cloud.

Supplies

lolin.jpg

Lolin C3 mini: https://www.aliexpress.com/item/1005004740051202.html

Install PlatformIO and Setup Project

setup.jpg
  • Install VSCode and the PlatformIO extension

Setup a New Project

platformIO.jpg
  • Launch PlatformIO: From the VSCode sidebar, click on the PIO Home and select "Create New Project".
  • Project Configuration:
  • Name: Choose a name that reflects the purpose of your project.
  • Board: Look for and select 'WEMOS LOLIN C3 Mini'.
  • Framework: Select 'Arduino' because itโ€™s user-friendly and widely used.


LED Blink - Example Code

setupCode.jpg
  • Open platformio.ini file
  • Add the following 3 lines:
lib_deps = https://github.com/sensora-io/sensora-library
monitor_speed = 115200
monitor_raw = true


In the src/main.cpp file paste these lines of code

#include <Arduino.h>
#include <SensoraEsp.h>


void handleLedMessage(PropertyValue& val) {
  if (val.Bool()) {
    SENSORA_LOGI("turn ON");
    neopixelWrite(BUILTIN_LED, 0, 0, 255);
  } else {
    SENSORA_LOGI("turn OFF");
    neopixelWrite(BUILTIN_LED, 0, 0, 0);
  }
}


Property ledProperty("led", "Room LED");
void setup() {
  Serial.begin(115200);
  ledProperty.setDataType(DataType::Boolean)
      .setAccessMode(AccessMode::Write)
      .subscribe(handleLedMessage);


  pinMode(LED_BUILTIN, OUTPUT);
  Sensora.setup();
}


void loop() {
  Sensora.loop();
}

Build Your Project

build.jpg

Save the file and build the project to make sure there are no errors. Once the build is correct, proceed with uploading the code to the device. Make sure device is already connected via USB-C cable with your machine.

Setup Sensora Cloud

Sensora new proj.jpg
token.jpg
  • Go to sensora.io and create an account.
  • Create a New project and go through the setup process
  • Save your Device ID and Token in a secure place. You'll need them to configure your device later

Device Provision

device.jpg
connectDevice.jpg
wifiPass.jpg
deviceCredentials.jpg
  • Click Setup device to open the provision modal
  • Click Connect and the Serial popup will open. Select the same Serial port that the ESP32 is connected to.
  • Confirm the selection by clicking Connect.
  • Provide WiFi SSID (WiFi name) and WiFi password. Click Next and wait for connection.
  • Provide the Device Token that you stored before.


Create Widget

widget.jpg
widget2.jpg
widget3.jpg
  • Go to the Dashboard tab and click New Widget +
  • In the Interactive tab select the Switch widget
  • Fill in all the info and click Create

Congratulations!

ledOn.jpg

You have successfully created your IoT project using Sensora cloud. You can toggle the Switch widget On & Off and see the LED turning on & off instantly on your microcontroller.


Thank you! ๐Ÿ™