Beispiel #1
0
while True:
    waitData = getDataMqtt()
    if waitData:
        try:
            if (waitData["source"] == "MainApp") & (waitData["func"] == "recognize"):
                _dataWriteMainApp["func"] = waitData["func"]
                _dataWriteMainApp["data"] = [{"company":"","name":"","ID":"","mess":"","box": [],"score":0}]
                print "start Recognize Image!"
                FlagType = "recognize"
                _ImageBase64 = waitData["data"]["base64image"]
                FtpImage = saveImageFtp(ftpHost,ftpUser,ftpPass,ftpPath,_ImageBase64)
                if not FtpImage:
                    _dataWriteMainApp["data"][0]["mess"] = "image path is not exist!"
                    Mqtt.MqttPathPublish = "MainApp"
                    Mqtt.mqttPublish(json.dumps(_dataWriteMainApp))
                    print _dataWriteMainApp
                    continue
                _timeStart = time.time()
                _respont = recognizeFaceFtp(ftpHost,ftpUser,ftpPass,FtpImage)
                _timeStop = time.time()
                if os.path.isfile('/home/pi/maychamcong/log.txt'):
                    data = open('/home/pi/maychamcong/log.txt', 'a')
                    print _timeStop-_timeStart
                    now = datetime.now()
                    data.write("RecognizeFace " + str(now.strftime("%m/%d/%Y, %H:%M:%S:\n")))
                    data.write(str('total run-time of API in second: %fs\n\n' % (_timeStop-_timeStart)))
                    data.close()
                else:
                    print "file log.txt is not exist"
                #print _respont
from MqttClient import MQTTClient
import json

Mqtt = MQTTClient()

_dataWriteAudioPlay = {"source": "APIGetPost", "func": "play", "data": ""}
_dataWriteAudioPlay["data"] = "truongtrinhdakhoidongxong"
Mqtt.MqttPathPublish = "AudioPlay"

Mqtt.mqttPublish(json.dumps(_dataWriteAudioPlay))
print "test"
import threading
from MqttClient import MQTTClient

Mqtt = MQTTClient()
Mqtt.MqttPathPublish = "killer"

class myThread (threading.Thread):
	def __init__(self, threadID, name):
        	threading.Thread.__init__(self)
            	self.threadID = threadID
            	self.name = name
        def run(self):
            	Mqtt.mqttSubcribe()

queueLock = threading.Lock()
thread = myThread(1, "thread1")
thread.start()

print Mqtt.MqttServer,Mqtt.MqttPort
while True:
	t = Mqtt.getData()
	if t != None:
		print "client get: ", t
		Mqtt.mqttPublish("killer")