Skip to content

Commit 902a051

Browse files
Merge pull request #40 from OS2iot/feature/docs-for-mqtt-support
Feature/docs for mqtt support
2 parents a18e30d + 3d22229 commit 902a051

File tree

17 files changed

+173
-22
lines changed

17 files changed

+173
-22
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ docProps
88
word
99
customXml
1010
[Content_Types].customXml
11+
.idea

source/exit-strategy/exit-strategy.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
Exit strategy
22
=============
33

4-
There are two primary ways of systematically exporting the data from OS2iot:
4+
There are three primary ways of systematically exporting the data from OS2iot:
55

6-
1. Using the REST API
6+
1. Using the Export
7+
8+
a. Ideal if you just need to get all the information about devices in an application.
9+
10+
2. Using the REST API
711

812
a. Ideal if you want to import/change it into something else, and OS2iot is still running.
913

10-
2. Exporting the database
14+
3. Exporting the database
1115

1216
a. If OS2iot is no longer running, the postgres database will contain all the data from the system.
1317

18+
Export using CSV export
19+
-----------------------
20+
21+
It is possible, when on the details page for an application, to get a csv file containing all the devices in the application.
22+
23+
This csv file is formatted to be compatible with the bulk import feature, button located right next to it, to make it possible to reimport the devices into a different application.
24+
25+
1426
Export using the REST API
1527
-------------------------
1628
The REST API is automatically exported from the backend via swagger.

source/external-interface-design/external-interface-design.rst

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Integration patterns
2020
Internal systems
2121
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2222

23-
Internally, OS2iot consists of four components shown in this figure.
23+
Internally, OS2iot consists of five components shown in this figure.
2424

2525
|image2|
2626

@@ -30,7 +30,7 @@ Two different patterns are used between the internal components:
3030
| Used between the frontend, backend and database.
3131
3232
- | **Publish-subscribe**
33-
| Used in communication between the backend and MQTT broker for Chirpstack.
33+
| Used in communication between the backend and MQTT broker for Chirpstack and the internal MQTT broker.
3434
3535
External systems
3636
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -50,11 +50,13 @@ IoT devices
5050

5151
Figure 3 - IoT device integration overview
5252

53-
All IoT device integrations except LoRaWAN use callbacks to send data to
53+
All IoT device integrations except LoRaWAN and MQTT use callbacks to send data to
5454
OS2iot using HTTPS in a request-response manner. Device management for
5555
Sigfox (i.e. adding and modifying IoT devices) is done by
5656
sending requests to Sigfox's Cloud backend.
5757

58+
MQTT devices uses the MQTT protocol to communicate with the broker.
59+
5860
Data from Chirpstack devices are sent to OS2iot through Chirpstack using
5961
MQTT, where Chirpstack is the publisher and OS2iot is the subscriber.
6062
Device management is done from OS2iot by sending gRPC requests to
@@ -308,6 +310,40 @@ over the network by a device.
308310

309311
.. _update-existing-device-1:
310312

313+
MQTT
314+
^^^^
315+
316+
There are two kinds of MQTT devices available. MQTT-publisher and MQTT-subscriber. These two devices works in different matters which will be described below.
317+
318+
MQTT-publisher
319+
~~~~~~~~~~~~~~
320+
The MQTT-publisher device will make it possible for a physical device to communicate with the internal OS2IoT mosquitto broker.
321+
The MQTT-publisher is created in the OS2IoT backend and is created with the credentials that the device needs for communicating with the internal broker.
322+
323+
The MQTT-publisher device can either be created with username/password or credentials. If the publisher is created with username/password it will use port 8885, and if created with certificate it will use port 8884.
324+
325+
When a physical MQTT device will publish some data, then OS2IoT will check for the specific topic that the device is publishing to in the database, and if the topic is set in the database, it will process the data.
326+
If a MQTT-publisher device with the specific topic isn't created then the broker won't be able to find it in the database and therefore it will reject the data.
327+
328+
The specific topic for the created device will be :code:`device/organizationID/applicationID/deviceID`.
329+
330+
331+
332+
333+
MQTT-subscriber
334+
~~~~~~~~~~~~~~~
335+
336+
The MQTT-subscriber uses the MQTT protocol to subscribe to a topic on an external MQTT broker. A client is created in the OS2IoT backend.
337+
This client will connect to the external MQTT broker using the provided URL, port and authentication, and then subscribe to data on the provided topic.
338+
339+
OS2IoT doesn't have any knowlegde of the external broker so it's totally up to the user to provide the different inputs.
340+
If the input isn't valid and a connection can't be made to the external broker, a flag will be set in the database which tells OS2IoT that the connection can't be made and then OS2IoT will stop trying to connect to the external broker.
341+
342+
If the inputs from the user IS valid, then a connection will be made and the device will listen to any updates from the broker.
343+
344+
The MQTT-subscriber device has the possibility to use either certificate or username/password to a external broker if needed.
345+
346+
311347
Sigfox
312348
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
313349

