从网站获取值并控制继电器?

发布于 2024-10-02 06:37:15 字数 284 浏览 2 评论 0原文

今天我从一位客户那里收到了一个非常不寻常的问题。他们提供关键任务服务,在特定事件发生时通知人们非常重要。目前,他们有一个 API,当通过网络浏览器访问时,可以根据警报的状态简单地写出 TRUE 或 FALSE。

他们希望更进一步,因此他们希望拥有一台能够连续从现有 API 获取值的 PC,并根据该值切换继电器,从而打开/关闭警报或警告灯在他们的办公室。

我不知道如何构建这样一个东西,因为我只从事网络应用程序的工作。这听起来不像是一个需要太多脑细胞的项目,但对我来说无疑是一个挑战。我需要学习什么语言才能完成这样的事情?

I got a quite unusual question today from a client. They provide a mission-critical service where it's important that people are notified when a certain event happens. Currently they have an API that simply writes out TRUE or FALSE, when accessed by a web browser, depending on the state of their alert.

They want to take this even further, so they want to have a PC which would fetch the value from their existing API on a continuous basis, and depending on the value, toggle a relay, which would turn on/off an alarm or warning light in their office.

I have no idea of how one could build such a thing, as I work only on web applications. It doesn't sound like a project requiring too many braincells, but certainly a challenge for me. What languages do I need to learn to accomplish something like this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寻梦旅人 2024-10-09 06:37:15

由于软件事件将触发物理动作(打开灯),因此需要您与某种电子设备进行交互。

一个好的开始是 Arduino。它是开源硬件,让您可以使用 C++ 的变体与主板进行交互。

Since the software event will trigger a physical action (turning on a light) it will require you to interface with some sort of electronic device.

A good start would be Arduino. It's open-source hardware and let's you interface with the board using a variant of C++.

你げ笑在眉眼 2024-10-09 06:37:15

该项目由两部分组成:

  1. 将互联网连接到 PC。例如使用 Perl。

    使用 LWP::Simple 'get';
    
    
    我的 $url = 'http://...';
    我的 $value = get($url);
    if ($value =~ m/TRUE/) {
        switch_relay(1);
    }
    elsif ($value =~ m/FALSE/) {
        switch_relay(0);
    }
    
  2. 将 PC 连接到某些硬件,例如示例中的 switch_relay。有几种方法可以做到这一点。

    • 您可以使用 X10。不过我没用过所以可以
      对此更有帮助。
    • Velleman K8055、USB接口板,可通过USB连接。我将它与 Perl 一起使用,效果非常好。
    • 或者其他一些 USB 转硬件设备(例如 Arduino)也可以。
    • 更简单:如果您使用 USB 灯,则只需 关闭该设备的 USB 电源

This project consists of two parts:

  1. Connect the internet to the PC. For example using Perl.

    use LWP::Simple 'get';
    
    
    my $url   = 'http://...';
    my $value = get($url);
    if ($value =~ m/TRUE/) {
        switch_relay(1);
    }
    elsif ($value =~ m/FALSE/) {
        switch_relay(0);
    }
    
  2. Connect the PC to some hardware, switch_relay in the example. There are a few ways to do this.

    • You could use X10. But I haven't used it, so I can be
      more helpful with that.
    • There is the Velleman K8055, a USB interface board, which can be connected with USB. I used this with Perl and it worked really well.
    • Or some other USB to hardware device, like Arduino, would work as well.
    • Even simpler: If you use an USB lamp, you can just power off the USB power of that device.
波浪屿的海角声 2024-10-09 06:37:15

X10 + curl + 任何允许您通过串行端口进行通信的语言:

http://www.smarthome.com/1140/X10-Activehome-CM11A-Computer-Interface-CM11A/p.aspx

http://www.smarthome.com/manuals/protocol.txt

http://curl.haxx.se/

甚至可能只是一个将所有内容结合在一起的批处理文件,包括 http://www.computerhope.com/cttyhlp.htm + 'echo' 用于串行通信

X10 + curl + any language that lets you communicate over a serial port:

http://www.smarthome.com/1140/X10-Activehome-CM11A-Computer-Interface-CM11A/p.aspx

http://www.smarthome.com/manuals/protocol.txt

http://curl.haxx.se/

Perhaps even just a batch file to tie it all together, including http://www.computerhope.com/cttyhlp.htm + 'echo' for serial communication

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文