Firmware

RIoT field devices run custom firmware on ESP32 hardware. Each device handles sensor data acquisition, local buffering, and secure upload to the RIoT cloud.

Device Configuration

Each device loads its configuration from a conf.cfg file on the SD card mounted at /sdcard. The file is JSON-formatted and validated at boot. If the configuration is missing or invalid, the device restarts.

Full Configuration Structure

{
  "device_uid": "home-madrid:test-logger-01",
  "connectivity": {
    "type": "wifi",
    "ssid": "YourSSID",
    "password": "YourWiFiPassword"
  },
  "ntp_server": "pool.ntp.org",
  "auth": {
    "api_key": "your-api-key",
    "api_secret": "your-api-secret"
  },
  "cloud": {
    "host": "api.example.com",
    "port": 8443,
    "endpoints": {
      "data_ingest": "/v1/data/ingest",
      "log_ingest": "/v1/device/logs",
      "status_update": "/v1/device/status",
      "config_poll": "/v1/device/config",
      "config_upload": "/v1/device/config/upload",
      "config_ack": "/v1/device/config/ack",
      "config_test_result": "/v1/device/config/test-result",
      "config_rollback": "/v1/device/config/rollback",
      "command_poll": "/v1/device/commands"
    }
  },
  "mtls": {
    "enabled": true,
    "client_cert_path": "/sdcard/certs/client.crt",
    "client_key_path": "/sdcard/certs/client.key",
    "ca_cert_path": "/sdcard/certs/ca.crt",
    "skip_cert_common_name_check": false
  },
  "upload_interval_ms": 100000,
  "upload": {
    "batch_size": 50,
    "max_retries": 3,
    "retry_initial_delay_ms": 1000,
    "retry_max_delay_ms": 30000,
    "retry_backoff_multiplier": 2.0
  },
  "polling_intervals_ms": {
    "config": 300000,
    "commands": 60000
  },
  "config_ota": {
    "rollback_threshold": 3,
    "confirm_threshold": 2
  },
  "sensors": [
    {
      "type": "sht4x",
      "name": "ambient_temp_rh",
      "enabled": true,
      "sample_frequency_ms": 5000,
      "params": {
        "i2c_port": 0,
        "i2c_address": 68,
        "precision": "high"
      }
    }
  ]
}

Field Reference

FieldTypeDescription
device_uidstringUnique device identifier. Max 64 characters.
connectivity.typestringConnection type. Currently "wifi".
connectivity.ssidstringWiFi network name. Max 32 characters.
connectivity.passwordstringWiFi password. 8-63 characters.
ntp_serverstringNTP server hostname for RTC synchronization.
auth.api_keystringAPI key for backend authentication. Max 128 characters.
auth.api_secretstringAPI secret for backend authentication. Max 128 characters.
cloud.hoststringBackend API hostname. Max 253 characters.
cloud.portintBackend API port.
cloud.endpoints.*stringAPI endpoint paths. Max 512 characters each.
mtls.enabledboolEnable mutual TLS for device-to-cloud communication.
mtls.client_cert_pathstringPath to PEM client certificate on SD card.
mtls.client_key_pathstringPath to PEM client private key on SD card.
mtls.ca_cert_pathstringPath to PEM CA certificate for server validation.
upload_interval_msuint64Interval between upload batches (1,000 - 86,400,000 ms).
upload.batch_sizeuint32Records per upload batch (1 - 500). Default: 50.
upload.max_retriesuint32Maximum retry attempts per batch (0 - 10). Default: 3.
upload.retry_backoff_multiplierfloatExponential backoff multiplier (1.0 - 5.0). Default: 2.0.
polling_intervals_ms.configuint64Config OTA poll interval (60,000 - 86,400,000 ms).
polling_intervals_ms.commandsuint64Command poll interval (1,000 - 3,600,000 ms).
config_ota.rollback_thresholduint8Consecutive boot failures before config rollback. Default: 3.
config_ota.confirm_thresholduint8Successful boots to confirm config as known-good. Default: 2.
sensorsarraySensor definitions. Max 40 sensors.

Sensor Configuration

Each entry in the sensors array defines a sensor driver instance:

FieldTypeDescription
typestringSensor driver type. Must match a registered factory type.
namestringUnique sensor name. Used in readings and SD storage.
enabledboolWhether the sensor is active. Disabled sensors are skipped.
sample_frequency_msuint64Sampling interval in milliseconds.
paramsobjectDriver-specific parameters (I2C address, precision, pins, etc.).

mTLS Certificates

Place PEM-encoded certificates on the SD card:

/sdcard/
  certs/
    client.crt    # Device client certificate
    client.key    # Device private key
    ca.crt        # Platform CA certificate

Supported Sensors

TypeDescription
sht21Temperature and humidity
sht3xTemperature and humidity
sht4xTemperature and humidity (configurable precision and heater)
scd40CO2, temperature, and humidity
scd41CO2, temperature, and humidity (extended range)
adxl3453-axis accelerometer
veml7700Ambient light sensor
analogGeneric ADC input
digitalGeneric digital GPIO input
gpsGPS receiver (NMEA)