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