DEV Community

Cover image for Make a “Escape Meeting Button” by Soracom LTE-M Button
Tomotaka Kizawa
Tomotaka Kizawa

Posted on

Make a “Escape Meeting Button” by Soracom LTE-M Button

This article is a repost from my blog site at the following URL.

Make a “Escape Meeting Button” by Soracom LTE-M Button – kizawa.info

I would like to introduce an interesting use case using IoT buttons.I feel that development using IoT buttons will expand dreams.Would you like to develop using IoT buttons too?

favicon kizawa.info

Hello, I'm Tomotaka Kizawa as AWS Ambassador and SORACOM MVC award winner.
Then, I would like to introduce an interesting use case using IoT buttons.

Background

There are boring meetings, right?
I was thinking about how I could escape from such a meeting.
At that time, I found this article.

Justin Trudeau wears a hidden buzzer to escape meetings and now we all want one

Mr. Trudeau,Canadian prime minister has escape meeting button.
I want this one!

It's structure is below.cannot be imitated by common people.

Mr.Trudeau's Button structure

So I thought I could escape from the meeting by getting a call by pressing a button.

escape from the meeting by getting a call by pressing a button

Architecture

This architecture is very simple.
Invoke a Lambda function by pressing a button and make a call using Amazon Connect.

Architecture

I use Soracom LTE-M Button for IoT Button in this case.

Soracom LTE-M Button

This button has LTE-M connectivity and can be used in over 150 countries around the world.
You can buy this button in Mouser site.

There are three button press patterns: single, double, and long.

Notice
Due to an irregularity in the technical certification display, it cannot be used in Japan.
https://soracom.com/ja/news/20241002-1

Setup steps

Setup steps is below.

  1. Setup Soracom LTE-M Button
  2. Get a phone number in Amazon Connect and make a call flow.
  3. Make a lambda function to make a call.
  4. Setup SORACOM Funk (with serring of invoke lambda function)

Setup Soracom LTE-M Button

First, create a SORACOM user account in SORACOM user console.

Next, register your button in the console.
(Menu – SORACOM AIR FOR CELLULAR – SIM Management)
Please push the “Registar SIM” button.

Setup Soracom Button-1

Input ICCID and PUK information.

Setup Soracom Button-2

The input information for ICCID and PUK is written inside when you open the cover on the back of the button.

Setup Soracom Button-3

Setup Amazon Connect

Get a phone number in Amazon Connect and make a call flow.

Setup Amazon Connect Instance

First, create an instance by following the steps below.
In AWS User Console, please push “Add an instance” button.

Connect Setup-1

In this case, It is no problem that Identity model as “Store uses in Amazon Connect”.

Connect Setup-2

Please input the administrator user information.

Connect Setup-3

Settings for incoming and outgoing calls on this instance.
Check both and there is no problem.

Connect Setup-4

Setting for data storage on this instance.
There is no problem with the default settings.

Connect Setup-5

Check the settings and create the instance.

If settings have been completed successfully, please push the “Get started” button.
The Amazon Connect console will open in a separate tab.

Connect Setup-6

Get a phone number

Get a phone number may require documentation depending on legal restrictions in each country.

Select phone number’s country and phone number type (DID or Toll free dial)
Select from the displayed phone number suggestions.

Connect Setup-8

Create a call flow

Next, Make a call flow of outbound call.
Select “Routing”-“Flows” from the sidebar on the left.

Connect Setup-9

Create a new call flow. Click “Create New”.

Connect Setup-10

This time, you create a flow like the one below.
Create a flow like the one below by combining blocks.

Connect Setup-11

  • Set Voice
    • Specify the voice of your choice.
  • Play prompt
    • Specify the voice to speak.
    • This time, you will configure the Lambda function to utter the specified voice as follows.

Connect Setup-12

If you has complete settings, click “Save” > “Publish”.

Connect Setup-13

Connect Setup-14

After publishing is complete, check the ARN of the call flow.
This will be used later for Lambda configuration.

Lambda Function

Create a Lambda function to invoke the callflow.

Create IAM Pollicy and Role

First, create an IAM Role to be used for the Lambda function.
In IAM Policy page, Click “Create Policy” Button.

IAM Policy

The IAM Policy is below.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "connect:StartOutboundVoiceContact",
            "Resource": "*"
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

