def __init__(self, message): cluster_url = "http://ortc-developers.realtime.co/server/2.1" application_key = "[YOUR APPLICATION KEY HERE]" private_key = "[YOUR PRIVATE KEY]" authentication_token = "poll_token" channel = "poll_" + message["poll"] channels_permissions = {} channels_permissions[channel] = "w" def on_exception(sender, exception): print "exception: " + exception def on_connected(sender): print "connected" ortc_client.send(channel, json.dumps(message)) def on_authenticated(result, error): print "authenticated" ortc_client.connect(application_key, authentication_token) ortc_client = ortc.OrtcClient() ortc_client.cluster_url = cluster_url ortc_client.connection_metadata = 'pollExample' ortc_client.set_on_exception_callback(on_exception) ortc_client.set_on_connected_callback(on_connected) # ortc_client.set_on_subscribed_callback(on_subscribed) ortc_client.connect(application_key, authentication_token)
# /home/shares/public/RaspberryPi/motion/code # python3 motion-alert.py #!/usr/bin/python # -*- coding: utf-8 -*- import ortc APP_KEY = 'YOUR_APP_KEY' PVT_KEY = 'YOUR_PRIVATE_KEY' AUTH_TOKEN = 'abcdefg' CHANNEL = 'motion:cam1' ORTC_URL = 'http://ortc-developers.realtime.co/server/2.1' ortc_client = ortc.OrtcClient() def on_exception(sender, exception): print ('ORTC Exception: ' + exception) def on_connected(sender): print ('ORTC Connected') ortc_client.subscribe(CHANNEL, True, on_message) def on_disconnected(sender): print ('ORTC Disconnected') import thread thread.interrupt_main() def on_message(sender, channel, message): print ('ORTC Message ('+channel+'): ' + message) ortc_client.unsubscribe(channel)