*存档* = 如何搭建物联网管理web服务器= 嗨,大家好, 我是一个爱好程序员,需要一些建议 简而言之:我想创建一个小网络应用程序来控制我的飞利浦 Hue 灯和家里的其他物联网设备 我已经在 Python 中使用了 Hue API,并且有一些脚本运行良好。我还有一些脚本可以在不同的设备上通过 SSH 运行命令 因此,下一步我想创建一个具有漂亮 UI 的 Web 应用程序 在我过去,我还创建了一个小型 Android 应用程序,首先是在 Kotlin 中,然后是在 Flutter 和 Firebase 中,我很惊讶我可以如此轻松地在 Flutter 中获得一个半漂亮的 UI。我知道 Flutter 也可以用作网络应用程序,但我认为这不是合适的工具 我看了一下 React 和 Angular,并阅读了初学者指南。与 Flutter 相比,它们看起来需要更多工作才能使它们看起来更好,但也许我只需要一个更好的模板 在我的想象中,我想触发一个脚本来收集当前状态,该脚本将其写入某个 JSON 文件,然后 UI 显示一个漂亮的图形或图表。然后按下一个按钮,这将写入另一个文件并触发一个脚本,该脚本读取该文件并相应地更改灯光颜色 现在,老实说,我有点不知道该从哪里开始 根据我收集到的信息,我可以使用 Angular 构建前端,然后可能有一个 MongoDB 作为我的“文件系统”,我可以在其中存储和加载我的灯光或配置脚本的状态。我想我需要一个 API 来将数据库连接到我的用户界面。我希望我至少有一部分是对的 :D 你认为从 JS/TS 开始并在 Angular 或 React 中创建 UI 是正确的方向吗?或者这对我的意图来说是完全错误的吗? 谢谢你的建议! 您在这里绝对是在正确的轨道上,您缺少的一点是将它们全部绑定到服务器规范中 在您的情况下,我会做的是构建一个为网页提供服务的服务器。该网页向服务器公开的 REST API 发出 HTTP 请求。服务器是前端网页、脚本、数据库之间的中央连接点;不要尝试在不通过服务器的情况下从网页连接到数据库或更改灯状态 定义您的 API 端点。假设您想控制灯光;也许你需要: 获取授权令牌 [ HTTP GET/api/token with creds in header], returns token or 401 Get status of devices [ HTTP GET /api/devices with token in header], returns JSON status of all devices Get status of lights [ HTTP GET /api/devices/lights with token in header] returns JSON status of all lights Control a single light [ HTTP POST /api/light/ with token in header, payload specifying RGB], returns empty 200 on valid request, 422 otherwise And so forth. Once you have an API spec you can develop whatever you want to first; the server code for the API (Django is good if you're comfortable with Python), the front-end code, the server code for integrating your scripts or the DB. As long as the API is sufficiently specified then the parts will all talk to each other nicely. Separation of concerns makes it simple to build some bits, mock others up, modify and replace as needed A tip: don't write anything to files if you're just sending JSON data around. The server itself can *probably* just call all the script code directly with no need to pass files, and can definitely serve the JSON via HTTP to the web page for display purposes This sounds like a fun project. Can you tell me a little about your end goal with it? Maybe I’ll do something like it at my house. I guess what I’m wondering is aside from being a fun project, what (if any) controls does it give you over your devices that don’t come sort of “baked in” via remote controls or apps for example that may come with the device. Just would like to hear about your real world advantages of doing this == About Community == Members Online