def error(message):
    print("ERROR : " + str(message))


def connect_abc(message):
    print("CONNECTED " + str(message))

def connect_d(message):
    print("CONNECTED " + str(message))
    pubnub.unsubscribe(channel='d')


def reconnect(message):
    print("RECONNECTED " + str(message))


def disconnect(message):
    print("DISCONNECTED " + str(message))

print pubnub.channel_group_add_channel(channel_group='abc', channel="b")

pubnub.subscribe_group(channel_groups='abc', callback=callback_abc, error=error,
                 connect=connect_abc, reconnect=reconnect, disconnect=disconnect)

pubnub.subscribe(channels='d', callback=callback_d, error=error,
                 connect=connect_d, reconnect=reconnect, disconnect=disconnect)

pubnub.start()
Esempio n. 2
0
def error(message):
    print("ERROR : " + str(message))


def connect(message):
    print("CONNECTED " + str(message))


def reconnect(message):
    print("RECONNECTED " + str(message))


def disconnect(message):
    print("DISCONNECTED " + str(message))


print pubnub.channel_group_add_channel(channel_group='abc', channel="a")

pubnub.subscribe_group(channel_groups='abc',
                       callback=callback,
                       error=callback,
                       connect=connect,
                       reconnect=reconnect,
                       disconnect=disconnect)

#pubnub.subscribe(channels='d', callback=callback, error=callback,
#                 connect=connect, reconnect=reconnect, disconnect=disconnect)

pubnub.start()
Esempio n. 3
0

# Grant read, write and manage permissions to the pubnub instance that we initialized
pubnub.grant(channel_group='hydrobase',
             auth_key=app.config['PUBNUB_AUTH_KEY'],
             read=True,
             write=True,
             manage=True,
             ttl=0,
             callback=_callback,
             error=_error)

# Subscribe to the channel group 'hydrobase' that contains the channels for all users to get the data
# coming in from different devices and put that into the DB
pubnub.subscribe_group(channel_groups=app.config['PUBNUB_CHANNEL_GRP'],
                       callback=sub_callback,
                       error=_error)

from app.views import mod_app
from app.auth.views import mod_auth
from app.dashboard.views import mod_dashboard
from app.devices.views import mod_devices
from app.grows.views import mod_grows
from app.plant_profiles.views import mod_plant_profiles
from app.documentation.views import mod_documentation

app.register_blueprint(mod_app)
app.register_blueprint(mod_auth)
app.register_blueprint(mod_dashboard)
app.register_blueprint(mod_devices)
app.register_blueprint(mod_grows)
Esempio n. 4
0
def reconnect(message):
    print("RECONNECTED")


def disconnect(message):
    print("DISCONNECTED")


pubnub.channel_group_add_channel("abg", "abcd")
pubnub.channel_group_add_channel("cdg", "efgh")

pubnub.subscribe(channels=channel, callback=callback, error=callback,
                 connect=connect, reconnect=reconnect, disconnect=disconnect)

pubnub.subscribe_group(channel_groups=channel_group, callback=callback, error=callback,
                       connect=connect, reconnect=reconnect, disconnect=disconnect)


def cb(resp):
    print(datetime.now().strftime('%H:%M:%S'), resp)


def err(resp):
    print(datetime.now().strftime('%H:%M:%S'), resp)


pubnub.timeout(5, set_heartbeat, 120, cb, err)
pubnub.timeout(90, set_heartbeat, 60, cb, err)
pubnub.timeout(180, set_heartbeat, 30, cb, err)
pubnub.timeout(240, set_heartbeat, 15, cb, err)
pubnub.timeout(300, set_heartbeat, 8, cb, err)
Esempio n. 5
0
		
		# insert in display
		logging.basicConfig(filename='hydrobase_display.log',level=logging.INFO)
		logging.info(message_array)
		db.display.insert_many(message_array)

		# insert in data db if last entry was more than 4 hpurs back
		if int(time_diff.seconds) >= 14400:
			logging.basicConfig(filename='hydrobase_data.log',level=logging.INFO)
			logging.info(message_array)
			db.data.insert_many(message_array)
		

if __name__ == '__main__':

	client = MongoClient('mongodb://*****:*****@ds011268.mlab.com:11268/analytics-hydrobase')
	db = client['analytics-hydrobase']

	#initialize the pubnub instance
	pubnub = Pubnub(publish_key='pub-c-93c6c384-e1a0-412f-87cf-e626aaab6a00', \
		subscribe_key='sub-c-8ec9d89e-e4aa-11e5-a4f2-0619f8945a4f', secret_key='sec-c-YzQyMTU3NmYtMDNhMS00MzM5LTg3MTgtZjA2N2U0N2IyNGY3', \
		auth_key='40ed6434-1991-4f7a-8034-20a072abde43')

	# Grant read, write and manage permissions to the pubnub instance that we initialized
	pubnub.grant(channel_group='hydrobase', auth_key='40ed6434-1991-4f7a-8034-20a072abde43',\
	 read=True, write=True, manage=True, ttl=0, callback=_callback, error=_error)

	# Subscribe to the channel group 'hydrobase' that contains the channels for all users to get the data 
	# coming in from different devices and put that into the DB
	pubnub.subscribe_group(channel_groups='hydrobase', \
		callback=sub_callback, error=_error)