Skip to content

Adding mobile notifications

Samson Chen edited this page Sep 4, 2023 · 11 revisions

How to add mobile notifications

Since all the messages are going to AWS IoT, you can define the AWS IoT ACT engine rule to get the notifications when there is a new MQTT message triggered.

mobile notification

You can also generate logs of all the triggered events.

mobile notification

IFTTT

We are using the IFTTT service to accomplish this task. You need an account in IFTTT.

Explore the webhook service.

IFTTT Service

Activate the service, then go to its Documentation.

IFTTT Documentation

You will see your IFTTT webhook API key.

IFTTT API Key

Create IFTTT Applets

Once the webhook service is activated, you can create the IF-This-Then-That applets. You can create IF-Webhook-Then-Send_a_notification_from_IFTTT_app. You also need to install the IFTTT mobile app on your phone so you can receive the notification.

IFTTT Applet

You can also create the IF-Webhook-Then-Dropbox_append_to_a_text_file to generate the event logs sent through Dropbox.


Webhook Lambda Function

We will need to build the Lambda function to be used in AWS Lambda, a serverless cloud. The source of this project was developed by Golang, so you will need the Golang SDK.

The Go Language

It is a simple Go code. The Webhook Code

Modify the code with your IFTTT API key and the event name when you created the applets.

Build the code with the target platform linux.

GOARCH=amd64 GOOS=linux go build -tags lambda.norpc -o bootstrap main.go

Note: Starting from December 31st, 2023, provided.al2 is required for the AWS Lambda with Golang.

The binary output needs to be named bootstrap. Zip the built binary file.

zip ifttt_webhook.zip bootstrap

Create IAM for the Lambda function

Let's go back to AWS console. We need to create a new IAM role for the Lambda function to run.

IAM Console

Create a new role.

IAM Role

Select 'AWS service' as the type of the trusted entity. Choose 'Lambda' for the use case.

IAM Role

Let's make it simple to choose 'AWSLambda_FullAccess' as the permission policy. If you are familiar with the AWS IAM, you can narrow down the permission selections on this role.

IAM Role

Let's call this role 'IFTTT', and create it.

IAM Role

Create Lambda function

Let's go to Lambda Management Console.

Lambda Console

Create a new Lambda function.

Lambda Function

Let's call the function name 'iftttWebhook'. The runtime is provided.al2. Custom runtime on Amazon Linux 2. Choose the permission from the existing role. Select the role 'IFTTT' we just created previously. Click 'Create function'.

Lambda Function

After the function is created, we need to edit the runtime settings.

Lambda Function

Change the Handler to 'bootstrap'.

Lambda Function

Upload the zipped built binary from the ifttt_webhook Go program.

Lambda Function Lambda Function

Create the AWS IoT Core Rule

We need to go back to the AWS IoT Core.

AWS IoT

Go to the IoT Core Act -> Rules.

IoT Rule

Create a rule.

IoT Rule
  • Name: EventToIFTTT
  • Description: IFTTT Webhook Trigger
  • Rule query statement:
SELECT * FROM 'mycontrol/demo' WHERE command > 0
IoT Rule

Add action. Choose 'Send a message to a Lambda function'.

IoT Rule

Select the Lambda function we just created previously.

IoT Rule

Create this rule. You are good to go.

IoT Rule
Clone this wiki locally