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

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

问题描述

有人知道Google Core IoT上的设备离线时触发事件的简便方法吗?在我切换到Google的IoT实施之前,通过在MQTT断开连接时触发事件来 非常容易 ,但这似乎很简单.

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?

我需要回过头来让他们了解,这是物联网设备管理的基本要求!

Who's back do I need to scratch to get them to see that something like this is a basic requirement for IoT device management!

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函数来检查设备是否在线(但该设备仍无法处理离线事件,并且仅仅是针对 应该是任何物联网服务提供商所固有的东西 !): 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也不支持(

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日志中.在云控制台中,您可以创建一个导出器,将这些事件发布到发布/订阅主题:

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 然后,您可以从订阅了相同发布/订阅主题的云功能中消费:

    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天全站免登陆