Google Core IoT 设备离线事件或连接状态 [英] Google Core IoT Device Offline Event or Connection Status

查看:24
本文介绍了Google Core IoT 设备离线事件或连接状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道当 Google Core IoT 上的设备离线时触发事件的简单方法吗?在我切换到 Google 的 IoT 实现之前,通过在 MQTT 断开连接时触发一个事件来非常轻松处理这个问题,但 Google 似乎没有简单的方法可以做到这一点.

Does anybody know of an easy way to trigger an event when a device on Google Core IoT goes offline? Before I switched to Google's IoT implementation, this was very easily handled by triggering an event when MQTT disconnects, but it seems Google has no easy way of doing this.

有没有人知道是否有什么计划?

Does anybody know if there is something planned for this?

谁回来了,我需要从头开始让他们看到这样的事情是物联网设备管理的基本要求!

AWS 和 Microsoft 等其他平台已经实现了这一点(或通过某种方式轻松处理):https://docs.aws.amazon.com/iot/latest/developerguide/life-cycle-events.html

Other platforms like AWS and Microsoft already have this implemented (or some way to handle it easily): https://docs.aws.amazon.com/iot/latest/developerguide/life-cycle-events.html

与 Auzure 物联网集线器的设备连接(在线/离线)状态

我希望我在编写我的所有代码并使用 Google 的 IoT 平台实现我的设置之前就知道这一点,我想这是我假设的事情如此简单的错,并且应该物联网设备的标准将可用.

I wish I had known this before writing all my code and implementing my setup using Google's IoT platform, I guess that's my fault for assuming something so simple and that should be standard for IoT devices would be available.

如果您甚至无法提供基本的线下/线上活动,您将如何与其他物联网提供商竞争?!

How are you going to compete with other IoT providers if you can't even provide basic offline/online events?!

我在这个 SO 问题中的回复显示了我如何编写 100 多行代码来创建一个 Firebase 函数来检查设备是否在线(但它仍然不处理离线事件,并且只是一个 hack任何物联网服务提供商都应该具有的特性!):https://stackoverflow.com/a/54609628/378506

My reply in this SO question shows how I had to write 100+ lines of code just to create a firebase function to check if a device is online (but that still doesn't handle offline events, and is just a hack for something that should be native to ANY IoT service provider!): https://stackoverflow.com/a/54609628/378506

我希望其他人找到了一种方法来做到这一点,因为我花了很多天时间搜索 SO、Google、Google Core IoT 文档,但仍然没有找到任何东西.

I'm hoping someone else has figured out a way to do this, as i've spent numerous days searching SO, Google, Google Core IoT Documentation, and still have not found anything.

即使 MQTT Last Will 得到支持,我们也可以使其工作,但即使如此,Google 也不支持 (https://cloud.google.com/iot/docs/requirements) ...来吧伙计们!

Even if MQTT Last Will was supported we could make that work, but even that IS NOT SUPPORTED by Google (https://cloud.google.com/iot/docs/requirements) ... come on guys!

推荐答案

您的云项目确实可以访问各个 MQTT 连接/断开连接事件,但目前它们仅显示在 Stackdriver 日志中.在云控制台中,您可以创建将这些事件发布到 Pub/Sub 主题的导出器:

Your cloud project does have access to the individual MQTT connect/disconnect events, but currently they only show up in the Stackdriver logs. Within the cloud console, you can create an exporter that will publish these events to a Pub/Sub topic:

  1. 访问Stackdriver Logs云控制台.
  2. 输入以下高级过滤器:

  1. Visit the Stackdriver Logs in the Cloud Console.
  2. Enter the following advanced filter:

resource.type="cloudiot_device"
jsonPayload.eventType="DISCONNECT" OR "CONNECT"

  • 点击创建导出

    出口商发布完整的LogEntry,其中然后,您可以从订阅相同 Pub/Sub 主题的云函数中使用:

    The exporter publishes the full LogEntry, which you can then consume from a cloud function subscribed to the same Pub/Sub topic:

    export const checkDeviceOnline = functions.pubsub.topic('online-state').onPublish(async (message) => {
      const logEntry = JSON.parse(Buffer.from(message.data, 'base64').toString());
      const deviceId = logEntry.labels.device_id;
    
      let online;
      switch (logEntry.jsonPayload.eventType) {
        case 'CONNECT':
          online = true;
          break;
        case 'DISCONNECT':
          online = false;
          break;
        default:
          throw new Error('Invalid message type');
      }
    
      // ...write updated state to Firebase...
    
    });
    

    请注意,在连接丢失的情况下,设备无法访问与实际 DISCONNECT 事件之间的时间延迟可能与 MQTT 保持活动间隔一样长.如果您需要立即检查设备是否可访问,您可以向该设备发送命令.

    Note that in cases of connectivity loss, the time lag between the device being unreachable and an actual DISCONNECT event could be as long the MQTT keep-alive interval. If you need an immediate check on whether a device is reachable, you can send a command to that device.

    这篇关于Google Core IoT 设备离线事件或连接状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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