Getting Started
Prerequisites
Before you begin, ensure you have the following:
A Uniot-compatible device (e.g., ESP8266/ESP32 or Arduino-based hardware).
A computer with internet access.
Basic familiarity with IoT concepts (optional but helpful).
Installing Uniot Core Firmware
The best way to get started with Uniot Core is to install it via PlatformIO. Here’s how to proceed:
Create a new PlatformIO project or open an existing one.
When configuring your
platformio.inifile for Uniot Core, pay attention to the following important details:Uniot-Core Dependency Installation: Ensure you include the
uniot-corelibrary in thelib_depssection to integrate Uniot's core features. Specify the version explicitly (e.g.,uniot-io/[email protected]) to maintain compatibility.Setting Build Flags: Use the
build_flagssection to customize the firmware behavior. Key flags include:-D UNIOT_USE_LITTLEFSto specify the file system (e.g., LittleFS or SPIFFS by default).-D UNIOT_CREATOR_IDfor identifying the firmware creator.-D MQTT_MAX_PACKET_SIZEto adjust MQTT buffer size if necessary.-D UNIOT_LISP_HEAPto adjust the memory size of UniotLisp environment-D UNIOT_LOG_ENABLEDand-D UNIOT_LOG_LEVELfor enabling and configuring logging levels.
Microcontroller Selection: Define separate environments for each supported microcontroller model. For example:
ESP12Efor ESP8266-based boards.ESP32for ESP32 boards.ESP32C3for ESP32-C3 boards with USB-specific configurations.
Platform and Framework: Ensure that the
platformandframeworksettings match your microcontroller (e.g.,espressif8266for ESP8266 orespressif32for ESP32).Filesystem Configuration: Use the
board_build.filesystemsetting (e.g.,littlefs- ifUNIOT_USE_LITTLEFSis set to1) to specify the filesystem type supported by Uniot Core.Default Environment: Set the
default_envsto the environment corresponding to your primary microcontroller (e.g.,ESP12E).USB and Debug Settings (Optional): For certain devices like the
ESP32C3, additional USB-specific flags may be required, such as-D ARDUINO_USB_MODE=1.
By carefully customizing these parameters, you can ensure that your development environment is optimized for Uniot Core.
[platformio]
default_envs = ESP12E
[env]
board_build.filesystem = littlefs
monitor_speed = 115200
lib_deps =
    uniot-io/uniot-core@^0.8.1
build_unflags =
    -std=gnu++11
build_flags =
    -std=gnu++17
    -D UNIOT_USE_LITTLEFS=1
    -D UNIOT_CREATOR_ID=\"UNIOT\"
    -D MQTT_MAX_PACKET_SIZE=2048
    -D UNIOT_LOG_ENABLED=1
    -D UNIOT_LOG_LEVEL=4
[env:ESP12E]
platform = espressif8266
framework = arduino
board = esp12e
[env:ESP32]
platform = espressif32
framework = arduino
board = esp32doit-devkit-v1
[env:ESP32C3]
platform = espressif32
framework = arduino
board = esp32-c3-devkitm-1
build_flags =
    ${env.build_flags}
    -D ARDUINO_USB_MODE=1
    -D SERIALCONS=USBSerial
    -D ARDUINO_USB_CDC_ON_BOOT=1As an example, we will use the ESP8266 Witty Cloud module. The module’s compact design and onboard LED's and sensors make it ideal for small IoT applications.

The following code demonstrates setting up Uniot Core to manage digital and analog inputs/outputs for this module:
#include <Uniot.h>
using namespace uniot;
// WittyCloud board pin definitions
#define PIN_BUTTON 4
#define PIN_RED 15
#define PIN_GREEN 12
#define PIN_BLUE 13
#define PIN_LDR A0
#define BTN_PIN_LEVEL LOW
#define LED_PIN_LEVEL HIGH
void setup() {
  // Configure WiFi with status LED and reset button
  Uniot.configWiFiStatusLed(PIN_RED, LED_PIN_LEVEL);
  Uniot.configWiFiResetButton(PIN_BUTTON, BTN_PIN_LEVEL);
  Uniot.configWiFiResetOnReboot(5, 10000);
  // Register GPIO pins for Lisp access
  Uniot.registerLispDigitalOutput(PIN_RED, PIN_GREEN, PIN_BLUE);
  Uniot.registerLispDigitalInput(PIN_BUTTON);
  Uniot.registerLispAnalogOutput(PIN_RED, PIN_GREEN, PIN_BLUE);
  Uniot.registerLispAnalogInput(PIN_LDR);
  // Initialize and start Uniot
  Uniot.begin();
}
void loop() {
  Uniot.loop();
}This example showcases how to utilize Uniot Core features like managing digital/analog IOs and configuring WiFi. The Witty Cloud module’s capabilities, including onboard LEDs and a button, allow for a seamless testing environment.
After successful compilation, connect your device to your computer via USB.
Ensure your device is in bootloader mode before initiating the flashing process. For ESP8266, you may need to press and hold the FLASH button during power-up to enter the correct mode. Use commands like
pio run --target uploadto simplify the process with PlatformIO.
Adding Devices to the Platform
Open the Uniot Platform on your browser.
Create an account or log in if you already have one.
To add a new device to the Uniot Platform, navigate to the Devices page, click the “Add new device” button, and follow instructions.
After adding and authorising the device, you can deploy an automation script on it.
Your First Automation Script
For an easy start, navigate to the Sandbox page and locate the welcome script titled “My First Script”.

This visual script generates the following code, which is executed directly on the device:
;;; begin-user-library
;; This block describes the library of user functions.
;; So the editor knows that your device implements it.
;
; (defjs bclicked (button_id)) ;-> Bool
; (defjs dwrite (pin state)) ;-> Bool
;
;;; end-user-library
(define state ())
(setq state ())
; Runs the task every '50' ms. Since 'times' is '0',
; it runs indefinitely. The context is released after
; each run, allowing other processes to run smoothly.
(task 0 50 '
 (list
  ; If the button '0' is clicked, emit an event 'led' to toggle state.
  (if
   (bclicked 0)
   (list
    (push_event 'led
     (not state))))
  ; When the ‘led’ event is triggered, set ‘state’ to the received
  ; value and write to pin ‘0’, driving the LED accordingly.
  (if
   (is_event 'led)
   (list
    (setq state
     (pop_event 'led))
    (dwrite 0 state)))))This script uses several blocks to demonstrate key concepts of automation:
State Variable Initialization: The block initializes a
statevariable asfalse. This variable tracks the LED's on/off status.Run Task Block: Configured to run every 50 milliseconds indefinitely (as the
timesparameter is set to0), ensuring the script continuously checks button activity and event triggers.Button Check Block: Monitors if the button (that occupies the register with index
0, for details check the list of registers, which can be found in the device information on the Devices page) is clicked. When clicked, a global event namedledis generated. This event can be heard by other devices in the network as well as by the dashboard, emitted with the toggled state value (not state).Event Trigger Block: Responds to the
ledevent by updating thestatevariable to the event's value and writing the new state to pin with registered index0, controlling the LED.
Last updated