# Arduino Library

OTAdrive Arduino library provides all features of our service with user friendly interface. The library exists on both GitHub repository (opens new window) and PlatformIO registry (opens new window).

ESP8266 HTTP server

# Installation

# Install on PlatformIO

To install the library on PlatformIO project you find the project in PIO library manager and add it to your project.

PlatformIO add library OTAdrive

Or you can simply add following line in lib_deps section of the platfomrio.io file:

lib_deps =
   otadrive/OTAdrive

# Install on Arduino IDE

You could find OTAdrive library on library manager and add it to your project.

Arduino IDE add library OTAdrive

# Methods

Bellow is the list of OTAdrive library.

Method Description Parameters
setInfo Set general information of your firmware. You should call this method first. ApiKey,Version
updateFirmware Updates firmware from the OTAdrive server, if a newer version available. -
syncResources Sync SPIFFS files with the OTAdrive server -
setFileSystem Sets the fileSystem object. You have to call it before use syncResources() -
getConfigs Gets device configuration as string -

# Usage

You can find a complete example Here (opens new window). The library is compatible with ESP32 and ESP8266 with no action, just include otadrive_esp.h and start to use our service like charm.

The following code shows all features of this library:

// retrive firmware info from OTAdrive server
updateInfo inf = OTADRIVE.updateFirmwareInfo();
// update firmware if newer available
if (inf.available)
{
  Serial.printf("\nNew version available: %s, %dBytes\n",inf.version.c_str(), inf.size);
  OTADRIVE.updateFirmware();
}
else
{
  Serial.println("No newer version");
}

// sync local files with OTAdrive server
OTADRIVE.syncResources();
// list local files to serial port
listDir(FILESYS, "/", 0);

// get configuration of device
String c = OTADRIVE.getConfigs();
Serial.printf("\nconfiguration: %s\n", c.c_str());

# setInfo(String ApiKey, String Version)

You have to call setInfo once and before any usage of OTAdrive library.

void setup()
{
  ...
  // Set ApiKey and version of firmware
  OTADRIVE.setInfo("c0af643b-4f90-4905-9807-db8be5164cde", "2.5.5");
}

# updateFirmware()

This method calls update firmware API and updates your ESP8266/ESP32 firmware if a newer(different) version available on the OTAdrive server. You can show the update progress to users by using onUpdateFirmwareProgress event.Read more

OTADRIVE.updateFirmware();

# syncResources()

This method calls resource API and download new files from server to local storage (SPIFFS or LittleFS). If you modify files on server, this method detects changes and replace old file with modified file. Read more

// sync local files with OTAdrive server
OTADRIVE.syncResources();

# getConfigs()

This method calls configuration API and get configuration of device from server. Read more

String c = OTADRIVE.getConfigs();
Serial.printf("configuration: %s\n", c.c_str());