简体   繁体   English

如何基于我的其余API实现操作

[英]How can I implement actions based on my rest API

I have a plan of automating a process via REST api and multiple smart devices. 我有一个通过REST api和多个智能设备自动化流程的计划。 What I am trying to do is the following. 我想要做的是以下内容。 I have 4 devices that each do a series of actions to complete their task. 我有4个设备,每个设备都执行一系列操作来完成他们的任务。 (practicaly Im gonna be lighting 4 leds in a particular series based on the device). (实际上,我将根据设备点亮特定系列中的4个LED)。 Im currently emulating this in Java (since I dont have the devices at hand) 我目前正在用Java模拟这个(因为我手头没有设备)

So for example lets say device no.1 lights up the red led first for 10 seconds, after that device no.2 needs to light up for 10 seconds etc. That's the task. 因此,例如,假设设备1号首先点亮红色LED指示灯10秒钟,之后设备2号点亮需要点亮10秒等等。这就是任务。 This is done automatically and forever till I shutdown the program. 这是自动完成的,直到我关闭程序。

I have developed a REST API using JAVA and the JAX-RS library where I state the devices and their info (so device name, current state ex. Yellow Led ON/OFF etc.). 我使用JAVA和JAX-RS库开发了一个REST API,其中我说明了设备及其信息(因此设备名称,当前状态,例如Yellow Led ON / OFF等)。

What I dont understand is how I am gonna make the program I have now respond to the info from the API. 我不明白的是我将如何制作我现在回复API信息的程序。 How can I make my program get notified when a value is changed on the API info? 如何在API信息上更改值时,如何通知程序?

How can I make device 2 poll the API till it gets the response to start its action? 如何让设备2轮询API直到获得响应以启动其操作? Or make it so it starts the action if i manually change the value on the server data? 或者,如果我手动更改服务器数据上的值,它会启动操作? Example if the yellow led is on, and i go in the server database and put it on off, how will my application get notified and change the state of the simulated led? 例如,如果黄色LED指示灯亮起,我进入服务器数据库并将其关闭,我的应用程序将如何得到通知并更改模拟指示灯的状态?

Since you are using HTTP, most suitable solution is to use web sockets . 由于您使用的是HTTP,因此最合适的解决方案是使用Web套接字 You can use them for full duplex communication. 您可以将它们用于全双工通信。 When you receive input from one device, you can process it and inform other devices. 当您从一台设备接收输入时,您可以处理它并通知其他设备。 Note that this is not suitable for a large client base. 请注意,这不适合大型客户群。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将自己的方法的操作实施到main方法中? - How can I implement the actions of my own method into the main method? 如何实现此REST API并保持DRY? - How can I implement this REST API and stay DRY? 如何在我的Web应用程序中实现REST。我想为我的网站制作一个休息API? - How to implement REST in my Web Application. I want to make a rest API for my website? 如何在Java代码中实现ImageJ API? - How can I implement ImageJ API in my Java code? 如何在Android App中实现基于令牌的Rest API - How to implement Token based Rest API in android App 如何使用基于REST的应用程序实现在线/离线功能? - How do I implement online/offline feature with REST based application? 如何从我的Android设备访问我的本地REST API? - How can I access my local REST api from my android device? 我们可以在Spring Boot中基于​​rest api的path参数实现@Conditional Bean吗? - Can we implement @Conditional Bean based on rest api's path param in spring boot? 如何将基于Rest的Java Web应用程序与okta for sso集成? - How can I integrate my rest based java webapp with okta for sso? 如何在我的backtracker(java)中实现呢? - How can I implement that in my backtracker (java)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM