Untitled
@app.route("/control", methods=["POST"]) def control(): action = request.json.get("action") if action == "FORWARD": move_forward() elif action == "STOP": stop() elif action == "BUZZ_ON": buzz_on() elif action == "BUZZ_OFF": buzz_off() elif action == "LED1_ON": GPIO.output(LED1, GPIO.HIGH) elif action == "LED1_OFF": GPIO.output(LED1, GPIO.LOW) elif action == "LED2_ON": GPIO.output(LED2, GPIO.HIGH) elif action == "LED2_OFF": GPIO.output(LED2, GPIO.LOW) else: return jsonify({"status": "Invalid action"}), 400 return jsonify({"status": "Success"}) if __name__ == "__main__": try: app.run(host="0.0.0.0", port=5000) except KeyboardInterrupt: GPIO.cleanup()
Leave a Comment