With what context is data sent from a Lambda to AWS IoT core? - aws-iot

We can use a lambda function to connect to AWS IoT Greengrass core and publish messages. For device to receieve msg published by lambda, 2 things need to be satisfied: 1) There needs to be a subscription to the lambda in the greengrass (with appropriate topic) and 2) the subscriber's code does a .subscribe to that topic. Lambda example:
import greengrasssdk
import json
# Greengrass client to publish to
client = greengrasssdk.client('iot-data')
# Executed on every messages received from the subscription
def lambda_handler(event, context):
client.publish(topic='lab/greengrass/telemetry', payload=json.dumps(event))
return
Here the message is published in context of the Lambda and not a device. Similarly if I had to send msg from lambda to AWS IoT Core, the msg doesn't go from context of lambda as a device, but lambda itself.
However, we could also publish message via Lambda that represents a thing to AWS IoT Core or other device, and for this we will need to pass in credentials (thing credentials) to identify the Lambda as a device (thing).
Have I understood this right?

Not quite. I think you are missing the concept of Subscriptions in greengrass here!
You can make the Lambdas and Devices communicate among themselves or with the AWS IoT Core without having to configure lambda as a Thing.
Checkout the Subscriptions section in your Greengrass core where it will allow you to create subscriptions between one lambda/device/AWS IoT Core to the other.
Ofcourse for onboarding a device to greengrass you need to register it as a thing and download credentials for it and place it as required. But that's not the case to have a lambda publish messages to other lambdas or devices!

Related

Connect to a message service bus that is running with a MassTransit and RabbitMQ dotnet service using Javascript

I have a backend microservice that is using MassTransit and RabbitMQ to publish some messages. I am interested in implement a solution to relay those messages to my app's front end which is written in ReactJS.
I have researched online on various tutorials, most of them show me how to use a JavaScript rabbitMQ client to subscribe/connect to the service bus. But since it is wrapped in MassTransit, and the URL is in the format of "rabbitmq://...", how do I subscribe to this messaging host using Javascript? Ideally I would like to use a WebSocket connection, research tells me that I should consider either STOMP or MQTT, is that something I need to configure in my backend MassTransit/rabbitmq service?
My backend service also have some http endpoints that I can reach using a plain http/https URL, such as https://localhost:7179/api/doSomeJob. Will this help with my intention of using a WebSocket connection to subscribe to the MassTransit service bus?

Send Telemetry Data to Azure IoT Central Device using HTTP GET Requests

I'm trying to send telemetry to a device in Azure Iot Central, with HTTP GET requests.
I have a legacy iot application, and I am trying to migrate it to Azure IoT Central, so for now I need to synchronize my ongoing Iot Data to Azure IoT Central.
One way I found to do it quickly was to use Logic Apps.
I have successfully created the Iot Central application and Logic Apps configuration, and I also found a way to get device information and update properties, but I'm not finding where to send telemetry data.
Is it possible to do with Logic Apps, or there is another way to send the telemetry?
Any hints will be very useful, thanks!
you should use the REST POST request to send a telemetry data to the IoT Central App.
The following is an example for device1:
Note, that the iothubhostname must be obtained from DPS service and also the Authorization header (sas token) is required.
and the following screen snippet shows the IoT Central App Dashboard:

Using Amazon MQ or AWS IoT for self managed IoT Devices

