AWS IoT - How to create a Web Application - amazon-web-services

I'm new to AWS and web application development.
I have a project where I have a motor and relay connected to a Raspberry Pi 4 Model B.
The Raspberry Pi is to communicate to a web application through AWS IoT to send/receive messages and commands from registered user accounts.
The web application should contain a Sign In page as well as a dashboard.
I wish to also host the web application on the AWS cloud.
I am unsure which of AWS services I should be using and how to use them.
So far, I've only worked out to use AWS IoT Core to communicate between the Raspberry Pi and AWS IoT Core without any web application involved.
Can anyone advise on what services/web framework I might need to know to create a web application that can send/receive commands/messages to/from the Raspberry Pi?
Any advice is much appreciated!

You can use AWS Greengrass service. Install the Greengrass Core on your IOT devices (Raspberry Pi) which will install and include the X.502 certificates required to connect to your AWS Account. once you set up the Greengrass, you can install components from Greengrass V2 onto your device from your AWS Account. Deploy a component which would be able to publish messages on an IOT Core topic as and when required by taking data from sensors. Use MQTT protocol for sending messages to IOT Core. Once you receive the messages in IOT Core you can send them to other AWS Services using IOT Core Rules.

Related

Running a Greengrass Core on a Raspberry Pi 3b+

I have 2 greengrass cores, one is running on an AWS EC2 instance and the other is running on a Raspberry Pi.
In my project, I am sending video frames from my local machine to my RaspberryPi, then I process those frames, locate a marker with a QR code that is in the frame and send the coordinates of the marker to Greengrass. I am then reading those coordinates from my laptop.
In first scenario my greengrass was running on an EC2 instance (had it from before) and in order to boost performance I decided to run another greengrass core on my Raspberry Pi and use that one instead. My thinking was that instead of having a triangle Laptop->RBPi->EC2->Laptop I will essentially remove the EC2 instance and the cloud component from this process and therefore improve my performance.
The problem is that I do not see much/any difference in performance.
In both cases, if I want to connect to my greengrass core instance I use the AWS endpoint as the my "contact" point and the only difference is that in core's connectivity setting I am using my Raspberry Pi's IP address in one scenario and the IP address of the EC2 instance in the other. Am I wrong in doing it like this, is there another way?
How does this communication work in practice? Does my message go to the AWS endpoint somewhere in the cloud and is then sent to my greengrass core device (Raspberry Pi or EC2)?
Greengrass is an IoT service, and due to its purpose, it uses fast and lightweight MQTT protocol for communication.
Its communication model is based on "Publish-Subscribe" model, with MQTT broker in the middle.
You are right saying the message goes to AWS endpoint - that would be the AWS IoT Core MQTT broker.
When a IoT device (i.e. RPI or EC2) runs Greengrass or in fact any other IoT MQTT client software, when it 'sends' a message - it publishes it to that broker on specific topic. On the other side there is another IoT device which in turn is subscribed to that topic through the same broker.
The broker acts like a hub where devices publish messages and subscribe to receive those messages with the use of topics, thus the communication is possible.
IoT devices need that broker to communicate, hence it really doesn't matter whether you run Greengrass on EC2 or RPI since both have to publish to subscribe to the topic on the AWS IoT broker.

how to establish a private network connection of AWS server to a remote IoT device running linux?

how to deploy a code to a remote IoT device running linux? Is there any zombie program to be written on the remote IoT device to establish a connection? Or is there any custom publisher subscriber shell script/python program needs to be handled at IoT device side? Is there any alternative web servers / Is it possible to deploy a code from gitlab to remote IoT device?
AWS IoT Greengrass is exactly the service you are looking for. You can set it up to be started with systemd and it will run a daemon that keeps your IoT device and the shadow device in sync. You can even deploy long-running lambda functions on your device that will only run locally (not in the cloud). All the deployment, secure connection, updating and offline handling is done by Greengrass.
I played with that and my Raspi with Sense HAT as my home office sensor. Now have a fancy dashboard of my room temperature, humidity and more... lots of fun.
You can get started here.

AWS IoT: Possible to connect mobile devices

Is it possible to programmatically connect a mobile device to IoT in AWS?
Would the end-user need to do any configuration on their side for this to work?
It depends on the type of device that you have in hand. The device must have a device certificate, private key, and root CA certificate installed for communicating with AWS IoT Core.
There is a SDK that can help you programatically. The AWS IoT Device SDKs help you to connect your devices to AWS IoT. Here is a list of SDKs based on the platform that you are using.
Here is a good link for reference establishing connection with AWS IoT core service

how to connect device to AWS greengrass

I am using MOKOSMART_mkgw1 to collect data and send it to AWS IoT Core.
for that, I need to set the following configurations,
endpoint (aws iot endpoint)
topic (any)
device certificate and private key
root ca.
I was able to connect and send data to aws iot core.
now I want to connect it to aws greengrass device instead of iot core directly.
i have greengrass running, on ip 192.196.1.12 on port 8883 (windows machine).
i download Group CA using basic discovery api. so i used this mqtt settings for device:
broker endpoint (192.168.1.12:8883)
topic (same as registered in subscription in aws iot GG)
device certificate and private key (the device is registered in aws iot GG)
Group CA (downloaded by basic discovery sample application)
but i am still not able to connect to aws gg?
my understanding is aws GG also has a MQTT broker. so by providing a proper authentication and topic, i should be able to connect to it, whether or not I have aws device SDKs or not. am i wrong? what does "basic discovery example" do extra to be able to connect to aws gg ??
I am so sorry for wasting your time if you brainstorm on this question.
the issue was, I was passing a random clientID in MQTT.
instead, I passed "Device Name" as the client ID and it worked.
keep this question here if someone else falls in the same hole.

AWS GREENGRASS Cannot connect to device

I am new to AWS IoT. Can you please guide me or refer me some helpful material to implement whole greengrass. I want to use raspberry pi as my greengrass core in gg group and I want to establish communication between different devices which in my case are esp8266 and esp32 through raspberry pi.
Instead of terminal in my computer I want to use one esp8266 as publisher and another esp8266 as subscriber and exchange data between them via raspberry pi (greengrass core). I have no idea if I have to install device SDK on esp or what? I am finding no way out from here.
Thank you so much for help.
First you should read about Greengrass which you can find useful information and how to install it on RaspberryPi here.
Then you should choose which kinds of OS you want to use for your ESPs. You can use:
Amazon FreeRTOS
MongooseOS
Zerynth
I recommend to use Amazon FreeRTOS because it is well-known and the documentations are very good. You can find more information to get started with it here. You should consider that all of your devices (RaspberryPi and ESPs) should be in the same network and you should set the IP of the broker in your ESPs to the IP of your RaspberryPi in your local network. Also you should set the devices to be in same group in AWS IoT console and deploy the configuration to the Greengrass. The policies for IoT devices should allow them to publish/subscribe. For connecting to the AWS broker all of devices should have valid certifications and for connecting ESPs to the Greengrass network CA root certificate should be replaced by Greengrass group certificate.
You can't use esp8266 with aws Greengrass, because esp8266 doesn't support TLS 1.2 communication and aws IoT required TLS 1.2.
You can use esp32, which support TLS 1.2 and can exchange certificate, and establish the secure connection with aws greengrass.
I have written an article, which explain each and every steps, how you can start from stracth to advance level.
Zerynth official has featured this article on their blog. So follow it and complete your solution.