Next, Create an IAM Role with this IAM Policy attached.
In IAM role page, Click “Create role” Button.

IAM Role-1

Please specify AWS service and Lambda as Trusted entity type.

IAM Role-2

Set the IAM Policy you created earlier.

IAM Role-3

Pleast input IAM role’s name.

IAM Role-4

The creation of the IAM Role has been completed.

make Lamnda Function

Let’s start creating the Lambda function.
Set as follows. Set the IAM role you created earlier.

Lambda-1

The function program is below.(Python)

import json
import boto3
import os

connect = boto3.client('connect')
FlowID = os.environ['FlowID']
InstanceID = os.environ['InstanceID']
MobilePhoneNumber = os.environ['MobilePhoneNumber']
ConnectPhoneNumber = os.environ['ConnectPhoneNumber']

def lambda_handler(event, context):
    # Get click type from event.(these values was set by SORACOM.)
    clickType = event['detect_type']

    # Set message.
    if clickType == "Single short click":
        message = os.environ['message_single']
    elif clickType == "Double short click":
        message = os.environ['message_double']
    elif clickType == "Single long click":
        message = os.environ['message_long']
    else:
        message = 'Error'

    # Call to your mobile phone. See your connect flow.
    response = connect.start_outbound_voice_contact(
        DestinationPhoneNumber = os.environ['MobilePhoneNumber'],
        ContactFlowId = os.environ['FlowID'],
        InstanceId = os.environ['InstanceID'],
        SourcePhoneNumber = os.environ['ConnectPhoneNumber'],
        Attributes = {
            'message': message
        }
    )

    return {
        'statusCode': 200,
        'body': json.dumps(response)
    }
Enter fullscreen mode Exit fullscreen mode

After lambda function created, Specify environment variables as below.

  • ConnectPhoneNumber
    • Specify the phone number you created with Amazon Connect.
  • FlowID
    • The Amazon Connect’s FlowID (String after “/contact-flow/” in ARN)
  • InstanceID
    • The Amazon Connect’s InstanceID (String between “/instance/” and “/contact-flow/” in ARN)
  • MobilePhoneNumber
    • The phone number call to.
  • message_double
    • The voice you want to make when double-clicked
  • message_long
    • The voice you want to make when long-clicked
  • message_single
    • The voice you want to make when single-clicked

Lambda-2

After lambda fucnctions deployed check the ARN of the function.
This will be used later for SORACOM Funk configuration.

SORACOM Funk

SORACOM Funk service can directly call FaaS functions on public cloud.
When connecting to AWS Lambda, you can connect via IAM assume role because the SORACOM system is built on AWS.

make IAM Pollicy and Role

Create an IAM role to call functions with SORACOM Funk.

First, create IAM policy as below.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowAuroraToExampleFunction",
            "Effect": "Allow",
            "Action": "lambda:InvokeFunction",
            "Resource": "arn:aws:lambda:ap-northeast-1:123456789012:function:SORACOMButton-Escape2"
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

Next, create a IAM role using the created IAM policy.
Settings An AWS account is “another AWS account” 950858143650, This is SORACOM Carrier network(Global)’s account.

And, to improve security, I recommend to set an external ID.

IAM Role-5

Setup SORACOM Funk

Finally, Setup the SORACOM Funk in SORACOM user console.
Create credential in security settings.

  • CREDENTIAL SET ID
    • Name of This credential.
  • Type : AWS IAM Role credentials
  • ROLE ARN
    • ARN of the created IAM role
  • EXTERNAL ID
    • Specified when creating the IAM role

Funk-2

Next,Create SIM group.
In this group, Enable SORACOM Funk settings and input as below.

  • SERVICE : AWS Lambda
  • FUNCTION ARN
    • ARN of the created Lambda function.
  • CREDENTIALS
    • Select credentials created above
  • CONTENT TYPE
    • JSON (Default)

Funk-3

Summary

When developing using IoT Buttons, you can call cloud processing such as executing Lambda functions by pressing the button.
I think it’s useful as a way to quickly realize your needs and ideas.

And, Serverless architecture has low running costs.

I feel that development using IoT buttons will expand dreams.
Would you like to develop using IoT buttons too?

Thanks,

Top comments (0)