自动更新网页内容 [英] Auto-updating Webpage content

查看:143
本文介绍了自动更新网页内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个系统,有一堆传感器,一台Linux机器进行通信的。我需要一个网络接口,这显示传感器的状态,并自动更新他们时,任何的变化的传感器(或只是自动更新它们每隔几秒钟)。状态

I am working on a system that has a bunch of sensors communicating with a linux machine. I need to make a web interface for this to display status of sensors and automatically update them when the status of any of the sensors changes(or just automatically update them every few seconds).

在code读取传感器都是用C code。哪些传感器数据通过连续请求数据自动或甚推到网络浏览器的选项?

The code for reading sensors is all in C code. What are the options for pushing the sensor data to the web browser automatically or even by continuously requesting the data?

我曾考虑以下方案: 在用于传感器数据,这可以通过如php一个服务器侧脚本被读出的C程序分配共享存储器。然后有一些AJAX什么要求对循环或计时器事件的数据。

I have considered the following scheme: Allocate shared memory in the C program for the sensor data, which can be read by a server side script like php. Then have some ajax or something requesting the data on a loop or timer event.

是否有可能将数据推送到客户端,而不是拉?

Is it possible to push the data to the client rather than pull?

我真的没有用PHP / AJAX的经验,于是就如何落实这一任何提示将是巨大的。

I really do not have any experience with php/ajax, so any tips on how to implement this would be great.

一些关键要素,我不知道的:

Some key elements I do not know:

- 如何做到在JavaScript时机

-How to do timing in javascript

- 如何得到某种结构化数据的javascript的从请求飞服务器(如PHP页面读取传感器数据)

-How to get some sort of structured data in javascript on the fly from a request to the server(eg php page reading the sensor data)

推荐答案

正如你所说,要获取数据,有两种解决方法:

As you say , to getting data , you have two solutions :

A)拉动数据AJAX

您可以轻松地做一些阶段性任务与setInterval的:

You easily can do some periodical task with setInterval :

setInterval(callbackserver, PERIOD_MILLIS);

如果你使用像jQuery框架,有很多插件的定期更新。

If you use a framework like jquery, there is plenty of plugin for periodical updating.

B)与JS服务器将数据推

数据可以推拔到浏览器来代替。对于您需要根据协议,例如彗星的服务器。检查这个项目了解更多信息。

Data can be push to the browser instead of pulling it. For that you need a server based on protocol like Comet. Check this project for more information

如何获得某种形式的结构化数据的javascript的从请求飞服务器

How to get some sort of structured data in javascript on the fly from a request to the server

JSON似乎是结构化的数据翻过LANGAGE一个完美的解决方案。

json seems to be a perfect solution for structured data accross langage.

我曾考虑以下方案:在分配共享内存   用于传感器数据,这可以通过一个服务器侧被读C程序   像PHP脚本

I have considered the following scheme: Allocate shared memory in the C program for the sensor data, which can be read by a server side script like php

为什么不直接做在C中的守护进程,并通过PHP从它那里得到的数据与 EXEC(mydeamon - 数据)命令为例

Why not simply make a deamon in C and get data from it via PHP with a exec("mydeamon -data") command for exemple

这篇关于自动更新网页内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