Google 核心物联网设备离线事件或连接状态
Google Core IoT Device Offline Event or Connection Status
有人知道在 Google Core IoT 上的设备离线时触发事件的简单方法吗?在我切换到 Google 的 IoT 实现之前,这是 非常容易 通过在 MQTT 断开连接时触发事件来处理,但看起来Google 没有简单的方法来做到这一点。
有人知道是否有为此计划的东西吗?
谁回来了我需要挠挠他们让他们看到这样的东西是物联网设备管理的基本要求!
AWS 和 Microsoft 等其他平台已经实现了此功能(或以某种方式轻松处理):
https://docs.aws.amazon.com/iot/latest/developerguide/life-cycle-events.html
Device connectivity(online/offline)status with the Auzure iot hub
我希望我在使用 Google 的 IoT 平台编写所有代码和实施我的设置之前就知道这一点,我想这是我的错误假设 所以简单,这应该是物联网设备的标准。
如果连基本的 offline/online 事件都无法提供,您将如何与其他物联网提供商竞争?!
我在这个 SO 问题中的回复表明我不得不编写 100 多行代码来创建一个 firebase 函数来检查设备是否在线(但它仍然不处理离线事件,只是一个破解 应该是任何物联网服务提供商 的原生内容!):
我希望其他人已经想出了一个方法来做到这一点,因为我花了很多天搜索 SO,Google,Google 核心物联网文档,但仍然没有找到任何东西。
即使 MQTT Last Will 得到支持,我们也可以让它工作,但 Google (https://cloud.google.com/iot/docs/requirements) 甚至不支持......拜托伙计们!
您的云项目确实可以访问各个 MQTT connect/disconnect 事件,但目前它们仅显示在 Stackdriver 日志中。在云控制台中,您可以创建一个将这些事件发布到 Pub/Sub 主题的导出器:
- 访问 Stackdriver Logs
云控制台。
输入以下高级过滤器:
resource.type="cloudiot_device"
jsonPayload.eventType="DISCONNECT" OR "CONNECT"
单击创建导出
- 为接收器名称输入一个值
- Select Cloud Pub/Sub for Sink Service
- 创建一个新的 Cloud Pub/Sub 主题作为 Sink Destination
导出器发布了完整的 LogEntry,然后您可以从订阅相同 Pub/Sub 主题的云函数中使用它:
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 保持活动间隔一样长。如果您需要立即检查设备是否可达,您可以向该设备发送命令。
我认为最好的解决方案是
We need 3 things
cloud sheduler ,
and 2 cloud functions
第一个函数将是@devunwired 的答案,但
// ...write updated state to Firebase... schedule a second function to trigger in 2-3 min (let device to recconect)
第二个函数将向设备发送命令
if the device resposne to command
if stored status is connected dont do nothing
else if the stored status is disconnected then update the status to connected and do what ever you want maybe email
else
if stored status is disconnected dont do nothing
if stored status is connected change the status alert by email or something
有人知道在 Google Core IoT 上的设备离线时触发事件的简单方法吗?在我切换到 Google 的 IoT 实现之前,这是 非常容易 通过在 MQTT 断开连接时触发事件来处理,但看起来Google 没有简单的方法来做到这一点。
有人知道是否有为此计划的东西吗?
谁回来了我需要挠挠他们让他们看到这样的东西是物联网设备管理的基本要求!
AWS 和 Microsoft 等其他平台已经实现了此功能(或以某种方式轻松处理): https://docs.aws.amazon.com/iot/latest/developerguide/life-cycle-events.html
Device connectivity(online/offline)status with the Auzure iot hub
我希望我在使用 Google 的 IoT 平台编写所有代码和实施我的设置之前就知道这一点,我想这是我的错误假设 所以简单,这应该是物联网设备的标准。
如果连基本的 offline/online 事件都无法提供,您将如何与其他物联网提供商竞争?!
我在这个 SO 问题中的回复表明我不得不编写 100 多行代码来创建一个 firebase 函数来检查设备是否在线(但它仍然不处理离线事件,只是一个破解 应该是任何物联网服务提供商 的原生内容!):
我希望其他人已经想出了一个方法来做到这一点,因为我花了很多天搜索 SO,Google,Google 核心物联网文档,但仍然没有找到任何东西。
即使 MQTT Last Will 得到支持,我们也可以让它工作,但 Google (https://cloud.google.com/iot/docs/requirements) 甚至不支持......拜托伙计们!
您的云项目确实可以访问各个 MQTT connect/disconnect 事件,但目前它们仅显示在 Stackdriver 日志中。在云控制台中,您可以创建一个将这些事件发布到 Pub/Sub 主题的导出器:
- 访问 Stackdriver Logs 云控制台。
输入以下高级过滤器:
resource.type="cloudiot_device" jsonPayload.eventType="DISCONNECT" OR "CONNECT"
单击创建导出
- 为接收器名称输入一个值
- Select Cloud Pub/Sub for Sink Service
- 创建一个新的 Cloud Pub/Sub 主题作为 Sink Destination
导出器发布了完整的 LogEntry,然后您可以从订阅相同 Pub/Sub 主题的云函数中使用它:
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 保持活动间隔一样长。如果您需要立即检查设备是否可达,您可以向该设备发送命令。
我认为最好的解决方案是
We need 3 things
cloud sheduler ,
and 2 cloud functions
第一个函数将是@devunwired 的答案,但
// ...write updated state to Firebase... schedule a second function to trigger in 2-3 min (let device to recconect)
第二个函数将向设备发送命令
if the device resposne to command
if stored status is connected dont do nothing
else if the stored status is disconnected then update the status to connected and do what ever you want maybe email
else
if stored status is disconnected dont do nothing
if stored status is connected change the status alert by email or something