Show last authors
1 **~ Contents:**
2
3 {{toc/}}
4
5
6 = **1. Introduction** =
7
8
9 //The Dragino LoRaWAN gateway can communicate with [[Amazon>>url:https://portal.aws.amazon.com/]] LoRaWAN Network Server~://
10
11
12 **//Below list of the support products and Requirements~://**
13
14 1. //LoRaWAN Gateway model: [[LIG16>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/171-lig16.html]], [[LG308>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/140-lg308.html]], [[DLOS8>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/160-dlos8.html]] [[LPS8>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/148-lps8.html]]//
15 1. //Firmware version since:[[lgw~~-~~-build-v5.4.1614945073>>url:http://www.dragino.com/downloads/index.php?dir=LoRa_Gateway/LIG16/Firmware/Release/lgw--build-v5.4.1614945073-20210305-1953/]]//
16
17 **//What you'll learn in this tutorial//**
18
19
20 //1. How to register a gateway with AWS//
21
22 //2. How to register an end node with AWS//
23
24 //3. How to accept payload date with AWS//
25
26
27 = **2. Gateway Setup Instruction** =
28
29
30 == **2.1 sign up for [[an AWS >>url:https://portal.aws.amazon.com/]]account and select the area** ==
31
32
33 //Sign up for an AWS account//
34
35 [[image:image-20220524141920-1.png]]
36
37
38 //Select area//
39
40 [[image:image-20220524142008-2.png]]
41
42
43 //**Note:** Currently, AWS IoT Core for LoRaWAN is available today in US East (N. Virginia) and Europe (Ireland) Regions. if you are not in either of these areas, their options will not affect your usage.//
44
45
46 == 2.2 Step 2: [[Add an IAM role>>url:https://console.aws.amazon.com/iam/home#/roles]] ==
47
48
49 **//To add the IAM role to allow the Configuration and Update Server (CUPS) to manage gateway credentials:、//**
50
51 //**1.** Open the Roles hub of the IAM console and choose Create role.//
52
53 //**2.** If you think that you might have already added the IoTWirelessGatewayCertManagerRole role, in the search bar, enter IoTWirelessGatewayCertManagerRole.//
54
55 //If you see an IoTWirelessGatewayCertManagerRole role in the search results, you have the necessary IAM role. You can leave the procedure now.//
56
57 //If the search results are empty, you don't have the necessary IAM role. Continue the procedure to add it.//
58
59 //**3. **In Select type of trusted entity, choose Another AWS account.//
60
61 //**4.** In Account ID, enter your AWS account ID and then choose Next: Permissions.//
62
63 //**5.** In the search box, enter AWSIoTWirelessGatewayCertManager.//
64
65 //**6.** In the list of search results, select the policy named AWSIoTWirelessGatewayCertManager.//
66
67 //**7.** Choose Next: Tags, and then choose Next: Review.//
68
69 //**8.** In Role name, enter IoTWirelessGatewayCertManagerRole, and then choose to Create role.//
70
71 //**9.** To edit the new role, in the confirmation message, choose IoTWirelessGatewayCertManagerRole.//
72
73 //**10.** In Summary, choose the Trust relationships tab and then choose Edit trust relationship.//
74
75 //**11.** In the Policy Document, change the Principal property to look like this example.//
76
77
78 (% class="box" %)
79 (((
80 "Principal": {
81 "Service": "iotwireless.amazonaws.com"
82 },
83 )))
84
85 (% class="box" %)
86 (((
87 After you change the Principal property, the complete policy document should look like this example.
88 )))
89
90 (% class="box" %)
91 (((
92 {
93 "Version": "2012-10-17",
94 "Statement": [
95 {
96 "Effect": "Allow",
97 "Principal": {
98 "Service": "iotwireless.amazonaws.com"
99 },
100 "Action": "sts:AssumeRole",
101 "Condition": {}
102 }
103 ]
104 }
105
106
107 )))
108
109
110 **12.** To save your changes and exit, choose Update Trust Policy. Note: You’ve now created the IoTWirelessGatewayCertManagerRole. You won’t need to do this again.
111
112 [[image:image-20220525172556-1.png]]
113
114 tart create role
115
116 [[image:image-20220525172629-2.png]]
117
118 Choose Another AWS account
119
120 [[image:image-20220525172718-3.png]]
121
122
123 start Create policy
124
125 [[image:image-20220525172756-4.png]]
126
127
128 Choose Next review
129
130
131 [[image:image-20220525173033-7.png]]
132
133 In role name,enter AWSIoTWirelessGatewayCertManagerRole,and then choose Create role.
134
135 [[image:image-20220525172948-6.png]]
136
137
138 To edit the_new role
139
140 [[image:image-20220525173155-8.png]]
141
142
143 Choose Edit trust relationship.
144
145 [[image:image-20220525173226-9.png]]
146
147
148 Change policy Document
149
150
151 == 2.3 Step 3: Add gateway ==
152
153
154 Locate IoT Core in the AWS Service Control Panel, and locate the Wireless Connection in the IoT Core Control Panel to start adding the Gateway
155
156 [[image:image-20220525173308-10.png]]
157
158 Locate IoT Core in the AWS Service Control Panel
159
160 [[image:image-20220525173340-11.png]]
161
162 locate the Wireless Connection in the IoT Core Control Panel
163
164
165 == 2.4 Step 4: Get a unique Gateway ID in the gateway ==
166
167
168 Every gateway has a Gateway ID, the ID can be found at Amazon AWS IoT.
169
170 [[image:image-20220525173425-12.png]]
171
172 Gateway ID
173
174
175 **Note**:User must use the Gateway ID of the Amazon AWS IoT page as the EUI
176
177 **Notice**: In latest firmware. the AWS-IoT configured page is under LoRaWAN Basic Station page.
178
179
180 [[image:image-20220525173456-13.png]]
181
182 LoRaWAN Basic Station
183
184
185 == 2.5 Step 5: Configure the gateway and Creation gateway certificates ==
186
187 Configure the gateway and Creation gateway certificates
188
189 [[image:image-20220525173537-14.png]]
190
191 Configure the gateway
192
193 [[image:image-20220525173615-15.png]]
194
195 Creation gateway certificates
196
197 **Note: **User Make sure the name of the downloaded file remains the same
198
199 == 2.6 Step 6: Add gateway file ==
200
201 user returns to your gateway, and start adding the three file they got to the gateway.
202
203 [[image:image-20220525173647-16.png]]
204
205 Configure the gateway
206
207 if the user Upload successfully you will see:
208
209 [[image:image-20220525173710-17.png]]
210
211 Uploaded successfully
212
213 (% style="color:red" %)**Notice: **(% style="color:black" %)User must select the correct Upload on the suffix name, otherwise the upload fails.
214
215 == 2.7 Step 7: Add CUPS URI ==
216
217 Users enter the CUPS endpoint copied in the previous step into the CUPS URI and click **"Save&Apply"**
218
219 [[image:image-20220525173735-18.png]]
220
221 CUPS URI
222
223 [[image:image-20220525173759-19.png]]
224
225 CUPS URI Setting
226
227 **Notice:** After the user hits "Save&Apply", the gateway will start Station mode on its own
228
229 == 2.8 Step 8:Last upLink received ==
230
231 After the above settings, the gateway should be able to connect, the figure below shows the data of the Last upLink received
232
233 [[image:image-20220525174247-20.png]]
234
235 UpLink received
236
237 = 3. Add wireless device =
238
239 == 3.1 step 1:Add device profile ==
240
241 === 3.1.1 CREATE DEVICE PROFILE ===
242
243 select profile in the Control Panel and add configuration adn service files.the device's configuration paranmeters depend on the LoRaWAN specification it uses.The configuration parameters are found in the device's documentation or on the device itself.
244
245 [[image:image-20220525174325-21.png]]
246
247 Add device profile
248
249 **Provide device data**
250
251 (% class="box" %)
252 (((
253 **Device profile name** : a descriptive name of your choice for this profile, e.g. “Workshop device profile of ”
254 **Frequency band (RFRegion)**  : please select a frequency band your device and gateway will be using. For most European countries EU868 is a right choice. For USA US915 is a right choice. If in doubt, you can review a regional parameters document, section “1.2 Quick cross reference table”.
255 **MAC version** : this parameter should specify the most recent version of LoRaWAN specification supported by your device. Unless device documentation states otherwise, please select 1.0.3.
256 **Regional parameters version**: please select RP002-1.0.1, unless specified otherwise in your device documentation
257 **MaxEIRP** : please enter the default value 15
258 **Supports class **: please select class A, unless you are aware of specific requirements to use classes B and C and your device supports it
259 )))
260
261 [[image:image-20220525174354-22.png]]
262
263 device profile
264
265 **Notice** **: **See the documentation for more information: [[https:~~/~~/docs.aws.amazon.com/iot/latest/developerguide/connect-iot-lorawan-define-profiles.html>>url:https://docs.aws.amazon.com/iot/latest/developerguide/connect-iot-lorawan-define-profiles.html]]
266
267
268 === 3.1.2 CREATE SERVICE PROFILE ===
269
270 Select “Profiles” view and click on “Add service profile”
271
272 [[image:image-20220525174516-23.png]]
273
274 Add a service profile
275
276 (% class="box" %)
277 (((
278 Choose a service profile name (e.g. “Default service profile”)
279 Ensure that AddGWMetaData parameter is enabled. By enabling this parameter you will receive additional metadata with each device payload, for example RSSI and SNR for the data transmission.
280 This metadata could be used for network coverage optimization.
281 Finally, scroll down and click on “Add service profile”.
282 )))
283
284 [[image:image-20220525174610-24.png]]
285
286 Add service profile2
287
288
289 == 3.2 Step 2:Create an IAM roles for destinations ==
290
291 AWS IoT Core for LoRaWAN destinations require IAM roles that give AWS IoT Core for LoRaWAN the permissions necessary to send data to the AWS IoT rule. If such a role is not already defined, you'll need to define it so that it will appear in the list of roles.
292
293 **To create an IAM policy for your AWS IoT Core for LoRaWAN destination role**
294
295 **1.** Open the Policies hub of the IAM console.
296
297 **2. **Choose Create policy, and choose the JSON tab.
298
299 **3. **In the editor, delete any content from the editor and paste this policy document.
300
301 (% class="box" %)
302 (((
303 {
304 "Version": "2012-10-17",
305 "Statement": [
306 {
307 "Effect": "Allow",
308 "Action": [
309 "iot:DescribeEndpoint",
310 "iot:Publish"
311 ],
312 "Resource": "*"
313 }
314 ]
315 }
316 )))
317
318 **4.** Choose Review policy, and in Name, enter a name for this policy. You'll need this name to use in the next procedure. You can also describe this policy in Description, if you want.
319
320 **5.** Choose Create policy.
321
322 **To create an IAM role for an AWS IoT Core for LoRaWAN destination:**
323
324 **1.** Open the Roles hub of the IAM console and choose Create role.
325
326 **2.** In Select type of trusted entity, choose Another AWS account.
327
328 **3. **In Account ID, enter your AWS account ID, and then choose Next: Permissions.
329
330 **4.** In the search box, enter the name of the IAM policy that you created in the previous procedure.
331
332 **5.** In the search results, check the IAM policy that you created in the previous procedure.
333
334 **6.** Choose Next: Tags, and then choose Next: Review.
335
336 **7. **In Role name, enter the name of this role, and then choose Create role.
337
338 **8.** In the confirmation message, choose the name of the role you created to edit the new role.
339
340 **9. **In Summary, choose the Trust relationships tab, and then choose Edit trust relationship.
341
342 **10.** In Policy Document, change the Principal property to look like this example.
343
344 (% class="box" %)
345 (((
346 "Principal": {
347 "Service": "iotwireless.amazonaws.com"
348 },
349 )))
350
351 After you change the Principal property, the complete policy document should look like this example.
352
353 (% class="box" %)
354 (((
355 {
356 "Version": "2012-10-17",
357 "Statement": [
358 {
359 "Effect": "Allow",
360 "Principal": {
361 "Service": "iotwireless.amazonaws.com"
362 },
363 "Action": "sts:AssumeRole",
364 "Condition": {}
365 }
366 ]
367 }
368 )))
369
370 **~11. **To save your changes and exit, choose Update Trust Policy.
371
372 With this role defined, you can find it in the list of roles when you configure your AWS IoT Core for LoRaWAN destinations.
373
374 === 3.2.1 CREATE DESTINATION ===
375
376 **Select Destinations view**
377
378 Please click on “Destinations” menu and afterwards please click on “Add destination”.
379
380 [[image:image-20220525174704-25.png]]
381
382 Select destinations
383
384 **Provide input**
385
386 Please provide the following input:
387
388 (% class="box" %)
389 (((
390 Please choose an IAM role that shall be used for the invocation of AWS IoT Rule.
391 Please select the destination name (e.g. “WorkshopDestination<Your name without spaces>”)
392 Please select the AWS IoT Rule name (e.g. “MyWorkshopLoRaWANRule<Your name without spaces>”)
393 )))
394
395 click on “Add destination”
396
397 [[image:image-20220524144452-17.png]]
398
399 provide input
400
401 === 3.2.2 CREATE IOT RULE ===
402
403 **Create Rule**
404
405 user navigating to AWS IoT , Act, Rules and clicking on “Create” button.
406
407 [[image:image-20220524144530-18.png]]
408
409 Rule create
410
411 //Provide a rule name'//
412
413 (((
414 Please input the same IoT Rule name you used in a previous step when creating a new AWS IoT Core for the LoRaWAN destination (e.g. “test_example”).
415 )))
416
417 [[image:image-20220524201202-2.png||height="351" width="611"]]
418
419 Enter Rule name
420
421 **Provide IoT SQL query statement**
422
423 Please put the following text into the rule query statement: **SELECT *, timestamp() as timestamp**
424
425 [[image:image-20220524201532-4.png||height="387" width="615"]]
426
427
428 Enter SQL query statement
429
430 **Select action “Republish to an AWS IoT Topic”**
431
432 [[image:image-20220524203543-8.png||height="637" width="601"]]
433
434
435 == 3.3 Step 3: Create a destination for end node payloadDate ==
436
437 The PayloadDate of the node will be sent to this destination
438
439 **a.** In the [[destinatons>>url:https://console.aws.amazon.com/iot/home?region=us-east-1#/wireless/destinations]],choose add destination.
440
441 **b.** In IMA Role, select the Role you created in the last step
442
443 **c.** In Destination name, give this destination a destination name.
444
445 **d.** In Rule name, give this rule a new name and remember it.
446
447 **e.** choose Add Destination.
448
449 [[image:image-20220524204934-9.png||height="663" width="627"]]
450
451 Add destination
452
453 **Note:**The destination rule configuration sent by the end node payloadDate will be in the next step
454
455 == 3.4 Step 4: CREATE WIRELESS DEVICE ==
456
457 Users can register end nodes with AWS
458
459 === 3.4.1 Open Add wireless device ===
460
461 (% class="box" %)
462 (((
463 (((
464 **a.** In Device,choose Add wireless device.
465 **b.** In Wireless device specification,select OTTA 1.0.x
466 **c. **In OTTA 1.0.x
467 **d.** In Profiles,select profilees,and choose Next
468 )))
469 )))
470
471 [[image:image-20220524144949-25.png]]
472
473 Add device
474
475 [[image:image-20220524145008-26.png]]
476
477 Enter device keys
478
479 **Select device and service profile**
480
481 (((
482 Scroll down and endure that “Associate a thing with your wireless device” option is enabled. AWS will create a thing in AWS IoT for you and associate it with this device. Things in AWS IoT can make it easier to search for and manage your devices.
483 )))
484
485 [[image:image-20220524145033-27.png]]
486
487 Seleck profile
488
489 === 3.4.2 Select a destination ===
490
491 **Plese select a destination you have created in one of the previous steps and choose add device**
492
493 [[image:image-20220524145113-28.png]]
494
495 Add device_choose destition
496
497
498 **REVIEW THE CREATED DEVICER**
499
500 [[image:image-20220524145149-29.png]]
501
502 Uplink Received
503
504
505 **VERIFY DEVICE CONNECTIVITY**
506
507 [[image:image-20220524145239-30.png]]
508
509 Verify device connectivity
510
511 === 3.4.3 Verify date ingestion ===
512
513 **Open MQTT Test Client**
514
515 [[image:image-20220524145328-31.png]]
516
517 Open MQTT Client
518
519
520 **Subscribe to topic**
521
522 (((
523 Please input the topic name **workshop_lorawanmessages** in “Subscription topic” field and click on “Subscribe to topic”.
524
525 Users can choose to subscribe to "**#**" ,"#" indicates to subscribe to all.
526 )))
527
528 [[image:image-20220524145404-32.png]]
529
530 Subscription Topic
531
532 **Trigger your device to send telemetry**
533
534 User can start the registered device
535
536 **Review the incoming message from uesr's device**
537
538 Please find below an explanation for some of the attributes:
539
540 (% class="box" %)
541 (((
542 **PayloadData ** : Base64-encoded payload from the device
543 **~ WirelessMetadata.FPort**           : FPort used by the device
544 **~ WirelessMetadata.LoRaWAN.DevEui**  : EUI of the device sending the data
545 **~ WirelessMetadata.LoRaWAN.Gateways**: Information on RSSI and SNR per gateway
546 )))
547
548 [[image:image-20220524145507-33.png]]
549
550 Review message
551
552 (% class="box" %)
553 (((
554 {
555 "WirelessDeviceId": "3ff07678-0c3d-4ed7-a01a-4e2cc927e315",
556 "PayloadData": "AAAAAAAAAAAPo2I=",
557 "WirelessMetadata": {
558 "LoRaWAN": {
559 "DataRate": "5",
560 "DevEui": "a840410801818749",
561 "FCnt": 579,
562 "FPort": 2,
563 "Frequency": "867500000",
564 "Gateways": [
565 {
566 "GatewayEui": "a84041ffff1ec39f",
567 "Rssi": -79,
568 "Snr": 7.25
569 },
570 {
571 "GatewayEui": "a84041ffff1ee2a0",
572 "Rssi": -129,
573 "Snr": -4
574 }
575 ],
576 "Timestamp": "2021-04-10T08:16:06Z"
577 }
578 },
579 "timestamp": 1618042566345
580 }
581 )))
582
583 **How to decode Base64 data into hexadecimal representation**
584
585 You can run the following command in your shell to decode Base64 payload data into their hexadecimal representation.
586
587 MacOS
588
589 (% class="box" %)
590 (((
591 $  echo -n "<Value of PayloadData>" | base64 -D | hexdump -v -e '/1 "%02x"'
592 )))
593
594 Linux
595
596 (% class="box" %)
597 (((
598 $  echo -n "<Value of PayloadData>" | base64 -d | hexdump -v -e '/1 "%02x"'
599 )))
600
601 Example
602
603 (% class="box" %)
604 (((
605 $  echo -n "7WkoOEfwfTTioxG6CatHBw==" | base64 -D | hexdump -v -e '/1 "%02x"'
606 ed69283847f07d34e2a311ba09ab4707
607 )))
608
609 = 4. Format a notification by using an AWS Lambda function =
610
611 == 4.1 Introduction ==
612
613 This tutorial demonstrates how to send MQTT message data to an AWS Lambda action for formatting and sending to another AWS service. In this tutorial, the AWS Lambda action uses the AWS SDK to send the formatted message to the Amazon SNS topic
614
615 === 4.1.1 What you'll learn in this tutorial ===
616
617 How to create and test an AWS Lambda function
618
619 How to use the AWS SDK in an AWS Lambda function to publish an Amazon SNS notification
620
621 How to use simple SQL queries and functions in a rule query statement
622
623 How to use the MQTT client to test an AWS IoT rule
624
625 === 4.1.2 In this tutorial, you'll: ===
626
627 (((
628 Create an AWS Lambda function that sends a text message
629 )))
630
631 (((
632 Create an AWS IoT rule with an AWS Lambda rule action
633 )))
634
635 (((
636 Test the AWS IoT rule and AWS Lambda rule action
637 )))
638
639 == 4.2 Approach A: DECODING BINARY PAYLOADS ==
640
641 === 4.2.1 Step 1 :Start deployment of a severless application with AWS Lambda function and AWS ioT Rule ===
642
643 **1:Open AWS Lambda console by clicking on [[link>>url:https://console.aws.amazon.com/lambda/home?region=us-east-1#/create/app?applicationId=arn:aws:serverlessrepo:us-east-1:614797420359:applications/aws-iot-corelorawan-sampledecoder]]**
644
645 [[image:image-20220524145607-34.png]]
646
647 Deployment Lambda
648
649
650 **2:Select a decoder**
651
652 (((
653 Please scroll down to the bottom of the page. Please provide the parameter decoder name based on the following table.
654 )))
655
656 Device Decoder name
657
658 LHT65 dragino_lht65
659
660 LBT1 dragino_lbt1
661
662 LSE01 dragino_lse01
663
664 LGT92 dragino_lgt92
665
666 LDS01 dragino_lds01
667
668 After that please check the box **“I acknowledge that this app creates resource policies.”** and click on **“Deploy”**.
669
670 [[image:image-20220525093033-1.png||height="292" width="615"]]
671
672 Seleck a decoder name
673
674
675 **3:Review deployment**
676
677 (((
678 Please wait few seconds for a successful deployment. After that please click on the name of the Lambda function “TransformLoRaWANBinaryPayloadFunction”.
679 )))
680
681 [[image:image-20220524145715-36.png]]
682
683 Review deployment
684
685
686 **4. Create the test event**
687
688 Please click on “Configure the test event”
689
690 [[image:image-20220524145752-37.png]]
691
692 Create the test event
693
694 (((
695 In the window that opens, please provide the event name e.g. IoTCoreForLoRaWANEvent. After that please paste the following JSON content:
696 )))
697
698 (% class="box" %)
699 (((
700 {
701 "PayloadData": "<Sample PayloadData>",
702 "WirelessDeviceId": "57728ff8-5d1d-4130-9de2-f004d8722bc2",
703 "WirelessMetadata": {
704 "LoRaWAN": {
705 "DataRate": 0,
706 "DevEui": "a84041d55182720b",
707 "FPort": 2,
708 "Frequency": 867900000,
709 "Gateways": [
710 {
711 "GatewayEui": "dca632fffe45b3c0",
712 "Rssi": -76,
713 "Snr": 9.75
714 }
715 ],
716 "Timestamp": "2020-12-07T14:41:48Z"
717 }
718 }
719 }
720 )))
721
722 [[image:image-20220524145826-38.png]]
723
724 Create a new event
725
726
727 **5. Provide PayloadData sample**
728
729 (((
730 Please replace the string <Sample PayloadData> in the JSON document with a sample payload for the device you selected in step 2 according to this table. After that please click on “Create”.
731 )))
732
733 (% class="box" %)
734 (((
735 (((
736 Device name          Sample “PayloadData”
737 )))
738
739 (((
740 LHT65  ~-~-  y6QHxgG4AQhmf/8=
741 )))
742
743 (((
744 LSE01         ~-~-     AuHtlACmawQPVGM=
745 LGT92         ~-~-     DSEAAAEVCMUGpAA=
746 LBT1  ~-~-     DxwAAAIDQUJCQ0NEREVFRkYwMjcxMjFGNkFDMy0wNTk=
747 )))
748 )))
749
750 ~[~[File:replace <Sample PayloadDate>.png|600px|none|thumb|replace <Sample PayloadDate>]]
751
752 **6.Edit project Files**
753
754 The project file needs to be modified when the user needs to test or add a new decoder, feel invited to switch to the “Code” section of the AWS Lambda function and inspect the Python source code. You will find the decoders for the individual devices in the directory decoders. The AWS Lambda function handler is in file **app.py**
755
756 Users can find the required decoder in this **[[link>>url:https://github.com/aws-samples/aws-iot-core-lorawan/tree/main/transform_binary_payload]], **then added to the project.
757
758 How to modify see the figure below:
759
760 (% class="box" %)
761 (((
762 1) Add a decoder in app.py  ~-~-->  For example, add code: import dragino_lht52
763
764 2) Add the decoder name to "VALID_PAYLOAD_DECODER_NAMES"  ~-~-->  add dragino_lht52
765
766 3) Add the statement  ~-~-->  DECODER_NAME = "dragino_lht52"
767
768 **(The user can input the decoding project that needs to be tested)**
769
770 4)Comment out "DECODER_NAME = os.environ.get("DECODER_NAME")"
771
772 **(Comment out it in order to use other project files)**
773 )))
774
775 [[image:image-20220525094832-3.png||height="276" width="627"]]
776
777 After the user finishes editing, Click on the **"Deploy"**
778
779 **7. Run a test**
780
781 Please click on **“Test”**.
782
783 [[image:image-20220524145910-39.png]]
784
785 **8. Check whether the decoding succeeds **
786
787 The following example is the successful decoding of LHT52,
788
789 [[image:image-20220525100532-4.png||height="488" width="612"]]
790
791 **7. Note the AWS Lamdbda function ARN**
792
793 (((
794 As a preparation for the next step, please note the ARN of the deployed AWS Lambda function. We will need this ARN later to review the created AWS IoT Rule.
795 )))
796
797 [[image:image-20220524150010-40.png]]
798
799 === 4.2.2 Step 2:Update the Destination rule and get the device's payload ===
800
801 In this step, you update the IoT rule that forwards the device payload to your application. This rule is associated with the destination created earlier in Set up a Destination for device traffic.
802
803 (((
804 ~1. Find the IoT Rule
805
806 2. Create a Destination with IoT Rule (MyWorkshopLoRaWANRuleWithDecoder_dragino_lht65)
807
808 3. Update the destination to the device
809
810 4. Check the payload
811
812 5. Approach A with MQTT
813
814 6. Approach B with Lambda
815 )))
816
817 ==== 4.2.2.1 1. Find the IoT Rule MyWorkshopLoRaWANRuleWithDecoder_… ====
818
819 Please put the IoT Rule name prefix **MyWorkshopLoRaWANRuleWithDecoder_** into the search field and click on the search symbol. The rule named **MyWorkshopLoRaWANRuleWithDecoder_<Decoder name>** should appear:
820
821 [[image:image-20220524150134-42.png]]
822
823 Find the IoT rule
824
825 ==== 4.2.2.2 2. Create a Destination with IoT Rule ====
826
827 (MyWorkshopLoRaWANRuleWithDecoder_dragino_lht65)
828
829 [[image:image-20220524150209-43.png]]
830
831 Create a Destnation
832
833 ==== 4.2.2.3 3. Update the destination to the device ====
834
835 [[image:image-20220524150412-44.png]]
836
837 Update the destination to the device
838
839 ==== 4.2.2.4 4.Check the payload ====
840
841 **Approach A with MQTT**
842
843 click the rule
844
845 [[image:image-20220524150459-45.png]]
846
847 click the rule
848
849 Copy the Topic name
850
851 [[image:image-20220524150604-46.png]]
852
853 copy the rule name
854
855 Open MQTT client and subscrlibe Topic
856
857 [[image:image-20220524150650-47.png]]
858
859 Open MQTT client and subscrlibe Topic
860
861 Get the payload
862
863 [[image:image-20220524150737-48.png]]
864
865 Get the payload
866
867 **Approach B with Lamdbda**
868
869 open lamdbda console and click the application
870
871 [[image:image-20220524150822-49.png]]
872
873 open lamdbda console and click the application
874
875 [[image:image-20220524150915-50.png]]
876
877 open lamdbda console and click the application
878
879 View logs in CloudWatch
880
881 [[image:image-20220524151006-51.png]]
882
883 View logs in CloudWatch
884
885 [[image:image-20220524151040-52.png]]
886
887 View logs in CloudWatch
888
889 == 4.3 Approach B Create an AWS Lambda function that sends a text message ==
890
891 The AWS Lambda function in this tutorial receives the result of the rule query statement, inserts the elements into a text string, and sends the resulting string to Amazon SNS as the message in a notification.
892
893 === 4.3.1 Step.1: To create an AWS Lambda function that sends a text message ===
894
895 ==== 4.3.1.1 1.Create a new AWS Lambda function. ====
896
897 **a.** In the [[AWS Lambda console>>url:https://console.aws.amazon.com/lambda/home]], choose Create function.
898
899 [[image:image-20220524151158-53.png]]
900
901 Create function
902
903 (((
904 **b.** In Create function, select Use a blueprint. Search for and select the hello-world-python blueprint, and then choose **Configure**.
905 )))
906
907 [[image:image-20220524151409-54.png]]
908
909 blueprint
910
911 **c. **In Basic information:
912
913 (% class="box" %)
914 (((
915 1). In Function name, enter the name of this function, format-high-temp-notification.
916 2). In Execution role, choose Create a new role from AWS policy templates.
917 3). In Role name, enter the name of the new role, format-high-temp-notification-role.
918 4). In Policy templates - optional, search for and select Amazon SNS publish policy.
919 5). Choose Create function.
920 )))
921
922 [[image:image-20220524151459-55.png]]
923
924 blueprint
925
926
927 ==== 4.3.1.2 2.Modify the blueprint code to format and send an Amazon SNS notification. ====
928
929 (((
930 **a.** After you created your function, you should see the format-high-temp-notification details page. If you don't, open it from the Lambda Functions page.
931 )))
932
933 (((
934 **b.** In the format-high-temp-notification details page, choose the Configuration tab and scroll to the Function code panel.
935 )))
936
937 (((
938 **c. **In the Function code window, in the Environment pane, choose the Python file, lambda_function.py.
939 )))
940
941 (((
942 **d.** In the Function code window, delete all of the original program code from the blueprint and replace it with this code.
943 )))
944
945 (% class="box" %)
946 (((
947 from ~_~_future~_~_ import print_function
948 import json
949 import boto3
950 print('Loading function')
951 def lambda_handler(event, context):
952 # Parse the JSON message
953 eventText = json.dumps(event)
954 # Print the parsed JSON message to the console. You can view this text in the Monitoring tab in the AWS Lambda console or in the Amazon CloudWatch Logs console.
955 print('Received event: ', eventText)
956 # Create an SNS client
957 sns = boto3.client('sns')
958 # Publish a message to the specified topic
959 response = sns.publish (
960 TopicArn = 'arn:aws:iam::123456789012:My_IoT_SNS_Topic',
961 Message = eventText
962 )
963 print(response)
964 )))
965
966 **e.** Choose Deploy.
967
968 **Note: **Replace the value of **TopicArn** with the ARN of the Amazon SNS topic that you created SNS topic in which [[SNS>>url:https://console.aws.amazon.com/sns/home?region=us-east-1]]
969
970 **Note: **If you don't have SNS topic it does't affect the use of Lambda.About how to Create SNS topic will be show next chapter
971
972
973 ==== 4.3.1.3 3.In a new window, look up the Amazon Resource Name (ARN) of your Amazon SNS topic from the tutorial about how to Send an Amazon SNS notification. ====
974
975 (((
976 **a. **In a new window, open the Topics page of the Amazon SNS console
977 )))
978
979 (((
980 **b.** In the Topics page, find the high_temp_notice notification topic in the list of Amazon SNS topics.
981 )))
982
983 (((
984 **c.** Find the ARN of the high_temp_notice notification topic to use in the next step.
985
986
987 )))
988
989 ==== 4.3.1.4 4.Create a test case for your Lambda function. ====
990
991 **a.** In the Lambda Functionspage of the console,from **Select a test event**to select Configure test events
992
993 [[image:image-20220524151730-56.png]]
994
995 Configure test events
996
997
998 (((
999 **b. **On Configure test event, enter a name for your test event and replace the message JSON with the following:
1000 )))
1001
1002 (% class="box" %)
1003 (((
1004 {
1005 "message" : "Hello, world"
1006 }
1007 )))
1008
1009 **c.** choose Create
1010
1011 [[image:image-20220524152032-57.png]]
1012
1013 event create
1014
1015
1016 (((
1017 **d. **In the upper right of the Lambda function details page, choose Test to test your Lambda function with the message you specified in the test event.
1018 )))
1019
1020 [[image:image-20220524152057-58.png]]
1021
1022 event test
1023
1024
1025 **e.** Under your Lambda function code, on the Execution result tab, you see the output from the Lambda function.
1026
1027 [[image:image-20220524152131-59.png]]
1028
1029 event output
1030
1031 Now The Lambda function table is created
1032
1033 === 4.3.2 Step.2: Create Rule with Lambda function ===
1034
1035 **~1. **Browse to the AWS IoT console, and in the navigation pane, select **Act**
1036
1037 [[File:Console Act.png>>url:https://wiki.dragino.com/index.php?title=Special:Upload&wpDestFile=Console_Act.png]]
1038
1039 (% class="box" %)
1040 (((
1041 console_Act
1042 )))
1043
1044 **2. **Choose Create to create an AWS IoT rule.
1045
1046 [[image:image-20220524152224-61.png]]
1047
1048 create Rule
1049
1050 **3.** On the Create a rule page, enter a name for your rule.
1051
1052 [[image:image-20220524152356-62.png]]
1053
1054 enter a Rule name
1055
1056 **4.** In Rule query statement, enter the following query:
1057
1058 (% class="box" %)
1059 (((
1060 SELECT * FROM "my/lambda/topic"
1061 )))
1062
1063 [[image:image-20220524152441-63.png]]
1064
1065 enter the following query
1066
1067 **5.** In Set one or more actions, select Add action.
1068
1069 [[image:image-20220524152520-64.png]]
1070
1071 Add action
1072
1073 **6.** Under the select operation, select Send a Message to a Lambda Function and then select the configuration operation.
1074
1075
1076 select operation
1077
1078 = 5. For End Node =
1079
1080 == 5.1 AWS Downlink Note ==
1081
1082 Prerequisites: The node must be online in real-time before downlink.
1083
1084 [[image:image-20220525113243-2.png||height="346" width="623"]]
1085
1086 Convert the data to Base64
1087
1088 [[image:image-20220525113612-3.png||height="377" width="622"]]
1089
1090 When the serial port logs of downlink are received, the Receive date is displayed
1091
1092 [[image:image-20220525115046-4.png]]
1093
1094 In addition to the above methods, there is also a downlink,This method requires a certain amount of manipulation,
1095
1096 Users can view this [[Downlink method 2>>url:https://github.com/aws-samples/aws-iot-core-lorawan/tree/main/send_downlink_payload]]
1097
1098 == 5.2 Node decoder ==
1099
1100 [[Decode LHT65>>url:https://github.com/aws-samples/aws-iot-core-lorawan/tree/main/transform_binary_payload]]
1101
1102 = 6. Reference =
1103
1104 * [[Video Introduction for how to use LoRaWAN AWS-IoT Core>>url:https://www.youtube.com/watch?v=eKK0M8iC6l4]]
1105 * [[AWS LoRaWAN Workshop>>url:https://iotwireless.workshop.aws/]]
Copyright ©2010-2022 Dragino Technology Co., LTD. All rights reserved
Dragino Wiki v2.0