示例#1
0
文件: app.py 项目: jphacks/TK_1621
def on_open(ws):
    camera = Camera()
    filepath = uuid.uuid4()
    filename = '%s.jpg' % filepath
    camera.snapshot(filename)
    file = open('images/'+filename, "rb").read()
    file_data = base64.b64encode(file)
    ws.send(json.dumps({'upload_file': file_data}))
    time.sleep(0.2)
示例#2
0
            jtalk.speak("遠くの%s" % text)
        else:
            jtalk.speak("%-3.2fメートル前方に%s" % (distance, text))
    except UnboundLocalError:
        print 'エラーが発生しました'


def on_publish(client, userdata, mid):
    print("publish: {0}".format(mid))


if __name__ == "__main__":
    client = mqtt.Client(protocol=mqtt.MQTTv311)
    client.on_connect = on_connect
    client.on_message = on_message
    client.on_publish = on_publish
    client.connect(host, port=port, keepalive=60)
    client.loop_start()

    accel = Acceralation()
    camera = Camera()
    while True:
        if accel.permit_snapshot():
            filepath = uuid.uuid4()
            filename = '%s.jpg' % filepath
            camera.snapshot(filename)
            file = open('images/' + filename, "rb").read()
            file_data = base64.b64encode(file)
            client.publish(pub_topic, file_data, 0)
            time.sleep(10.0)