- Last edited one year ago ago
How to customize STM32 Wireless Long Range demo
This demo is based on 5 flows, with a specific role for each page:
- STM32WL Demo Tool: This is the first tab, and displays the help information.
- Serial port configuration: This flow manages the serial port. The serial port selection must be done in this flow.
- Demo main flow: This flow is the heart of the demo. It manages the dynamics of the dashboard.
- Sensor panels: This flow contains all the UI elements of each of the sensor panels.
- AT Command: This flow handles command parsing, errors, and the serial log part.
1 Serial port configuration
This flow is quite simple. It features one serial node input and one output to handle connection with the concentrator.
In order to change the com port, the user must change both nodes. The serial port status node is used to detect events related to serial port, such as board disconnection. The input for the serial port and the events are sent to the AT Command flow.
2 Demo main flow
This is the complex part of the demo, but the user does not normally need to adapt it. The page can however be changed if the user wished to build a different application or add additional features. The flow is divided into 3 main parts:
2.1 Home page/region selection
This section manages the country selection fields when the application starts.
When the application is initialized, the Region picklist is set to the current region by the "Reset region" node.
When user changes the Region picklist, the region value is saved in the flow context, and the SubRegion picklist is configured with the proper values.
When the user changes the SubRegion picklist, the SubRegion value is saved in flow context.
2.2 Demo main part
The central section manages the dynamic of the dashboard.
The central part is comprised of the FSM nodes that implement the finite state machine. The states are:
- "INIT": The concentrator is not connected or not yet initialized. A reset command is sent in this state.
- "IDLE": The concentrator has answered the reset command, and is ready to start. The country selection page is displayed.
- "SEND_REGION": The user has pressed the start button, the set region command is sent to the board, and the application waits for the answer.
- "SEND_SUBREGION": The concentrator has answered to the set region command, and the sub region command is sent.
- "STARTING": The concentrator has acknowledged the sub region, and the application sends the start command.
- "STARTED": The concentrator is started, beacons are sent periodically, and sensor-status collection starts.
The FSM reacts to input signals:
- Start button: messages with topic "start" cause the demo to start (in IDLE state).
- Reset button: the demo goes into INIT state and data is initialized when a message with topic "reset" is received.
- Input from the AT command flow. The inputs are parsed in the AT Command flow, and have the following topics: "resetok" when a device has performed reset, "connect" when a board is connected, "disconnect" when a board is disconnected, "ok" when an AT command is successful, and "error" when an error occurs. These inputs go through a switch node to separate the data from the sensor and the command status.
On the right side, there are some function nodes that are used to set data and manage the display. The Dashboard UI is managed with UI groups, which are visible or hidden as required. The two nodes "Display the country page" and "Display the sensor panels" generate a configuration message to hide and display the correct UI group for each state. The "Reset the UI" node is used to detect the first display of the dashboard, and configures the UI elements properly. The "Reset the data" node clears the list of sensors, and formats a "reset" message to clear all the charts in sensor panels and the Main sensor table.
Four nodes are used to send the command to the concentrator. The message is created with the AT command, and the Flow name. The flow name can be used to route answers if more than one flow is sending AT commands.
2.3 Sensor data management
Data from sensors is first decoded by the "parse data" node. The data arrives in a string and is split into an object with fields. The "compute sensor data" node then checks the data against previous data received to check if packets have been missed, and computes the PER and the statistics. The result is stored in memory and sent in a new message to update the charts and the Sensor table. The node also detects when a new sensor appears, sends a message in the second output to display, and closes the new sensor panel.
2.4 Sensor list management
The sensor list is displayed with the "Sensor list" node. This is a standard ui_table dashboard node. In order to obtain good performance and to cache the data properly, a sub flow ui-table-handler is used. The table handler holds the table configuration (column list, colors, sizes). The ui-table handler is a subflow shared by Christian-Me in node-RED forums. announce-remote-device-table-and-collaboration-wanted. Incoming data from the sensor goes to the "Inject data" node and is formatted for the ui-table handler. The "reset table" node builds a message to clear the content of the table. The "reset counters" parse the sensor data, and reset the number of packets and stats of all sensors. The "Display charts" node sends a message to "open" the sensor panel when the sensor is clicked in the table.
3 Sensor panels
The sensor tab groups all sensor panels. For each sensor, there is a sub-flow and the UI graphic components (graph and gauge). The pattern is repeated 15 times.
For each sensor there is one subflow to filter data. Each time sensor data is received, it is sent to all sensors. The "Split sensor data" filter filters the sensor number and then dispatches the data on various outputs:
- EUI: used to display the EUI in each sensor panel
- Temperature: connected to a chart in the sensor panel
- PER: (not used by default)
- Voltage: connected to a gauge in the sensor panel
- RSSI: (not used)
- Missed packet: connected to a chart in the sensor panel.
- Pressure: connected to a gauge in the sensor panel
- Orientation: connected to a 3D node in sensor panel to display device in 3D oriented mode
- Activity: connected to activity node in sensor panel that display activity and associated icon
- Distance: (not used)
- Step_count: connected to a text in sensor panel
- Swipe count: (not used)
- Acceleration avg: connected to a chart in sensor panel
- Acceleration max: connected to a chart in sensor panel
- Humidity: (not used)
To change the sensor Id, double click on the "SplitSensorData" node and set the value in the "sensor" field. Other output can be selected by editing the sub-flow template.
- Some graphical elements to display the data: The gauge, text, chart must be in the panel UI group. ie "[SM32WL Demo] Sensor 6". The group name must not be changed because it is used to show/open the group when sensor data are received.
4 AT command
The AT command tab is in charge of handling AT command logic and performing the log.
The AT commands are sent by the main flow and enter in the "validate command" node. The validate command performs these tasks:
- Check that another command is not ongoing. If there is another command, it sends a error "Busy" error.
- Store the command to be processed and the origin of the message (the Flow name is indicated in the message)
- Forward the command to serial port.
When the command is sent to a Serial port, it is also sent to the timer node to create a timeout. If there is no answer after the timeout, an error is raised.
When the response from a board is received, it is processed by "result formatter" node. This changes the message to make it understandable by other nodes (FSM, data decoding, and timeout). The node also handles the connect, disconnect and reset messages. The "timeout reset" checks the answer type, and if it is the end of a command, the timeout timer is stopped. When Timeout timer ends, a message is sent to "Result formatter" to cancel the ongoing AT command and raise a timeout error in the main flow.
The bottom part of the tab manages the log area.
The logs are come from the serial port or from the flow output. Direction information is added in the "from" field of each message. The logs are then formatted: a time stamp is added, and an object is created with the timestamp, direction and log information. The data is then sent to the ui-table handler and displayed in the ui-table. The scroll down function node has two goals:
- to store auto scroll the status when changes
- If auto-scroll is on, each time a new message is added to the log, send a request to the ui-table to scroll to the last line of the log.