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-20220530163030-21.png||height="581" width="1364"]]
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-20220530163201-23.png]]
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-20220530163352-25.png]]
423
424 Add service profile2
425
426
427 == 3.2 Step 2 : Create an IAM roles for destinations ==
428
429
430 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.
431
432
433 (% style="color:blue" %)**To create an IAM policy for your AWS IoT Core for LoRaWAN destination role:**
434
435 (% style="color:red" %)**1.**(%%) Open the Policies hub of the IAM console.
436
437 (% style="color:red" %)**2. **(%%)Choose Create policy, and choose the JSON tab.
438
439 (% style="color:red" %)**3. **(%%)In the editor, delete any content from the editor and paste this policy document.
440
441 (% class="box" %)
442 (((
443 {
444 "Version": "2012-10-17",
445 "Statement": [
446 {
447 "Effect": "Allow",
448 "Action": [
449 "iot:DescribeEndpoint",
450 "iot:Publish"
451 ],
452 "Resource": "*"
453 }
454 ]
455 }
456 )))
457
458 (% 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.
459
460 (% style="color:red" %)**5.**(%%) Choose Create policy.
461
462
463 (% style="color:blue" %)**To create an IAM role for an AWS IoT Core for LoRaWAN destination:**
464
465 (% style="color:red" %)**1.** (%%)Open the Roles hub of the IAM console and choose Create role.
466
467 (% style="color:red" %)**2.**(%%) In Select type of trusted entity, choose Another AWS account.
468
469 (% style="color:red" %)**3. **(%%)In Account ID, enter your AWS account ID, and then choose Next: Permissions.
470
471 (% style="color:red" %)**4.**(%%) In the search box, enter the name of the IAM policy that you created in the previous procedure.
472
473 (% style="color:red" %)**5.**(%%) In the search results, check the IAM policy that you created in the previous procedure.
474
475 (% style="color:red" %)**6.**(%%) Choose Next: Tags, and then choose Next: Review.
476
477 (% style="color:red" %)**7. **(%%)In Role name, enter the name of this role, and then choose Create role.
478
479 (% style="color:red" %)**8.**(%%) In the confirmation message, choose the name of the role you created to edit the new role.
480
481 (% style="color:red" %)**9. **(%%)In Summary, choose the Trust relationships tab, and then choose Edit trust relationship.
482
483 (% style="color:red" %)**10.**(%%) In Policy Document, change the Principal property to look like this example.
484
485 (% class="box" %)
486 (((
487 "Principal": {
488 "Service": "iotwireless.amazonaws.com"
489 },
490 )))
491
492
493 After you change the Principal property, the complete policy document should look like this example.
494
495 (% class="box" %)
496 (((
497 {
498 "Version": "2012-10-17",
499 "Statement": [
500 {
501 "Effect": "Allow",
502 "Principal": {
503 "Service": "iotwireless.amazonaws.com"
504 },
505 "Action": "sts:AssumeRole",
506 "Condition": {}
507 }
508 ]
509 }
510 )))
511
512 (% style="color:red" %)**11. **(%%)To save your changes and exit, choose Update Trust Policy.
513
514 With this role defined, you can find it in the list of roles when you configure your AWS IoT Core for LoRaWAN destinations.
515
516
517 === 3.2.1 CREATE DESTINATION ===
518
519
520 (% style="color:blue" %)**Select Destinations view**
521
522
523 Please click on **“(% style="color:red" %)Destinations” (%%)**menu and afterwards please click on **“(% style="color:red" %)Add destination”(%%)**(% style="color:red" %).
524
525 [[image:image-20220530163507-26.png]]
526
527 Select destinations
528
529
530
531 (% style="color:blue" %)**Provide input**
532
533 Please provide the following input:
534
535 (% class="box" %)
536 (((
537 Please choose an IAM role that shall be used for the invocation of AWS IoT Rule.
538 Please select the destination name (e.g. “WorkshopDestination<Your name without spaces>”)
539 Please select the AWS IoT Rule name (e.g. “MyWorkshopLoRaWANRule<Your name without spaces>”)
540 )))
541
542
543 click on **“(% style="color:red" %)Add destination”(%%)**
544
545 [[image:image-20220530163600-27.png]]
546
547 provide input
548
549
550 === 3.2.2 CREATE IOT RULE ===
551
552
553 (% style="color:blue" %)**Create Rule**
554
555 user navigating to AWS IoT , Act, Rules and clicking on (% style="color:red" %)**“Create” **(%%)button.
556
557
558 [[image:image-20220525193329-45.png]]
559
560 Rule create
561
562
563
564 **//Provide a rule name'//**
565
566 (((
567 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”).
568 )))
569
570 [[image:image-20220601100315-2.png]]
571
572 Enter Rule name
573
574
575
576 (% style="color:blue" %)**Provide IoT SQL query statement**
577
578 Please put the following text into the rule query statement: (% style="color:#037691" %)**SELECT *, timestamp() as timestamp**
579
580 [[image:image-20220601100401-3.png]]
581
582 Enter SQL query statement
583
584
585 **Select action “(% style="color:red" %)Republish to an AWS IoT Topic”(%%)**
586
587 [[image:image-20220601100505-4.png]]
588
589
590 == 3.3 Step 3 : Create a destination for end node payloadDate ==
591
592
593 (% style="color:blue" %)**The PayloadDate of the node will be sent to this destination**
594
595 (% style="color:red" %)**a.**(%%) In the [[destinatons>>url:https://console.aws.amazon.com/iot/home?region=us-east-1#/wireless/destinations]],choose add destination.
596
597 (% style="color:red" %)**b.**(%%) In IMA Role, select the Role you created in the last step
598
599 (% style="color:red" %)**c.** (%%)In Destination name, give this destination a destination name.
600
601 (% style="color:red" %)**d.**(%%) In Rule name, give this rule a new name and remember it.
602
603 (% style="color:red" %)**e.**(%%) choose Add Destination.
604
605 [[image:image-20220524204934-9.png||height="663" width="627"]]
606
607 Add destination
608
609
610 (% style="color:red" %)**Note: **(%%)The destination rule configuration sent by the end node payloadDate will be in the next step.
611
612
613 == 3.4 Step 4 : CREATE WIRELESS DEVICE ==
614
615
616 Users can register end nodes with AWS.
617
618
619 === 3.4.1 Open Add wireless device ===
620
621
622 (% class="box" %)
623 (((
624 (((
625 (% style="color:red" %)**a.**(%%) In Device,choose Add wireless device.
626 (% style="color:red" %)**b.**(%%) In Wireless device specification,select OTTA 1.0.x
627 (% style="color:red" %)**c. **(%%)In OTTA 1.0.x
628 (% style="color:red" %)**d.**(%%) In Profiles,select profilees,and choose Next
629 )))
630 )))
631
632 [[image:image-20220530164137-28.png||height="544" width="1331"]]
633
634 Add device
635
636
637
638 [[image:image-20220530164246-29.png||height="614" width="1333"]](% style="display:none" %)
639
640 Enter device keys
641
642
643
644 (% style="color:blue" %)**Select device and service profile**
645
646 (((
647 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.
648
649
650 )))
651
652 [[image:image-20220530164324-30.png||height="658" width="1331"]](% style="display:none" %)
653
654 Seleck profile
655
656
657 === 3.4.2 Select a destination ===
658
659
660 **Plese select a destination you have created in one of the previous steps and choose add device**
661
662 [[image:image-20220530164504-32.png]]
663
664 Add device_choose destition
665
666
667 **REVIEW THE CREATED DEVICER**
668
669 [[image:image-20220530164440-31.png||height="384" width="1371"]]
670
671 Uplink Received
672
673
674 **VERIFY DEVICE CONNECTIVITY**
675
676 [[image:image-20220530164545-33.png||height="528" width="1383"]]
677
678 Verify device connectivity
679
680
681 === 3.4.3 Verify data ingestion ===
682
683
684 (% style="color:blue" %)**Open MQTT Test Client**
685
686 [[image:image-20220530164819-36.png||height="539" width="1392"]]
687
688
689 Open MQTT Client
690
691
692 (% style="color:blue" %)**Subscribe to topic**
693
694 (((
695 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" %).
696
697 Users can choose to subscribe to "**#**" ,"#" indicates to subscribe to all.
698
699 [[image:image-20220530170719-38.png]]
700 )))
701
702
703 Subscription Topic
704
705
706
707 (% style="color:blue" %)**Trigger your device to send telemetry**
708
709 User can start the registered device
710
711
712 (% style="color:blue" %)**Review the incoming message from uesr's device**
713
714 Please find below an explanation for some of the attributes:
715
716 (% class="box" %)
717 (((
718 (% style="color:#037691" %)**PayloadData** (%%) :  Base64-encoded payload from the device
719 (% style="color:#037691" %)**WirelessMetadata.FPort**(%%) :  FPort used by the device
720 (% style="color:#037691" %)**WirelessMetadata.LoRaWAN.DevEui**(%%)  :  EUI of the device sending the data
721 (% style="color:#037691" %)**WirelessMetadata.LoRaWAN.Gateways **(%%): Information on RSSI and SNR per gateway
722 )))
723
724 [[image:image-20220530170810-39.png||height="598" width="1396"]](% style="display:none" %)
725
726 Review message
727
728
729 (% class="box" %)
730 (((
731 {
732 "WirelessDeviceId": "3ff07678-0c3d-4ed7-a01a-4e2cc927e315",
733 "PayloadData": "AAAAAAAAAAAPo2I=",
734 "WirelessMetadata": {
735 "LoRaWAN": {
736 "DataRate": "5",
737 "DevEui": "a840410801818749",
738 "FCnt": 579,
739 "FPort": 2,
740 "Frequency": "867500000",
741 "Gateways": [
742 {
743 "GatewayEui": "a84041ffff1ec39f",
744 "Rssi": -79,
745 "Snr": 7.25
746 },
747 {
748 "GatewayEui": "a84041ffff1ee2a0",
749 "Rssi": -129,
750 "Snr": -4
751 }
752 ],
753 "Timestamp": "2021-04-10T08:16:06Z"
754 }
755 },
756 "timestamp": 1618042566345
757 }
758 )))
759
760
761 (% style="color:blue" %)**How to decode Base64 data into hexadecimal representation**
762
763 You can run the following command in your shell to decode Base64 payload data into their hexadecimal representation.
764
765
766 (% style="color:blue" %)**MacOS**
767
768 (% class="box" %)
769 (((
770 **$  echo -n "<Value of PayloadData>" | base64 -D | hexdump -v -e '/1 "%02x"'**
771 )))
772
773
774 (% style="color:blue" %)**Linux**
775
776 (% class="box" %)
777 (((
778 **$  echo -n "<Value of PayloadData>" | base64 -d | hexdump -v -e '/1 "%02x"'**
779 )))
780
781
782 (% style="color:blue" %)**Example**
783
784 (% class="box" %)
785 (((
786 **$  echo -n "7WkoOEfwfTTioxG6CatHBw==" | base64 -D | hexdump -v -e '/1 "%02x"'
787 ed69283847f07d34e2a311ba09ab4707**
788 )))
789
790
791 = 4. Format a notification by using an AWS Lambda function =
792
793 == 4.1 Introduction ==
794
795
796 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
797
798
799 === 4.1.1 What you'll learn in this tutorial ===
800
801
802 How to create and test an AWS Lambda function
803
804 How to use the AWS SDK in an AWS Lambda function to publish an Amazon SNS notification
805
806 How to use simple SQL queries and functions in a rule query statement
807
808 How to use the MQTT client to test an AWS IoT rule
809
810
811 === 4.1.2 In this tutorial, you'll: ===
812
813
814 (((
815 Create an AWS Lambda function that sends a text message
816 )))
817
818 (((
819 Create an AWS IoT rule with an AWS Lambda rule action
820 )))
821
822 (((
823 Test the AWS IoT rule and AWS Lambda rule action
824
825
826 )))
827
828 == 4.2 Approach A: DECODING BINARY PAYLOADS ==
829
830 === 4.2.1 Step 1 : Start deployment of a severless application with AWS Lambda function and AWS ioT Rule ===
831
832
833 (% style="color:blue" %)**1. Open AWS Lambda console by clicking on link**
834
835 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]]**
836
837
838 [[image:image-20231113140646-1.png||height="560" width="1085"]]
839
840
841 (% style="color:blue" %)**2. Select a decoder**
842
843 (((
844 Please scroll down to the bottom of the page. Please provide the parameter decoder name based on the following table.
845 )))
846
847 Device Decoder name
848
849 LHT65 dragino_lht65
850
851 LBT1 dragino_lbt1
852
853 LSE01 dragino_lse01
854
855 LGT92 dragino_lgt92
856
857 LDS01 dragino_lds01
858
859 After that please check the box **“I acknowledge that AWS CloudFormation might create IAM resources".**
860
861 **"I acknowledge that AWS CloudFormation might create IAM resources with custom names."**
862
863 **"I acknowledge that AWS CloudFormation might require the following capability: CAPABILITY_AUTO_EXPAND"**
864
865 and click on **"Create stack"**
866
867 [[image:image-20231113141017-2.png||height="579" width="1121"]]
868
869 Seleck a decoder name
870
871
872 (% style="color:blue" %)**3. Review deployment**
873
874 (((
875 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" %).
876 )))
877
878 [[image:image-20220530155838-2.png||height="504" width="1181"]](% style="display:none" %)
879
880 Review deployment
881
882
883 (% style="color:blue" %)**4. Create the test event**
884
885 Please click on **“(% style="color:red" %)Configure the test event”(%%)**
886
887 [[image:image-20220530155925-3.png||height="599" width="1385"]]
888
889 Create the test event
890
891
892 (((
893 In the window that opens, please provide the event name e.g. IoTCoreForLoRaWANEvent. After that please paste the following JSON content:
894 )))
895
896 (% class="box" %)
897 (((
898 {
899 "PayloadData": "<Sample PayloadData>",
900 "WirelessDeviceId": "57728ff8-5d1d-4130-9de2-f004d8722bc2",
901 "WirelessMetadata": {
902 "LoRaWAN": {
903 "DataRate": 0,
904 "DevEui": "a84041d55182720b",
905 "FPort": 2,
906 "Frequency": 867900000,
907 "Gateways": [
908 {
909 "GatewayEui": "dca632fffe45b3c0",
910 "Rssi": -76,
911 "Snr": 9.75
912 }
913 ],
914 "Timestamp": "2020-12-07T14:41:48Z"
915 }
916 }
917 }
918 )))
919
920
921 [[image:image-20220530160030-4.png]]
922
923 Create a new event
924
925
926 (% style="color:blue" %)**5. Provide PayloadData sample**
927
928 (((
929 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”**.
930 )))
931
932 (% class="box" %)
933 (((
934 (((
935 Device name          Sample “PayloadData”
936 )))
937
938 (((
939 LHT65  ~-~-  y6QHxgG4AQhmf/8=
940 )))
941
942 (((
943 LSE01         ~-~-     AuHtlACmawQPVGM=
944 LGT92         ~-~-     DSEAAAEVCMUGpAA=
945 LBT1  ~-~-     DxwAAAIDQUJCQ0NEREVFRkYwMjcxMjFGNkFDMy0wNTk=
946 )))
947 )))
948
949 ~[~[File:replace <Sample PayloadDate>.png|600px|none|thumb|replace <Sample PayloadDate>]]
950
951
952 (% style="color:blue" %)**6. Edit project Files**
953
954 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**
955
956 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.
957
958 How to modify see the figure below:
959
960 (% class="box" %)
961 (((
962 1) Add a decoder in app.py  ~-~-->  For example, add code: import dragino_lht52
963
964 2) Add the decoder name to "VALID_PAYLOAD_DECODER_NAMES"  ~-~-->  add dragino_lht52
965
966 3) Add the statement  ~-~-->  DECODER_NAME = "dragino_lht52"
967
968 **(The user can input the decoding project that needs to be tested)**
969
970 4)Comment out "DECODER_NAME = os.environ.get("DECODER_NAME")"
971
972 **(Comment out it in order to use other project files)**
973 )))
974
975 [[image:image-20220601100037-1.png||height="615" width="1386"]]
976
977 After the user finishes editing, Click on the **"(% style="color:red" %)Deploy"(%%)**
978
979
980 (% style="color:blue" %)**7. Run a test**
981
982 Please click on **“(% style="color:red" %)Test”(%%)**(% style="color:red" %).
983
984 [[image:image-20220530160314-5.png||height="563" width="1373"]]
985
986
987 (% style="color:blue" %)**8. Check whether the decoding succeeds **
988
989 The following example is the successful decoding of LHT52,
990
991 [[image:image-20220525100532-4.png||height="488" width="612"]]
992
993
994 (% style="color:blue" %)**9. Note the AWS Lamdbda function ARN**
995
996 (((
997 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.
998 )))
999
1000 [[image:image-20220530160518-6.png||height="729" width="1370"]]
1001
1002
1003 === 4.2.2 Step 2 : Update the Destination rule and get the device's payload ===
1004
1005
1006 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.
1007
1008 (((
1009 ~1. Find the IoT Rule
1010
1011 2. Create a Destination with IoT Rule (MyWorkshopLoRaWANRuleWithDecoder_dragino_lht65)
1012
1013 3. Update the destination to the device
1014
1015 4. Check the payload
1016
1017 5. Approach A with MQTT
1018
1019 6. Approach B with Lambda
1020
1021
1022
1023 )))
1024
1025 ==== (% style="color:blue" %)**1. Find the IoT Rule MyWorkshopLoRaWANRuleWithDecoder_…**(%%) ====
1026
1027
1028 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:
1029
1030 [[image:image-20220530160632-7.png]]
1031
1032 Find the IoT rule
1033
1034
1035 ==== (% style="color:blue" %)**2. Create a Destination with IoT Rule**(%%) ====
1036
1037
1038 (MyWorkshopLoRaWANRuleWithDecoder_dragino_lht65)
1039
1040 [[image:image-20220530160712-8.png]]
1041
1042 Create a Destnation
1043
1044
1045 ==== (% style="color:blue" %)**3. Update the destination to the device**(%%) ====
1046
1047
1048 [[image:image-20220530160803-9.png]]
1049
1050 Update the destination to the device
1051
1052
1053 ==== (% style="color:blue" %)**4.  Check the payload**(%%) ====
1054
1055
1056 (% style="color:blue" %)**Approach A with MQTT**
1057
1058 click the rule
1059
1060 [[image:image-20220525184325-18.png]]
1061
1062 click the rule
1063
1064
1065
1066 **Copy the Topic name**
1067
1068 [[image:image-20220525185444-24.png]]
1069
1070 copy the rule name
1071
1072
1073 Open MQTT client and subscrlibe Topic
1074
1075 [[image:image-20220525185554-25.png||height="787" width="1419"]]
1076
1077 Open MQTT client and subscrlibe Topic
1078
1079
1080
1081 Get the payload
1082
1083 [[image:image-20220525190308-27.png]]
1084
1085 Get the payload
1086
1087
1088
1089 (% style="color:blue" %)**Approach B with Lamdbda**
1090
1091 open lamdbda console and click the application
1092
1093 [[image:image-20220525190617-28.png]]
1094
1095 open lamdbda console and click the application
1096
1097
1098
1099 [[image:image-20220525190749-30.png||height="409" width="1404"]]
1100
1101 open lamdbda console and click the application
1102
1103
1104
1105 View logs in CloudWatch
1106
1107 [[image:image-20220525183907-15.png||height="529" width="1397"]]
1108
1109 View logs in CloudWatch
1110
1111
1112
1113 [[image:image-20220525190854-31.png||height="627" width="1393"]]
1114
1115 View logs in CloudWatch
1116
1117
1118 == 4.3 Approach B Create an AWS Lambda function that sends a text message ==
1119
1120
1121 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.
1122
1123
1124 === 4.3.1 Step 1 : To create an AWS Lambda function that sends a text message ===
1125
1126
1127 ==== (% style="color:blue" %)**1.  Create a new AWS Lambda function.**(%%) ====
1128
1129
1130 (% style="color:red" %)**a.**(%%) In the [[AWS Lambda console>>url:https://console.aws.amazon.com/lambda/home]], choose Create function.
1131
1132 [[image:image-20220525191138-32.png]]
1133
1134 Create function
1135
1136
1137 (((
1138 (% 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**.
1139 )))
1140
1141 [[image:image-20220525191640-33.png]]
1142
1143 blueprint
1144
1145
1146 (% style="color:red" %)**c. **(%%)In Basic information:
1147
1148 (% class="box" %)
1149 (((
1150 1). In Function name, enter the name of this function, format-high-temp-notification.
1151 2). In Execution role, choose Create a new role from AWS policy templates.
1152 3). In Role name, enter the name of the new role, format-high-temp-notification-role.
1153 4). In Policy templates - optional, search for and select Amazon SNS publish policy.
1154 5). Choose Create function.
1155 )))
1156
1157 [[image:image-20220525191717-34.png]]
1158
1159 blueprint
1160
1161
1162 ==== (% style="color:blue" %)**2.  Modify the blueprint code to format and send an Amazon SNS notification.**(%%) ====
1163
1164
1165 (((
1166 (% 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.
1167 )))
1168
1169 (((
1170 (% style="color:red" %)**b.**(%%) In the format-high-temp-notification details page, choose the Configuration tab and scroll to the Function code panel.
1171 )))
1172
1173 (((
1174 (% style="color:red" %)**c. **(%%)In the Function code window, in the Environment pane, choose the Python file, lambda_function.py.
1175 )))
1176
1177 (((
1178 (% 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.
1179
1180
1181 )))
1182
1183 (% class="box" %)
1184 (((
1185 from ~_~_future~_~_ import print_function
1186 import json
1187 import boto3
1188 print('Loading function')
1189 def lambda_handler(event, context):
1190 # Parse the JSON message
1191 eventText = json.dumps(event)
1192 # 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.
1193 print('Received event: ', eventText)
1194 # Create an SNS client
1195 sns = boto3.client('sns')
1196 # Publish a message to the specified topic
1197 response = sns.publish (
1198 TopicArn = 'arn:aws:iam::123456789012:My_IoT_SNS_Topic',
1199 Message = eventText
1200 )
1201 print(response)
1202 )))
1203
1204 (% style="color:red" %)**e.**(%%) Choose Deploy.
1205
1206
1207 (% 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]]
1208
1209 (% 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
1210
1211
1212 ==== (% 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.**(%%) ====
1213
1214
1215 (((
1216 (% style="color:red" %)**a. **(%%)In a new window, open the Topics page of the Amazon SNS console
1217 )))
1218
1219 (((
1220 (% style="color:red" %)**b.**(%%) In the Topics page, find the high_temp_notice notification topic in the list of Amazon SNS topics.
1221 )))
1222
1223 (((
1224 (% style="color:red" %)**c.** (%%)Find the ARN of the high_temp_notice notification topic to use in the next step.
1225
1226
1227 )))
1228
1229 ==== (% style="color:blue" %)**4.  Create a test case for your Lambda function.**(%%) ====
1230
1231
1232 (% style="color:red" %)**a.**(%%) In the Lambda Functionspage of the console,from (% style="color:red" %)**Select a test event**(%%)to select Configure test events
1233
1234 [[image:image-20220525191819-35.png||height="706" width="1412"]]
1235
1236 Configure test events
1237
1238
1239 (((
1240 (% style="color:red" %)**b. **(%%)On Configure test event, enter a name for your test event and replace the message JSON with the following:
1241 )))
1242
1243 (% class="box" %)
1244 (((
1245 {
1246 "message" : "Hello, world"
1247 }
1248 )))
1249
1250
1251 (% style="color:red" %)**c.** (%%)choose Create
1252
1253 [[image:image-20220525191853-36.png]]
1254
1255 event create
1256
1257
1258 (((
1259 (% 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.
1260 )))
1261
1262 [[image:image-20220525191938-37.png||height="705" width="1416"]]
1263
1264 event test
1265
1266
1267 (% style="color:red" %)**e.**(%%) Under your Lambda function code, on the Execution result tab, you see the output from the Lambda function.
1268
1269 [[image:image-20220525192325-38.png||height="716" width="1412"]]
1270
1271 event output
1272
1273
1274 Now The Lambda function table is created
1275
1276
1277
1278 === 4.3.2 Step 2 : Create Rule with Lambda function ===
1279
1280
1281 (% style="color:red" %)**1. **(%%)Browse to the AWS IoT console, and in the navigation pane, select (% style="color:red" %)**Act**
1282
1283 File: Console Act.png
1284
1285 (((
1286 (% class="box infomessage" %)
1287 (((
1288 **console_Act**
1289 )))
1290 )))
1291
1292
1293 (% style="color:red" %)**2. **(%%)Choose Create to create an AWS IoT rule.
1294
1295 [[image:image-20220525192403-39.png]]
1296
1297 create Rule
1298
1299
1300 (% style="color:red" %)**3.** (%%)On the Create a rule page, enter a name for your rule.
1301
1302 [[image:image-20220525192424-40.png]]
1303
1304 enter a Rule name
1305
1306
1307 (% style="color:red" %)**4.**(%%) In Rule query statement, enter the following query:
1308
1309
1310 (((
1311 (% class="box infomessage" %)
1312 (((
1313 **SELECT * FROM "my/lambda/topic"**
1314 )))
1315 )))
1316
1317 [[image:image-20220525192453-41.png]]
1318
1319 enter the following query
1320
1321
1322 (% style="color:red" %)**5.**(%%) In Set one or more actions, select Add action.
1323
1324 [[image:image-20220525192524-42.png||height="840" width="1414"]]
1325
1326 Add action
1327
1328
1329 (% style="color:red" %)**6.**(%%) Under the select operation, select Send a Message to a Lambda Function and then select the configuration operation.
1330
1331 [[image:image-20220525192619-43.png]]
1332
1333 select operation
1334
1335
1336 = 5. For End Node =
1337
1338 == 5.1 AWS Downlink Note ==
1339
1340
1341 Prerequisites: The node must be online in real-time before downlink.
1342
1343
1344 [[image:image-20220525113243-2.png||height="346" width="623"]]
1345
1346 Convert the data to Base64
1347
1348 [[image:image-20220525113612-3.png||height="377" width="622"]]
1349
1350
1351 When the serial port logs of downlink are received, the Receive date is displayed
1352
1353 [[image:image-20220525115046-4.png]]
1354
1355 In addition to the above methods, there is also a downlink,This method requires a certain amount of manipulation,
1356
1357 Users can view this [[Downlink method 2>>url:https://github.com/aws-samples/aws-iot-core-lorawan/tree/main/send_downlink_payload]]
1358
1359
1360 == 5.2 Node decoder ==
1361
1362
1363 [[Decode LHT65>>url:https://github.com/aws-samples/aws-iot-core-lorawan/tree/main/transform_binary_payload]]
1364
1365
1366 = 6. Trouble Shooting =
1367
1368 == 6.1 Time sync& Time drift ==
1369
1370
1371 === **Time Sync** ===
1372
1373 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.
1374
1375
1376 For example, the station keeps statistics on the time sync quality and discards measurements whose quality is considered an outlier:
1377
1378 Time sync rejected: quality=413 threshold=354 and  Time sync qualities: min=293 q90=354 max=407 (previous q90=2147483647)
1379
1380 [[image:image-20230721092820-2.png]]
1381
1382
1383 === **Time drift** ===
1384
1385
1386 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
1387
1388 [[image:image-20230721092542-1.png]]
1389
1390
1391 = 7. Reference =
1392
1393
1394 * [[Video Introduction for how to use LoRaWAN AWS-IoT Core>>url:https://www.youtube.com/watch?v=eKK0M8iC6l4]]
1395
1396 * [[AWS LoRaWAN Workshop>>url:https://iotwireless.workshop.aws/]]
Copyright ©2010-2022 Dragino Technology Co., LTD. All rights reserved
Dragino Wiki v2.0