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