|
1 | 1 | import os |
2 | 2 | import sys |
3 | | - |
| 3 | +import ssl |
4 | 4 |
|
5 | 5 | sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../"))) |
6 | 6 |
|
|
9 | 9 | from hololinked.server.mqtt import MQTTPublisher |
10 | 10 | from hololinked.serializers import Serializers |
11 | 11 | from hololinked.config import global_config |
| 12 | +from hololinked.server import run |
12 | 13 | from things import TestThing, OceanOpticsSpectrometer |
13 | 14 |
|
14 | | -import ssl |
15 | | - |
16 | 15 | global_config.DEBUG = True |
17 | 16 |
|
18 | | -thing = TestThing(id="example-test") |
19 | | -# thing = OceanOpticsSpectrometer(id="example-test", serial_number="simulation") |
| 17 | +thing1 = TestThing(id="test-thing") |
| 18 | +thing2 = OceanOpticsSpectrometer(id="test-spectrometer", serial_number="simulation") |
20 | 19 |
|
21 | 20 |
|
22 | 21 | Serializers.register_for_object(TestThing.db_init_int_prop, Serializers.pickle) |
|
32 | 31 | # ] |
33 | 32 | # ) |
34 | 33 |
|
35 | | -http_server = HTTPServer(port=9000) |
36 | | -zmq_server = ZMQServer(id="example-test-server", things=[thing], access_points="IPC") |
37 | | - |
38 | 34 | mqtt_ssl = ssl.create_default_context(ssl.Purpose.SERVER_AUTH) |
39 | 35 | if not os.path.exists("ca.crt"): |
40 | 36 | raise FileNotFoundError("CA certificate 'ca.crt' not found in current directory for MQTT TLS connection") |
|
43 | 39 | mqtt_ssl.verify_mode = ssl.CERT_REQUIRED |
44 | 40 | mqtt_ssl.minimum_version = ssl.TLSVersion.TLSv1_2 |
45 | 41 |
|
| 42 | +http_server = HTTPServer(port=9000) |
| 43 | +zmq_server = ZMQServer(id="example-test-server", access_points="IPC") |
46 | 44 | mqtt_publisher = MQTTPublisher( |
47 | 45 | hostname="localhost", |
48 | 46 | port=8883, |
|
51 | 49 | qos=1, |
52 | 50 | ssl_context=mqtt_ssl, |
53 | 51 | ) |
54 | | -thing.run(servers=[http_server, zmq_server, mqtt_publisher]) |
| 52 | +zmq_server.add_things(thing1, thing2) |
| 53 | +mqtt_publisher.add_things(thing2) |
| 54 | +http_server.add_things(thing1) |
| 55 | + |
| 56 | +run(zmq_server, mqtt_publisher, http_server) |
0 commit comments