I've tried Amazon MQ today and found out that it is very easy to setup and we can integrate the pub/sub feature on our IoT device side quickly. But unfortunately, when I check the limitations of Amazon MQ, the maximum connection for an instance is only 1000.
The ff screenshot taken from Amazon MQ Docs:
This is too low. And I don't see a quota increase options for that. Plus, I am only allowed to have a maximum of 20 brokers per region, so basically a max of 20k devices only. And to create 20 brokers, the cost is too high as compared to setting up an MQTT broker by myself in an EC2 instance of 8Gb memory and 2CPUs, I can handle up to 50k connections.
Then I saw another option which is to use the AWS IoT for device management. It supports up to 500k devices. But the downside is I have to register all my devices as "Thing", and I have to get certificate for each device. But I really don't need Amazon to manage my devices and keep track of the device's states, we already have it done. Plus, we have to familiarize our self on how devices are managed using the AWS IoT device management console. Therefore, using the AWS IoT service as a message broker is more time consuming to implement than using Amazon MQ.
So, my question is, is Amazon MQ really not designed for IoT devices? Is there anyway to use just the MQTT broker service alone of AWS IoT device management without using its management features(I don't think this is possible)?
Amazon MQ is a cloud managed service for Apache ActiveMQ. One of its aims is to make it easy to migrate an existing product using the protocols that ActiveMQ supports to a cloud managed solution.
So, my question is, is Amazon MQ really not designed for IoT devices?
Your question presumes that there is a black and white answer. Amazon MQ may be entirely suitable for an existing product that needs a managed cloud broker. For another product with different requirements it may not be suitable.
Is there anyway to use just the MQTT broker service alone of AWS IoT device management without using its management features(I don't think this is possible)?
Yes, it is possible to use the AWS IoT broker without using the 'thing' management features. From https://docs.aws.amazon.com/iot/latest/developerguide/iot-thing-management.html
You do not need to create a thing in the registry to connect a device to AWS IoT.
You can connect a client device to the AWS IoT MQTT broker using just a certificate without creating a thing. Though typically each device has its own certificate and the thing registry is a means to manage the relationship between a device and a certificate.
There are also alternate means for clients to authenticate.
As of now Amazon proposes managed RabbitMQ, where there are no fixed limits on the number of connections (it just depends on the size of your machines):
EDIT: they don't support the mqtt plugin for the moment, so this will do for AMQP, but not for MQTT.

How to susbcribe to a telemetry events using MQTT and using C code?

How to susbcribe to a telemetry events using MQTT and using C code? (this is a microcontroller code)
I can send data to a specified topic but when I trying to subscribe to this topic I got error message
This is the message from the log
"mqttTopic": "/devices/my-device/events/my_telem_topic1",
This is the error message from the log
"message": "SUBSCRIBE: Failed to subscribe to topic: '/devices/my-device/events/my_telem_topic1'."
To add to what Kamal posted:
Part of the confusion here is that both MQTT and Pub/Sub (where IoT Core puts your device's telemetry events) are called "topics".
There are 4 MQTT topics for devices to work with (this is all on device side, not Cloud side):
/devices/<device-id>/commands
/devices/<device-id>/config
/devices/<device-id>/state
/devices/<device-id>/events
The first two are there for devices to subscribe to in order to get updates from the IoT Core Admin SDK, the latter two are topics for device to publish data to the Cloud.
In order for a device to subscribe to another device's telemetry, it would need to be able to subscribe to the Pub/Sub topic that's receiving telemetry from the other device. This won't be done as part of the MQTT implementation, but rather, you'd need to implement the Pub/Sub API on your device. This is going to require a separate authentication path as well, likely a service account key that you add to your GCP project, then download to your device. The links in Kamal's answer should get you started if you want to go down that route.
Depending on what you're doing however, as they say, you can probably process the incoming telemetry from one device in a Cloud Function or similar, then set a config for the device that wants to be responsive to that telemetry. That way, if the device is online, it'll get it right away, or if it's not online, it'll get it upon reconnecting to IoT Core.
Telemetry events sent to Cloud IoT are sent to a Cloud Pub/Sub topic that is configured when the device registry is created and are not intended to be retrieved via MQTT on devices. One could use any of the mechanisms available in Google Cloud to subscribe to these messages (Cloud Functions, Cloud Dataflow, or a custom-written subscriber). Commands can be received by devices via MQTT. The topic for a device's commands is /devices/{device-id}/commands/#. APIs are available to send commands to devices.
One would generally send telemetry events from devices, analyze them with one of the aforementioned Cloud products, and then possibly generate commands to devices based on the results of that analysis.

How to change MQTT hostname for Google Iot Core

I am working on an iot device using google-cloud-iot-core, but i would like to have allow for 3rd party support, so i want to change the host name of the mqtt, how can it be done?
Thanks in advance
If you change that endpoint, then you're no longer talking to IoT Core. It's not configurable, as that's the endpoint to talk to the service.
You can setup your own MQTT server somewhere else (could do it in GCE or GKE with a custom container) and make the hostname whatever you want, and then setup your own broker to take the MQTT payloads and create Pub/Sub messages, or even to act as a forwarding proxy to IoT Core itself I suppose (although security and auth might get a bit odd).
Or you could even just go directly to Pub/Sub. It all just depends on your need.
As I mentioned, changing the hostname for IoT Core (the mqtt.googleapis.com) it means that you aren't using IoT Core any longer. There's no other way to access the communication broker piece of IoT Core to do the Pub/Sub message creation, etc. If you don't use the IoT Core endpoint (hostname) then you'd be on your own for creating the Pub/Sub messages from the IoT device data.

Resources