gpt4 book ai didi

java - 将数据从树莓派远程发送到 Spring Web 应用程序

转载 作者:行者123 更新时间:2023-12-01 09:34:35 29 4
gpt4 key购买 nike

我我想要这样的架构...... /image/hHbPb.png

你能帮我吗?我不明白我应该如何将数据从 respberry 发送到网络服务器。我有一个 spring mvc web 应用程序...用户应该能够测量某些东西(例如温度)并通过 web 应用程序界面(jsp 页面)发送它。我可以编写一个网络服务来将数据从表单发布到网络服务器。但是我应该如何将数据从树莓派发送到表单?或者有什么更好的解决办法吗?

最佳答案

Pi 和 Spring App 之间使用REST(例如以 JSON/XML 表示的 POST、GET 方法)。您可以让 Raspberry Pi 每 X 次向 Spring 应用程序发送数据,也可以将 Raspberry Pi 设为服务器,这样 Spring 将向 Raspberry Pi 发送请求,而 Raspberry Pi 将返回数据。第二种方式需要在 Raspberry 上构建 RESTful API。

第一种方法。

PI: here is your temperature (POST /temperature)
PI: here is your temperature (POST /temperature)
PI: here is your temperature (POST /temperature)
PI: here is your temperature (POST /temperature)
PI: here is your temperature (POST /temperature)

第二种方式。

SPRING: give me temperature (GET /temperature)
PI: here is your temperature (returns JSON)
SPRING retrives data from JSON and saves it into database.

您可以在此处了解如何构建 RESTful Web 服务:Spring Guide以及如何使用 RESTful Web 服务:Spring Guide .

请记住,您可以在 Raspberry Pi 上使用 Java,这样您就可以使用 Pi4J 编写 Spring 应用程序。

完成构建后,您只需从数据库获取数据并将其呈现给用户。

注意:如果您想以较小的延迟传输大量数据,那么您应该考虑使用典型的 TCP/UDP 连接。

关于java - 将数据从树莓派远程发送到 Spring Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39109148/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com