In a series of articles, I have briefly introduced the Java library created to obtain general environmental information and operation information of industrial automation equipment. It is as follows when organized.
-BLE Advertised Signal Scan (using bluez-dbus) -CC2650 --Temperature (object, ambient), humidity, illuminance, barometric pressure, motion (angular velocity, acceleration, magnetism) ([bluez-dbus](https:: //github.com/hypfvieh/bluez-dbus) used) -MH-Z19B --CO2 concentration (using jSerialComm) -PPD42ND --PM2.5 concentration (using Pi4J) -OPC-UA --Industrial automation equipment operation information (using Eclipse Milo)
A simple tool (** rainy) that acquires and monitors these data and puts in a mechanism to use the acquired data for other purposes. **). I put Java in Raspberry Pi 3B and run it on Apache Felix (OSGi framework). ** rainy ** built and put together in a tool is published as ** rainy-felix.zip ** here ** I am.
The outline image of ** rainy ** is as follows. In addition, the following image is a configuration in which the monitoring function coexists on the same Raspberry Pi 3B. The equipment used is as follows. The devices for connecting to the MH-Z19B with a USB serial communication adapter are as follows. This article is almost the same as Github here.
--Obtain general environmental information and operation information of industrial automation equipment indoors (private / office / factory). --Monitor these data in near real time and make them available for other purposes. --Run as a Java / OSGi application on a Raspberry Pi 3B (arm) and Ubuntu machine (amd64).
I think ** rainy ** is not enough in function and performance for official operation, but I think it is a compact and easy-to-try tool.
# wget https://dl.influxdata.com/influxdb/releases/influxdb_1.7.8_amd64.deb
# dpkg -i influxdb_1.7.8_amd64.deb
# systemctl enable influxdb.service
# systemctl start influxdb.service
The procedure to install InfluxDB on Rasbperry Pi 3B is as follows.
# wget https://dl.influxdata.com/influxdb/releases/influxdb_1.7.8_armhf.deb
# dpkg -i influxdb_1.7.8_armhf.deb
# systemctl enable influxdb.service
# systemctl start influxdb.service
# apt-get update
# apt-get install mosquitto
# apt-get install mosquitto-clients
# systemctl enable mosquitto.service
# systemctl start mosquitto.service
The procedure for installing Mosquitto on the Rasbperry Pi 3B is the same.
# wget https://dl.grafana.com/oss/release/grafana_6.3.4_amd64.deb
# dpkg -i grafana_6.3.4_amd64.deb
# systemctl enable grafana-server.service
# systemctl start grafana-server.service
The procedure to install Grafana on Rasbperry Pi 3B is as follows.
# wget https://dl.grafana.com/oss/release/grafana_6.3.4_armhf.deb
# dpkg -i grafana_6.3.4_armhf.deb
# systemctl enable grafana-server.service
# systemctl start grafana-server.service
# wget https://dl.influxdata.com/chronograf/releases/chronograf_1.7.14_amd64.deb
# dpkg -i chronograf_1.7.14_amd64.deb
# systemctl enable chronograf.service
# systemctl start chronograf.service
The procedure to install Chronograf on Rasbperry Pi 3B is as follows.
# wget https://dl.influxdata.com/chronograf/releases/chronograf_1.7.14_armhf.deb
# dpkg -i chronograf_1.7.14_armhf.deb
# systemctl enable chronograf.service
# systemctl start chronograf.service
# openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout cert.key -out cert.pem -subj "/CN=localhost" -days 365
# mkdir /etc/rainy
# cp cert.pem cert.key /etc/rainy/
# cd /etc/rainy
# chmod 0644 cert.pem cert.key
--Edit /etc/grafana/grafana.ini
.
@@ -29,7 +29,7 @@
#################################### Server ####################################
[server]
# Protocol (http, https, socket)
-;protocol = http
+protocol = https
# The ip address to bind to, empty will bind to all interfaces
;http_addr =
@@ -58,8 +58,8 @@
;enable_gzip = false
# https certs & key file
-;cert_file =
-;cert_key =
+cert_file = /etc/rainy/cert.pem
+cert_key = /etc/rainy/cert.key
# Unix socket path
;socket =
--Restart Grafana and connect to https: // hostAddress: 3000 /
in your browser.
# systemctl restart grafana-server.service
--Edit / etc / default / chronograf
.
TLS_CERTIFICATE=/etc/rainy/cert.pem
TLS_PRIVATE_KEY=/etc/rainy/cert.key
--Restart Chronograf and connect to https: // hostAddress: 8888 /
in your browser.
# systemctl restart chronograf.service
bluetoothAdapter
hci0
. To see the available adapter names, use the hciconfig
command as follows:# hciconfig -a
hci0: Type: Primary Bus: UART
BD Address: B8:27:EB:7D:0F:7D ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING
RX bytes:28342 acl:441 sco:0 events:2265 errors:0
TX bytes:34605 acl:441 sco:0 commands:1955 errors:0
Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH SNIFF
Link mode: SLAVE ACCEPT
Name: 'raspberrypi'
Class: 0x000000
Service Classes: Unspecified
Device Class: Miscellaneous,
HCI Version: 4.1 (0x7) Revision: 0x168
LMP Version: 4.1 (0x7) Subversion: 0x2209
Manufacturer: Broadcom Corporation (15)
influxDB
true
when using InfluxDB. The default is false
.mqtt
true
when using the MQTT broker. The default is false
.prettyPrinting
true
to output JSON format data to the log when sending to the MQTT broker. The default is false
. You also need to change the following log levels in conf / logging.properties
. #io.github.s5uishida.level=INFO
-->
io.github.s5uishida.level=FINE
readCrontab
batteryLevel
true
to get the battery level. The default is false
.
--Temperature sensor setting example
temperature
true
to get the temperature. The default is false
.temperatureNotify
true
. The default is false
. When the notification function is enabled, the schedule specified by readCrontab
is disabled.temperatureNotificationPeriod
1000
.
--Motion (angular velocity / acceleration / magnetism)gyroscope
true
to get the angular velocity. The default is false
.accelerometer
true
if you want to get the acceleration. The default is false
.magnetometer
true
if you want to get magnetism. The default is false
.movementNotify
true
if you want to use the sensor notification function for exercise. When the notification function is enabled, the schedule specified by readCrontab
is disabled.movementNotificationPeriod
1000
.wakeOnMotion
true
if you want to send sensor data about exercise when shaking is detected. When enabled, it will send sensor data about exercise at specified notification time intervals over a 10 second period. The default is false
.accelerometerRange
2
.devices
hcitool
command as follows.# hcitool lescan
LE Scan ...
B0:B4:48:B9:92:86 (unknown)
B0:B4:48:B9:92:86 CC2650 SensorTag
Run the hcitool
command and press the power button on the CC2650 to see the addresses scanned as above.
**important point. When used with the PPD42NS, connect pin 4 (yellow) on the PPD42NS to pin 19 (GPIO10) or pin 38 (GPIO20) on the Raspberry Pi 3B. Alternatively, when connecting pin 4 (yellow) of PPD42NS to pin 8 (GPIO14) of Raspberry Pi 3B, connect to Raspberry Pi 3B via USB serial communication adapter to MH-Z19B (DSD TECH SH- U09C USB to TTL Serial Adapter with FTDI FT232RL Chip etc.). If you connect the MH-Z19B to a USB serial communication adapter, the serial communication port name will be / dev / ttyUSB0
. ** **
portName
/ dev / ttyAMA0
.influxDB
true
when using InfluxDB. The default is false
.mqtt
true
when using the MQTT broker. The default is false
.prettyPrinting
true
to output JSON format data to the log when sending to the MQTT broker. The default is false
. You also need to change the following log levels in conf / logging.properties
. #io.github.s5uishida.level=INFO
-->
io.github.s5uishida.level=FINE
readCrontab
gpioPin
GPIO_10
, GPIO_20
or GPIO_14
. The default is GPIO_10
.influxDB
true
when using InfluxDB. The default is false
.mqtt
true
when using the MQTT broker. The default is false
.prettyPrinting
true
to output JSON format data to the log when sending to the MQTT broker. The default is false
. You also need to change the following log levels in conf / logging.properties
. #io.github.s5uishida.level=INFO
-->
io.github.s5uishida.level=FINE
readCrontab
influxDB
true
when using InfluxDB. The default is false
.mqtt
true
when using the MQTT broker. The default is false
.prettyPrinting
true
to output JSON format data to the log when sending to the MQTT broker. The default is false
. You also need to change the following log levels in conf / logging.properties
. #io.github.s5uishida.level=INFO
-->
io.github.s5uishida.level=FINE
keyStoreType
keyStoreAlias
keyStorePassword
certificate
use
true
when connecting to this OPC-UA server. The default is false
.serverName
endpointIP
endpointPort
securityPolicy
Basic128Rsa15
, Basic256
, Basic256Sha256
, None
. The default is None
.securityMode
Sign
, SignAndEncrypt
, or None
for securityMode. The default is None
.userName
password
requestTimeout
10000
(msec).sessionTimeout
10000
(msec).publishingInterval
1000
.samplingInterval
500
.queueSize
10
.dataChangeTrigger
0
for DataChangeTrigger.Status1
for DataChangeTrigger.StatusValue2
for DataChangeTrigger.StatusValueTimestamp1
.nodeIDs
<namespaceIndex>,<identifier>,<depth>
Below is a sample. If depth is set to -1
, the node ID will be searched from the node ID to the end.
nodeIDs=2,Dynamic/RandomInt32,0 \
2,Dynamic/RandomInt64,0 \
2,Dynamic,-1 \
0,2295,-1
In the above example, the node IDs are explicitly specified as 2, Dynamic / RandomInt32
and 2, Dynamic / RandomInt64
, and together with 2, Dynamic
and 0,2295
(VendorServerInfo). Search the node ID of the hierarchy to the end.
There is also milo-example.properties
in the conf / opcua
directory. This is an example of connecting settings to milo-example-server that built the sample server included in Eclipse Milo.
For reference, as a simple tool to check the Address Space of the OPC-UA server, [toem impulse OPC / UA Extension (Eclipse pulug-in)](https://toem.de/index.php/projects/impulse- There is opcua).
# cd /path/to/rainy-felix/bin
# sh rainy-start.sh
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.felix.framework.ext.ClassPathExtenderFactory$DefaultClassLoaderExtender (file:/path/to/rainy-felix/bin/felix.jar) to method java.net.URLClassLoader.addURL(java.net.URL)
WARNING: Please consider reporting this to the maintainers of org.apache.felix.framework.ext.ClassPathExtenderFactory$DefaultClassLoaderExtender
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
-> ps
START LEVEL 1
ID State Level Name
[ 0] [Active ] [ 0] System Bundle (6.0.3)
[ 1] [Active ] [ 1] bcpkix (1.62)
[ 2] [Active ] [ 1] bcprov (1.62)
[ 3] [Active ] [ 1] bluetooth scanner (0.1.1)
[ 4] [Active ] [ 1] bluez-dbus-osgi (0.1.2.201908052042)
[ 5] [Active ] [ 1] bsd-parser-core (0.3.3)
[ 6] [Active ] [ 1] bsd-parser-gson (0.3.3)
[ 7] [Active ] [ 1] java driver for ti sensortag cc2650 (0.1.0)
[ 8] [Active ] [ 1] Apache Commons Lang (3.9.0)
[ 9] [Active ] [ 1] cron4j-osgi (2.2.5)
[ 10] [Active ] [ 1] dbus-java-with-java-utils-osgi (3.0.2)
[ 11] [Active ] [ 1] Gson (2.8.5)
[ 12] [Active ] [ 1] Guava: Google Core Libraries for Java (26.0.0.jre)
[ 13] [Active ] [ 1] Java client for InfluxDB (2.15)
[ 14] [Active ] [ 1] jSerialComm (2.5.1)
[ 15] [Active ] [ 1] Jackson-annotations (2.9.9)
[ 16] [Active ] [ 1] Jackson-core (2.9.9)
[ 17] [Active ] [ 1] jackson-databind (2.9.9.1)
[ 18] [Active ] [ 1] JavaBeans Activation Framework (1.2.0)
[ 19] [Active ] [ 1] jaxb-api (2.4.0.b1808300359)
[ 20] [Active ] [ 1] file:/home/pi/rainy-felix/bundle/jaxb-runtime-2.4.0-b180830.0438.jar
[ 21] [Active ] [ 1] java driver for mh-z19b - intelligent infrared co2 module (0.1.2)
[ 22] [Active ] [ 1] A modern JSON library for Kotlin and Java (1.7.0)
[ 23] [Active ] [ 1] MessagePack serializer implementation for Java (0.8.17)
[ 24] [Active ] [ 1] Netty/Buffer (4.1.38.Final)
[ 25] [Active ] [ 1] netty-channel-fsm-osgi (0.3.0)
[ 26] [Active ] [ 1] Netty/Codec (4.1.38.Final)
[ 27] [Active ] [ 1] Netty/Codec/HTTP (4.1.38.Final)
[ 28] [Active ] [ 1] Netty/Common (4.1.38.Final)
[ 29] [Active ] [ 1] Netty/Handler (4.1.38.Final)
[ 30] [Active ] [ 1] Netty/Resolver (4.1.38.Final)
[ 31] [Active ] [ 1] Netty/Transport (4.1.38.Final)
[ 32] [Active ] [ 1] Apache Felix Shell Service (1.4.3)
[ 33] [Active ] [ 1] Apache Felix Shell TUI (1.4.1)
[ 34] [Active ] [ 1] Apache ServiceMix :: Bundles :: jsr305 (3.0.2.1)
[ 35] [Active ] [ 1] Apache ServiceMix :: Bundles :: okhttp (3.14.1.1)
[ 36] [Active ] [ 1] Apache ServiceMix :: Bundles :: okio (1.15.0.1)
[ 37] [Active ] [ 1] Apache ServiceMix :: Bundles :: retrofit (2.5.0.2)
[ 38] [Active ] [ 1] Paho MQTT Client (1.2.1)
[ 39] [Active ] [ 1] OSGi LogService implemented over SLF4J (1.7.26)
[ 40] [Active ] [ 1] Pi4J :: Java Library (Core) (1.2)
[ 41] [Active ] [ 1] java driver for ppd42ns - dust sensor module (0.1.6)
[ 42] [Active ] [ 1] osgi activator of rainy - a tiny tool for iot data collection and monitoring (0.1.6)
[ 43] [Active ] [ 1] OPC-UA bundle of rainy - a tiny tool for iot data collection and monitoring (0.1.4)
[ 44] [Active ] [ 1] rainy - a tiny tool for iot data collection and monitoring (0.1.14)
[ 45] [Active ] [ 1] sdk-client (0.3.3)
[ 46] [Active ] [ 1] sdk-core (0.3.3)
[ 47] [Active ] [ 1] slf4j-api (1.7.26)
[ 48] [Resolved ] [ 1] slf4j-jdk14 (1.7.26)
[ 49] [Active ] [ 1] stack-client (0.3.3)
[ 50] [Active ] [ 1] stack-core (0.3.3)
[ 51] [Active ] [ 1] strict-machine-osgi (0.1.0)
->
-> stop 0
If you change the following log level of conf / logging.properties
to ʻINFO-> FINE and restart ** rainy **, the acquired sensor data will be the log file
logs / rainy.log.0 It is output to `.
#io.github.s5uishida.level=INFO
-->
io.github.s5uishida.level=FINE
An example of log file output is as follows. The beginning of the line is omitted.
[/dev/ttyAMA0] co2:850
[hci0] B0:B4:48:B9:92:86 obj:28.28125 amb:32.28125
[hci0] B0:B4:48:B9:92:86 humidity:59.362793
[hci0] B0:B4:48:B9:92:86 pressure:1012.27
[hci0] B0:B4:48:B9:92:86 optical:227.28
[hci0] B0:B4:48:B9:92:86 gyr[x]:-1.3198851
[hci0] B0:B4:48:B9:92:86 gyr[y]:-0.2593994
[hci0] B0:B4:48:B9:92:86 gyr[z]:0.7476806
[hci0] B0:B4:48:B9:92:86 acc[x]:0.0056152344
[hci0] B0:B4:48:B9:92:86 acc[y]:-0.007080078
[hci0] B0:B4:48:B9:92:86 acc[z]:0.9707031
[hci0] B0:B4:48:B9:92:86 mag[x]:127.0
[hci0] B0:B4:48:B9:92:86 mag[y]:420.0
[hci0] B0:B4:48:B9:92:86 mag[z]:302.0
[GPIO_10] pcs:1373.6702 ugm3:2.1420693
To reduce the number of writes to the SD card of Raspberry Pi 3B, it is usually recommended to set the log level to ʻINFO`.
From the log file logs / rainy.log.0
, check the database name created in InfluxDB. Below is an example of the database name created for each sensor.
RP3B_01__dev_ttyAMA0
--CC2650 ⇒ B0_B4_48_B9_92_86
and B0_B4_48_ED_B6_04
--Eclipse Milo public demo server ⇒ milo_digitalpetri_com_62541_milo
RP3B_01_GPIO_10
execute - CREATE DATABASE RP3B_01__dev_ttyAMA0
...
execute - CREATE DATABASE B0_B4_48_B9_92_86
...
execute - CREATE DATABASE B0_B4_48_ED_B6_04
...
execute - CREATE DATABASE milo_digitalpetri_com_62541_milo
...
execute - CREATE DATABASE RP3B_01_GPIO_10
These database names are needed as information to connect to InfluxDB when creating dashboards in Grafana or Chronograf.
Connect to InfluxDB from visualization tools Grafana and Chronograf to monitor time-series sensor data.
For how to use Grafana, refer to Getting started here. The graph below is an example of a dashboard created with Grafana. The graph below is an example of a magnetic (3 axis) 3D image using the Plotly (https://grafana.com/grafana/plugins/natel-plotly-panel) panel. The graph below is an example of an image of sensor data mapped to a floor using the ImageIt (https://grafana.com/grafana/plugins/pierosavi-imageit-panel) panel. CC2650 is placed in three rooms, and MH-Z19B (CO2 concentration) and PPD42NS (PM2.5 concentration) are placed in the main room.
For how to use Chronograf, refer to Getting started at here. The graph below is an example of a dashboard created with Chronograf. The graph below is an example dashboard image for the following node IDs in the Eclipse Milo public demo server.
1,VendorServerInfo/ProcessCpuLoad
1,VendorServerInfo/SystemCpuLoad
1,VendorServerInfo/UsedMemory
2,Dynamic/RandomDouble
2,Dynamic/RandomFloat
2,Dynamic/RandomInt32
2,Dynamic/RandomInt64
The upper row shows the data of each node ID of 1, VendorServerInfo / ProcessCpuLoad
, 1, VendorServerInfo / SystemCpuLoad
, and 1, VendorServerInfo / UsedMemory
. The middle row shows the data of each node ID of 2, Dynamic / Random Double
and 2, Dynamic / Random Float
superimposed. The lower row shows the data of each node ID of 2, Dynamic / RandomInt32
and 2, Dynamic / RandomInt64
.Visualization tools Grafana and Chronograf make it easy to create a dashboard of time series data for each sensor sent to InfluxDB.
You can check the data sent to the MQTT broker by running the MQTT client command as follows:
# mosquitto_sub -d -t rainy/B0_B4_48_ED_B6_04
Client mosqsub|2095-u1804 sending CONNECT
Client mosqsub|2095-u1804 received CONNACK
Client mosqsub|2095-u1804 sending SUBSCRIBE (Mid: 1, Topic: rainy/B0_B4_48_ED_B6_04, QoS: 0)
Client mosqsub|2095-u1804 received SUBACK
Subscribed (mid: 1): 0
Client mosqsub|2095-u1804 received PUBLISH (d0, q0, r0, m0, 'rainy/B0_B4_48_ED_B6_04', ... (670 bytes))
{"deviceID":"B0:B4:48:ED:B6:04","clientID":"RP3B-01","samplingDate":"2019-08-09 12:56:00.009","samplingTimeMillis":1565351760009,"samplingTimeNanos":0,"firmwareVersion":"1.30 (May 23 2016)","batteryLevel":{"value":72,"unit":"%"},"objectTemperature":{"value":27.46875,"unit":"deg C"},"ambientTemperature":{"value":32.03125,"unit":"deg C"},"humidity":{"value":34.61914,"unit":"%"},"pressure":{"value":1009.16,"unit":"hPa"},"optical":{"value":203.84,"unit":"lux"},"gyroscope":{"x":-10.589599,"y":-7.8887935,"z":-2.281189,"unit":"deg/s"},"accelerometer":{"x":-0.029785156,"y":-0.06347656,"z":1.1887207,"unit":"G"},"magnetometer":{"x":138.0,"y":125.0,"z":-199.0,"unit":"uT"}}
The license for the following bundles I created is the MIT license.
Please check each license for the following bundles of the 3rd party you are using.
We would like to thank the developers of these handles and those who have contributed.
This series consists of the following articles:
[2019.11.16] For the latest information on simple tools, please refer to here.
Recommended Posts