Guest User

Untitled

a guest
May 28th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. import os
  2. import argparse
  3. import six
  4. import txaio
  5. import json
  6. import datetime
  7.  
  8. from twisted.logger import Logger
  9. from autobahn.twisted.wamp import ApplicationSession
  10. from autobahn.twisted.wamp import ApplicationRunner
  11. from autobahn.wamp.exception import ApplicationError
  12. from twisted.internet.task import LoopingCall
  13. from twisted.internet import reactor
  14.  
  15. import Adafruit_DHT
  16.  
  17.  
  18. class ClientSession(ApplicationSession):
  19.  
  20. def onConnect(self):
  21. self.log.info("Client connected")
  22. self.join(self.config.realm, [u'anonymous'])
  23.  
  24. def onChallenge(self, challenge):
  25. self.log.info("Challenge for method {authmethod} received", authmethod=challenge.method)
  26. raise Exception("We haven't asked for authentication!")
  27.  
  28. def onJoin(self, details):
  29.  
  30. self.topic='topic.not.set.yet'
  31.  
  32. ## SUBSCRIBE to the topic and receive events
  33. ##
  34. def received(msg):
  35. self.log.info("data fro temperature event received: {msg}", msg=msg)
  36.  
  37. sub = yield self.subscribe(received, self.topic)
  38.  
  39.  
  40.  
  41.  
  42. def onLeave(self, details):
  43. self.log.info('session left: {}'.format(details))
  44. self.disconnect()
  45.  
  46. def onDisconnect(self):
  47. self.log.info('transport disconnected')
  48. reactor.stop()
  49.  
  50. if __name__ == '__main__':
  51.  
  52. print ('parse command line parameters')
  53. parser = argparse.ArgumentParser()
  54. parser.add_argument('-d', '--debug', action='store_true', help='Enable debug output.')
  55. parser.add_argument('--url', dest='url', type=six.text_type, default=u'ws://localhost:8080/ws', help='')
  56. parser.add_argument('--realm', dest='realm', type=six.text_type, default='realm1', help='The realm to join (default: "realm1").')
  57.  
  58. args = parser.parse_args()
  59.  
  60. runner = ApplicationRunner(url=args.url, realm=args.realm, extra=extra)
  61. runner.run(ClientSession, auto_reconnect=True)
Add Comment
Please, Sign In to add comment