IOT-ESP32
devices.h File Reference

Manage interactions with physical devices. More...

Data Structures

struct  device_presence_t
 Device presence information. More...
 
struct  device_t
 Representation of a device. More...
 
struct  devices_t
 Handles for all devices definitions. More...
 

Typedefs

typedef uint8_t(* device_presence_cb_t) (device_presence_t)
 Callback when device presence changes. More...
 
typedef void(* device_update_cb_t) (device_data_t, uint8_t)
 Callback to provide result of update. More...
 

Enumerations

enum  action_t
 Possible GATT characteristic value types. More...
 

Functions

device_tcreate_device (device_id_t)
 Define a new device. More...
 
void delete_device (device_t *)
 Clear the device record for the given device ptr. More...
 
sensor_t * device_add_sensor (device_t *, sensor_type_t)
 Add a sensor to an existing device. More...
 
void device_enable_ble_bas ()
 set the BLE service to use on devices to BAS More...
 
void device_enable_ble_presence ()
 attach the device presence handlers to BLE updates More...
 
void device_init ()
 Allocate devices per iot-config.h and start management task. More...
 
void device_load_static_list (sensor_type_t sensor_type=SENSOR_NONE)
 Load the definition of static device id's. More...
 
void device_payload_free (device_data_t *)
 Free heap memory allocation associated with a device payload. More...
 
sensor_data_entry_t device_payload_get_entry (device_data_t *, uint8_t)
 Return a handle to a payload sensor entry by index. More...
 
device_data_t * device_payload_init (const char *, uint8_t)
 Allocate a new device payload from heap. More...
 
void device_process_payload (device_data_t *)
 Schedule a device payload for async delivery. More...
 
uint8_t device_send_update (const char *, sensor_type_t, uint16_t)
 Craft an update on behalf of a device and queue for delivery. More...
 
device_tget_device (device_id_t)
 Get a pointer to a sigle device by the device_id. More...
 
devices_t get_devices ()
 Get list of pointer references to all of the devices. More...
 
void set_device_presence_cb (device_presence_cb_t)
 Set a callback from presence updates. More...
 
void set_device_update_cb (device_update_cb_t)
 Set the callback handler from device updates. More...
 

Detailed Description

Manage interactions with physical devices.

Typedef Documentation

◆ device_update_cb_t

device_update_cb_t

Callback to provide result of update.

Parameters
device_datacontains scope list with status results
errsa counter of number of errors encounterd in process

◆ device_presence_cb_t

device_presence_cb_t

Callback when device presence changes.

Parameters
device_presence
Returns
uint8_t

Enumeration Type Documentation

◆ action_t

enum action_t

Possible GATT characteristic value types.

Function Documentation

◆ set_device_update_cb()

void set_device_update_cb ( device_update_cb_t  )

Set the callback handler from device updates.

Since updates are async in another task, provide a callback with a result

Parameters
handlerdevice_update_cb_t

◆ set_device_presence_cb()

void set_device_presence_cb ( device_presence_cb_t  )

Set a callback from presence updates.

Provide a callback for notification on any presence status update

Parameters
handlerdevice_presence_cb_t

◆ get_devices()

devices_t get_devices ( )

Get list of pointer references to all of the devices.

Returns
devices_t

◆ get_device()

device_t * get_device ( device_id_t  )

Get a pointer to a sigle device by the device_id.

Returns
device_id

◆ create_device()

device_t * create_device ( device_id_t  )

Define a new device.

Update the first device slot which is not currently in use this device_id and return the pointer to the record. Returns null if no slots available.

Returns
device_t* ptr to new device or null if not available

◆ delete_device()

void delete_device ( device_t )

Clear the device record for the given device ptr.

Parameters
device*device ptr

◆ device_load_static_list()

void device_load_static_list ( sensor_type_t  sensor_type = SENSOR_NONE)

Load the definition of static device id's.

Configures devices with id's from STATIC_DEVICE_LIST. These are also added to the BLE whitelist, so ble_init() must be called first. If no sensor type is provided, the device will have none configured.

Parameters
sensor_typea default sensor_type to configure, if desired

◆ device_payload_init()

device_data_t * device_payload_init ( const char *  ,
uint8_t   
)

Allocate a new device payload from heap.

Parameters
device_idthe device_id for the payload
num_entriesnumber of sensor entries to allocate
Returns
device_data_t*

◆ device_payload_get_entry()

sensor_data_entry_t device_payload_get_entry ( device_data_t *  ,
uint8_t   
)

Return a handle to a payload sensor entry by index.

Retruns a handle for use with the sensor_payload_entry_*() calls

Parameters
payloada device payload
idxthe requested sensor data index we plan to update
Returns
sensor_data_entry_t

◆ device_payload_free()

void device_payload_free ( device_data_t *  )

Free heap memory allocation associated with a device payload.

Parameters
payload

◆ device_process_payload()

void device_process_payload ( device_data_t *  )

Schedule a device payload for async delivery.

Destination(s) will be assigned based on sensor rules which assign destination scopes to the payload prior to placing it in a queue to attempt to ensure they are all satisfied.

Parameters
payload

◆ device_add_sensor()

sensor_t * device_add_sensor ( device_t ,
sensor_type_t   
)

Add a sensor to an existing device.

Will add the specified type to the first unused slot for the device. Returns a null ptr if there are no available slots.

Parameters
device
sensor_type
Returns
sensor_t ptr or null

◆ device_enable_ble_presence()

void device_enable_ble_presence ( )

attach the device presence handlers to BLE updates

Cause BLE connect/disconnect to schedule presence events with SmartThings handler

◆ device_send_update()

uint8_t device_send_update ( const char *  ,
sensor_type_t  ,
uint16_t   
)

Craft an update on behalf of a device and queue for delivery.

Parameters
device_id
typesensor_type_t
statevalue
Returns
uint8_t

◆ device_enable_ble_bas()

void device_enable_ble_bas ( )

set the BLE service to use on devices to BAS

Configure a subscription to devices BLE BAS service with network handler

◆ device_init()

void device_init ( )

Allocate devices per iot-config.h and start management task.