示例#1
0
def AMQPProcess(log_q, send_q, rcv_q, cmd_q):
    logger = log.loggerInit(log_q)
    logger.log(logging.INFO, "AMQPProcess is started")
    for task in ALL_TASKS:
        # Connect for sending:
        AMQPClient = amqp.hyperAMQPClient()
        AMQPSendTopic_lightManager = AMQPClient.topicGenerator(
            HOST_MAC_ADDRESS, "0001", task, "sub")
        logger.log(logging.DEBUG, AMQPSendTopic_lightManager)
        AMQPClient.declareTopic(AMQPSendTopic_lightManager)

        # For receiving:
        AMQPRcvTopic_lightManager = AMQPClient.topicGenerator(
            HOST_MAC_ADDRESS, "0001", task, "pub")
        AMQPClient.declareTopic(AMQPRcvTopic_lightManager)
        AMQPClient.startSubcribe(AMQPReceiveMessageCallback,
                                 AMQPRcvTopic_lightManager)

    while True:
        try:
            jsonStr = send_q.get()
        except Exception as e:
            continue
        try:
            jsonStr = json.loads(jsonStr)

            AMQPClient.publishMessage(routing_key=AMQPSendTopic_lightManager)
        except Exception as e:
            logger.log(
                logging.ERROR,
                "Failed to run Humidifier Process: exception={})".format(e))
示例#2
0
def AirPurifierProcess(log_q, audio_q, cmd_q):
    try:
        logger = log.loggerInit(log_q)
    except Exception as e:
        print("Create logger failed")
        exit()

    try:
        print("AirPurifier Process is started")
        logger.log(logging.INFO, "AirPurifier Process is started")

        mqttc = mqtt.hyperMQTTClient(log_q, connect_cb=mqttc_on_connect_cb)
        logger.log(logging.INFO, "Wait some seconds to connect to MQTT server")
        mqttc.connect()
        time.sleep(1)

        # while(is_connected != True):
        #     continue

        logger.log(logging.INFO, "Connect success!")
        mqttc.subscribe(mbp162_pub_topic)
        mqttc.subscribe(mbp162_sub_topic)
        mqttc.subscribe(hyper_sub_topic)
        # mqttc.add_broadcast(mbp162_sub_topic)
        getsetting_message = "2app_topic_sub=" + hyper_sub_topic + "&time=1513618350814&action=command&cofmmand=get_projector_setting"
        mqttc.publish(mbp162_sub_topic, getsetting_message)

        mqttc.loop_forever()
    except Exception as e:
        logger.log(logging.ERROR,
                   "Failed to create custom metric: exception={})".format(e))
        raise e
def AMQPProcess(log_q, send_q, rcv_q):
    logger = log.loggerInit(log_q)
    logger.log(logging.INFO, "AMQPProcess is started")
    # Connect for sending:
    AMQPClient = amqp.hyperAMQPClient()
    AMQPSendTopic_lightManager = AMQPClient.topicGenerator(
        HOST_MAC_ADDRESS, "0001", "lightManager", "sub")
    logger.log(logging.DEBUG, AMQPSendTopic_lightManager)
    AMQPClient.declareTopic(AMQPSendTopic_lightManager)

    # For receiving:
    AMQPRcvTopic_lightManager = AMQPClient.topicGenerator(
        HOST_MAC_ADDRESS, "0001", "lightManager", "pub")
    AMQPClient.declareTopic(AMQPRcvTopic_lightManager)
    # AMQPClient.publishMessage(AMQPTopic, "Hello Hyper")
    AMQPClient.startSubcribe(AMQPReceiveMessageCallback,
                             AMQPRcvTopic_lightManager)

    while True:
        try:
            jsonStr = send_q.get_nowait()
            jsonStr = json.loads(jsonStr)

            AMQPClient.publishMessage(routing_key=AMQPSendTopic_lightManager)
        except Exception as e:
            pass
示例#4
0
def main():
    """
    In seperate method so it can be called from other modules.
    """
    args = parse_args()
    applyArgs(args)

    connections.init()
    aggregation.stats_init()

    if not args.timberoff:
        timber.timberRun()
        logger.loggerInit()

    if not args.hissoff:
        gossip.gossipRun()

    if args.timberoff and args.hissoff:
        debug("Nothing to run")
    else:
        reactor.run()
