Skip to content

Commit c73e72e

Browse files
author
kasemir
committed
MQTT info
1 parent 82ec2a1 commit c73e72e

File tree

4 files changed

+117
-2
lines changed

4 files changed

+117
-2
lines changed

app/alarm/ui/doc/index.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,11 @@ The email server is configured in the alarm preferences.
310310
``infopv:SomePV``:
311311
Writes the alarm detail to a PV.
312312

313-
The PV needs to hold a string, for example::
313+
The PV needs to hold a string, for example
314+
`mqtt://alarm/message<VString>` for an MQTT topic
315+
or
316+
`ca://NameOfPV.VAL$`
317+
for Channel Access where the PV refers to a string record::
314318
315319
# Example for "Info PV"
316320
# used with automated action set to "infopv:NameOfPV"

core/pv-mqtt/Readme.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
MQTT PV Support
2+
===============
3+
4+
MQTT is a broker-based protocol used in the Internet-of-Things (IoT) ecosystem.
5+
See https://mqtt.org for details.
6+
The `mqtt:...` PV support allows CS-Studio tools to read and write PVs via MQTT.
7+
8+
9+
Example Broker Setup and first steps
10+
------------------------------------
11+
12+
This example uses Eclipse Mosquitto on Linux.
13+
See https://mqtt.org for links to several other MQTT brokers and clients.
14+
15+
Download: Get source release `mosquitto-....tar.gz` from https://mosquitto.org/download
16+
17+
Unpack: `tar vzxf mosquitto-....tar.gz`
18+
19+
Build: `make WITH_CJSON=no`
20+
21+
Install:
22+
23+
```
24+
export LD_LIBRARY_PATH=`pwd`/lib
25+
# Optionally, add the following to a `bin` folder that's on your $PATH
26+
# src/mosquitto, client/mosquitto_sub, client/mosquitto_pub
27+
```
28+
29+
Run broker:
30+
31+
```
32+
# Allow remote access through firewall.
33+
# Depending on Linux release, similar to this
34+
sudo firewall-cmd --add-port=1883/tcp
35+
36+
# Create configuration file that allows remote access
37+
echo "listener 1883" >> mosquitto.conf
38+
echo "allow_anonymous true" >> mosquitto.conf
39+
40+
# Start broker with that configuration file
41+
src/mosquitto -c mosquitto.conf
42+
mosquitto version ... starting
43+
Config loaded from mosquitto.conf.
44+
...
45+
Opening ipv4 listen socket on port 1883.
46+
```
47+
48+
See https://mosquitto.org/documentation/authentication-methods
49+
for a more secure configuration.
50+
51+
Subscribe to value updates: `client/mosquitto_sub -t sensors/temperature -q 1 `
52+
53+
Publish a value: `client/mosquitto_pub -t sensors/temperature -q 1 -m 42`
54+
55+
By default, the broker will not persist messages.
56+
The subscribe command shown above will receive all newly
57+
published messages. If you close the `mosquitto_sub` and then restart it,
58+
it will show nothing until a new value is published.
59+
60+
To persist data on the broker, each client that publishes or subscribes
61+
needs to connect with a unique client ID and an option to _not_ 'clean' the session,
62+
using options like `--id 8765 --disable-clean-session` for the `.._sub` and `.._pub`
63+
commands shown above.
64+
65+
66+
MQTT PV Configuration
67+
---------------------
68+
69+
By default, the MQTT PV will look for a broker on localhost
70+
and the default MQTT broker port 1883.
71+
72+
To change this, add a variant of the following to your Phoebus settings:
73+
74+
```
75+
# MQTT Broker
76+
# All "mqtt://some/tag" PVs will use this broker
77+
#org.phoebus.pv.mqtt/mqtt_broker=tcp://localhost:1883
78+
org.phoebus.pv.mqtt/mqtt_broker=tcp://my_host.site.org:1883
79+
```
80+
81+
The MQTT PV will create a unique internal ID to read persisted messages,
82+
allowing the PV to start up with the last known value of an MQTT topic
83+
without need to wait for the next update.
84+
85+
86+
MQTT PV Syntax
87+
--------------
88+
89+
To interface with the example MQTT tag shown above,
90+
use the PV `mqtt://sensors/temperature`.
91+
92+
The general format is `mqtt://` followed by the MQTT topic,
93+
for example `sensors/temperature`,
94+
and an optional `<VType>`.
95+
96+
MQTT treats all tag data as text. By default, an MQTT PV expects
97+
the text to contain a number, but the optional `<VType>` will
98+
instruct the PV to parse the text in other ways.
99+
100+
| `VType` | PV Value Parser |
101+
| ---------------- | ---------------------------------------------------------------------------- |
102+
| `<VDouble>` | This is the default, expecting the topic to parse as a floating point number |
103+
| `<VString>` | PV reads text as string |
104+
| `<VLong>` | Parse as long integer |
105+
| `<VDoubleArray>` | Parse as array of comma-separated floating point numbers |
106+
| `<VStringArray>` | Parse text as array of comma-separated strings |
107+

services/alarm-server/.classpath

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
<classpathentry combineaccessrules="false" kind="src" path="/core-util"/>
1010
<classpathentry combineaccessrules="false" kind="src" path="/core-pv"/>
1111
<classpathentry combineaccessrules="false" kind="src" path="/core-formula"/>
12-
<classpathentry combineaccessrules="false" kind="src" path="/core-vtype"/>
12+
<classpathentry combineaccessrules="false" kind="src" path="/core-pv-ca"/>
13+
<classpathentry combineaccessrules="false" kind="src" path="/core-pv-pva"/>
14+
<classpathentry combineaccessrules="false" kind="src" path="/core-pv-mqtt"/>
15+
<classpathentry combineaccessrules="false" kind="src" path="/core-vtype"/>
1316
<classpathentry combineaccessrules="false" kind="src" path="/core-email"/>
1417
<classpathentry combineaccessrules="false" kind="src" path="/app-alarm-model"/>
1518
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>

services/alarm-server/src/main/resources/alarm_server_logging.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ org.apache.kafka.level = WARNING
2929

3030
org.phoebus.applications.alarm.level = INFO
3131
com.cosylab.epics.caj.level = WARNING
32+
org.eclipse.paho.client.level = CONFIG
3233
org.phoebus.framework.rdb.level = WARNING
3334
org.phoebus.pv.level = CONFIG

0 commit comments

Comments
 (0)