Skip to content

Network general

Types

Name Type Description
mira_link_metric_t uint16_t
mira_net_antenna_t uint8_t Antenna index type.

Enums

mira_net_state_t

Name Value Description
MIRA_NET_STATE_NOT_ASSOCIATED

The node is not part of a network yet.

MIRA_NET_STATE_IS_COORDINATOR

Tells if the node is the coordinator (root).

MIRA_NET_STATE_ASSOCIATED

The node is in sync, but has no parent yet.

MIRA_NET_STATE_JOINED

The node has a parent and can send packets. Packets may not be routable to this node.

mira_net_rate_t

Name Value Description
MIRA_NET_RATE_FAST 0
MIRA_NET_RATE_MID 8
MIRA_NET_RATE_SLOW 12

mira_net_mode_t

Name Value Description
MIRA_NET_MODE_ROOT 0
MIRA_NET_MODE_MESH
MIRA_NET_MODE_LEAF

Structs

mira_net_address_t

Type Name Description
uint8_t[16] u8
uint16_t[8] u16
uint32_t[4] u32

This is binary compatible with uip_addr_t for ipv6.

Structs

mira_net_config_t

Type Name Description
uint32_t pan_id Network ID, must be same for all nodes in the network.
The Pan ID shall be a 32-bit value, that meets the following requirements:
  • It shall not be the Access Address for BLE advertisements (0x8E89BED6).
  • It shall not have a sequence that only differs one bit from any other known PAN ID or BLE advertisement Access Address.
  • It shall have a minimum of two transitions in the most significant six bits.
  • It shall have no more than six consecutive zeros or ones.
  • It shall have no more than 24 transitions.
  • It shall not have all four octets equal.
uint8_t[16] key The encryption key for all data in the network. Must be the same for all nodes in the network.
mira_net_mode_t mode Set to mesh/leaf/root depending on desired mode of operation.
Not all modes may be supported by all builds. If not supported, mira_net_init() will fail with MIRA_ERROR_INVALID_VALUE
uint8_t rate Higher value of rate reduces power consumption at the expense of data rate.
Different nodes in the network may have different rates, and routes with higher rates are preferred over routes with lower rates.
Recommended values are defined in mira_net_rate_t.
Rates 0 to 10 are supported for meshing nodes and root node. Rates 0 to 12 are supported for leaf nodes.
Rates 13 and higher are not supported.
mira_net_antenna_t antenna The preferred antenna. If the specified antenna is not available on the module, the default antenna is selected.
mira_net_address_t prefix If unset, fd00::/64 is default.
This parameter only applies when mode == MIRA_NET_MODE_ROOT, for other modes, the prefix is derived from the joined network.
Only first /64 is used.
mira_size_t max_nbrs Size of neighbour table.
The neighbour table defines the number of nodes available within reach. It tracks the other nodes within hearable distance.
If unset (or set do 0), the default value of 64 is set.
mira_size_t max_links Size of link table.
The link table tracks the topology of the entire network. Each node needs to have a slot in the link table.
The link table only applies to root nodes, and is ignored on mesh or leaf nodes.
If unset (or set do 0), the default value of 250 is set.

Network configuration.

Functions

mira_net_init

mira_status_t mira_net_init(
    const mira_net_config_t*  config);

Initialize the mira network.

Parameters

Parameter Description
config Network configuration.

Return

See enum definition.

Value Description
MIRA_SUCCESS Mira net successfully initialized.
MIRA_ERROR_INVALID_VALUE Unsupported configuration parameters.
MIRA_ERROR_UNKNOWN An unknown error occurred.

mira_net_is_init

int mira_net_is_init(
    void);

tells if mira_net_init has been called.

Return

0 until mira_net_init has been called.

mira_net_get_address

mira_status_t mira_net_get_address(
    mira_net_address_t*  dst);

Get the IP address.

Parameters

Parameter Description
dst The destination where to store the retrieved IP address.

Return

MIRA_SUCCESS if successful.

mira_net_get_state

mira_net_state_t mira_net_get_state(
    void);

Get the current state of network association.

Please note that there is no way to locally see if this node is reachable from other nodes unless they send a packet to it. The joined state means this node is able to send packets to other nodes.

Return

Current network state, see enum definition.

Value Description
MIRA_NET_STATE_IS_COORDINATOR Node state is coordinator.
MIRA_NET_STATE_NOT_ASSOCIATED Node state is not associated.
MIRA_NET_STATE_ASSOCIATED Node state is associated.
MIRA_NET_STATE_JOINED Node state is joined.

mira_net_get_root_address

mira_status_t mira_net_get_root_address(
    mira_net_address_t*  dst);

Get the IP address of the root node.

Parameters

Parameter Description
dst The destination where to store the retrieved IP address of the root node.

Return

See enum definition.

Value Description
MIRA_SUCCESS Got valid address.
MIRA_NET_ERROR_NOT_ASSOCIATED Node is not associated.

mira_net_get_parent_address

mira_status_t mira_net_get_parent_address(
    mira_net_address_t*  dst);

Gets the IP address of the parent node.

Parameters

Parameter Description
dst The destination where to store the retrieved IP address of the parent.

Return

See enum definition.

Value Description
MIRA_SUCCESS Got valid address.
MIRA_NET_ERROR_NOT_ASSOCIATED Node is not associated.
mira_link_metric_t mira_net_get_parent_link_metric(
    void);

Gets the link quality metric to the parent node.

The link metric (as a 9.7 fixed point number) is a quality index of a particular link between two nodes. The value returned is called ETX, which is an approximate number of transmissions required for a successful transfer. Range is from 1.0 (0x0080) to infinity (0xFFFF). A value of 1.0 means a perfect link. Higher numbers are worse. To calculate an approximate packet delivery rate use the following formula: PDR = 1.0 / ETX.

Return

A link quality metric as an unsigned 9.7 fix point number.

mira_net_reset_scanning

mira_status_t mira_net_reset_scanning(
    void);

Reset network scanning.

Network scanning will timeout after 5 minutes and sleep to conserve battery power in the case that there is no network to join. The sleep period is 5 minutes the first time, and doubles after each active scan period. The sleep period cannot be longer than 23 hours.

Return

MIRA_SUCCESS if successful.