MQTT Communication: Publishing Events
Description
Nominal Studio enables component events to be configured, based on data triggers. MQTT flag events can be configured to trigger when a particular property or value is reached. By default, Studio will have events that are triggered when a Spacecraft enters or leaves an Eclipse caused by a planet blocking the sun or when the altitude drops below the surface. However, additional events can be created that are connected to MQTT. This document will explain how to create the events and have the data published over the network.
Configuring an Event
For this tutorial, a GPS event will be triggered when a specific latitude is reached and when a particular longitude is reached. These events will be published over MQTT. To start, a new spacecraft must be added with the GPS component attached. Apart from the default chassis, no other components are required. All components have values that can be triggered by events, however, so this tutorial can be adjusted to work with other parameters.
Note
The GPS sensor can be found under the sensor tab. Add the sensor to the chassis at some desired location.
Select the GPS from the hierarchy in the outliner, by dropping the arrows until the GPS component is found, and the properties panel will display the list of information once the component box is selected.
By default, a GPS constellation will not be initialized in Studio. The GPS component will update the latitude, longitude and altitude based on the true position of the spacecraft, and not one that is simulated using GPS constellation equations. The current latitude and longitude that are initialized are based on the spacecraft’s position and the current epoch of the simulation. In this example, the longitude is 127.7
degrees and the latitude is 0.1
degrees. Since we want to configure both a latitude and longitude trigger, the inclination of the spacecraft orbit needs to change to a non-zero value. This will allow the maximum latitude value to be equal to the inclination value specified.
Returning to the GPS, the initial latitude and longitude values should not have changed if the inclination value changed. Select the events tab, which is the fifth button in the properties panel. By default, there will be no events configured and an Add Event
button will be present.
Press Add Event
and ensure that the event component is GPS
. If another component is present, press the drop-down and find the GPS component that was added to the spacecraft. For the type, since this will be a publishable event, the Flag
option will be used. More information about events in Studio can be found in a separate tutorial. A flag event will trigger when a condition is met. Under action, MQTT
can be selected which will broadcast the event over the MQTT topic used in the previous tutorial. The watch object should also be the GPS
, as this is the object that is being monitored for a value change.
The actual parameter to check is the parameter. Selecting this will list all available properties that can be evaluated on the GPS component. These include all integer, float and vector properties. For the first event, select Latitude
. The evaluation defines the criteria for when the event is triggered. The Larger
condition will trigger when the parameter is larger than the value defined in the final box. For this tutorial, given the satellite inclination of 30
degrees, a value of 20
will be used.
Note
When using a vector property, currently only the magnitude of the property can be evaluated and not the individual values.
Once the MQTT event is created, the event will be present in the timeline. This will show a flag indication on the timeline when the event occurs. An additional event can also be configured in the same way to trigger once the longitude exceeds 150
degrees.
Viewing the Event
As per the previous tutorial, using HiveMQ, a topic can be subscribed to. This must be the output topic that is defined in the MQTT Client panel. Copy this topic to the HiveMQ interface and make sure that it is subscribed to.
Once ready, hit simulate in Studio and speed up the simulation so the spacecraft propagates around the Earth faster. Once the values are reached, both in latitude and longitude, the events will be triggered and broadcast over MQTT. These events are in a JSON format and contain the parameters triggered from the event configuration.
Additionally, the timeline will display when the events are triggered (for the duration that the condition is met). For the case of the latitude, when the latitude dips below 20 degrees, the line will stop.
Hovering the mouse over the event will display some information about the event and how long it lasted. This can provide additional information about the events and can be used for data analysis.