Firmware

Configuration

Before uploading the firmware on the MCU, it requires to be configured. The configuration is done by copying the file include/config.example.h to the file include/config.h. After copying, the following parameters must be set:

Once configured, the firmware can be uploaded on the MCU.

Execution

Initialization

The firmware initialization is what is contained in the setup() function, according to the Arduino framework. It is composed of the following steps:

uint8_t basket_id[4];
uint8_t digest[20];

sha1(mac, digest);
for (i = 0; i < 20; i++)
    basket_id[i % 4] ^= digest[i];

The loop

After the MCU has initialized, it loops over this procedure:

Whenever a measurement is produced, it is sent to the Bridge over the established TCP connection, and is structured according to our custom binary protocol. After a packet is delivered, the on-board LED1 will light for a small amount of time.

Querying from peripherals

The process of querying from a peripheral is designed with the aid of finite-state machines (FSM), for every peripheral. FSM have been generally used to handle several states of the peripheral including possible disconnection, need of re-initialization, but mostly in order to have a unique callback when an input is firstly receive that will correspond to the delivery of the respective packet.

In the following diagrams, the states highlighted in red are the states where a packet is sent as soon as the state is entered. The only exception is the Accelerometer’s “Read data” state that as long as the MCU is in this state it will repeatedly deliver packets, interspersed by some amount of time.

Basket detection FSM

Custom buttons FSM

People detection FSM

Accelerometer FSM