简体   繁体   English

Node js任务,收集数据,服务Web以及从Beaglebone发送数据

[英]Node js tasks, collecting data, serving web and sending data from beaglebone

I am starting a project and searching for the technology to use, I would like to use node js and javascript for the whole project but my app needs to collect data from sensors at specific time intervals, let's say 10ms, send collected data to a web service and serve a web page for configuration. 我正在开始一个项目并寻找要使用的技术,我想在整个项目中使用node js和javascript,但是我的应用需要在特定时间间隔(例如10毫秒)从传感器收集数据,将收集的数据发送到网络服务并提供用于配置的网页。 My question is if i can, with node js, be confident that the time interval is going to be fulfilled and how can i acomplished this. 我的问题是,是否可以使用节点js来确定将要满足的时间间隔,以及如何做到这一点。 Thanks in advance. 提前致谢。

Node will do just fine for this. Node可以做到这一点。 As node is a JavaScript runtime, you have access to all of the JavaScript language. 由于节点是JavaScript运行时,因此您可以访问所有JavaScript语言。 Doing something at a 10ms interval is trivial: 以10ms的间隔做某事是微不足道的:

setInterval(function () {
  // do your check for updates
}, 10); 

Usage of setInterval is not a good idea, because it does not wait for end of handler execution and can start another one immediately after previous. 使用setInterval并不是一个好主意,因为它不等待处理程序执行结束,并且可以在上一个执行之后立即开始另一个操作。 It means that you will not have guarantee of interval, setInterval just put your handler into event loop using specified interval, but your handler may work more time that interval for some reason and event loop queue just could be overflowed. 这意味着您将无法保证间隔,setInterval只是使用指定的间隔将您的处理程序置于事件循环中,但是由于某种原因,您的处理程序可能会在该间隔上花费更多的时间,并且事件循环队列可能会溢出。

I think it is better to use schedulers with setTimeout like this one 我认为这是更好地利用调度与setTimeout的喜欢这一个

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM