Connection Hooks

C

The full example code can be found on our GitHub.

Connection Hooks

Connections hooks are useful for when you want to add additional control to the connection lifecycle in the atSDK. This means you as the developer can implement things like automatically reconnecting when connections drop (example below).

Usage

1. Enable hooks in your context's atserver_connection

Since not every connection uses hooks, you must explicitly enable it.

atclient_connection_hooks_enable(&(atclient->atserver_connection));

2. Write a void* function

Write a function that we would like our atclient connection to run at certain times during the program.

void *pre_write_hook(atclient_connection_hook_params *params)
{
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "pre_write_hook called\n");
    return NULL;
}

3. Set the hook

For example, we can set the ATCLIENT_CONNECTION_HOOK_TYPE_PRE_WRITE hook to run our function pre_write_hook before we write any data to our atServer connection.

Examples

The full example code can be found on our GitHub.

Automatically reconnect when the connection drops

Last updated