Sending messages to SQS

Introduction to Amazon Web Services (AWS) IoT Triggering Raspberry Pi with AWS Cloud and ESP32
6 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€64.96
List Price:  €92.81
You save:  €27.84
£55.77
List Price:  £79.68
You save:  £23.90
CA$95.68
List Price:  CA$136.70
You save:  CA$41.01
A$106.02
List Price:  A$151.47
You save:  A$45.44
S$94.41
List Price:  S$134.88
You save:  S$40.47
HK$546.80
List Price:  HK$781.18
You save:  HK$234.37
CHF 63.34
List Price:  CHF 90.49
You save:  CHF 27.15
NOK kr761.11
List Price:  NOK kr1,087.35
You save:  NOK kr326.23
DKK kr485.02
List Price:  DKK kr692.92
You save:  DKK kr207.89
NZ$116.42
List Price:  NZ$166.33
You save:  NZ$49.90
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,660.01
List Price:  ৳10,943.35
You save:  ৳3,283.33
₹5,835.78
List Price:  ₹8,337.18
You save:  ₹2,501.40
RM331.75
List Price:  RM473.95
You save:  RM142.20
₦86,437.65
List Price:  ₦123,487.65
You save:  ₦37,050
₨19,416.31
List Price:  ₨27,738.77
You save:  ₨8,322.46
฿2,572.74
List Price:  ฿3,675.50
You save:  ฿1,102.76
₺2,264.43
List Price:  ₺3,235.04
You save:  ₺970.61
B$356.70
List Price:  B$509.60
You save:  B$152.89
R1,295.44
List Price:  R1,850.72
You save:  R555.27
Лв127.05
List Price:  Лв181.51
You save:  Лв54.46
₩94,909.58
List Price:  ₩135,590.93
You save:  ₩40,681.35
₪259.50
List Price:  ₪370.74
You save:  ₪111.23
₱3,993.87
List Price:  ₱5,705.78
You save:  ₱1,711.90
¥10,712.31
List Price:  ¥15,303.96
You save:  ¥4,591.65
MX$1,187.89
List Price:  MX$1,697.07
You save:  MX$509.17
QR254.57
List Price:  QR363.69
You save:  QR109.12
P950.82
List Price:  P1,358.38
You save:  P407.55
KSh9,247.76
List Price:  KSh13,211.65
You save:  KSh3,963.89
E£3,352.12
List Price:  E£4,788.95
You save:  E£1,436.83
ብር4,006.43
List Price:  ብር5,723.72
You save:  ብር1,717.28
Kz58,511.64
List Price:  Kz83,591.64
You save:  Kz25,080
CLP$65,950.47
List Price:  CLP$94,219
You save:  CLP$28,268.52
CN¥506.53
List Price:  CN¥723.64
You save:  CN¥217.11
RD$4,055.76
List Price:  RD$5,794.19
You save:  RD$1,738.43
DA9,420.16
List Price:  DA13,457.95
You save:  DA4,037.79
FJ$157.70
List Price:  FJ$225.30
You save:  FJ$67.59
Q542.52
List Price:  Q775.06
You save:  Q232.54
GY$14,601.52
List Price:  GY$20,860.22
You save:  GY$6,258.69
ISK kr9,764.23
List Price:  ISK kr13,949.49
You save:  ISK kr4,185.26
DH703.98
List Price:  DH1,005.73
You save:  DH301.75
L1,236.34
List Price:  L1,766.28
You save:  L529.93
ден3,998.59
List Price:  ден5,712.52
You save:  ден1,713.92
MOP$561.77
List Price:  MOP$802.57
You save:  MOP$240.79
N$1,291.99
List Price:  N$1,845.78
You save:  N$553.78
C$2,569.36
List Price:  C$3,670.67
You save:  C$1,101.31
रु9,319.09
List Price:  रु13,313.56
You save:  रु3,994.46
S/260.54
List Price:  S/372.22
You save:  S/111.67
K269.79
List Price:  K385.44
You save:  K115.64
SAR262.50
List Price:  SAR375.02
You save:  SAR112.51
ZK1,882.68
List Price:  ZK2,689.66
You save:  ZK806.98
L323.40
List Price:  L462.03
You save:  L138.62
Kč1,628.77
List Price:  Kč2,326.92
You save:  Kč698.14
Ft25,305.79
List Price:  Ft36,152.68
You save:  Ft10,846.88
SEK kr755.02
List Price:  SEK kr1,078.64
You save:  SEK kr323.62
ARS$61,468.17
List Price:  ARS$87,815.44
You save:  ARS$26,347.26
Bs483.33
List Price:  Bs690.51
You save:  Bs207.17
COP$271,845.87
List Price:  COP$388,367.89
You save:  COP$116,522.02
₡35,672.25
List Price:  ₡50,962.55
You save:  ₡15,290.29
L1,724.16
List Price:  L2,463.20
You save:  L739.03
₲522,510.75
List Price:  ₲746,475.93
You save:  ₲223,965.17
$U2,674.97
List Price:  $U3,821.56
You save:  $U1,146.58
zł281.37
List Price:  zł401.98
You save:  zł120.60
Already have an account? Log In

