Browse Source

MQTT auth and improvements implemented

master
Dirk Alders 2 years ago
parent
commit
c440b10bbe
3 changed files with 22 additions and 6 deletions
  1. 15
    1
      .gitignore
  2. 5
    4
      config_example/config.py
  3. 2
    1
      powerplug.py

+ 15
- 1
.gitignore View File

1
 # ---> powerplug-energenie
1
 # ---> powerplug-energenie
2
 #
2
 #
3
 config.py
3
 config.py
4
-
4
+*.err
5
 
5
 
6
 # ---> Python
6
 # ---> Python
7
 # Byte-compiled / optimized / DLL files
7
 # Byte-compiled / optimized / DLL files
119
 # Pyre type checker
119
 # Pyre type checker
120
 .pyre/
120
 .pyre/
121
 
121
 
122
+# ---> VirtualEnv
123
+# Virtualenv
124
+# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
125
+.Python
126
+[Bb]in
127
+[Ii]nclude
128
+[Ll]ib
129
+[Ll]ib64
130
+[Ll]ocal
131
+[Ss]cripts
132
+pyvenv.cfg
133
+.venv
134
+pip-selfcheck.json
135
+
122
 # ---> Linux
136
 # ---> Linux
123
 *~
137
 *~
124
 
138
 

+ 5
- 4
config_example/config.py View File

3
 import os
3
 import os
4
 import report
4
 import report
5
 
5
 
6
-
7
-MQTT_SERVER = "multimedia"
6
+MQTT_USER = "user"
7
+MQTT_PASS = "pass"
8
+MQTT_SERVER = "localhost"
8
 MQTT_TOPIC = "hifi/powerplug"
9
 MQTT_TOPIC = "hifi/powerplug"
9
 
10
 
10
 #
11
 #
12
 #
13
 #
13
 __BASEPATH__ = os.path.abspath(os.path.dirname(__file__))
14
 __BASEPATH__ = os.path.abspath(os.path.dirname(__file__))
14
 APP_NAME = "powerplug"
15
 APP_NAME = "powerplug"
15
-LOGTARGET = 'stdout'   # possible choices are: 'logfile' or 'stdout'
16
+LOGTARGET = 'logfile'   # possible choices are: 'logfile' or 'stdout'
16
 LOGLVL = 'DEBUG'
17
 LOGLVL = 'DEBUG'
17
 
18
 
18
-LOGHOST = 'localhost'
19
+LOGHOST = 'cutelog'
19
 LOGPORT = 19996
20
 LOGPORT = 19996
20
 
21
 
21
 formatter = report.LONG_FMT
22
 formatter = report.LONG_FMT

+ 2
- 1
powerplug.py View File

52
     def __init__(self):
52
     def __init__(self):
53
         self.__client__ = mqtt.Client("mqtt_powerplug")                         # create client object
53
         self.__client__ = mqtt.Client("mqtt_powerplug")                         # create client object
54
         self.__client__.on_message = self.__receive__                           # attach function to callback
54
         self.__client__.on_message = self.__receive__                           # attach function to callback
55
-        self.__client__.connect("192.168.0.131", 1883)                          # establish connection
55
+        self.__client__.username_pw_set(config.MQTT_USER, config.MQTT_PASS)     # login with credentials
56
+        self.__client__.connect(config.MQTT_SERVER, 1883)                       # establish connection
56
         self.__client__.loop_start()                                            # start the loop
57
         self.__client__.loop_start()                                            # start the loop
57
         self.__topics__ = []
58
         self.__topics__ = []
58
         for subtopic in self.SUBTOPICS:
59
         for subtopic in self.SUBTOPICS:

Loading…
Cancel
Save