@@ -514,7 +550,7 @@ See `the seperate page for KOMBIT adgangsstyring <../kombit-adgangsstyring/kombi
514550

515551
.. |image1| image:: media/image5.png
516552
.. |image2| image:: media/image6.png
517-
.. |image3| image:: media/image7.png
553+
.. |image3| image:: media/image5.png
518554
.. |image4| image:: media/image8.png
519555
.. |image5| image:: media/image9.png
520556
.. |image6| image:: media/image10.png
Loading
Loading
-30.5 KB
Binary file not shown.

source/installation-guide/installation-guide.rst

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,13 @@ OS2IoT-backend takes several environment variables as configuration, if these ar
245245
+-------------------------------+------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
246246
| METADATA_SAVED_COUNT | Maximum number of message metadata to store from an IoT device | :code:`20` |
247247
+-------------------------------+------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
248-
| DEVICE_STATS_INTERVAL_IN_DAYS | How many days back to fetch IoT device statistics | :code:`29` |
248+
| MQTT_BROKER_HOSTNAME | The hostname of the MQTT broker. | :code:`localhost` |
249+
+-------------------------------+------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
250+
| MQTT_SUPER_USER_PASSWORD | The password for the internal MQTT listener. | :code:`SuperUser` |
251+
+-------------------------------+------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
252+
| ENCRYPTION_SYMMETRIC_KEY | A symmetric key that is used for encrypting | :code:`SecretKey` |
253+
+-------------------------------+------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
254+
| CA_KEY_PASSWORD | The password for the Certificate Authority key. | :code:`os2iot` |
249255
+-------------------------------+------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
250256
251257
Logs levels
@@ -268,3 +274,48 @@ Defaults are set in :code:`OS2IoT-frontend/src/environments/environment.ts`
268274
+-------------------------------+--------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
269275
| TABLE_PAGE_SIZE | Default page size of tables | :code:`25` |
270276
+-------------------------------+--------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
277+
278+
OS2IoT-Mosquitto broker
279+
^^^^^^^^^^^^^^^^^^^^^^^
280+
281+
To get the mosquitto broker working, you have to create some certificates and update some values. These following steps is done with Windows. If you use linux, then write :code:`sudo` before the commands.
282+
283+
Prerequisites: openssl installed and accesible from path
284+
285+
Generate files:
286+
287+
1. Open the command prompt in administrator mode.
288+
289+
2. Create a certificate authority(CA) key with this command: :code:`openssl genrsa -des3 -out ca.key 2048`. You will be prompted to enter a password. It's very important that you save this password, since it will be used later.
290+
291+
3. Create the CA certificate with this command: :code:`openssl req -new -x509 -days 1826 -key ca.key -out ca.crt`. You will be asked to enter the password from the step before. After this, you will be prompted to enter informations. These values are not important, except one: "Common name". Common name HAS to be the ip/hostname of your broker.
292+
293+
4. Create the server key (for the broker) with the command: :code:`openssl genrsa -out server.key 2048`
294+
295+
6. Create the server signing request with the command: :code:`openssl req -new -out server.csr -key server.key`. You will be prompted to enter some informations. These values are not important, except one: "Common name". Common name HAS to be the ip/hostname of your broker. The rest of the values should not be exact the same as in step 4.
296+
297+
7. Create the server certificate (that is signed by the CA) with this command: :code:`openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 360`. You will be prompted to enter the password from step 3.
298+
299+
If you want to get docker container with mosquitto running, then follow these steps:
300+
301+
1. Place the generated files, ca.key, ca.crt, server.key and server.crt from the above steps in the folder "OS2IoT-docker/configuration/mosquitto-broker-os2iot". You don't need the server.csr.
302+
303+
2. Open the mosquitto-os2iot.conf file placed in OS2IoT-docker/configuration/mosquitto-broker-os2iot in a text editor and update the values to match your database.
304+
305+
3. Copy the files ca.crt and ca.key and place them in OS2IoT-backend/resources.
306+
307+
4. Update the :code:`MQTT_BROKER_HOSTNAME` with the ip/hostname that you used for step 4 and 6, and :code:`CA_KEY_PASSWORD` with the password that you entered in step 3 in the docker-compose.yml file placed in OS2IoT-docker.
308+
309+
If you want to use kubernetes to host mosquitto then you need some futher steps.
310+
311+
Prerequisites: kubectl installed and accesible from path
312+
313+
1. Open a command prompt in administrator mode.
314+
315+
2. Create a secret with the server.key and server.crt with the command: :code:`kubectl create secret generic server-keys --from-file=server.key=path/to/server.key --from-file=server.crt=path/to/server.crt`. Replace path/to/ with the path to your server.key and server.crt, created in the steps above.
316+
317+
3. Create a secret with the ca.crt and ca.key with the command: :code:`kubectl create secret generic ca-keys --from-file=ca.crt=path/to/ca.crt --from-file=ca.key=path/to/ca.key`. Replace path/to/ with the path to your server.key and server.crt, created in the steps above.
318+
319+
4. Update the empty values in OS2IoT-docker/helm/charts/mosquitto-os2iot/values.yaml
320+
321+
5. Update the :code:`MQTT_BROKER_HOSTNAME` with the ip/hostname that you used for step 4 and 6 in the steps above, and :code:`CA_KEY_PASSWORD` with the password that you entered in step 3 in the steps above, in the file "OS2IoT-docker/helm/charts/os2iot-backend/deployment.yaml".

source/iot-data-handling/iot-data-handling.rst

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ The following sequence diagram illustrates how data is processed when it is rece
1010
Data ingestion
1111
--------------
1212

13-
OS2iot supports three types of devices:
13+
OS2iot supports four types of devices:
1414

1515
1. LoRaWAN devices (using Chirpstack)
1616

1717
2. SigFox devices
1818

1919
3. Generic HTTP devices
20+
21+
4. MQTT devices
2022

2123
OS2iot ingests data for each of these device types in a slightly different way:
2224

@@ -57,6 +59,30 @@ The endpoint :code:`/api/v1/receive-data?apiKey=<guid>` is used for this, where
5759
If the API-key is valid and corresponds to a device in OS2iot, then the response will be 204 No Content, and the message is further processed.
5860
If the API-key is unknown, then the resposne will be 403 Bad Request with the message: :code:`MESSAGE.DEVICE-DOES-NOT-EXIST`
5961

62+
MQTT
63+
^^^^
64+
65+
OS2IoT supports two kinds of MQTT devices. An MQTT-publisher and an MQTT-subscriber.
66+
67+
OS2IoT supports two kinds of authorization for MQTT devices: Username/password and certificate.
68+
69+
MQTT-publisher
70+
~~~~~~~~~~~~~~
71+
72+
When an MQTT-publisher is created, the credentials for connecting to the internal MQTT-broker are generated.
73+
These consists of a URL, a port and a topic for the device to send data to.
74+
If the authorization type is certificate then the required certificates will be generated. If username/password is used these are manually entered.
75+
76+
When a known MQTT-publisher sends data to the topic assigned to it, the message will be further processed.
77+
If a device attempts to send to a different topic the message will be discarded.
78+
79+
MQTT-subscriber
80+
~~~~~~~~~~~~~~~
81+
82+
When an MQTT-subscriber is created a connection to the external broker is made using the entered credentials.
83+
When a message is received by the external broker on the topic configured, OS2IoT will also receive the message and further process it.
84+
85+
6086
Payload transformation and storage
6187
----------------------------------
6288

source/logical-data-model/logical-datamodel.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,18 @@ DataTargetType
9393
~~~~~~~~~~~~~~~~~
9494

9595
1. HttpPush
96+
2. Fiware
97+
3. MQTT
98+
4. OpenDataDK
9699

97100
IoTDeviceType
98101
~~~~~~~~~~~~~~~~~
99102

100103
1. GenericHttp
101104
2. LoRaWAN
102105
3. SigFox
106+
4. MQTTBroker
107+
5. MQTTSubscriber
103108

104109
ErrorCodes
105110
~~~~~~~~~~~~~~~~~
@@ -184,5 +189,10 @@ SigFoxPayloadType
184189
5. RadioPlanningFrame
185190
6. Sensitv2
186191

192+
AuthenticationType
193+
~~~~~~~~~~~~~~~~~~
194+
1. PASSWORD
195+
2. CERTIFICATE
196+
187197
.. |image1| image:: ./media/image4.png
188198

65.5 KB
Loading

0 commit comments

Comments
 (0)