Skip to content

4. Configuration Reference

Ioannis Charalampidis edited this page Jan 16, 2019 · 3 revisions

The uNode library is configured by a statically declared global variable of type uNodeConfig that should be defined in the beginning of your sketch. It’s complete specification is listed below:

uNodeConfig unode_config = {

  //
  // LoRa module configuration
  //
  .lora = {

    //
    // The activation mode to use. Can be one of:
    //  LORA_TTN_DISABLED, LORA_TTN_ABP, LORA_TTN_OTAA
    //
    .mode = LORA_TTN_ABP,

    //
    // The activation mode details. Both options are mutually exclusive
    //
    .activation = {
      // ABP Activation Configuration
      .abp = {
        .appKey = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        .netKey = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        .devAddr = 0x00000000
      }
      // OTAA Activation Configuration
      .otaa = {
        .appKey = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        // (The following keys should be copied from the TTN Console in LSB format)
        .appEui = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        .devEui = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
      }
    },

    // The default Spreading Factor for the LoRa module. Can be one of:
    //    LORA_SF_DEFAULT, LORA_SF12, LORA_SF11, LORA_SF10, LORA_SF9,
    //    LORA_SF8, LORA_SF7, LORA_SF7B
    .tx_sf = LORA_SF_DEFAULT,

    // The default transmission value to use. Can be one of:
    //    CONFIG_DEFAULT or an 8-bit number
    .tx_power = 14,

    // When using managed transmission, this defines the number of seconds to wait
    // for a transmission acknowledgment before considering it timed out (in ms).
    .tx_timeout = 10000,

    // When using managed transmission, this defines the number of re-transmission
    // attempts to perform, before bailing out.
    .tx_retries = 3,

    // Enable or disable Adaptive Data Rate (ADR) on the LoRa Chip. Can be
    //  1 (enabled), 0 (disabled)
    .adr = 0

  },

  //
  // Configures the log messages emitted by the library. By default, they are
  // written on the serial port, but you can disable or adjust it according to
  // your needs.
  //
  // You can either use one of the pre-defined constants: 
  //    LOG_DEFAULT, LOG_DISABLED, LOG_INFO, LOG_INFO_74880, LOG_INFO_9600
  //
  .logging = LOG_DEFAULT,
  //
  // ... or you can manually configure it
  //
  .logging = {

    //
    // The logging level. Can be one of:
    //    LOG_LEVEL_DEFAULT, LOG_LEVEL_DISABLED, LOG_LEVEL_INFO
    //
    .level = LOG_LEVEL_DEFAULT,

    //
    // The baud rate for the serial console. Can be one of:
    //    CONFIG_DEFAULT or any valid baud rate, eg. 115200
    //
    uint32_t      baud;
  },

  //
  // Configures the undervoltage protection module
  //
  // You can use either use one of the pre-defined constants:
  //    UNDERVOLTAGE_DEFAULT or UNDERVOLTAGE_DISABLED
  //
  .undervoltageProtection = UNDERVOLTAGE_DEFAULT,
  //
  // ... or you can manually configure it
  //
  .undervoltageProtection = {

    //
    // Cut-off voltage (in mV)
    //
    .disableThreshold = 3100,

    //
    // Activation voltage (in mV)
    //
    .enableThreshold = 3200

  }

};

4.1. LoRA configuration - Disabled

If you are not planning to use the LoRa functionality of the node you can disable the LoRa module completely using the following configuration:

uNodeConfig unode_config = {
  .lora = {
    .mode = LORA_DISABLED
  }
  ...
}

4.2. LoRA configuration - TTN OTAA Activation

To use Over-The-Air Activation (OTAA) you first need to go to https://console.thethingsnetwork.org and create a new device, selecting OTAA as your activation mode.

Then you can use the following configuration. Make sure to replace the appKey, appEui and devEui with the values you configured on the TTN console (the EUIs must be in LSB order):

uNodeConfig unode_config = {
    .mode = LORA_TTN_OTAA,
    .activation = {
      .otaa = {
        .appKey = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 … },
        .appEui = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        .devEui = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
      }
    }
  ...
}

4.3. LoRA configuration - TTN ABP Activation

To use Activation by Device Personalisation (ABP) you first need to go to https://console.thethingsnetwork.org and create a new device, selecting ABP as your activation mode.

Then you can use the following configuration. Make sure to replace the appKey, netKey and devAddr with the values you configured on the TTN console:

uNodeConfig unode_config = {
    .mode = LORA_TTN_ABP,
    .activation = {
      .abp = {
        .appKey = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, … },
        .netKey = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, … },
        .devAddr = 0x00000000
      }
    }
  ...
}

4.4. Debug logging

The library reports by default it's actions over the serial port for debugging purposes. The messages look like the following:

[uNode] Booted firmware v0.8
[uNode] VCC measured at 3687 mV
[Power] Enabling GPIO Expansion
[Power] Enabling VBus
[Power] Enabling LoRa
[LoRa] Ready
[LoRa] Sending 6 bytes
[LoRa] Joining                                                                                                         
...

If you want to use the serial port for other purposes, you should disable the library logging. This can be done like so:

uNodeConfig unode_config = {
  ...
  .logging = LOG_DISABLED
  ...
};

4.5. Under-voltage Protection

You can use this option if you have attached a LiPo battery directly on the μNode. This will put the device an indefinite low-power sleep when the voltage drops below 3.1v (the ESP8266 is not guaranteed to work reliably with voltages below 3.0v)

The default configuration uses the following values:

  • Disable the device when the voltage drops below 3.1v
  • Enable the device when the voltage is 3.2v or higher

To use the default configuration, use

uNodeConfig unode_config = {
  ...
  .undervoltageProtection = UNDERVOLTAGE_DEFAULT
  ...
};

⚠️ WARNING: If you are planning to use A0 analog input you should disable under voltage protection because the voltage is measured using the same ADC converter.

// Do not use ADC to measure voltage, by commenting-out the following
// line in the examples:
//ADC_MODE(ADC_VCC);

// Make sure to disable the undervoltage protection
uNodeConfig unode_config = {
  ...
  .undervoltageProtection = UNDERVOLTAGE_DISABLED
  ...
};