def devices():
    try:
        cmd = request.vars.value
        tok = request.vars.tokken
        resp = ''
        js = ''
        if cmd and tok:
            if tok == get_tokken():
                res = cmd.split('-')
                row = db((Embarcado.id==res[1])&(Embarcado.id_serial == Serial.id)).select().first()
                if row.serial.status:
                    rq = str(row.embarcado.codigo_arduino)
                    resp = int(device_send(row.serial, rq))
                    row.embarcado.update_record(status = resp)
                    js = "on_off('%s', %s)" % (cmd,resp)
                    js2 = "window.location.reload()"
                    websocket_send('http://127.0.0.1:8888',js, 'mykey', 'mysection')
                    websocket_send('http://127.0.0.1:8888',js2, 'mykey', 'mygroup')
                else:
                    resp = "%s Desativada!" % (row2.device)
            else:
                resp = "Tokken incorreto!\nAtualize sua página!"
        else:
            resp = "Parametros Vazios!"
        
        return dict(cmd=resp)
    except Exception, e:
        return dict(cmd=e)
        pass
Beispiel #2
0
def say_number():
	''' Sends a message to the robot face to speak a number or coordinate '''
	typeMessage = request.vars['type']
	number = request.vars['number']
	coordinate = request.vars['coordinate'] if request.vars['coordinate'] != None else "{}"
	message_wrapper = ('{"type":"say_number", "value":{"type":"%s","number":"%s","coordinate":%s}}' % (typeMessage, number, coordinate))
	websocket_send('http://' + 'localhost' + ':' + __socket_port, message_wrapper, 'mykey', 'robot')
def __push_notification(type, data):
    websocket_send(
        'http://127.0.0.1:8888', 
        json.dumps(dict(type=type,data=data)), 
        'mykey', 
        'mygroup')
    return 0
Beispiel #4
0
def _update_card(element):
    from gluon.contrib.websocket_messaging import websocket_send
    import json
    # sending websocket message
    # js = "console.log('Here boy!!!')"
    data = json.dumps(element)
    print "novo"
    websocket_send('http://localhost:8888', element, 'mykey', 'mygroup')
Beispiel #5
0
def check_solution():
    #current_problem = db(db.problemBank.id == session.problemNum).select()[0]
    #currentProblemJSON = stringifyProblem(current_problem, "check")
    #return dict(problems=currentProblemJSON)
    session.problemNum = request.vars.index
    #data = currentProblemJSON
    data = request.vars.data
    websocket_send('http://' + get_ip(request.vars) + ':' + __socket_port, data, 'mykey', "applet")
Beispiel #6
0
def loadOptions(data):
    ''' DEPRECATED '''
    db.currState.update_or_insert(db.currState.name=='menuOptions', name='menuOptions', value=data)
    s2 = db(db.currState.name=='menuOptions')
    val = s2.select()[0].value
    # notifying interface
    websocket_send('http://' + get_ip(request.vars) + ':' + __socket_port, data, 'mykey', __socket_group_name)
    return val
Beispiel #7
0
    def _notify_websocket_server(self, entry, message):
        """

        :type entry: gluon.dal.Row
        :param message: a json serializable
        """
        notification_group = entry.ws_group or self.name
        websocket_send("http://%s:%s" % (self.ws['host'], self.ws['port']), simplejson.dumps(message), self.ws['password'], notification_group)
Beispiel #8
0
def index():
    form = SQLFORM(Post, formstyle='divs')
    if form.process().accepted:
        # sending websocket message
        js = "jQuery('.new').slideDown('slow')"
        websocket_send('http://localhost:8888', js, 'mykey', 'mygroup')
    messages = db(Post).select(orderby=~Post.created_on)
    return dict(form=form, messages=messages)
Beispiel #9
0
 def _notify_clients(self, message, group='default'):
     try:
         websocket_send("http://%s:%s" % (self.host, self.port), json(message), self.password, group)
     except IOError as e:
         if self.verbose:
             print("{notifier}: Unable to notify clients \"{exception}\". "
                   "The server is up and running? Follow the instructions "
                   "at \"gluon/contrib/websocket_messaging.py\"".format(notifier=self.__class__.__name__,
                                                                        exception=e.strerror))
def post_Solution_Check():
    #current_problem = db(db.problemBank.id == session.problemNum).select()[0]
    #currentProblemJSON = stringifyProblem(current_problem, "check")
    #return dict(problems=currentProblemJSON)
    #session.problemNum = request.vars.index
    #data = currentProblemJSON
    data = request.vars.data
    # The group name 'interface' is what mobile is registered to. You can see it in the config file on the mobile side.
    websocket_send('http://' + __current_ip + ':' + __socket_port, data, 'mykey', 'interface')