def voiceProcess(log_q, mng_q, aud_q):
    logger = log.loggerInit(log_q)
    logger.log(logging.INFO, "voiceProcess is started")
    while True:
        global state
        if state == "Sleep":
            state = "Pause"
            hotWordDetect()
        elif state == "Run":
            logger.log(logging.INFO, "Voice is detected")
            [action, actionIncomplete, score, parameters, speechScript, speechScript2] = voice2JSON()
            logger.log(logging.INFO, "Action: " + action)
            logger.log(logging.DEBUG, "actionIncomplete: " + str(actionIncomplete))
            logger.log(logging.DEBUG, "score: " + str(score))
            logger.log(logging.DEBUG, "parameters: " + str(parameters))
            logger.log(logging.DEBUG, "speechScript: " + speechScript)
            logger.log(logging.DEBUG, "speechScript2: " + speechScript2)
            if (action == -1 or action == "smalltalk.greetings.bye"):
                aud_q.put(json_utils.jsonSimpleGenerate("speech", speechScript))
                state = "Sleep"
                continue
            if (score < 0.5 or actionIncomplete == 'true' or not(speechScript)):
                try:
                    aud_q.put_nowait(json_utils.jsonSimpleGenerate("speech", "I am not sure to understand what you mean. Can you repeat or explain more?"))
                    # mng_q.put_nowait(jsonSimpleGenerate("action", action))
                    continue
                except Exception as e:
                    logger.log(logging.WARNING, "Action is not complete or score is low")
                    state = "Sleep"
                    continue
            else:
                try:
                    # ManagerJSONQueue.put(jsonSimpleGenerate("action", action))
                    if not aud_q.full():
                        if (speechScript and speechScript != -1):
                            logger.log(logging.DEBUG, "Put script to AudioQueue")
                            aud_q.put_nowait(json_utils.jsonSimpleGenerate("speech", speechScript))
                        if (speechScript2 and speechScript2 != -1 and speechScript != speechScript2):
                            time.sleep(1)
                            logger.log(logging.DEBUG, "Put script to AudioQueue")
                            aud_q.put_nowait(json_utils.jsonSimpleGenerate("speech", speechScript2))
                    else:
                        logger.log(logging.WARNING, "Audio queue is full")
                        state = "Sleep"
                        continue    
                except Exception as e:
                    logger.log(logging.WARNING, str(type(e)))
                    state = "Sleep"
                    continue
        elif state == "Pause":
            time.sleep(1)
示例#6
0
def audioProcess(log_q, audio_q):
    logger = log.loggerInit(log_q)
    logger.log(logging.INFO, "audioProcess is started")

    while True:
        time.sleep(1)
        try:
            jsonStr = audio_q.get_nowait()
            logger.log(logging.DEBUG, "JSON: " + jsonStr)
            jsonStr = json.loads(jsonStr)

            if jsonStr["speech"]:
                logger.log(logging.INFO, AGENT_NAME + ":" + jsonStr["speech"])
                tts = gTTS(text=jsonStr["speech"], lang='en')
                tts.save("speech.mp3")
                os.system("mpg321 speech.mp3")
        except Exception as e:
            print('.', end='', flush=True)
            pass
示例#7
0
 def __init__(self,
              log_q,
              connect_cb=on_connect,
              message_cb=on_message,
              publish_cb=on_publish,
              disconnect_cb=on_disconnect):
     try:
         self.logger = log.loggerInit(log_q)
     except Exception as e:
         raise e
     try:
         self.client = mqtt.Client()
         self.client.on_connect = connect_cb
         self.client.on_message = message_cb
         self.client.on_publish = publish_cb
         self.client.on_disconnect = disconnect_cb
         self.subscribe_list = []
         self.broadcastTopic = []
         self.is_connected = 0
         self.logger.log(logging.INFO, "Created MQTT client")
     except Exception as e:
         logger.log(logging.ERROR, "Can not init MQTT client!")