I tried to make the phone ring when it was posted at the IoT post

This post is a continuation of This article (Introduction to IoT post).

Try ringing the phone when it is posted to the IoT smart post

In the previous IoT post, I received an email when it was posted, but here I tried to use the AWS function to make the phone ring.

When a call is detected by using a part of the telephone call center mechanism called "Amazon Connect" via AWS serverless "Lambda", a call is started to the specified phone number and a notification that the post has arrived. Can now be done.

Specifically, as shown in the figure below, we are building a function to start a Python function on "Lambda" from Amazon API Gateway from the microcomputer board, connect to Amazon Connect, and call the specified phone number. .. The advantage of using Amazon Connect is that when the phone rings, the synthetic voice can read the character string on Lambda's Python as it is in Japanese. I haven't seen it this time, but by making the contents of the parameters of ApiGateway dynamic, for example, it will be possible to tell the time of posting by voice, and it will be possible to easily realize dynamic reading aloud. ..

IoTポスト_FaaS経由電話で通知.png (60.6 kB)

The time required was about 2 to 3 hours while checking and taking screenshots from the state where the account was set. If you are used to it, it will take less than 30 minutes.

Amazon Connect settings

I referred to the following blog article

Build a mechanism to make a call with Amazon Connect for $ 4 a month https://dev.classmethod.jp/cloud/aws/amazon-connect-system-alert/#toc-amazon-conenct

First,

Create an Amazon Connect instance https://dev.classmethod.jp/cloud/aws/hello-connect-tokyo-region/#toc-amazon-connect

↑ While watching this, perform from instance of Connect to setting and testing.

88d67739-299f-43ec-8a30-1534c43c7152.png

746a170f-0104-4076-bda1-cade38615b4b.png

If you check the incoming call of the telephony option and get the phone number-link the inquiry flow to the phone number, you can test by calling the obtained phone number. After the test, uncheck the incoming call in the Telephony option settings.

Lambda settings

You can make a call from Lambda via Python. Here, I created a function with the name iotPost_AmazonConnect.

lambda_function.py


import boto3
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)

def lambda_handler(event, context):
    logger.info(event)
    logger.info(context)

    connect = boto3.client('connect', region_name='ap-northeast-1')
 
    message = 'Notification from IoT Smart Post. Posting has been detected. Please take out the mailed item and check it. Thank you for using.'
    logger.info(message)

    response = connect.start_outbound_voice_contact(
        DestinationPhoneNumber='+810000004717',
        ContactFlowId='edf8xxxx-xxxx-xxxx-xxxx-xxxxxxxx16f4',
        InstanceId='e82dxxxx-xxxx-xxxx-xxxx-xxxxxxxx6cf3',
        SourcePhoneNumber='+815000000000',
        Attributes={
            'message': message
        }
    )
    logger.info(response)

b14efede-1f92-4038-83ca-9146de809456.png

Also set the role of the Lambda function.

Here, we have given this function full rights to Amazon Connect (AmazonConnctFullAccess). 0d9215b2-a22e-450f-9cf6-bf47cebd1db3.png

Sound or test 1

If you press the test button here and start it with an appropriate json, the phone will ring and the character string specified in lambda_function.py will be read aloud in Japanese.

電話呼び出しイメージ

API Gateway settings

As shown in the figure below in the previous article, it is usually an image of one as a notification destination from AWS SNS. 一般的な位置づけ

This time, we will call a Lambda function from API Gateway. I took a screenshot here with the POST method setup, but I actually set it up with the GET method. 56f3c482-1a9f-4949-b8b4-4a7d561378cb.png

When you check the resource, you will see a screen like the screenshot.

Sound or test 2

If you click on the test, the phone will actually ring and you will hear the announcement. 1a3bbdda-f8bb-44b8-bf51-c91a7b4ca749.png

Sound or test 3

↓ After completing the API Gateway settings, you will get a URL like this, so when you actually access it with the GET method, the phone will ring and you will be notified that it has been posted. https://????????????.execute-api.ap-northeast-1.amazonaws.com/public a6714a54-ee6e-44f8-b156-2df363e6f399.png

Change the notification destination URL on the microcomputer board

After that, you can change the notification URL of the microcomputer board with Arduino IDE.

