Skip to content

Commit

Permalink
fixing error with publishing local mqtt broker, making remote and loc…
Browse files Browse the repository at this point in the history
…al password the same
  • Loading branch information
sailoog committed Apr 19, 2016
1 parent b4c5600 commit f5f32da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
3 changes: 2 additions & 1 deletion classes/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,5 @@ def run_action(self,option,text,conf,a):
topic=self.mqtt_list[self.getmqttlistIndex(option)][1]
payload= text
auth = {'username':conf.get('MQTT','username'), 'password':conf.get('MQTT','password')}
publish.single(topic, payload=payload, hostname=conf.get('MQTT','broker'), port=conf.get('MQTT','port'), auth=auth)
publish.single(topic, payload=payload, hostname=conf.get('MQTT','broker'), port=conf.get('MQTT','port'), auth=auth)
publish.single(topic, payload=payload, hostname='127.0.0.1', port='1883', auth=auth)
27 changes: 12 additions & 15 deletions openplotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,8 @@ def __init__(self):

wx.StaticText(self.page16, label=_('Username'), pos=(280, 30))
self.mqtt_user = wx.TextCtrl(self.page16, -1, size=(120, 32), pos=(280, 50))
wx.StaticText(self.page16, label=_('Remote password'), pos=(410, 30))
wx.StaticText(self.page16, label=_('Password'), pos=(410, 30))
self.mqtt_pass = wx.TextCtrl(self.page16, -1, size=(120, 32), pos=(410, 50))
self.set_rem_pass_but =wx.Button(self.page16, label=_('Local password'), pos=(540, 50))
self.Bind(wx.EVT_BUTTON, self.set_rem_pass, self.set_rem_pass_but)

wx.StaticText(self.page16, label=_('Topics'), pos=(20, 90))

Expand Down Expand Up @@ -2656,16 +2654,22 @@ def delete_topic(self,e):
self.list_topics.DeleteItem(selected_topic)

def apply_changes_mqtt(self,e):
if not self.mqtt_user.GetValue() or not self.mqtt_pass.GetValue():
username=self.mqtt_user.GetValue()
passw=self.mqtt_pass.GetValue()
if not username or not passw:
self.ShowMessage(_('Enter at least username and password.'))
return
self.conf.set('MQTT', 'broker', self.mqtt_broker.GetValue())
self.conf.set('MQTT', 'port', self.mqtt_port.GetValue())
self.conf.set('MQTT', 'username', self.mqtt_user.GetValue())
if not '*****' in self.mqtt_pass.GetValue():
self.conf.set('MQTT', 'password', self.mqtt_pass.GetValue())
self.mqtt_pass.SetValue('***************')
self.conf.set('MQTT', 'username', username)
self.conf.set('MQTT', 'topics', str(self.topics))
if not '*******' in passw:
self.mqtt_pass.SetValue('***************')
self.conf.set('MQTT', 'password', passw)
file = open("/etc/mosquitto/passwd.pw", "w")
file.write(username+':'+passw)
file.close()
subprocess.call(['sudo','mosquitto_passwd','-U','/etc/mosquitto/passwd.pw'])
subprocess.call(['sudo','service','mosquitto','restart'])
self.start_monitoring()
self.SetStatusText(_('MQTT topics changes applied and restarted'))
Expand All @@ -2674,13 +2678,6 @@ def cancel_changes_mqtt(self,e):
self.read_mqtt()
self.SetStatusText(_('MQTT topics changes cancelled'))

def set_rem_pass(self,e):
if not self.mqtt_user.GetValue():
self.ShowMessage(_('Enter an username.'))
return
self.ShowMessage(_('Your remote username and your local username will be the same. Set the local password in the next window.'))
subprocess.Popen(['lxterminal','-e','sudo','mosquitto_passwd','-c','/etc/mosquitto/passwd.pw',self.mqtt_user.GetValue()])

#Main#############################
if __name__ == "__main__":
app = wx.App()
Expand Down

0 comments on commit f5f32da

Please sign in to comment.