This post is a continuation of This article (Introduction to IoT 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. ..
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.
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.
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.
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)
Here, we have given this function full rights to Amazon Connect (AmazonConnctFullAccess).
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.
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.
When you check the resource, you will see a screen like the screenshot.
If you click on the test, the phone will actually ring and you will hear the announcement.
↓ 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
After that, you can change the notification URL of the microcomputer board with Arduino IDE.
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.