Skip to content

Commit

Permalink
starting on #415... syntax works, but connects fail.
Browse files Browse the repository at this point in the history
  • Loading branch information
petersilva committed Jul 5, 2023
1 parent 2bfc089 commit a9c3a9c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion sarracenia/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __str__(self):
if self.url.hostname:
s += '@' + self.url.hostname
if self.url.port:
s += ':' + self.url.port
s += ':' + str(self.url.port)
if self.url.path:
s += self.url.path

Expand Down
20 changes: 12 additions & 8 deletions sarracenia/moth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
}

def ProtocolPresent(p) -> bool:
if ( p in ['amqp', 'amqps' ] ) and sarracenia.extras['amqp']['present']:
if ( p[0:4] in ['amqp'] ) and sarracenia.extras['amqp']['present']:
return True
if ( p in ['mqtt', 'mqtts' ] ) and sarracenia.extras['mqtt']['present']:
if ( p[0:4] in ['mqtt'] ) and sarracenia.extras['mqtt']['present']:
return True
if p in sarracenia.extras:
logger.critical( f"support for {p} missing, please install python packages: {' '.join(sarracenia.extras[p]['modules_needed'])}" )
Expand Down Expand Up @@ -218,9 +218,11 @@ def subFactory(props) -> 'Moth':
return None

for sc in Moth.__subclasses__():
if (props['broker'].url.scheme == sc.__name__.lower()) or (
(props['broker'].url.scheme[0:-1] == sc.__name__.lower()) and
(props['broker'].url.scheme[-1] == 's')):
driver=sc.__name__.lower()
scheme=props['broker'].url.scheme
if (scheme == driver) or \
( (scheme[0:-1] == driver) and (scheme[-1] in [ 's', 'w' ])) or \
( (scheme[0:-2] == driver) and (scheme[-2] == 'ws')):
return sc(props, True)
logger.error('broker intialization failure')
return None
Expand All @@ -240,9 +242,11 @@ def pubFactory(props) -> 'Moth':
return None

for sc in Moth.__subclasses__():
if (props['broker'].url.scheme == sc.__name__.lower()) or (
(props['broker'].url.scheme[0:-1] == sc.__name__.lower()) and
(props['broker'].url.scheme[-1] == 's')):
driver=sc.__name__.lower()
scheme=props['broker'].url.scheme
if (scheme == driver) or \
( (scheme[0:-1] == driver) and (scheme[-1] in [ 's', 'w' ])) or \
( (scheme[0:-2] == driver) and (scheme[-2] == 'ws')):
return sc(props, False)

# ProtocolPresent test should ensure that we never get here...
Expand Down
25 changes: 21 additions & 4 deletions sarracenia/moth/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,15 @@ def __clientSetup(self, cid) -> paho.mqtt.client.Client:

self.connect_in_progress = True

client = paho.mqtt.client.Client( userdata=self, \
client_id=cid, protocol=paho.mqtt.client.MQTTv5 )
if (self.o['broker'].url.scheme[-2:] == 'ws' ) or \
(self.o['broker'].url.scheme[-1] == 'w' ) :
logger.critical("yo! FIXME. I have websockets")
client = paho.mqtt.client.Client( userdata=self, transport="websockets", \
client_id=cid, protocol=paho.mqtt.client.MQTTv5 )
else:
logger.critical("yo! FIXME. darnwebnot")
client = paho.mqtt.client.Client( userdata=self, \
client_id=cid, protocol=paho.mqtt.client.MQTTv5 )

client.connected = False
client.on_connect = MQTT.__sub_on_connect
Expand Down Expand Up @@ -432,8 +439,18 @@ def __putSetup(self):
if self.o['message_ttl'] > 0:
props.MessageExpiryInterval = int(self.o['message_ttl'])

self.client = paho.mqtt.client.Client(
protocol=self.proto_version, userdata=self)
if (self.o['broker'].url.scheme[-2:] == 'ws' ) or \
(self.o['broker'].url.scheme[-1] == 'w' ) :
logger.critical("yo! FIXME. I have websockets")
self.client = paho.mqtt.client.Client( userdata=self, transport="websockets", \
protocol=self.proto_version )
else:
logger.critical("yo! FIXME. darnwebnot")
self.client = paho.mqtt.client.Client( userdata=self, \
protocol=self.proto_version )

#self.client = paho.mqtt.client.Client(
# protocol=self.proto_version, userdata=self)

self.client.enable_logger(logger)
self.client.on_connect = MQTT.__pub_on_connect
Expand Down

0 comments on commit a9c3a9c

Please sign in to comment.