Configurations

You can't find any IoT device which doesn't need to configure for operations. There are many cases you should configure your device to work. The simplest example is WiFi credentials or IP configuration of the network, sometimes you need to set up IoT server address, etc. OTAdrive configuration service provides a simple json object as configuration. You don't have to recompile and update your firmware to just change a parameter for your customer. For example in our LED blinker project, we shouldn't recompile our firmware just to change the blinking speed. Blinking speed could be a configurable parameter and we can just fetch new parameters from OTAdrive.

Define first configuration

The configuration service is an rest api let device to fetch the parameters you defined. To define a configuration go to configurations tab of your product and click [+] button.
OTA drive configuration page

Enter a name and description for your configuration then enter your field in json format.
OTAdrive configuration new dialog

Now you should set this configuration to your deviceGroup , goto device group tab and select configuration for your group then click on save button. OTAdrive configuration set

Check the result

It's test time, just replace your APIkey and device serial in followin url and open it in your browser.

http://otadrive.com/deviceapi/config/k=xxx&s=yyy

OTAdrive configuration set

Custom Fields

OTAdrive allows making some fields in your configuration JSON as custom fields. A custom field is a JSON property that could be different for each device in the same group. For example, it's useful for WiFi credentials.
You can do this simply by defining the value of the JSON property in the following format. In the following example the FieldA will pass as abcd to all devices in the group instead you change it for a device.

{
    "FieldA":"<!--abcd-->"
}

Lets check a real example of custom field usage. Here you have some common properties in your IoT product, now you may have to change some fields (mostly SSID and Password) on some devices. This could be done by defining the configuration as bellow. OTAdrive configuration set

Now you can change custom fields (WiFi SSID and Password) by clicking on the GEAR button in the devices table.
OTAdrive configuration set

Coding

You cand check our code example repository for ESP32, here and ESP8266 here.

Get configs from the server

You can get the configuration of your device by call the OTADRIVE.getConfigs() method simply. The following code shows you how to get the configurations and use it in your program.

void updateConfigs()
{
  String payload = OTADRIVE.getConfigs();
  DynamicJsonDocument doc(512);
  deserializeJson(doc, payload);

  Serial.printf("http content: %s\n", payload.c_str());

  if (doc.containsKey("onDelay") &&
      doc.containsKey("offDelay"))
  {
    onDelay = doc["onDelay"].as<int>();
    offDelay = doc["offDelay"].as<int>();
    saveConfigs();
  }
}

Secure Configurations

Please check here for ESP32
Please check here for ESP8266