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 Change policy Document
148
149
150 == 2.3 Step 3: Add gateway ==
151
152
153 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
154
155 [[image:image-20220525173308-10.png]]
156
157 Locate IoT Core in the AWS Service Control Panel
158
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
194 [[image:image-20220525173615-15.png]]
195
196 Creation gateway certificates
197
198 **Note: **User Make sure the name of the downloaded file remains the same.
199
200
201 == 2.6 Step 6: Add gateway file ==
202
203 user returns to your gateway, and start adding the three file they got to the gateway.
204
205 [[image:image-20220525173647-16.png]]
206
207 Configure the gateway
208
209 if the user Upload successfully you will see:
210
211 [[image:image-20220525173710-17.png]]
212
213 Uploaded successfully
214
215 (% style="color:red" %)**Notice: **(% style="color:black" %)User must select the correct Upload on the suffix name, otherwise the upload fails.
216
217
218 == 2.7 Step 7: Add CUPS URI ==
219
220 Users enter the CUPS endpoint copied in the previous step into the CUPS URI and click **"Save&Apply"**
221
222 [[image:image-20220525173735-18.png]]
223
224 CUPS URI
225
226
227 [[image:image-20220525173759-19.png]]
228
229 CUPS URI Setting
230
231 **Notice:** After the user hits "Save&Apply", the gateway will start Station mode on its own
232
233
234 == 2.8 Step 8:Last upLink received ==
235
236 After the above settings, the gateway should be able to connect, the figure below shows the data of the Last upLink received
237
238 [[image:image-20220525174247-20.png]]
239
240 UpLink received
241
242
243 = 3. Add wireless device =
244
245 == 3.1 step 1:Add device profile ==
246
247 === 3.1.1 CREATE DEVICE PROFILE ===
248
249 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.
250
251 [[image:image-20220525174325-21.png]]
252
253 Add device profile
254
255
256 **Provide device data**
257
258 (% class="box" %)
259 (((
260 **Device profile name** : a descriptive name of your choice for this profile, e.g. “Workshop device profile of ”
261 **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”.
262 **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.
263 **Regional parameters version**: please select RP002-1.0.1, unless specified otherwise in your device documentation
264 **MaxEIRP** : please enter the default value 15
265 **Supports class **: please select class A, unless you are aware of specific requirements to use classes B and C and your device supports it
266 )))
267
268 [[image:image-20220525174354-22.png]]
269
270 device profile
271
272 **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]]
273
274
275 === 3.1.2 CREATE SERVICE PROFILE ===
276
277 Select “Profiles” view and click on “Add service profile”
278
279 [[image:image-20220525174516-23.png]]
280
281 Add a service profile
282
283 (% class="box" %)
284 (((
285 Choose a service profile name (e.g. “Default service profile”)
286 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.
287 This metadata could be used for network coverage optimization.
288 Finally, scroll down and click on “Add service profile”.
289 )))
290
291 [[image:image-20220525174610-24.png]]
292
293 Add service profile2
294
295
296 == 3.2 Step 2:Create an IAM roles for destinations ==
297
298 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.
299
300 **To create an IAM policy for your AWS IoT Core for LoRaWAN destination role**
301
302 **1.** Open the Policies hub of the IAM console.
303
304 **2. **Choose Create policy, and choose the JSON tab.
305
306 **3. **In the editor, delete any content from the editor and paste this policy document.
307
308 (% class="box" %)
309 (((
310 {
311 "Version": "2012-10-17",
312 "Statement": [
313 {
314 "Effect": "Allow",
315 "Action": [
316 "iot:DescribeEndpoint",
317 "iot:Publish"
318 ],
319 "Resource": "*"
320 }
321 ]
322 }
323 )))
324
325 **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.
326
327 **5.** Choose Create policy.
328
329
330 **To create an IAM role for an AWS IoT Core for LoRaWAN destination:**
331
332 **1.** Open the Roles hub of the IAM console and choose Create role.
333
334 **2.** In Select type of trusted entity, choose Another AWS account.
335
336 **3. **In Account ID, enter your AWS account ID, and then choose Next: Permissions.
337
338 **4.** In the search box, enter the name of the IAM policy that you created in the previous procedure.
339
340 **5.** In the search results, check the IAM policy that you created in the previous procedure.
341
342 **6.** Choose Next: Tags, and then choose Next: Review.
343
344 **7. **In Role name, enter the name of this role, and then choose Create role.
345
346 **8.** In the confirmation message, choose the name of the role you created to edit the new role.
347
348 **9. **In Summary, choose the Trust relationships tab, and then choose Edit trust relationship.
349
350 **10.** In Policy Document, change the Principal property to look like this example.
351
352 (% class="box" %)
353 (((
354 "Principal": {
355 "Service": "iotwireless.amazonaws.com"
356 },
357 )))
358
359 After you change the Principal property, the complete policy document should look like this example.
360
361 (% class="box" %)
362 (((
363 {
364 "Version": "2012-10-17",
365 "Statement": [
366 {
367 "Effect": "Allow",
368 "Principal": {
369 "Service": "iotwireless.amazonaws.com"
370 },
371 "Action": "sts:AssumeRole",
372 "Condition": {}
373 }
374 ]
375 }
376 )))
377
378 **~11. **To save your changes and exit, choose Update Trust Policy.
379
380 With this role defined, you can find it in the list of roles when you configure your AWS IoT Core for LoRaWAN destinations.
381
382
383 === 3.2.1 CREATE DESTINATION ===
384
385 **Select Destinations view**
386
387 Please click on “Destinations” menu and afterwards please click on “Add destination”.
388
389 [[image:image-20220525174704-25.png]]
390
391 Select destinations
392
393
394 **Provide input**
395
396 Please provide the following input:
397
398 (% class="box" %)
399 (((
400 Please choose an IAM role that shall be used for the invocation of AWS IoT Rule.
401 Please select the destination name (e.g. “WorkshopDestination<Your name without spaces>”)
402 Please select the AWS IoT Rule name (e.g. “MyWorkshopLoRaWANRule<Your name without spaces>”)
403 )))
404
405 click on “Add destination”
406
407 [[image:image-20220525174729-26.png]]
408
409 provide input
410
411
412 === 3.2.2 CREATE IOT RULE ===
413
414 **Create Rule**
415
416 user navigating to AWS IoT , Act, Rules and clicking on “Create” button.
417
418 [[image:image-20220525193329-45.png]]
419
420 Rule create
421
422
423 //Provide a rule name'//
424
425 (((
426 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”).
427 )))
428
429 [[image:image-20220524201202-2.png||height="351" width="611"]]
430
431 Enter Rule name
432
433
434 **Provide IoT SQL query statement**
435
436 Please put the following text into the rule query statement: **SELECT *, timestamp() as timestamp**
437
438 [[image:image-20220524201532-4.png||height="387" width="615"]]
439
440 Enter SQL query statement
441
442
443 **Select action “Republish to an AWS IoT Topic”**
444
445 [[image:image-20220524203543-8.png||height="637" width="601"]]
446
447
448 == 3.3 Step 3: Create a destination for end node payloadDate ==
449
450 The PayloadDate of the node will be sent to this destination
451
452 **a.** In the [[destinatons>>url:https://console.aws.amazon.com/iot/home?region=us-east-1#/wireless/destinations]],choose add destination.
453
454 **b.** In IMA Role, select the Role you created in the last step
455
456 **c.** In Destination name, give this destination a destination name.
457
458 **d.** In Rule name, give this rule a new name and remember it.
459
460 **e.** choose Add Destination.
461
462 [[image:image-20220524204934-9.png||height="663" width="627"]]
463
464 Add destination
465
466 **Note:**The destination rule configuration sent by the end node payloadDate will be in the next step
467
468
469 == 3.4 Step 4: CREATE WIRELESS DEVICE ==
470
471 Users can register end nodes with AWS
472
473
474 === 3.4.1 Open Add wireless device ===
475
476 (% class="box" %)
477 (((
478 (((
479 **a.** In Device,choose Add wireless device.
480 **b.** In Wireless device specification,select OTTA 1.0.x
481 **c. **In OTTA 1.0.x
482 **d.** In Profiles,select profilees,and choose Next
483 )))
484 )))
485
486 [[image:image-20220525175201-28.png]]
487
488 Add device
489
490
491 [[image:image-20220525175256-29.png]]
492
493 Enter device keys
494
495
496 **Select device and service profile**
497
498 (((
499 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.
500 )))
501
502 [[image:image-20220525175338-30.png]]
503
504 Seleck profile
505
506
507 === 3.4.2 Select a destination ===
508
509 **Plese select a destination you have created in one of the previous steps and choose add device**
510
511 [[image:image-20220525175408-31.png]]
512
513 Add device_choose destition
514
515
516 **REVIEW THE CREATED DEVICER**
517
518 [[image:image-20220525175438-32.png]]
519
520 Uplink Received
521
522
523 **VERIFY DEVICE CONNECTIVITY**
524
525 [[image:image-20220525175509-33.png]]
526
527 Verify device connectivity
528
529
530 === 3.4.3 Verify date ingestion ===
531
532 **Open MQTT Test Client**
533
534 [[image:image-20220525175552-34.png]]
535
536 Open MQTT Client
537
538
539 **Subscribe to topic**
540
541 (((
542 Please input the topic name **workshop_lorawanmessages** in “Subscription topic” field and click on “Subscribe to topic”.
543
544 Users can choose to subscribe to "**#**" ,"#" indicates to subscribe to all.
545 )))
546
547 [[image:image-20220525175724-35.png]]
548
549 Subscription Topic
550
551
552 **Trigger your device to send telemetry**
553
554 User can start the registered device
555
556 **Review the incoming message from uesr's device**
557
558 Please find below an explanation for some of the attributes:
559
560 (% class="box" %)
561 (((
562 **PayloadData ** : Base64-encoded payload from the device
563 **~ WirelessMetadata.FPort**           : FPort used by the device
564 **~ WirelessMetadata.LoRaWAN.DevEui**  : EUI of the device sending the data
565 **~ WirelessMetadata.LoRaWAN.Gateways**: Information on RSSI and SNR per gateway
566 )))
567
568 [[image:image-20220525193459-46.png]]
569
570 Review message
571
572
573 (% class="box" %)
574 (((
575 {
576 "WirelessDeviceId": "3ff07678-0c3d-4ed7-a01a-4e2cc927e315",
577 "PayloadData": "AAAAAAAAAAAPo2I=",
578 "WirelessMetadata": {
579 "LoRaWAN": {
580 "DataRate": "5",
581 "DevEui": "a840410801818749",
582 "FCnt": 579,
583 "FPort": 2,
584 "Frequency": "867500000",
585 "Gateways": [
586 {
587 "GatewayEui": "a84041ffff1ec39f",
588 "Rssi": -79,
589 "Snr": 7.25
590 },
591 {
592 "GatewayEui": "a84041ffff1ee2a0",
593 "Rssi": -129,
594 "Snr": -4
595 }
596 ],
597 "Timestamp": "2021-04-10T08:16:06Z"
598 }
599 },
600 "timestamp": 1618042566345
601 }
602 )))
603
604 **How to decode Base64 data into hexadecimal representation**
605
606 You can run the following command in your shell to decode Base64 payload data into their hexadecimal representation.
607
608 MacOS
609
610 (% class="box" %)
611 (((
612 $  echo -n "<Value of PayloadData>" | base64 -D | hexdump -v -e '/1 "%02x"'
613 )))
614
615 Linux
616
617 (% class="box" %)
618 (((
619 $  echo -n "<Value of PayloadData>" | base64 -d | hexdump -v -e '/1 "%02x"'
620 )))
621
622 Example
623
624 (% class="box" %)
625 (((
626 $  echo -n "7WkoOEfwfTTioxG6CatHBw==" | base64 -D | hexdump -v -e '/1 "%02x"'
627 ed69283847f07d34e2a311ba09ab4707
628 )))
629
630
631 = 4. Format a notification by using an AWS Lambda function =
632
633 == 4.1 Introduction ==
634
635 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
636
637
638 === 4.1.1 What you'll learn in this tutorial ===
639
640 How to create and test an AWS Lambda function
641
642 How to use the AWS SDK in an AWS Lambda function to publish an Amazon SNS notification
643
644 How to use simple SQL queries and functions in a rule query statement
645
646 How to use the MQTT client to test an AWS IoT rule
647
648
649 === 4.1.2 In this tutorial, you'll: ===
650
651 (((
652 Create an AWS Lambda function that sends a text message
653 )))
654
655 (((
656 Create an AWS IoT rule with an AWS Lambda rule action
657 )))
658
659 (((
660 Test the AWS IoT rule and AWS Lambda rule action
661
662
663 )))
664
665 == 4.2 Approach A: DECODING BINARY PAYLOADS ==
666
667 === 4.2.1 Step 1 :Start deployment of a severless application with AWS Lambda function and AWS ioT Rule ===
668
669 **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]]**
670
671 [[image:image-20220525193652-47.png]]
672
673 Deployment Lambda
674
675
676 **2:Select a decoder**
677
678 (((
679 Please scroll down to the bottom of the page. Please provide the parameter decoder name based on the following table.
680 )))
681
682 Device Decoder name
683
684 LHT65 dragino_lht65
685
686 LBT1 dragino_lbt1
687
688 LSE01 dragino_lse01
689
690 LGT92 dragino_lgt92
691
692 LDS01 dragino_lds01
693
694 After that please check the box **“I acknowledge that this app creates resource policies.”** and click on **“Deploy”**.
695
696 [[image:image-20220530155623-1.png]]
697
698 Seleck a decoder name
699
700
701 **3:Review deployment**
702
703 (((
704 Please wait few seconds for a successful deployment. After that please click on the name of the Lambda function “TransformLoRaWANBinaryPayloadFunction”.
705 )))
706
707 [[image:image-20220530155838-2.png]]
708
709 Review deployment
710
711
712 **4. Create the test event**
713
714 Please click on “Configure the test event”
715
716 [[image:image-20220530155925-3.png]]
717
718 Create the test event
719
720
721 (((
722 In the window that opens, please provide the event name e.g. IoTCoreForLoRaWANEvent. After that please paste the following JSON content:
723 )))
724
725 (% class="box" %)
726 (((
727 {
728 "PayloadData": "<Sample PayloadData>",
729 "WirelessDeviceId": "57728ff8-5d1d-4130-9de2-f004d8722bc2",
730 "WirelessMetadata": {
731 "LoRaWAN": {
732 "DataRate": 0,
733 "DevEui": "a84041d55182720b",
734 "FPort": 2,
735 "Frequency": 867900000,
736 "Gateways": [
737 {
738 "GatewayEui": "dca632fffe45b3c0",
739 "Rssi": -76,
740 "Snr": 9.75
741 }
742 ],
743 "Timestamp": "2020-12-07T14:41:48Z"
744 }
745 }
746 }
747 )))
748
749
750 [[image:image-20220530160030-4.png]]
751
752 Create a new event
753
754
755 **5. Provide PayloadData sample**
756
757 (((
758 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”.
759 )))
760
761 (% class="box" %)
762 (((
763 (((
764 Device name          Sample “PayloadData”
765 )))
766
767 (((
768 LHT65  ~-~-  y6QHxgG4AQhmf/8=
769 )))
770
771 (((
772 LSE01         ~-~-     AuHtlACmawQPVGM=
773 LGT92         ~-~-     DSEAAAEVCMUGpAA=
774 LBT1  ~-~-     DxwAAAIDQUJCQ0NEREVFRkYwMjcxMjFGNkFDMy0wNTk=
775 )))
776 )))
777
778 ~[~[File:replace <Sample PayloadDate>.png|600px|none|thumb|replace <Sample PayloadDate>]]
779
780
781 **6.Edit project Files**
782
783 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**
784
785 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.
786
787 How to modify see the figure below:
788
789 (% class="box" %)
790 (((
791 1) Add a decoder in app.py  ~-~-->  For example, add code: import dragino_lht52
792
793 2) Add the decoder name to "VALID_PAYLOAD_DECODER_NAMES"  ~-~-->  add dragino_lht52
794
795 3) Add the statement  ~-~-->  DECODER_NAME = "dragino_lht52"
796
797 **(The user can input the decoding project that needs to be tested)**
798
799 4)Comment out "DECODER_NAME = os.environ.get("DECODER_NAME")"
800
801 **(Comment out it in order to use other project files)**
802 )))
803
804 [[image:image-20220525094832-3.png||height="276" width="627"]]
805
806 After the user finishes editing, Click on the **"Deploy"**
807
808
809 **7. Run a test**
810
811 Please click on **“Test”**.
812
813 [[image:image-20220525181711-3.png]]
814
815 **8. Check whether the decoding succeeds **
816
817 The following example is the successful decoding of LHT52,
818
819 [[image:image-20220525100532-4.png||height="488" width="612"]]
820
821 **9. Note the AWS Lamdbda function ARN**
822
823 (((
824 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.
825 )))
826
827 [[image:image-20220525181551-2.png]]
828
829 === 4.2.2 Step 2:Update the Destination rule and get the device's payload ===
830
831 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.
832
833 (((
834 ~1. Find the IoT Rule
835
836 2. Create a Destination with IoT Rule (MyWorkshopLoRaWANRuleWithDecoder_dragino_lht65)
837
838 3. Update the destination to the device
839
840 4. Check the payload
841
842 5. Approach A with MQTT
843
844 6. Approach B with Lambda
845 )))
846
847 ==== 4.2.2.1 1. Find the IoT Rule MyWorkshopLoRaWANRuleWithDecoder_… ====
848
849 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:
850
851 [[image:image-20220525185246-22.png]]
852
853 Find the IoT rule
854
855 ==== 4.2.2.2 2. Create a Destination with IoT Rule ====
856
857 (MyWorkshopLoRaWANRuleWithDecoder_dragino_lht65)
858
859 [[image:image-20220524150209-43.png]]
860
861 Create a Destnation
862
863
864 ==== 4.2.2.3 3. Update the destination to the device ====
865
866 [[image:image-20220525185016-20.png]]
867
868 Update the destination to the device
869
870
871 ==== 4.2.2.4 4.Check the payload ====
872
873 **Approach A with MQTT**
874
875 click the rule
876
877 [[image:image-20220525184325-18.png]]
878
879 click the rule
880
881
882 Copy the Topic name
883
884 [[image:image-20220525185444-24.png]]
885
886 copy the rule name
887
888
889 Open MQTT client and subscrlibe Topic
890
891 [[image:image-20220525185554-25.png]]
892
893 Open MQTT client and subscrlibe Topic
894
895
896 Get the payload
897
898 [[image:image-20220525190308-27.png]]
899
900
901 Get the payload
902
903 **Approach B with Lamdbda**
904
905 open lamdbda console and click the application
906
907 [[image:image-20220525190617-28.png]]
908
909 open lamdbda console and click the application
910
911 [[image:image-20220525190749-30.png]]
912
913 open lamdbda console and click the application
914
915 View logs in CloudWatch
916
917 [[image:image-20220525183907-15.png]]
918
919 View logs in CloudWatch
920
921 [[image:image-20220525190854-31.png]]
922
923 View logs in CloudWatch
924
925 == 4.3 Approach B Create an AWS Lambda function that sends a text message ==
926
927 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.
928
929 === 4.3.1 Step.1: To create an AWS Lambda function that sends a text message ===
930
931 ==== 4.3.1.1 1.Create a new AWS Lambda function. ====
932
933 **a.** In the [[AWS Lambda console>>url:https://console.aws.amazon.com/lambda/home]], choose Create function.
934
935 [[image:image-20220525191138-32.png]]
936
937 Create function
938
939 (((
940 **b.** In Create function, select Use a blueprint. Search for and select the hello-world-python blueprint, and then choose **Configure**.
941 )))
942
943 [[image:image-20220525191640-33.png]]
944
945 blueprint
946
947 **c. **In Basic information:
948
949 (% class="box" %)
950 (((
951 1). In Function name, enter the name of this function, format-high-temp-notification.
952 2). In Execution role, choose Create a new role from AWS policy templates.
953 3). In Role name, enter the name of the new role, format-high-temp-notification-role.
954 4). In Policy templates - optional, search for and select Amazon SNS publish policy.
955 5). Choose Create function.
956 )))
957
958 [[image:image-20220525191717-34.png]]
959
960 blueprint
961
962
963 ==== 4.3.1.2 2.Modify the blueprint code to format and send an Amazon SNS notification. ====
964
965 (((
966 **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.
967 )))
968
969 (((
970 **b.** In the format-high-temp-notification details page, choose the Configuration tab and scroll to the Function code panel.
971 )))
972
973 (((
974 **c. **In the Function code window, in the Environment pane, choose the Python file, lambda_function.py.
975 )))
976
977 (((
978 **d.** In the Function code window, delete all of the original program code from the blueprint and replace it with this code.
979 )))
980
981 (% class="box" %)
982 (((
983 from ~_~_future~_~_ import print_function
984 import json
985 import boto3
986 print('Loading function')
987 def lambda_handler(event, context):
988 # Parse the JSON message
989 eventText = json.dumps(event)
990 # 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.
991 print('Received event: ', eventText)
992 # Create an SNS client
993 sns = boto3.client('sns')
994 # Publish a message to the specified topic
995 response = sns.publish (
996 TopicArn = 'arn:aws:iam::123456789012:My_IoT_SNS_Topic',
997 Message = eventText
998 )
999 print(response)
1000 )))
1001
1002 **e.** Choose Deploy.
1003
1004 **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]]
1005
1006 **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
1007
1008
1009 ==== 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. ====
1010
1011 (((
1012 **a. **In a new window, open the Topics page of the Amazon SNS console
1013 )))
1014
1015 (((
1016 **b.** In the Topics page, find the high_temp_notice notification topic in the list of Amazon SNS topics.
1017 )))
1018
1019 (((
1020 **c.** Find the ARN of the high_temp_notice notification topic to use in the next step.
1021
1022
1023 )))
1024
1025 ==== 4.3.1.4 4.Create a test case for your Lambda function. ====
1026
1027 **a.** In the Lambda Functionspage of the console,from **Select a test event**to select Configure test events
1028
1029 [[image:image-20220525191819-35.png]]
1030
1031 Configure test events
1032
1033
1034 (((
1035 **b. **On Configure test event, enter a name for your test event and replace the message JSON with the following:
1036 )))
1037
1038 (% class="box" %)
1039 (((
1040 {
1041 "message" : "Hello, world"
1042 }
1043 )))
1044
1045 **c.** choose Create
1046
1047 [[image:image-20220525191853-36.png]]
1048
1049 event create
1050
1051
1052 (((
1053 **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.
1054 )))
1055
1056 [[image:image-20220525191938-37.png]]
1057
1058 event test
1059
1060
1061 **e.** Under your Lambda function code, on the Execution result tab, you see the output from the Lambda function.
1062
1063 [[image:image-20220525192325-38.png]]
1064
1065 event output
1066
1067 Now The Lambda function table is created
1068
1069 === 4.3.2 Step.2: Create Rule with Lambda function ===
1070
1071 **~1. **Browse to the AWS IoT console, and in the navigation pane, select **Act**
1072
1073 [[File:Console Act.png>>url:https://wiki.dragino.com/index.php?title=Special:Upload&wpDestFile=Console_Act.png]]
1074
1075 (% class="box" %)
1076 (((
1077 console_Act
1078 )))
1079
1080 **2. **Choose Create to create an AWS IoT rule.
1081
1082 [[image:image-20220525192403-39.png]]
1083
1084 create Rule
1085
1086 **3.** On the Create a rule page, enter a name for your rule.
1087
1088 [[image:image-20220525192424-40.png]]
1089
1090 enter a Rule name
1091
1092 **4.** In Rule query statement, enter the following query:
1093
1094 (% class="box" %)
1095 (((
1096 SELECT * FROM "my/lambda/topic"
1097 )))
1098
1099 [[image:image-20220525192453-41.png]]
1100
1101 enter the following query
1102
1103 **5.** In Set one or more actions, select Add action.
1104
1105 [[image:image-20220525192524-42.png]]
1106
1107 Add action
1108
1109 **6.** Under the select operation, select Send a Message to a Lambda Function and then select the configuration operation.
1110
1111 [[image:image-20220525192619-43.png]]
1112
1113 select operation
1114
1115 = 5. For End Node =
1116
1117 == 5.1 AWS Downlink Note ==
1118
1119 Prerequisites: The node must be online in real-time before downlink.
1120
1121 [[image:image-20220525113243-2.png||height="346" width="623"]]
1122
1123 Convert the data to Base64
1124
1125 [[image:image-20220525113612-3.png||height="377" width="622"]]
1126
1127 When the serial port logs of downlink are received, the Receive date is displayed
1128
1129 [[image:image-20220525115046-4.png]]
1130
1131 In addition to the above methods, there is also a downlink,This method requires a certain amount of manipulation,
1132
1133 Users can view this [[Downlink method 2>>url:https://github.com/aws-samples/aws-iot-core-lorawan/tree/main/send_downlink_payload]]
1134
1135 == 5.2 Node decoder ==
1136
1137 [[Decode LHT65>>url:https://github.com/aws-samples/aws-iot-core-lorawan/tree/main/transform_binary_payload]]
1138
1139 = 6. Reference =
1140
1141 * [[Video Introduction for how to use LoRaWAN AWS-IoT Core>>url:https://www.youtube.com/watch?v=eKK0M8iC6l4]]
1142 * [[AWS LoRaWAN Workshop>>url:https://iotwireless.workshop.aws/]]
Copyright ©2010-2022 Dragino Technology Co., LTD. All rights reserved
Dragino Wiki v2.0