-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtemplate-poly.py
More file actions
executable file
·75 lines (64 loc) · 2.34 KB
/
template-poly.py
File metadata and controls
executable file
·75 lines (64 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
"""
This is a NodeServer template for Polyglot v3 written in Python3
v2 version by Einstein.42 (James Milne) milne.james@gmail.com
v3 version by (Bob Paauwe) bpaauwe@yahoo.com
"""
import udi_interface
import sys
"""
Import the polyglot interface module. This is in pypy so you can just install it
normally. Replace pip with pip3 if you are using python3.
Virtualenv:
pip install udi_interface
Not Virutalenv:
pip install udi_interface --user
* It is recommended you ALWAYS develop your NodeServers in virtualenv
to maintain cleanliness, however that isn't required. Keep track of any
other modules you install and add these to the requirements.txt file.
"""
"""
udi_interface has a LOGGER that is created by default and logs to:
logs/debug.log
You can use LOGGER.info, LOGGER.warning, LOGGER.debug, LOGGER.error,
LOGGER.critical levels as needed in your node server.
"""
LOGGER = udi_interface.LOGGER
""" Grab My Controller Node (optional) """
from nodes import TemplateController
if __name__ == "__main__":
try:
"""
Instantiates the Interface to Polyglot.
* Optionally pass list of class names
- PG2 had the controller node name here
"""
polyglot = udi_interface.Interface([TemplateController])
"""
Starts MQTT and connects to Polyglot.
"""
polyglot.start()
"""
Creates the Controller Node and passes in the Interface, the node's
parent address, node's address, and name/title
* address, parent address, and name/title are new for Polyglot
version 3
* use 'controller' for both parent and address and PG3 will be able
to automatically update node server status
"""
control = TemplateController(polyglot, 'controller', 'controller', 'PythonTemplate')
"""
Sits around and does nothing forever, keeping your program running.
* runForever() moved from controller class to interface class in
Polyglot version 3
"""
polyglot.runForever()
except (KeyboardInterrupt, SystemExit):
LOGGER.warning("Received interrupt or exit...")
"""
Catch SIGTERM or Control-C and exit cleanly.
"""
polyglot.stop()
except Exception as err:
LOGGER.error('Excption: {0}'.format(err), exc_info=True)
sys.exit(0)