How to retrieve attributes of the thing associated with an IoT Core for LoRaWAN device

0

An AWS IoT Core for LoRaWAN device's message payload and associated wireless data is received at the rules engine with the DevEUI and WirelessDeviceID easily accessible. When a LoRaWAN device is created, it can be associated with a thing, which is given an automatically generated name. A usable name can be given to the thing as an attribute.

We would like to retrieve the associated thing and attributes based on the WirelessDeviceID as part of the lambda function that parses the binary payload and generate the topic name based on this information. I have not been able to find a way to retrieve this information from a lambda function. If this is not possible from lambda, is there a query that can be used as part of IoT Analytics to get at this information?

We are trying to avoid having to program each individual LoRaWAN device with its name and other identifying information using either downlink messages. Though this would allow the device to include the information in its payload, we are trying to minimize the size of each message transmitted. We have considered using the Shadow Service as a means to store the device's name, building location, etc., but we're not sure this is the right way to go.

Any direction on how best to show the meaningful name on historic data plots and in alert conditions detected by the rules engine would be appreciated.

  • The idea with Fleet Hub is to, as you say, use it for alarms and general observability of device data. For demo purposes, we have been showing alarms by setting up a query for SNS in a rule action, but if the customer eventually wants to modify or add alarms, the thinking is that Fleet Hub would provide a way for them to manage this without having to bring up the rule and edit the query for SNS. There are two types of devices in the system, and an alert condition on one of the device types depends on the state of another, so the query might get complicated.

    The devices will be reporting sensor data once per hour, and we're looking at using either DynamoDB or Timestream to store the data for reports and graphs that go back up to some number years, so for that part of the system we have to get at the thing attributes using the wireless ID as the link to the Thing.

tkobet
asked a year ago400 views
1 Answer
0
Accepted Answer

Hi. You can use the WirelessDeviceId that comes in the Lamba event, and call the GetWirelessDevice API. Python/boto3 snippet:

    iotwireless = boto3.client('iotwireless')
    
    response = iotwireless.get_wireless_device(
        Identifier=event['WirelessDeviceId'],
        IdentifierType='WirelessDeviceId'
    )

    thing_name = response['ThingName']

You need to be careful about the API TPS limits though: https://docs.aws.amazon.com/general/latest/gr/iot-core.html#wireless-limits

profile pictureAWS
EXPERT
Greg_B
answered a year ago
  • This will get us the device name, but after getting into it there are a few issues. The lambda function will have to be given permission to use getWirelessDevice (we're using javascript), which is ok, but this function returns a large amount of information that would not be needed. Also, I can see us eventually running into the TPS limit. If we did go this route, once the thing name is acquired from the data returned, we would then still need additional steps to get at the thing attributes (if that is possible from lambda).

    If the WirelessDeviceID is included in the topic data output by the lambda function, could this be used down the chain from the lambda function to get at the thing name and attributes? If the goal is to get some of the thing attributes returned in a database query result along with the sensor data from the LoRaWAN device to fully identify the source of the sensor readings, how best to either retrieve the attributes and write them to the table along with the data, or retrieve them as part of the database query?

    I can paste the previous paragraph into a new question post if that would be more appropriate.

  • The TPS limit is adjustable, so you can request a quota increase. Alternatively, you might, for example, have a DynamoDB table to look up the thing name for the Wireless Device ID. Once you have the thing name, you can use DescribeThing to get the attributes. It has a soft limit of 350 TPS in most regions. Will you use fleet indexing? If not, the data you wish to store in Thing attributes, might perhaps also go well in a DynamoDB table.

  • And please be aware there is an SQL function to help with accessing DynamoDB tables in IoT Core rules: https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-functions.html#iot-sql-function-get-dynamodb

  • We are planning to use fleet indexing as it's my understanding this is required in order to use Fleet Hub. This being the case, we have a choice between using AWS.Iot.getStatitistics() to query the fleet index based on WirelessDeviceId, or populating a DynamoDB table as each new device is added and using get_dynamodb() to query the table for the attributes we would need. Is that correct?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions