Ensure you have completed all the steps in the following documents before continuing:
You should still be in the Dataflow Editor interface from the previous chapter.
Make sure your Raspberry Pi is connected and running (with green status LEDs) before starting this section. If not, ask the instructor for assistance.
... > l-broker > downstream > dataflow
dataflow and select Create Dataflow
publish-local-sensor and click Invoke
... > dataflow > publish-local-sensor
publish-local-sensor dataflow in the right-hand editor workspace by clicking on its dataflow icon
... > l-broker > downstream > mqtt > local-broker > Data > sensor

Metrics section, drag pi-sense to the editor workspace Dataflow section
If you don’t see any data listed under
Metricsfrompi-sensecheck that the Raspberry Pi is powered on and the status LEDs are green. Make sure you have correctly set up the MQTT DSLink and MQTT configuration as detailed above as well.
If you do see
pi-sensedata listed, you probably noticed that it is changing every 3 seconds. The EFM Dataflow Editor shows data updates in realtime.
pi_sense to pi-sense-sensor-mqtt
Properties section, mouse over the lastUpdate field until a blue dot appears

Pinned box

Pinning a field adds it to that block’s listed fields in the Dataflow section so it is easy to link it to the input field of other blocks.

... > l-broker > data
data and drag publish to the editor workspace Dataflow section

Properties section:
true
/data/sensor/pi-sense
Make sure you are updating the
Pathproperty toward the bottom and not thepathproperty near the middle of thePropertiessection. ThePathis how other EFM brokers are able to subscribe to the local broker’s published data.
value field to the publish Value field by dragging the red arrowhead from one block to the open spot on the other

If you ever accidentally link the wrong fields, you can simply double-click the arrowhead and the link will be removed. If you ever drag the wrong block to the editor workspace
Dataflowsection, just select the block and hit the delete key on your keyboard.
lastUpdate field to the publish Timestamp field

You can confirm that the data is successfully published by navigating to
... > l-broker > dataand expanding thesensor > pi-senseentry under theMetricssection. The data values should change every 3 seconds, just like the source data. This is an example of how EFM can publish data upstream as it is received locally without modification. The next dataflow will add some additional filtering logic to its publish activity.
publish-local-sensor dataflow by clicking the x icon next to its name above the editor workspace
... > l-broker > downstream > dataflow
dataflow and select Create Dataflow
publish-local-control and click Invoke
... > dataflow > publish-local-control
publish-local-control dataflow in the right-hand editor workspace by clicking on its dataflow icon
... > l-broker > downstream > mqtt > local-broker > Data > control

Metrics section, drag pi-sense to the editor workspace Dataflow section
If you don’t see any data listed under
Metricsfrompi-sensewhen actuating the joystick check if thesensorMQTT data is still coming in every 3 seconds. If not, double-check the status LEDs on the Raspberry Pi and make sure it is still connected to the MQTT server. Ask the instructor for assistance if needed.
pi_sense to pi-sense-control-mqtt
Properties section, mouse over the lastUpdate field until a blue dot appears
Pinned box
Blocks section, expand Table Operations
JSON Parser to the editor workspace Dataflow section
This block will parse the JSON data that is received over MQTT and convert it into table format. Take a minute to look at all the different blocks that are available for dataflow logic and processing. As you create progressively more complex dataflows below you will become familiar with many of these blocks.
jsonParser to control-table
value field to the control-table input field
... > l-broker > data
data and drag publish to the editor workspace Dataflow section
Properties section:
true
/data/control/pi-sense
enabled field in the Properties section until a blue dot appears
Pinned box
Blocks section, drag Logic > If to the editor workspace Dataflow section
if to released-filter
control-table and click on the Table button for the output field in the Properties section to see the underlying table data

action column to the released-filter input 0 field
The resulting field input 0 indicator for the
released-filterblock will be gray with a circle indicating it’s from an external resource that can’t be easily represented graphically within the dataflow editor.
released-filter and edit the following values in the right-hand Properties section:
released
true
false
This one
ifblock is providing the main logic for this dataflow. It is evaluating the joystick action and filtering out onlyreleasedevents. This will prevent publishing unnecessarypressedandheldjoystick events when we link this logic to the publish block.
Most dataflows can be broken down logically to an “input-logic-output” cycle. It can be helpful to keep this in mind when trying to understand more complex dataflows. You may have also noticed that data-oriented dataflow blocks (usually used for input and output) are red while logic and operations blocks are orange.
output field to the publish enabled field
value field to the publish Value field
lastUpdate field to the publish Timestamp field