Transcript

Video 4.2 sending messages to Sq s. In this video, we will learn the following programming lambda, understanding the code testing. In the previous video, we created a lambda function, my sp 32 underscore function and an IoT rule. My ESP 32 underscore lambda underscore rule. Now, we will program the lambda function, open AWS lambda. Here, select my ESP 32 underscore function, we will start writing a Python code here in the lambda function, which will send on and off messages to ask us based on the temperature values. Now, open the repository that you have downloaded at the beginning of this course.

Here, you can find section four selected, then, video 4.2. Now opened up identified with the name code for writing messages. SQL copied entire code. Now go back to the lambda function and select my sp 32 underscore function here, and then scroll down. In function code, you have lambda function here, paste the entire code. This code will sync on and off messages to the sq.

Sq based on the temperature values. Now, let's understand the code. In this first line, we are importing AWS SDK for Python. Next, here, we need to give access key and secret key of the IM user that we have created earlier. Open the Google Sheet that we have downloaded by creating the Iam user ID from this copy and paste access key. Similarly, copy the secret key and paste it here.

Next region for North Virginia it is us hyphen East hyphen, one. You can give the region in which you You are creating your project. Next queue URL on top, select services and search for Sq s, right click and open the link in a new tab. Here, we will create a new queue. For creating a new queue, select Create a new cue here. Now, we need to give the name for our cue, I will give my sp 32 underscore triggering underscore cue, standard cue and then click Create cue.

Yes, we created a new cue for triggering. Now let's copy this queue URL from here and paste it in the lambda function like this. Next, we are declaring a function post underscore message with client message body and URL as arguments. response. This sends a message to the queue with the specified queue URL and message body. Next, we are defining a function with the handle name as lamda underscore handler with event and context as arguments.

Generally, you can give any function name or argument names throughout the course. Okay, let's first see what is lambda underscore handler. While creating a lambda function, we need to specify a handler. This handler will act as a function in the code. The lambda function will act when a service executes the code. This is a general syntax structure for creating a handler function in bitin.

Here, we are configuring Boto, basically for providing the credentials to Boto three, we are passing the credentials as parameters by creating the client. Next, we are declaring an event temperature. Here we are normally storing the temperature values into x. If the temperature is more than 25 degrees, then we'll post a message on to the Sq Sq and if the temperature is less than Then 25 degrees, then we'll post an off message to the Sq sq. On top here, you can find save, selected, scroll up and here near my sp 32 underscore function you can find saved. Cool, we completed the code.

Now, we need to write a Python code on raspberry pi, which will check the queue and then turn often on the LED based on the message in the queue. But before that, we will test if the messages are being sent to this queue sq. Connect ESP 32 and the history 11 sensor to your laptop. Now, open our dyno and then tools serial monitor, you can see that the data is being published to AWS IoT Core. Now, we will go to the IoT Core and then select test here. Then giving the topic name.

Subscribe to the topic. Yes, we can see the data here. increase the temperature slowly. Now, we will go to the Sq Sq that we just created. Select queue actions on the top view or delete messages, start polling for messages. Here you can see the messages based on your temperature values.

Now, disconnect ESP 32 from your PC as your queue will be flooded with messages refresh Sq s, you can see that we have messages. If you are unable to receive any message then go to AWS lambda here on the top you can find monitoring selected. Now, if you have any errors, it will show in the third graph. Previously when I copied the code, I had an indentation error. So it showed me edit line. Now, I have resolved it, but how did I exactly know there?

Scroll down and you can find The recent logs selected. Now you can see that there are no errors in recent logs. So, I will show you my older logs, select logs on the left hand side. Now selecting this. Here, I will select an older log. Here you can see a syntax error selected, it will show you the exact location and reason for there.

This cloud watch logs will help you in resolving any error by using any service for solving this error. I removed all the indentations and gave them correctly again. Now, I will end this video here. In this video, we learned the following programming lambda, understanding the code testing. In the next video, we will program the Raspberry Pi for checking the queue. See you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.