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