Beispiel #11
0
def randomly_order_prompts():
	outcome = True if request.vars['trigger'] == 'hit' else False # either success or failure
	state = request.vars['state']
	prob_num = int(request.vars['number'])
	trig = request.vars['trigger']
	ang = request.vars['angle']
	# wrapping info in package
	message_wrapper = '{"type":"order", "value":{"trigger":"%s","angle":"%s","state":"%s","number":"%s"}}' % (trig,ang,state,prob_num)	
	websocket_send('http://' + 'localhost' + ':' + __socket_port, message_wrapper, 'mykey', 'robot')
	return message_wrapper
def _realtime_update(element):
    try:
        from gluon.contrib.websocket_messaging import websocket_send
        import json

        data = json.dumps(element)
        projectID = "project%s" %element["project_id"]
        websocket_send('http://localhost:8888', data, 'mykey', projectID)
    except:
        pass
def send_message():
    data = request.vars
    msg = dict()
    # creating message object
    msg['message'] = data.message
    msg['type'] = 'alert'
    # creating message json text
    msg_json = json.dumps(msg)
    # sending message
    websocket_send('http://' + __current_ip + ':' + __socket_port, msg_json, 'mykey', data.target)
Beispiel #14
0
def _realtime_update(element):
    try:
        from gluon.contrib.websocket_messaging import websocket_send
        import json

        data = json.dumps(element)
        projectID = "project%s" % element["project_id"]
        websocket_send('http://localhost:8888', data, 'mykey', projectID)
    except:
        pass
Beispiel #15
0
    def _notify_websocket_server(self, entry, message):
        """

        :type entry: gluon.dal.Row
        :param message: a json serializable
        """
        notification_group = entry.ws_group or self.name
        websocket_send("http://%s:%s" % (self.ws['host'], self.ws['port']),
                       simplejson.dumps(message), self.ws['password'],
                       notification_group)
Beispiel #16
0
 def _notify_clients(self, message, group='default'):
     try:
         websocket_send("http://%s:%s" % (self.host, self.port),
                        json(message), self.password, group)
     except IOError as e:
         if self.verbose:
             print("{notifier}: Unable to notify clients \"{exception}\". "
                   "The server is up and running? Follow the instructions "
                   "at \"gluon/contrib/websocket_messaging.py\"".format(
                       notifier=self.__class__.__name__,
                       exception=e.strerror))
Beispiel #17
0
def ajax_form():
    char_id = get_char()
    master = db.chars[char_id].master
    charname = db.chars[char_id].name
    now = datetime.datetime.now().time()
    form = SQLFORM.factory(Field("message"))
    if form.accepts(request, session):
        from gluon.contrib.websocket_messaging import websocket_send

        message = "{}:{} <b>{}</b>: {}".format(now.hour, now.minute, charname, form.vars.message)
        websocket_send("http://127.0.0.1:8888", message, "mykey", master)
    return form
Beispiel #18
0
def skip_prompts():
	#pdb.set_trace()
	outcome = True if request.vars['trigger'] == 'hit' else False # either success or failure
	state = request.vars['state']
	prob_num = int(request.vars['number'])
	trig = request.vars['trigger']
	ang = request.vars['angle']
	# wrapping info in package
	message_wrapper = '{"type":"cognitive_skip", "value":{"number":"%s"}}' % (prob_num)	
	websocket_send('http://' + 'localhost' + ':' + __socket_port, message_wrapper, 'mykey', 'robot')
	# websocket_send('http://' + ip + ':' + __socket_port, message_wrapper, 'mykey', 'robot')
	return message_wrapper
Beispiel #19
0
def send_message():
    """
	This message is used by the communication.js file to send a message to another application
	target: the desired target recipient of the message. Options: applet, interface, robot
	type: a value indicating what the message is about. The client code will use this to determine what to do with the message
	value: the json object containing the desired message params
	"""
    target = request.vars["target"]
    type = request.vars["type"]
    value = request.vars["value"]
    obj = {"type": type, "value": value}
    objJSON = json.dumps(obj)
    websocket_send("http://" + __current_ip + ":" + __socket_port, objJSON, "mykey", target)
Beispiel #20
0
def update_game_info():
    playermgmt.ensure_session_vars(auth)
    response.generic_patterns = ['json']
    
    update_fields = gluon.contrib.simplejson.loads(request.body.read())
    changed = game.update_game(request.vars.game_id, update_fields)
    websocket_send("http://" + config.websocket_server,
                   gluon.contrib.simplejson.dumps(changed),
                   config.websocket_key,
                   str(request.vars.game_id))


    return dict()
