[英]What is the best way for me to share bool values between my computer and my android phone using python?
For my project I am trying to have my Android phone take pictures of lights that are powered by my computer.对于我的项目,我试图让我的 Android 手机拍摄由我的计算机供电的灯的照片。 I am doing this through an app I am building with Kivy.我正在通过与 Kivy 一起构建的应用程序来执行此操作。 What I need to do is to for multiple lights is the following:我需要做的是为多个灯如下:
Android: Ask for light (x) to be turned on Computer: Turn light (x) on Android: Take photo and tell computer photo has been taken Computer: Turn light (x) off ... Android:要求打开灯 (x) 计算机:打开 Android 上的灯 (x):拍照并告诉计算机照片已拍摄 计算机:关闭灯 (x) ...
If I were to do this all on one computer I would make the status of the light a bool value (ex. lightOn == True) and would just check if it is True of False.如果我要在一台计算机上完成所有这些操作,我会将灯的状态设为布尔值(例如 lightOn == True),并且只检查它是否为 True 或 False。
What is the best way for me to share the status of the light between my computer and my android phone?在我的电脑和我的 android 手机之间共享灯状态的最佳方式是什么?
One way to achieve that is to use sockets, create a socket connection between the computer and your android device and then change the boolean values on given command passed through the socket connection socket tutorial .实现这一点的一种方法是使用套接字,在计算机和您的 android 设备之间创建一个套接字连接,然后更改通过套接字连接套接字教程传递的给定命令的布尔值。 one other solution not very optimal is to use an API the values will be set by the android application and the requests will be made from the computer, for this case I recommend flask-restful, it's really an easy way to create the API you'll need, flask-restful docs另一种不是很理想的解决方案是使用 API,这些值将由 android 应用程序设置,请求将从计算机发出,在这种情况下,我建议使用 Flask-restful,这确实是一种创建 API 的简单方法。我需要, flask-restful 文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.