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