Beispiel #21
0
def index():
    form = SQLFORM(Post, formstyle='divs')
    if form.process().accepted:
        session.flash = 'form accepted'
        js = "jQuery('.new').slideDown('slow')"
        websocket_send('http://127.0.0.1:8888', js, "chatkey", "mygroup")
    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    messages = db(Post).select(orderby=~Post.created_on)

    return dict(form=form, messages=messages)
Beispiel #22
0
def new_message():
    form = SQLFORM(Chat)

    date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    messageSent = "<b>" + auth.user.username + ":</b>" + request.vars.your_message + "</br>" + str(
        date)
    chatroomId = request.vars.room_id
    websocketURL = request.vars.wsURL
    # TORNADO SSD
    if form.accepts(request, formname=None):
        websocket_send('http://' + websocketURL + ':8888', messageSent,
                       'mykey', 'chatroom' + chatroomId)
    elif form.errors:
        return TABLE(*[TR(k, v) for k, v in form.errors.items()])
    return ()
Beispiel #23
0
def addurlmes():
    # not working
    #db(Chat).author=auth.user.first_name
    CR = db.chat
    date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    messageSent = "<b>" + auth.user.username + ":</b>" + request.vars.mi_url + "</br>" + str(
        date)
    print(request.vars.mi_url)
    chatroomId = request.vars.room_id
    websocketURL = request.vars.wsURL
    # TORNADO SSD
    websocket_send('http://' + websocketURL + ':8888', messageSent, 'mykey',
                   'chatroom' + chatroomId)
    CR.insert(your_message=request.vars.mi_url, room_id=chatroomId)
    return ()
def off_all():
    if request.args(0):
        dev = db((Embarcado.id_serial==Serial.id)
            &(Embarcado.id_grupo==request.args(0))
            &(Serial.status==True)
            &(Embarcado.status==True)
        ).select()
        for row in dev:
            if row.serial.status:
                rq = str(row.embarcado.codigo_arduino)
                resp = int(device_send(row.serial, rq))
                row.embarcado.update_record(status = resp)
        js = 'window.location.reload()'
        websocket_send('http://127.0.0.1:8888',js, 'mykey', 'mygroup')
        websocket_send('http://127.0.0.1:8888',js, 'mykey', 'mysection')
    redirect(URL('default', 'index'))
Beispiel #25
0
def end_game():
    playermgmt.ensure_session_vars(auth)
    response.generic_patterns = ['json']
    wininfo = gluon.contrib.simplejson.loads(request.body.read())

    try:
        saveid = game.end_game(request.vars.game_id, wininfo)
        websocket_send("http://" + config.websocket_server, 
                       gluon.contrib.simplejson.dumps(
                            {"gameFinished": True}),
                            config.websocket_key,
                            str(request.vars.game_id))
        return {"saveid": saveid}  
    #except game.storeGameException as e:
    except e:
        pass
Beispiel #26
0
def message():
    from gluon.contrib.websocket_messaging import websocket_send
    msg = request.body.read()
    data = json.loads(msg)
    insert = db.plates.insert(
        plate=data['results'][0]['plate'],
        confidence=data['results'][0]['confidence'],
        total_processing_time=data['processing_time_ms'],
        plate_processing_time=data['results'][0]['processing_time_ms'],
        epoch_time=data['epoch_time'],
        camera_id=data['camera_id'],
        site_id=data['site_id'],
        img_width=data['img_width'],
        img_height=data['img_height'],
        plate_img_uuid=data['uuid'])
    websocket_send('http://127.0.0.1:8888', msg, 'mykey', 'live_stream')
    pass
Beispiel #27
0
def make_attribution():
	outcome = True if request.vars['out'] == 'success' else False # either success or failure
	number = request.vars['number']
	attribution = __search_attribution(outcome)
	if not attribution:
		__reset(outcome)
		attribution = __search_attribution(outcome)
	# updating db
	attribution.used = True
	attribution.session = True
	attribution.update_record()
	# wrapping info in package
	message_wrapper = '{"type":"attribution", "value":{"emotion":"%s","file":"%s.aiff","message":"%s","number":"%s"}}' % (attribution.emotion,attribution.file_name,attribution.message,number)	
	websocket_send('http://' + 'localhost' + ':' + __socket_port, message_wrapper, 'mykey', 'robot')
	# websocket_send('http://' + ip + ':' + __socket_port, message_wrapper, 'mykey', 'robot')

	return message_wrapper
