コード例 #1
0
def update_gps():
    """ Update clients with latest GPS coords """
    data = request.get_json()
    print data
    payload = {"lat": data["latitude"], "lng": data["longitude"]}
    pusher_client.trigger("update-gps", payload)
    return json.dumps(payload)
コード例 #2
0
def update_location():
    """ Update clients with latest GPS coords (FORM) """
    print request.form
    payload = {
        "lat": request.form.get("latitude"),
        "lng": request.form.get("longitude")
    }
    pusher_client.trigger("update-gps", payload)
    return json.dumps(payload)
コード例 #3
0
def get_location():
    try:
        resp = urllib2.urlopen("http://ip-api.com/json/").read()
        obj = json.loads(resp)
        payload = {"lat": obj["lat"], "lng": obj["lon"]}
        print payload
        pusher_client.trigger("update-location", payload)
    except:
        print "Error"
コード例 #4
0
def start_drive(direction):
    directions = {
        "FORWARD": motor.forward,
        "REVERSE": motor.reverse,
        "LEFT": motor.left,
        "RIGHT": motor.right
    }
    if direction in directions:
        directions[direction]()
        sleep(0.5)
    else:
        collision.start()
        collision.drive(30)
        toggle_green()
        toggle_red()

    motor.neutral()
    pusher_client.trigger("drive-complete", "Autobot available")
コード例 #5
0
    ECHO = 18

    # Trigger distance
    TRIG_D = 40

    motor = Motor(LEFT1, LEFT2, RIGHT1, RIGHT2)
    sensor = soundsensor.Sensor(TRIG_D, TRIG, ECHO, LED_G, LED_R)
    motor.setup_GPIO()
    sensor.setup_GPIO()
    sensor.set_HUD = False

    collision = Collision(sensor, motor)

    try:
        toggle_green()
        toggle_red()
        toggle_green()
        toggle_red()
        toggle_green()
        toggle_red()
        app.run(host='0.0.0.0', port=3000)

        toggle_green()
        sleep(0.5)
        toggle_green()
        pusher_client.trigger("api-status", "Online")
    except KeyboardInterrupt:
        pusher_client.trigger("api-status", "Offline")
        motor.neutral()
        GPIO.cleanup()