V následujícím kódu jsou vytvořeny 2 metody "change_link" a "change_client". Pro změnu linkové vrstvy je použita metoda "change_link" a jejím úkolem je oznámit (například) připojení či odpojení kabelu ethernetu. Druhá metoda "change_client" detekuje změnu stavu MQTT clienta. Připojení callbacků probíhá v sekci inicializace, protože je potřeba volat ji pouze jednou.
#include"byzance.h"voidchange_link(nsapi_connection_status status){switch(status){case NSAPI_STATUS_LOCAL_UP:printf("LINK: \t > state changed to LOCAL_UP\n");break;case NSAPI_STATUS_GLOBAL_UP:printf("LINK: \t > state changed to GLOBAL_UP\n");break;case NSAPI_STATUS_DISCONNECTED:printf("LINK: \t > state changed to DISCONNECTED\n");break;case NSAPI_STATUS_CONNECTING:printf("LINK: \t > state changed to CONNECTING\n");break; }}voidchange_client(client_status_t status){switch(status){case CLIENT_CONNECTION_STATUS_DISCONNECTED:printf("CLIENT:\t > state changed to DISCONNECTED\n");break;case CLIENT_CONNECTION_STATUS_CONNECTING:printf("CLIENT:\t > state changed to CONNECTING\n");break;case CLIENT_CONNECTION_STATUS_CONNECTED:printf("CLIENT:\t > state changed to CONNECTED\n");break;case CLIENT_CONNECTION_STATUS_SUBSCRIBED:printf("CLIENT:\t > state changed to SUBSCRIBED\n");break;case CLIENT_CONNECTION_STATUS_REFUSED:printf("CLIENT:\t > state changed to REFUSED\n");break;case CLIENT_CONNECTION_STATUS_FAILED:printf("CLIENT:\t > state changed to FAILED\n");break; }}voidinit(){ Byzance::attach_link_connection_changed(&change_link); Byzance::attach_client_connection_changed(&change_client);}voidloop() { Thread::wait(500);}