Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kodi2mqtt_import
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
42loop
kodi2mqtt_import
Commits
f866f7ec
Commit
f866f7ec
authored
9 years ago
by
jvandenbroek
Browse files
Options
Downloads
Patches
Plain Diff
Changed reconnect logic
parent
2966aaa5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
service.mqtt/service.py
+28
-24
28 additions, 24 deletions
service.mqtt/service.py
with
28 additions
and
24 deletions
service.mqtt/service.py
+
28
−
24
View file @
f866f7ec
...
...
@@ -243,47 +243,51 @@ def startmqtt():
mqc
.
on_disconnect
=
disconnecthandler
if
__addon__
.
getSetting
(
"
mqttanonymousconnection
"
)
==
'
false
'
:
mqc
.
username_pw_set
(
__addon__
.
getSetting
(
"
mqttusername
"
),
__addon__
.
getSetting
(
"
mqttpassword
"
))
xbmc
.
lo
g
(
"
MQTT: Anonymous disabled, connecting as user: %s
"
%
__addon__
.
getSetting
(
"
mqttusername
"
))
mqttloggin
g
(
"
MQTT: Anonymous disabled, connecting as user: %s
"
%
__addon__
.
getSetting
(
"
mqttusername
"
))
if
__addon__
.
getSetting
(
"
mqtttlsconnection
"
)
==
'
true
'
and
__addon__
.
getSetting
(
"
mqtttlsconnectioncrt
"
)
!=
''
and
__addon__
.
getSetting
(
"
mqtttlsclient
"
)
==
'
false
'
:
mqc
.
tls_set
(
__addon__
.
getSetting
(
"
mqtttlsconnectioncrt
"
))
xbmc
.
lo
g
(
"
MQTT: TLS enabled, connecting using CA certificate: %s
"
%
__addon__
.
getSetting
(
"
mqtttlsconnectioncrt
"
))
mqttloggin
g
(
"
MQTT: TLS enabled, connecting using CA certificate: %s
"
%
__addon__
.
getSetting
(
"
mqtttlsconnectioncrt
"
))
elif
__addon__
.
getSetting
(
"
mqtttlsconnection
"
)
==
'
true
'
and
__addon__
.
getSetting
(
"
mqtttlsclient
"
)
==
'
true
'
and
__addon__
.
getSetting
(
"
mqtttlsclientcrt
"
)
!=
''
and
__addon__
.
getSetting
(
"
mqtttlsclientkey
"
)
!=
''
:
mqc
.
tls_set
(
__addon__
.
getSetting
(
"
mqtttlsconnectioncrt
"
),
__addon__
.
getSetting
(
"
mqtttlsclientcrt
"
),
__addon__
.
getSetting
(
"
mqtttlsclientkey
"
))
xbmc
.
lo
g
(
"
MQTT: TLS with client certificates enabled, connecting using certificates CA: %s, client %s and key: %s
"
%
(
__addon__
.
getSetting
(
"
mqttusername
"
),
__addon__
.
getSetting
(
"
mqtttlsclientcrt
"
),
__addon__
.
getSetting
(
"
mqtttlsclientkey
"
)))
mqttloggin
g
(
"
MQTT: TLS with client certificates enabled, connecting using certificates CA: %s, client %s and key: %s
"
%
(
__addon__
.
getSetting
(
"
mqttusername
"
),
__addon__
.
getSetting
(
"
mqtttlsclientcrt
"
),
__addon__
.
getSetting
(
"
mqtttlsclientkey
"
)))
topic
=
__addon__
.
getSetting
(
"
mqtttopic
"
)
if
not
topic
.
endswith
(
"
/
"
):
topic
+=
"
/
"
mqc
.
will_set
(
topic
+
"
connected
"
,
0
,
qos
=
2
,
retain
=
True
)
sleep
=
2
for
attempt
in
range
(
10
):
try
:
mqttlogging
(
"
MQTT: Connecting to MQTT broker at %s:%s
"
%
(
__addon__
.
getSetting
(
"
mqtthost
"
),
__addon__
.
getSetting
(
"
mqttport
"
)))
mqc
.
connect
(
__addon__
.
getSetting
(
"
mqtthost
"
),
__addon__
.
getSetting
(
"
mqttport
"
),
60
)
except
socket
.
error
:
mqttlogging
(
"
MQTT: Socket error raised, retry in %d seconds
"
%
sleep
)
monitor
.
waitForAbort
(
sleep
)
sleep
=
sleep
*
2
else
:
break
else
:
mqttlogging
(
"
MQTT: No connection possible, giving up
"
)
return
(
False
)
mqc
.
publish
(
topic
+
"
connected
"
,
2
,
qos
=
1
,
retain
=
True
)
mqc
.
loop_start
()
return
(
True
)
#
# Addon initialization and shutdown
#
if
(
__name__
==
"
__main__
"
):
global
monitor
,
player
xbmc
.
lo
g
(
'
MQTT: MQTT Adapter Version %s started
'
%
__version__
)
mqttloggin
g
(
'
MQTT: MQTT Adapter Version %s started
'
%
__version__
)
load_settings
()
monitor
=
MQTTMonitor
()
if
startmqtt
():
player
=
MQTTPlayer
()
retries
=
0
for
attempt
in
range
(
retries
,
20
):
try
:
startmqtt
()
except
socket
.
error
:
mqttlogging
(
"
MQTT: Socket error raised, retrying..
"
)
retries
+=
1
time
.
sleep
(
5
)
else
:
break
else
:
mqttlogging
(
"
MQTT: No connection possible, giving up.
"
)
mqc
.
loop_stop
(
True
)
while
not
monitor
.
waitForAbort
(
mqttinterval
):
if
mqttprogress
:
mqttlogging
(
"
MQTT: Progress Publishing enabled, interval is set to %d seconds
"
%
mqttinterval
)
while
not
monitor
.
waitForAbort
(
mqttinterval
):
publishprogress
()
else
:
mqttlogging
(
"
MQTT: Progress Publishing disabled, waiting for abort
"
)
monitor
.
waitForAbort
()
mqc
.
loop_stop
(
True
)
mqttlogging
(
"
MQTT: Shutting down
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment