Currently seeking assistance with the code on this site https://learn.microsoft.com/en-us/azure/iot-central/core/howto-create-custom-rules. Upon using the stream analytics job that uses a query to detect a disconnected deviceId, it returns null. Please see as follows:[all deviceId's for the disconnected device return a null, but timestamp is there.][1]
This is the query I used.
with
LeftSide as
(
SELECT
-- Get the device ID from the message metadata and create a column
GetMetadataPropertyValue([centraltelemetry], '[EventHub].[IoTConnectionDeviceId]') as deviceid1,
EventEnqueuedUtcTime AS time1
FROM
-- Use the event enqueued time for time-based operations
[centraltelemetry] TIMESTAMP BY EventEnqueuedUtcTime
),
RightSide as
(
SELECT
-- Get the device ID from the message metadata and create a column
GetMetadataPropertyValue([centraltelemetry], '[EventHub].[IoTConnectionDeviceId]') as deviceid2,
EventEnqueuedUtcTime AS time2
FROM
-- Use the event enqueued time for time-based operations
[centraltelemetry] TIMESTAMP BY EventEnqueuedUtcTime
)
SELECT
LeftSide.deviceid1 as deviceid,
LeftSide.time1 as time
INTO
[emailnotification]
FROM
LeftSide
LEFT OUTER JOIN
RightSide
ON
LeftSide.deviceid1=RightSide.deviceid2 AND DATEDIFF(second,LeftSide,RightSide) BETWEEN 1 AND 120
where
-- Find records where a device didn't send a message 120 seconds
RightSide.deviceid2 is NULL
```[enter image description here][2]
[1]: https://i.stack.imgur.com/CLOQv.png
[2]: https://i.stack.imgur.com/IU3SX.png
Since the Stream Analytics query uses the telemetry from the event hub as its input, can you please let me know if you followed the complete tutorial for the setup? In case yes, do you see the function log messages with the device id?
Also, do you receive the email from SendGrid with the deviceid? In order to analyze further, can you please also confirm that your stream analytics job is receiving inputs from the event hub?