The problem with the root certificate is ...

Since the ESP8266 side (WiFiClientSecure.h on Scketch) used this time does not include the server certificate (root certificate) for SSL of AWS, it is not possible to communicate directly with ApiGateway by SSL, and http (non-SSL) ) Needed to be transferred via another server or CloudFront. If the microcomputer board that is actually shipped requires encrypted communication such as SSL, you have to be careful about the issuer and expiration date of this root certificate.

That's all for DEMO.

Recommended Posts

I tried to make the phone ring when it was posted at the IoT post
When I tried to change the root password with ansible, I couldn't access it.
When I tried to make a VPC with AWS CDK but couldn't make it
In IPython, when I tried to see the value, it was a generator, so I came up with it when I was frustrated.
When I tried to do socket communication with Raspberry Pi, the protocol was different
What I did when I was angry to put it in with the enable-shared option
I tried to make it easy to change the setting of authenticated Proxy on Jupyter
When I try to make Apache SSL, it doesn't start.
I tried to automatically post to ChatWork at the time of deployment with fabric and ChatWork Api
When I tried to install PIL and matplotlib in a virtualenv environment, I was addicted to it.
When I tried the AtCoder Beginner Contest, it was a terrible result, so I look back
When I tried to install Ubuntu 18.04, "Initramfs unpacking failed: Decoding failed" was displayed and the startup failed.
I tried to make a site that makes it easy to see the update information of Azure
The record I was addicted to when putting MeCab on Heroku
I tried to make it possible to automatically send an email just by double-clicking the [Python] icon
A memorandum when I tried to get it automatically with selenium
I looked at the meta information of BigQuery & tried using it
I tried to register a station on the IoT platform "Rimotte"
I tried to make a 2channel post notification application with Python
The story that the guard was confined when the laboratory was converted to IoT
I tried to make a script that traces the tweets of a specific user on Twitter and saves the posted image at once
I tried to move the ball
I tried to estimate the interval.
[Python] When I tried to make a decompression tool with a zip file I just knew, I was addicted to sys.exit ()
I tried to make a system to automatically acquire the program guide → register it in the calendar in one day
I tried to make it possible to automatically send an email just by double-clicking the [GAS / Python] icon
zoom I tried to quantify the degree of excitement of the story at the meeting
I tried to make a calculator with Tkinter so I will write it
Matching karaoke keys ~ I tried to put it on Laravel ~ <on the way>
[Zaif] I tried to make it easy to trade virtual currencies with Python
I refactored "I tried to make Othello AI when programming beginners studied python"
Gorilla judgment machine, gorilla! !! Tried to make it!
I tried to recognize the wake word
I tried to summarize the graphical modeling.
I tried to estimate the pi stochastically
I tried to touch the COTOHA API
I tried to make a Web API
I refactored "I tried to make a script that saves posted images at once by going back to the tweets of a specific user on Twitter".
The tree.plot_tree of scikit-learn was very easy and convenient, so I tried to summarize how to use it easily.
When I investigated whether the COTOHA API could understand comics, it was reasonable.
Somehow the code I wrote worked and I was impressed, so I will post it
P100-PCIE-16GB was added to the GPU of Google Colab before I knew it
When I tried to create a virtual environment with Python, it didn't work
I want to make a music player and file music at the same time
I tried to use Resultoon on Mac + AVT-C875, but I was frustrated on the way.
I tried to verify the Big Bang theorem [Is it about to come back?]
I tried to rescue the data of the laptop by booting it on Ubuntu
I didn't understand the Resize of TensorFlow so I tried to summarize it visually.
I tried my best to make an optimization function, but it didn't work.
I referred to it when I got stuck in the django geodjango tutorial (editing)
I set up TensowFlow and was addicted to it, so make a note
I tried to optimize while drying the laundry
[Introduction to json] No, I was addicted to it. .. .. ♬
I tried to save the data with discord
I tried to make OneHotEncoder, which is often used for data analysis, so that it can reach the itch.
I tried using PyCaret at the fastest speed
I tried to touch the API of ebay
I tried to correct the keystone of the image
I tried to make AI for Smash Bros.
Qiita Job I tried to analyze the job offer
LeetCode I tried to summarize the simple ones