I am currently implement a project using Firebase Cloud Messagin (FCM) to send notification to mobile apps, the scenario is when "something happends", the hardware device can send the notification to all the mobile devices that belongs to it. (Hardware to mobile device is One to Many)
Simply, I implemented two APIs. The first one is for the app to store the devices' device tokens which are given by FCM to my server. The other one is for the hardware device to call and push notification to all the mobile devices that belong to it.
App -> FCM -> (register device and receive device token) -> save to my server
Hardware -> my server -> (retrieve all the mobile devices' token from DB) -> (call FCM send API) -> (push notification to app)
The framework described above works fine now. However, as the number of hardware devices increase, it may cause quite high load to my server. I am considering to use the AWS Simple Notification Service (SNS) in this case, but seems that AWS SNS can deal with the part of calling FCM API, my server still need to store the EndPoint ARN for AWS SNS to map to the devices.
Any advice on implementing AWS SNS in this case?
Related
I am working on a project wherein a mobile app (Flutter app) should create a unique identity (IOT thing) of my IOT device machine (on AWS) as soon as the user logins onto the app and also it should establish a connection (and subsequent communications) with the isolated IOT device after its configuration (Somewhat similar to Google Home configuration process).
The process starts with user logging onto the app (using AWS Amplify/Congnito to automatically add the user account in the cloud). Subsequently, the app needs to configure the IOT device (ESP32) and send Wifi credentials of home network by connecting to ESP's WiFi AP. However, since both the app and IOT device are isolated from each other (except during the configuration process), I don't have much idea on how exactly will mobile app connect (creating a unique IOT thing automatically) and communicate with the isolated IOT device over AWS IOT cloud.
I have worked with some of the AWS services like AWS Lambda, DynamoDB, AWS IOT for quite a while, hence I am aware of the basics. One of the possible solutions for the above maybe Fleet Provisioning by a Trusted User feature provided by AWS IOT (I did read it's documentation, but still confused). We can also use ESP32's Bluetooth feature for the app to scan nearby devices with which it needs to connect with, but I am not sure how will the connection establish through AWS cloud.
Since I am a beginner to AWS cloud services, it'd be great if someone can provide a possible solution for the above in detail. Also if possible, please provide a solution which would work incase of a large-scale deployment of the above project.
The parts you may be missing are missing are 1) MQTT messaging, which is the IoT message broker service provided by IoT Core, and 2) the need for an application program interface to handle creating and activating devices.
MQTT is a lightweight and widely adopted messaging protocol that is designed for constrained devices.
Your devices (things) will need to communicate back to AWS via MQTT messages, which are captured and processed by the IoT Rules service.
These rules typically trigger Lambda functions, which implement the process logic you need for your application.
See https://mqtt.org/ and https://docs.aws.amazon.com/iot/latest/developerguide/what-is-aws-iot.html
2} you will want to implement a simple API to handle device activation. The AWS API Gateway service makes it easy to implement APIs. For example, you can implement an endpoint for POST /device/ to create a device. That endpoint can trigger a Lambda handles device provisionsing.
Say I have 1000 IoT devices. Each device sends telemetry data to the Azure cloud each second. There is mobile app which displays that telemetry data. Mobile user can see data from specific IoT device only, based on his login. It's not an issue to receive all those d2c messages in the cloud, for example with Event Hubs (initially i wanted to use IoT Hub, but it's pretty expensive with huge amount of messages). It's also clear how to get general event stream (for example, by listening to events endpoint in IoT hub). However, this stream gives all messages, from all devices. Receiving all messages in mobile app and filtering them there does not look like right choice. How can I subscribe to events from specific IoT device only? Can I do this with Event Hubs and/or IoT Hub only, or do I need to utilize other Azure services? If yes, what will be the most cheap solution.
Update:
Original question was just about Azure. But is it possible to achieve what I need with AWS without requiring adding multiple parts to the system. Is Message Broker for AWS IoT what I need here (as I understood, this is built in functionality of AWS IoT Core)?
I'm trying to wrap my head around how AWS Mobile Push Notification works. Specifically I'm building out a web service that will be capable of sending notifications to my mobile app running on my users' devices. After reading all of their docs, it sounds like the high level flow is:
Configuration
I need to go into my respective Push Notification Services (GCM for Android and APNS for iOS) and configure them to get credentials that I configure my backend service to use for connecting to them at runtime
I need to log in to the AWS SNS console and generated a platform application ARN (PlatformApplicationARN) that I also configure my backend to use
Code Flow (Runtime)
When a new user signs up for the first time, or anytime an existing user signs in on a new device, I have the app send my service their device info. One critical piece of this device info is their device token (also referred to as a "registration ID" in the AWS docs). This token is generated by their OS and uniquely identifies their device within their respective Push Notification Services (again either GCM or APNS for me)
When my service receives this new device info, I save it, and I also use the device token to hit the AWS SNS API (along with my configured PlatformApplicationARN) to generate a unique EndpointARN for that particular device
Now, whenever my backend decides it needs to send a notification to that user, I can look up all the devices associated with that user (that I previously stored in my DB), and fetch each device's EndpointARN. Then its just a matter of hitting the AWS SNS API to send my notification message to that EndpointARN, and it sounds like AWS SNS will take care of everything else (and delivering the actual message to the device)
So before I go any further, I'm just looking for someone to help sanity check my understanding and provide any course correction if I've misunderstood anything or am missing any important pieces of the config/flow! Assuming I'm more or less on track...
I'm still not seeing how SNS will be able to connect to GCM and APNS once I send a notification message to an EndpointARN. Do they maintain their own integration/connection with these services? Or do I somehow inject my own GCM/APNS credentials into the AWS SNS API call somehow?
Also, I know push notifications can be fairly configurable, allowing you to do things like:
Determine what sound the device should play when it receives a notification
Determine what color LED to blink on/off when it receives a notification (on my Android phone, different apps cause green, blue even purple LEDs to blink!)
Determine whether the notification is received by the Android/iOS OS itself (in which case if I come back to my phone after being away from it for a few minutes, I can press any button and see a high-level listed summary of any new notifications I've received); or whether the notification is purely an "in-app" notification in which case I'll only see that I received it if I actually open up my app.
I'm wondering where all this configuration takes place? Any ideas?
I can confirm that the high level flow is:
Log into AWS SNS and create 2 different Platform Applications, 1 for Android (FCM -- Firebase Cloud Messaging) and the other for iOS (APNS -- Apple Push Notification Services)
For each Platform Application you'll get a PlatformApplicationArn and you will be asked for credentials so that SNS can connect to your respective FCM/APNS accounts
For FCM you will just need your Server API Key (this can be obtained from Firebase Cloud Manager)
For APNS you will need to go through a really labor-intensive process of creating certificates through the Key Chain Access tool on your Mac, this was not fun...
Add these 2 PlaformApplicationArns to your code's config
When a user registers a new device with your app, they will send you a device token (provisioned by FCM or APNS) that uniquely identifies them to FCM/APNS
Take this device token, combined with your PlatformApplicationArn for FCM or APNS and use the AWS SNS SDK to create an EndpointArn for the device. Store this EndpointArn however you like.
Now you can use the AWS SNS SDK to push messages to your EndpointArn (specific device) anytime you want to.
Does AWS offer a service for real-time publish&subscribe messaging for end clients? (web, mobile, desktop).
I'm looking for something that is topic based, optionally with a statfull model of data, where clients can subscribe to topics, receive data published on these topics at real time, etc.
(similar to what Google Firebase offers).
Thanks.
Yes. Amazon Simple Notification Service (SNS) provides:
Topic creation
Publishing of messages to the topic
Subscription to a topic via:
Email
HTTP/S endpoint (effectively, a REST call)
SMS
Sending to an Amazon SQS queue
Triggering an AWS Lambda function
Sending mobile notifications (iOS, Android, Baidu, Windows mobile, Windows desktop, Mac desktop)
SNS allows subscriber has the following type of protocols
HTTP/S
Lambda
SQS
Email/JSON
Application
not sure what does Application protocol refers to
and how can I fill in the endpoint
(a example is arn:aws:sns:us-east-1:5555555555:endpoint/ADM/application-name/uuid)
SNS -- the way I see it, conceptually -- is really two different products under one AWS service.
HTTP(S), Lambda, SQS, Email, Email/JSON, and SMS (you forgot SMS)
Mobile push notifications (that's "application" -- mobile apps)
For the application protocol, the endpoint is the EndpointArn of a mobile app and device.
http://docs.aws.amazon.com/sns/latest/api/API_Subscribe.html
Unless you are sending a mobile push notification, you don't publish to an EndpointArn. You publish to a TopicArn.
For everything other than mobile push (https, email, sqs, etc.), when you send a message to a topic, it goes to all of the subscribers to the topic. The individual subscribers aren't individually-addressable (unless there's been a big change that I managed to miss; I welcome correction if that is the case).
With mobile push, you can send messages singly to individually-addressable endpoints (EndpointArn) or to all of the endpoints subscribed to a topic.