What is a Configuration

A configuration is a set of parameters you've defined to control your IoT device behavior. For example, you want to enable/disable a feature on your device or customize its behavior for some customers or zones. Some popular configurations are shown in the following table as example:

  • Enable/Disable debug mode
  • WiFi SSID and Password
  • Change delay/timing of some operations
  • Select UI Language
  • etc.

OTAdrive presents the configuration parameters as a JSON object to the device. This object could have any data type and nested objects.

// example configuration
{
    "DebugMode":false,
    "DelayAfterDoorClose":2500,
    "WelcomeText":"Hello User!",
    "Melody":[250,45,68,78,45,45,45,78,1222,12,255,78]
}

Config Service

The OTAdrive lets you create unlimited configurations in your product's [Configurations] section. Each configuration can have thousands of config parameters in JSON format. You can assign none or one configuration for each group. Then, all devices in the group will see the parameters as defined in the configuration set.

When a device asks the server for the config, it sends its serial number to the OTAdrive. The OTAdrive will return the config JSON of the group you've assigned. So, you can change the configuration of all devices in a group with just a single click.

ota-device-groups

Custom Fields

Sometimes, you need different config property values for each device. For example, you may have generic Wi-Fi credentials for all devices, But some devices need to be different, in case. Here is where you need custom fields. A custom field is a property in your JSON you can set with a different value for each device in the group.

To convert a normal field to a custom field just use the following format as the value of your field.

{
    "FieldA":"<!--1122-->",
    "FieldB":"<!--ABCD-->",
    "FieldC":"<!--DEFAULT VALUE-->",
}

When you define a custom field, you can see it immediately on the right side of the window. Each custom field should have a default value. The default value is the value the device sees if you don't overwrite it. If you don't set a custom field for a device, the device will receive the default value when it asks for config from the OTAdrive.

ota-device-groups

You can define a config with multiple normal fields (fixed value) combined with several custom fields.

ota-device-groups

{
    "DebugMode":false,
    "DelayAfterDoorClose":"<!--2500-->",
    "WelcomeText":"<!--Hello User!-->",
    "Melody":[250,45,68,78,45,45,45,78,1222,12,255,78]
}

Assign Config

Assign configurations to a group just like you do it for firmware. You can open group assignments (Firmware,Config,Resource) from multiple forms. There are two common way.

  1. Go to [Groups] section and click one of the assignments badges.
    Open OTA Product
  2. Go to [Groups] then open your group, click one of the assignments badges or Change button.
    Open OTA Product

Set Custom Field

To change a custom field for a device, just find it in one of the devices tables (in all devices page, product's devices list or group's devices list), then click on the [GEAR] ⚽ button to open the custom field window for the device.

ota-device-groups

Coding

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();
  }
}