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