Beispiel #28
0
def websocket_send(data, group='viz', key=None):
	import json
	if not key: key=''
	from gluon.contrib.websocket_messaging import websocket_send
	try:
		return websocket_send(websocket_server(), json.dumps(data), key, group)
	except IOError:
		logger.error('failed to connect to websocket server')
	except:
		logger.exception('failed to update websocket server')
Beispiel #29
0
def make_cognitive_prompt():
	outcome = True if request.vars['trigger'] == 'hit' else False # either success or failure
	state = request.vars['state']
	prob_num = int(request.vars['number'])
	trig = request.vars['trigger']
	ang = request.vars['angle']
	error = request.vars['error']
	# wrapping info in package
	#message_wrapper = '{"type":"order", "value":{"trigger":"%s","angle":"%s","state":"%s","number":"%s"}}' % (trig,ang,state,prob_num)	
	# message_wrapper = '{"type":"cognitive", "value":{"trigger":"%s","angle":"%s","state":"%s","number":"%s"}}' % (trig,ang,state,prob_num)	
	message_wrapper = '{"type":"cognitive", "value":{"trigger":"%s","angle":"%s","state":"%s","number":"%s","error":"%s"}}' % (trig,ang,state,prob_num,error)	
	

	# This line caused a lot of grief while merging logs by me and Cognitive Prompts by Elissa.
	# Original line
	websocket_send('http://' + 'localhost' + ':' + __socket_port, message_wrapper, 'mykey', 'robot')
	# Adrin made the change here, and for all websocket_send calls.
	# websocket_send('http://' + ip + ':' + __socket_port, message_wrapper, 'mykey', 'robot')
	# websocket_send('http://' + __current_ip_local + ':' + __socket_port, message_wrapper, 'mykey', 'robot')
	# websocket_send('http://127.0.0.1:' + __socket_port, message_wrapper, 'mykey', 'robot')
	return message_wrapper
Beispiel #30
0
def websocket_refresh():
	websocket_send({'type':'refresh'})
Beispiel #31
0
def websocket_pass(team):
	websocket_send({'type':'pass', 'team':team['name']})
Beispiel #32
0
def websocket_fail(team):
	websocket_send({'type':'fail', 'team':team['name']})
Beispiel #33
0
def websocket_pwn(src, dst, service):
	websocket_send({'type':'pwn', 'from':src['name'], 'to':dst['name'], 'service':service['name'], 'servicergb':service['color']})
def loadOptions():
    websocket_send('http://' + __current_ip + ':' + __socket_port, response.json(request.vars), 'mykey', 'interface')
def executeSteps(data):
    ''' DEPRECATED '''
    websocket_send('http://' + __current_ip + ':' + __socket_port, data, 'mykey', __socket_group_name)
    return data
def executeEvent(data):
    ''' DEPRECATED '''
    db.menuOptions2.update_or_insert(db.menuOptions2.name=='test', name='test', value=data)
    websocket_send('http://' + __current_ip + ':' + __socket_port, data, 'mykey', __socket_group_name)
    return data
Beispiel #37
0
def socketAtualizaUsuario(tipoMsg=""):
    websocket_send('http://127.0.0.1:8888', tipoMsg, 'chat', 'conversa')
Beispiel #38
0
def connect_rtc():
    from gluon.contrib.websocket_messaging import websocket_send
    # MSG, KEY='rtc', GROUP='beewoo'
    websocket_send(HTTPS_WEBSOCKET_URL, request.vars.msg, 'rtc',
                   request.args[0])
Beispiel #39
0
def connect():
    from gluon.contrib.websocket_messaging import websocket_send
    websocket_send('http://' + host_name + ':8888', request.vars.msg, 'rtc',
                   request.args[0])
Beispiel #40
0
def sms_websocket():
    data = json.dumps(request.body.read())
    from gluon.contrib.websocket_messaging import websocket_send
    websocket_send('http://127.0.0.1:8888', data, 'mykey', 'sms_websocket')
Beispiel #41
0
def chat():
    if session.uuid:
        from gluon.contrib.websocket_messaging import websocket_send
        websocket_send('http://' + app_config.get('websocket', 'server'),
                       request.vars.msg,
                       app_config.get('websocket', 'password'), session.uuid)
def set_Problem_Number():
   data = request.vars.data
   websocket_send('http://' + __current_ip + ':' + __socket_port, data, 'mykey', 'interface')
def send_data(group, obj):
    txt = jsondumps(obj)
    ###txt = simplejson.dumps(obj)
    websocket_send('http://127.0.0.1:8888', txt, 'mykey', group)
def send():
	group = request.vars.group
	message = request.vars.message
	# TODO wrap object before sending
	websocket_send('http://' + __current_ip + ':' + __socket_port, message, __key, group)