You can confirm the data is successfully published by navigating to
... > l-broker > dataand expanding thecontrol > pi-senseentry under theMetricssection. The data values should change with each completed joystick move, but only showreleasedevents. You can confirm this within thepublish-local-controldataflow as well, watching theenabledfield in thepublishblock, which should change totrueduringreleasedevents and stayfalseotherwise.
This is an example of how EFM can intelligently filter input data streams locally before they are published upstream, which is especially critical for input data that comes at an extremely high rate or is likely to contain invalid or operationally uninteresting data. The next dataflow will use even more logic to tie filtered local control actions to local display output at the edge.
publish-local-control dataflow by clicking the x icon next to its name above the editor workspace
... > l-broker > downstream > dataflow
dataflow and select Create Dataflow
local-control-display and click Invoke
... > dataflow > local-control-display
local-control-display dataflow in the right-hand editor workspace by clicking on its dataflow icon
... > l-broker > downstream > mqtt > local-broker > Data > control
Metrics section, drag pi-sense to the editor workspace Dataflow section
pi_sense to pi-sense-control-mqtt
Properties section, mouse over the lastUpdate field until a blue dot appears
Pinned box
Blocks section, expand Table Operations
JSON Parser to the editor workspace Dataflow section
jsonParser to control-table
value field to the control-table input field
Blocks section, drag Logic > If to the editor workspace Dataflow section
if to held-filter
held-filter and edit the following values in the right-hand Properties section:
held
true
false
Does this process seem similar to the last dataflow? It is almost identical except the
iflogic will filter forheldevents instead ofreleasedand there is nopublishblock (yet). The rest of the dataflow will be new.
Blocks section, drag Logic > Case to the editor workspace Dataflow section
case to translate-direction
translate-direction block (3) times to make three more cases appear

The
Caseblock allows for evaluating a single input value against an arbitrary number of different known cases and provides distinct output values for each one. Here you will be using theCaseblock to translate the publisheddirectioninto a prettier value that will be displayed on the Sense HAT LED matrix.
translate-direction and edit the following values in the right-hand Properties section:
up
N
down
S
right
E
left
W
middle
*

control-table and click on the Table button for the output field in the Properties section to see the underlying table data
action column to the held-filter input 0 field
direction column to the translate-direction input field
Blocks section, drag String Operations > Concatenate to the editor workspace Dataflow section
concat to display-json
display-json block (1) time to make another input field appear
The
Concatentateblock joins text strings together in the input order listed. You will use it to form the JSON message that will be published to thedisplaytopic via MQTT back to the Raspberry Pi so it will display the specified text message.
display-json and edit the following values in the right-hand Properties section:
{ "action": "text", "text": "
", "color": [0, 0, 255] }

output field to the display-json input 1 field
... > l-broker > downstream > mqtt > local-broker
local-broker and drag the Publish action to the editor workspace Dataflow section

publish to set-display
set-display and edit the following values in the right-hand Properties section:
display/pi-sense
enabled field in the Properties section until a blue dot appears
Pinned box
output field to the set-display enabled field
output field to the set-display invoke field
Why use both the
enabledandinvokefields for this block? This approach will “debounce” the joystick output so that only direction changes are pushed to the display rather than an ongoing set of joystickheldevents, which would overwhelm the display with continuous messages.
output field to the set-display value field

If the Sense HAT is blank, double-check your
display-jsonblock and make sure there are no typos in theinput 0andinput 2fields. Ask the instructor for help if you get stuck.
This dataflow showcases a major feature of Kinetic EFM and fog computing: the ability to resiliently perform a multi-part input-logic-output cycle with both filtering and translation entirely at the edge in the local broker. If this were a roadway, factory, utility substation, or offshore drilling platform, this entire dataflow would continue to run locally even if the upstream connection were disrupted.
local-control-display dataflow by clicking the x icon next to its name above the editor workspace