Chmod +x examples, and add shebang lines
This commit is contained in:
parent
b8b2f37e7b
commit
cd2d25cf87
29
examples/IoT_TestDevice.py
Normal file → Executable file
29
examples/IoT_TestDevice.py
Normal file → Executable file
@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
"""
|
"""
|
||||||
SleekXMPP: The Sleek XMPP Library
|
SleekXMPP: The Sleek XMPP Library
|
||||||
@ -35,7 +36,7 @@ if sys.version_info < (3, 0):
|
|||||||
setdefaultencoding('utf8')
|
setdefaultencoding('utf8')
|
||||||
else:
|
else:
|
||||||
raw_input = input
|
raw_input = input
|
||||||
|
|
||||||
from sleekxmpp.plugins.xep_0323.device import Device
|
from sleekxmpp.plugins.xep_0323.device import Device
|
||||||
|
|
||||||
#from sleekxmpp.exceptions import IqError, IqTimeout
|
#from sleekxmpp.exceptions import IqError, IqTimeout
|
||||||
@ -68,7 +69,7 @@ class IoT_TestDevice(sleekxmpp.ClientXMPP):
|
|||||||
else:
|
else:
|
||||||
self.beServer=False
|
self.beServer=False
|
||||||
self.clientJID=clientJID
|
self.clientJID=clientJID
|
||||||
|
|
||||||
def testForRelease(self):
|
def testForRelease(self):
|
||||||
# todo thread safe
|
# todo thread safe
|
||||||
return self.releaseMe
|
return self.releaseMe
|
||||||
@ -76,14 +77,14 @@ class IoT_TestDevice(sleekxmpp.ClientXMPP):
|
|||||||
def doReleaseMe(self):
|
def doReleaseMe(self):
|
||||||
# todo thread safe
|
# todo thread safe
|
||||||
self.releaseMe=True
|
self.releaseMe=True
|
||||||
|
|
||||||
def addDevice(self, device):
|
def addDevice(self, device):
|
||||||
self.device=device
|
self.device=device
|
||||||
|
|
||||||
def session_start(self, event):
|
def session_start(self, event):
|
||||||
self.send_presence()
|
self.send_presence()
|
||||||
self.get_roster()
|
self.get_roster()
|
||||||
# tell your preffered friend that you are alive
|
# tell your preffered friend that you are alive
|
||||||
self.send_message(mto='jocke@jabber.sust.se', mbody=self.boundjid.bare +' is now online use xep_323 stanza to talk to me')
|
self.send_message(mto='jocke@jabber.sust.se', mbody=self.boundjid.bare +' is now online use xep_323 stanza to talk to me')
|
||||||
|
|
||||||
if not(self.beServer):
|
if not(self.beServer):
|
||||||
@ -96,7 +97,7 @@ class IoT_TestDevice(sleekxmpp.ClientXMPP):
|
|||||||
msg.reply("Hi I am " + self.boundjid.full + " and I am on IP " + ip).send()
|
msg.reply("Hi I am " + self.boundjid.full + " and I am on IP " + ip).send()
|
||||||
else:
|
else:
|
||||||
logging.debug("got unknown message type %s", str(msg['type']))
|
logging.debug("got unknown message type %s", str(msg['type']))
|
||||||
|
|
||||||
class TheDevice(Device):
|
class TheDevice(Device):
|
||||||
"""
|
"""
|
||||||
This is the actual device object that you will use to get information from your real hardware
|
This is the actual device object that you will use to get information from your real hardware
|
||||||
@ -112,8 +113,8 @@ class TheDevice(Device):
|
|||||||
"""
|
"""
|
||||||
self._set_momentary_timestamp(self._get_timestamp())
|
self._set_momentary_timestamp(self._get_timestamp())
|
||||||
self.counter+=self.counter
|
self.counter+=self.counter
|
||||||
self._add_field_momentary_data(self, "Temperature", self.counter)
|
self._add_field_momentary_data(self, "Temperature", self.counter)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
# Setup the command line arguments.
|
# Setup the command line arguments.
|
||||||
@ -123,7 +124,7 @@ if __name__ == '__main__':
|
|||||||
# python IoT_TestDevice.py -j "serverjid@yourdomain.com" -p "password" -n "TestIoT" --debug
|
# python IoT_TestDevice.py -j "serverjid@yourdomain.com" -p "password" -n "TestIoT" --debug
|
||||||
#
|
#
|
||||||
# "client" an IoT device or other party that would like to get data from another device
|
# "client" an IoT device or other party that would like to get data from another device
|
||||||
|
|
||||||
optp = OptionParser()
|
optp = OptionParser()
|
||||||
|
|
||||||
# Output verbosity options.
|
# Output verbosity options.
|
||||||
@ -151,7 +152,7 @@ if __name__ == '__main__':
|
|||||||
help="Another device to call for data on", default=None)
|
help="Another device to call for data on", default=None)
|
||||||
optp.add_option("-n", "--nodeid", dest="nodeid",
|
optp.add_option("-n", "--nodeid", dest="nodeid",
|
||||||
help="I am a device get ready to be called", default=None)
|
help="I am a device get ready to be called", default=None)
|
||||||
|
|
||||||
opts, args = optp.parse_args()
|
opts, args = optp.parse_args()
|
||||||
|
|
||||||
# Setup logging.
|
# Setup logging.
|
||||||
@ -162,7 +163,7 @@ if __name__ == '__main__':
|
|||||||
opts.jid = raw_input("Username: ")
|
opts.jid = raw_input("Username: ")
|
||||||
if opts.password is None:
|
if opts.password is None:
|
||||||
opts.password = getpass.getpass("Password: ")
|
opts.password = getpass.getpass("Password: ")
|
||||||
|
|
||||||
|
|
||||||
xmpp = IoT_TestDevice(opts.jid,opts.password)
|
xmpp = IoT_TestDevice(opts.jid,opts.password)
|
||||||
xmpp.register_plugin('xep_0030')
|
xmpp.register_plugin('xep_0030')
|
||||||
@ -183,12 +184,12 @@ if __name__ == '__main__':
|
|||||||
myDevice._add_field(name="Temperature", typename="numeric", unit="C");
|
myDevice._add_field(name="Temperature", typename="numeric", unit="C");
|
||||||
myDevice._set_momentary_timestamp("2013-03-07T16:24:30")
|
myDevice._set_momentary_timestamp("2013-03-07T16:24:30")
|
||||||
myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"});
|
myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"});
|
||||||
|
|
||||||
xmpp['xep_0323'].register_node(nodeId=opts.nodeid, device=myDevice, commTimeout=10);
|
xmpp['xep_0323'].register_node(nodeId=opts.nodeid, device=myDevice, commTimeout=10);
|
||||||
xmpp.beClientOrServer(server=True)
|
xmpp.beClientOrServer(server=True)
|
||||||
while not(xmpp.testForRelease()):
|
while not(xmpp.testForRelease()):
|
||||||
xmpp.connect()
|
xmpp.connect()
|
||||||
xmpp.process(block=True)
|
xmpp.process(block=True)
|
||||||
logging.debug("lost connection")
|
logging.debug("lost connection")
|
||||||
if opts.sensorjid:
|
if opts.sensorjid:
|
||||||
logging.debug("will try to call another device for data")
|
logging.debug("will try to call another device for data")
|
||||||
@ -196,7 +197,7 @@ if __name__ == '__main__':
|
|||||||
xmpp.connect()
|
xmpp.connect()
|
||||||
xmpp.process(block=True)
|
xmpp.process(block=True)
|
||||||
logging.debug("ready ending")
|
logging.debug("ready ending")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "noopp didn't happen"
|
print "noopp didn't happen"
|
||||||
|
|
||||||
|
0
examples/download_avatars.py
Normal file → Executable file
0
examples/download_avatars.py
Normal file → Executable file
@ -151,7 +151,7 @@ if __name__ == '__main__':
|
|||||||
#
|
#
|
||||||
# if xmpp.connect(('talk.google.com', 5222)):
|
# if xmpp.connect(('talk.google.com', 5222)):
|
||||||
# ...
|
# ...
|
||||||
xmpp.process(block=True)
|
xmpp.process(block=False)
|
||||||
print("Done")
|
print("Done")
|
||||||
else:
|
else:
|
||||||
print("Unable to connect.")
|
print("Unable to connect.")
|
||||||
|
3
examples/migrate_roster.py
Normal file → Executable file
3
examples/migrate_roster.py
Normal file → Executable file
@ -1,3 +1,6 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import getpass
|
import getpass
|
||||||
|
7
examples/pubsub_client.py
Normal file → Executable file
7
examples/pubsub_client.py
Normal file → Executable file
@ -1,3 +1,6 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import getpass
|
import getpass
|
||||||
@ -20,7 +23,7 @@ else:
|
|||||||
|
|
||||||
class PubsubClient(sleekxmpp.ClientXMPP):
|
class PubsubClient(sleekxmpp.ClientXMPP):
|
||||||
|
|
||||||
def __init__(self, jid, password, server,
|
def __init__(self, jid, password, server,
|
||||||
node=None, action='list', data=''):
|
node=None, action='list', data=''):
|
||||||
super(PubsubClient, self).__init__(jid, password)
|
super(PubsubClient, self).__init__(jid, password)
|
||||||
|
|
||||||
@ -28,7 +31,7 @@ class PubsubClient(sleekxmpp.ClientXMPP):
|
|||||||
self.register_plugin('xep_0059')
|
self.register_plugin('xep_0059')
|
||||||
self.register_plugin('xep_0060')
|
self.register_plugin('xep_0060')
|
||||||
|
|
||||||
self.actions = ['nodes', 'create', 'delete',
|
self.actions = ['nodes', 'create', 'delete',
|
||||||
'publish', 'get', 'retract',
|
'publish', 'get', 'retract',
|
||||||
'purge', 'subscribe', 'unsubscribe']
|
'purge', 'subscribe', 'unsubscribe']
|
||||||
|
|
||||||
|
5
examples/pubsub_events.py
Normal file → Executable file
5
examples/pubsub_events.py
Normal file → Executable file
@ -1,3 +1,6 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import getpass
|
import getpass
|
||||||
@ -77,7 +80,7 @@ class PubsubEvents(sleekxmpp.ClientXMPP):
|
|||||||
"""Handle receiving a node deletion event."""
|
"""Handle receiving a node deletion event."""
|
||||||
print('Deleted node %s' % (
|
print('Deleted node %s' % (
|
||||||
msg['pubsub_event']['delete']['node']))
|
msg['pubsub_event']['delete']['node']))
|
||||||
|
|
||||||
def _config(self, msg):
|
def _config(self, msg):
|
||||||
"""Handle receiving a node configuration event."""
|
"""Handle receiving a node configuration event."""
|
||||||
print('Configured node %s:' % (
|
print('Configured node %s:' % (
|
||||||
|
0
examples/register_account.py
Normal file → Executable file
0
examples/register_account.py
Normal file → Executable file
0
examples/roster_browser.py
Normal file → Executable file
0
examples/roster_browser.py
Normal file → Executable file
29
examples/rpc_async.py
Normal file → Executable file
29
examples/rpc_async.py
Normal file → Executable file
@ -1,3 +1,6 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
"""
|
"""
|
||||||
SleekXMPP: The Sleek XMPP Library
|
SleekXMPP: The Sleek XMPP Library
|
||||||
Copyright (C) 2011 Dann Martens
|
Copyright (C) 2011 Dann Martens
|
||||||
@ -11,34 +14,34 @@ from sleekxmpp.plugins.xep_0009.remote import Endpoint, remote, Remote, \
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
class Boomerang(Endpoint):
|
class Boomerang(Endpoint):
|
||||||
|
|
||||||
def FQN(self):
|
def FQN(self):
|
||||||
return 'boomerang'
|
return 'boomerang'
|
||||||
|
|
||||||
@remote
|
@remote
|
||||||
def throw(self):
|
def throw(self):
|
||||||
print "Duck!"
|
print "Duck!"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
session = Remote.new_session('kangaroo@xmpp.org/rpc', '*****')
|
session = Remote.new_session('kangaroo@xmpp.org/rpc', '*****')
|
||||||
|
|
||||||
session.new_handler(ANY_ALL, Boomerang)
|
session.new_handler(ANY_ALL, Boomerang)
|
||||||
|
|
||||||
boomerang = session.new_proxy('kangaroo@xmpp.org/rpc', Boomerang)
|
boomerang = session.new_proxy('kangaroo@xmpp.org/rpc', Boomerang)
|
||||||
|
|
||||||
callback = Future()
|
callback = Future()
|
||||||
|
|
||||||
boomerang.async(callback).throw()
|
boomerang.async(callback).throw()
|
||||||
|
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
29
examples/rpc_client_side.py
Normal file → Executable file
29
examples/rpc_client_side.py
Normal file → Executable file
@ -1,3 +1,6 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
"""
|
"""
|
||||||
SleekXMPP: The Sleek XMPP Library
|
SleekXMPP: The Sleek XMPP Library
|
||||||
Copyright (C) 2011 Dann Martens
|
Copyright (C) 2011 Dann Martens
|
||||||
@ -12,18 +15,18 @@ import threading
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
class Thermostat(Endpoint):
|
class Thermostat(Endpoint):
|
||||||
|
|
||||||
def FQN(self):
|
def FQN(self):
|
||||||
return 'thermostat'
|
return 'thermostat'
|
||||||
|
|
||||||
def __init__(self, initial_temperature):
|
def __init__(self, initial_temperature):
|
||||||
self._temperature = initial_temperature
|
self._temperature = initial_temperature
|
||||||
self._event = threading.Event()
|
self._event = threading.Event()
|
||||||
|
|
||||||
@remote
|
@remote
|
||||||
def set_temperature(self, temperature):
|
def set_temperature(self, temperature):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
@remote
|
@remote
|
||||||
def get_temperature(self):
|
def get_temperature(self):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
@ -31,23 +34,23 @@ class Thermostat(Endpoint):
|
|||||||
@remote(False)
|
@remote(False)
|
||||||
def release(self):
|
def release(self):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
session = Remote.new_session('operator@xmpp.org/rpc', '*****')
|
session = Remote.new_session('operator@xmpp.org/rpc', '*****')
|
||||||
|
|
||||||
thermostat = session.new_proxy('thermostat@xmpp.org/rpc', Thermostat)
|
thermostat = session.new_proxy('thermostat@xmpp.org/rpc', Thermostat)
|
||||||
|
|
||||||
print("Current temperature is %s" % thermostat.get_temperature())
|
print("Current temperature is %s" % thermostat.get_temperature())
|
||||||
|
|
||||||
thermostat.set_temperature(20)
|
thermostat.set_temperature(20)
|
||||||
|
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
31
examples/rpc_server_side.py
Normal file → Executable file
31
examples/rpc_server_side.py
Normal file → Executable file
@ -1,3 +1,6 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
"""
|
"""
|
||||||
SleekXMPP: The Sleek XMPP Library
|
SleekXMPP: The Sleek XMPP Library
|
||||||
Copyright (C) 2011 Dann Martens
|
Copyright (C) 2011 Dann Martens
|
||||||
@ -11,42 +14,42 @@ from sleekxmpp.plugins.xep_0009.remote import Endpoint, remote, Remote, \
|
|||||||
import threading
|
import threading
|
||||||
|
|
||||||
class Thermostat(Endpoint):
|
class Thermostat(Endpoint):
|
||||||
|
|
||||||
def FQN(self):
|
def FQN(self):
|
||||||
return 'thermostat'
|
return 'thermostat'
|
||||||
|
|
||||||
def __init__(self, initial_temperature):
|
def __init__(self, initial_temperature):
|
||||||
self._temperature = initial_temperature
|
self._temperature = initial_temperature
|
||||||
self._event = threading.Event()
|
self._event = threading.Event()
|
||||||
|
|
||||||
@remote
|
@remote
|
||||||
def set_temperature(self, temperature):
|
def set_temperature(self, temperature):
|
||||||
print("Setting temperature to %s" % temperature)
|
print("Setting temperature to %s" % temperature)
|
||||||
self._temperature = temperature
|
self._temperature = temperature
|
||||||
|
|
||||||
@remote
|
@remote
|
||||||
def get_temperature(self):
|
def get_temperature(self):
|
||||||
return self._temperature
|
return self._temperature
|
||||||
|
|
||||||
@remote(False)
|
@remote(False)
|
||||||
def release(self):
|
def release(self):
|
||||||
self._event.set()
|
self._event.set()
|
||||||
|
|
||||||
def wait_for_release(self):
|
def wait_for_release(self):
|
||||||
self._event.wait()
|
self._event.wait()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
session = Remote.new_session('sleek@xmpp.org/rpc', '*****')
|
session = Remote.new_session('sleek@xmpp.org/rpc', '*****')
|
||||||
|
|
||||||
thermostat = session.new_handler(ANY_ALL, Thermostat, 18)
|
thermostat = session.new_handler(ANY_ALL, Thermostat, 18)
|
||||||
|
|
||||||
thermostat.wait_for_release()
|
thermostat.wait_for_release()
|
||||||
|
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
0
examples/set_avatar.py
Normal file → Executable file
0
examples/set_avatar.py
Normal file → Executable file
0
examples/thirdparty_auth.py
Normal file → Executable file
0
examples/thirdparty_auth.py
Normal file → Executable file
0
examples/user_location.py
Normal file → Executable file
0
examples/user_location.py
Normal file → Executable file
0
examples/user_tune.py
Normal file → Executable file
0
examples/user_tune.py
Normal file → Executable file
Loading…
Reference in New Issue
Block a user