@startuml skinparam dpi 300 skinparam classFontSize 8 skinparam classFontName Helvetica autonumber box "Application" #LightGreen participant "Application" as application participant "Callback" as callback end box box "Libraries" #LightBlue participant "JSON" as json participant "Shadow" as shadow participant "MQTT" as mqtt end box box "AWS IoT Broker" #Yellow participant "AWS IoT Broker" as broker end box activate application application -> broker : Establish TLS session with the MQTT Broker application -> mqtt : Initialize MQTT application -> mqtt : Establish an MQTT connection activate mqtt mqtt -> broker: Establish MQTT Connection mqtt -> application : Return from MQTT library deactivate mqtt application -> shadow : Get the shadow delete response topic strings using macros from the shadow library:\n\ If classic shadow:\n\ SHADOW_TOPIC_STR_DELETE_ACC( "testShadow", SHADOW_NAME_CLASSIC )\n\ SHADOW_TOPIC_STR_DELETE_REJ( "testShadow", SHADOW_NAME_CLASSIC )\n\ If named shadow:\n\ SHADOW_TOPIC_STR_DELETE_ACC( "testShadow", "namedShadow" )\n\ SHADOW_TOPIC_STR_DELETE_REJ( "testShadow", "namedShadow" )\n activate shadow shadow -> application : Return assembled shadow topics deactivate shadow application -> mqtt : Subscribe to the shadow delete response topics ( SubscribeToTopic ) activate mqtt mqtt -> broker: Subscribe to the shadow delete response topics mqtt -> application : Return Success deactivate mqtt application -> shadow : Get the shadow delete operation topic string using the macro from the shadow library\n\ If classic shadow:\n\ SHADOW_TOPIC_STR_DELETE( "testShadow", SHADOW_NAME_CLASSIC )\n\ If named shadow:\n\ SHADOW_TOPIC_STR_DELETE( "testShadow", "namedShadow" ) activate shadow shadow -> application : Return the assembled shadow topic deactivate shadow application -> mqtt : Publish an empty message on the shadow delete topic to delete the shadow if it exists activate mqtt mqtt -> broker : Publish message on the shadow delete topic to the broker mqtt <- broker : Incoming message mqtt -> callback : Call Callback activate callback callback -> shadow : Parse the topic ( Shadow_MatchTopicString ) activate shadow shadow -> callback : Return the parsed result ( ShadowMessageType_t ) deactivate shadow callback -> mqtt : Return from the callback deactivate callback mqtt -> application : Return from MQTT library deactivate mqtt application -> mqtt : Unsubscribe from the shadow delete response topics ( UnsubscribeFromTopic ) activate mqtt mqtt -> broker : Unsubscribe from the shadow delete response topics mqtt -> application : Return from MQTT library deactivate mqtt application -> shadow : Get the following shadow topic strings using macros from the shadow library:\n\ If classic shadow:\n\ SHADOW_TOPIC_STR_UPDATE_DELTA( "testShadow", SHADOW_NAME_CLASSIC )\n\ SHADOW_TOPIC_STR_UPDATE_ACC( "testShadow", SHADOW_NAME_CLASSIC )\n\ SHADOW_TOPIC_STR_UPDATE_REJ( "testShadow", SHADOW_NAME_CLASSIC )\n\ If named shadow:\n\ SHADOW_TOPIC_STR_UPDATE_DELTA( "testShadow", "namedShadow" )\n\ SHADOW_TOPIC_STR_UPDATE_ACC( "testShadow", "namedShadow" )\n\ SHADOW_TOPIC_STR_UPDATE_REJ( "testShadow", "namedShadow" ) activate shadow shadow -> application : Return assembled shadow topics deactivate shadow application -> mqtt : MQTT_Subscribe subscribes to those shadow topics ( SubscribeToTopic ) activate mqtt mqtt -> broker: Subscribe to the shadow topics mqtt -> application : Return Success deactivate mqtt application -> shadow : Get the shadow update operation topic string using macro from shadow library:\n\ If classic shadow:\n\ SHADOW_TOPIC_STR_UPDATE( "testShadow", SHADOW_NAME_CLASSIC )\n\ If named shadow:\n\ SHADOW_TOPIC_STR_UPDATE( "testShadow", "namedShadow" ) activate shadow shadow -> application : Return the assembled shadow topic deactivate shadow application -> mqtt : Publish powerOn:1 in the message on the shadow update topic ( PublishToTopic ) activate mqtt mqtt -> broker : Publish message on the shadow update topic to the broker mqtt <- broker : Incoming message mqtt -> callback : Call Callback activate callback callback -> shadow : Parse the topic ( Shadow_MatchTopicString ) activate shadow shadow -> callback : Return the parsed result ( ShadowMessageType_t ) deactivate shadow callback -> json : Parse powerOn/value from shadow topic payload ( JSON_Search ) activate json json -> callback : Return parsed powerOn/value deactivate json callback -> mqtt : Return from the callback deactivate callback mqtt -> application : Return from MQTT library deactivate mqtt application -> mqtt : Unsubscribe from the subscribed shadow update topics ( UnsubscribeFromTopic ) activate mqtt mqtt -> broker : Unsubscribe from the subscribed shadow update topics mqtt -> application : Return from MQTT library deactivate mqtt application -> mqtt : Disconnect from connection ( DisconnectMqttSession ) activate mqtt mqtt -> broker : MQTT disconnect from the broker mqtt -> application : Return from MQTT library deactivate mqtt application -> broker : TLS disconnect from the broker deactivate application @enduml