Kaynağa Gözat

MQTT auth and improvements implemented

master
Dirk Alders 2 yıl önce
ebeveyn
işleme
c440b10bbe
3 değiştirilmiş dosya ile 22 ekleme ve 6 silme
  1. 15
    1
      .gitignore
  2. 5
    4
      config_example/config.py
  3. 2
    1
      powerplug.py

+ 15
- 1
.gitignore Dosyayı Görüntüle

@@ -1,7 +1,7 @@
1 1
 # ---> powerplug-energenie
2 2
 #
3 3
 config.py
4
-
4
+*.err
5 5
 
6 6
 # ---> Python
7 7
 # Byte-compiled / optimized / DLL files
@@ -119,6 +119,20 @@ dmypy.json
119 119
 # Pyre type checker
120 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 136
 # ---> Linux
123 137
 *~
124 138
 

+ 5
- 4
config_example/config.py Dosyayı Görüntüle

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

+ 2
- 1
powerplug.py Dosyayı Görüntüle

@@ -52,7 +52,8 @@ class mqtt_powerplug(object):
52 52
     def __init__(self):
53 53
         self.__client__ = mqtt.Client("mqtt_powerplug")                         # create client object
54 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 57
         self.__client__.loop_start()                                            # start the loop
57 58
         self.__topics__ = []
58 59
         for subtopic in self.SUBTOPICS:

Loading…
İptal
Kaydet