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