【问题标题】:WebIOPi no connection with I2C device alertWebIOPi 未连接 I2C 设备警报
【发布时间】:2018-01-02 10:34:16
【问题描述】:

我在 Raspberry Pi 2 上使用 WebIOPi。树莓通过 I2C 连接到 Arduino Nano(Python 脚本与 Nano 配合得很好 - 网页上的按钮可以打开或关闭 LED)。

当与 Arduino 的连接断开时(如果线路/线路 I2C 断开)是否可以发出诊断 Javascript 警报?

谢谢。

【问题讨论】:

    标签: arduino communication webiopi


    【解决方案1】:

    在低级别解决(python 脚本 + 返回一些值)。 示例 python 脚本:

    try:
        bus.write_byte(address, int(value))
        time.sleep(0.01)
        number = bus.read_byte(address)
        flag = number
    except IOError:
        number = 11 #error value (my fantasy)
        flag = number
    

    "flag" 变量在 javascript 中用于识别连接状态,如果 flag = 11 则出现 alert("no connection")

    【讨论】:

      猜你喜欢
      • 2013-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-09
      • 1970-01-01
      • 2013-07-19
      • 2010-10-13
      • 1970-01-01
      相关资源
      最近更新 更多