Version 29.5 by Xiaoling on 2022/06/01 18:00

Show last authors
1 (% style="text-align:center" %)
2 [[image:1652947681187-144.png||height="385" width="385"]]
3
4
5
6
7 **RS485-BL – Waterproof RS485 to LoRaWAN Converter User Manual**
8
9
10
11 **Table of Contents:**
12
13 {{toc/}}
14
15
16
17
18
19 = 1.Introduction =
20
21 == 1.1 What is RS485-BL RS485 to LoRaWAN Converter ==
22
23 (((
24
25 )))
26
27 (((
28 The Dragino RS485-BL is a **RS485 / UART to LoRaWAN Converter** for Internet of Things solutions. User can connect RS485 or UART sensor to RS485-BL converter, and configure RS485-BL to periodically read sensor data and upload via LoRaWAN network to IoT server.
29 )))
30
31 (((
32 RS485-BL can interface to RS485 sensor, 3.3v/5v UART sensor or interrupt sensor. RS485-BL provides **a 3.3v output** and** a 5v output** to power external sensors. Both output voltages are controllable to minimize the total system power consumption.
33 )))
34
35 (((
36 RS485-BL is IP67 **waterproof** and powered by **8500mAh Li-SOCI2 battery**, it is designed for long term use for several years.
37 )))
38
39 (((
40 RS485-BL runs standard **LoRaWAN 1.0.3 in Class A**. It can reach long transfer range and easy to integrate with LoRaWAN compatible gateway and IoT server.
41 )))
42
43 (((
44 For data uplink, RS485-BL sends user-defined commands to RS485 devices and gets the return from the RS485 devices. RS485-BL will process these returns data according to user-define rules to get the final payload and upload to LoRaWAN server.
45 )))
46
47 (((
48 For data downlink, RS485-BL runs in LoRaWAN Class A. When there is downlink commands from LoRaWAN server, RS485-BL will forward the commands from LoRaWAN server to RS485 devices.
49 )))
50
51 (((
52 Each RS485-BL pre-load with a set of unique keys for LoRaWAN registration, register these keys to LoRaWAN server and it will auto connect after power on.
53 )))
54
55 [[image:1652953304999-717.png||height="424" width="733"]]
56
57 == 1.2 Specifications ==
58
59 **Hardware System:**
60
61 * STM32L072CZT6 MCU
62 * SX1276/78 Wireless Chip 
63 * Power Consumption (exclude RS485 device):
64 ** Idle: 6uA@3.3v
65
66 *
67 ** 20dB Transmit: 130mA@3.3v
68
69 **Interface for Model:**
70
71 * 1 x RS485 Interface
72 * 1 x TTL Serial , 3.3v or 5v.
73 * 1 x I2C Interface, 3.3v or 5v.
74 * 1 x one wire interface
75 * 1 x Interrupt Interface
76 * 1 x Controllable 5V output, max
77
78 **LoRa Spec:**
79
80 * Frequency Range:
81 ** Band 1 (HF): 862 ~~ 1020 Mhz
82 ** Band 2 (LF): 410 ~~ 528 Mhz
83 * 168 dB maximum link budget.
84 * +20 dBm - 100 mW constant RF output vs.
85 * Programmable bit rate up to 300 kbps.
86 * High sensitivity: down to -148 dBm.
87 * Bullet-proof front end: IIP3 = -12.5 dBm.
88 * Excellent blocking immunity.
89 * Fully integrated synthesizer with a resolution of 61 Hz.
90 * LoRa modulation.
91 * Built-in bit synchronizer for clock recovery.
92 * Preamble detection.
93 * 127 dB Dynamic Range RSSI.
94 * Automatic RF Sense and CAD with ultra-fast AFC. ​​​
95
96 == 1.3 Features ==
97
98 * LoRaWAN Class A & Class C protocol (default Class A)
99 * Frequency Bands: CN470/EU433/KR920/US915/EU868/AS923/AU915/IN865/RU864
100 * AT Commands to change parameters
101 * Remote configure parameters via LoRaWAN Downlink
102 * Firmware upgradable via program port
103 * Support multiply RS485 devices by flexible rules
104 * Support Modbus protocol
105 * Support Interrupt uplink
106
107 == 1.4 Applications ==
108
109 * Smart Buildings & Home Automation
110 * Logistics and Supply Chain Management
111 * Smart Metering
112 * Smart Agriculture
113 * Smart Cities
114 * Smart Factory
115
116 == 1.5 Firmware Change log ==
117
118 [[RS485-BL Image files – Download link and Change log>>url:http://www.dragino.com/downloads/index.php?dir=LoRa_End_Node/RS485-BL/Firmware/||style="background-color: rgb(255, 255, 255);"]]
119
120 == 1.6 Hardware Change log ==
121
122 (((
123 v1.4
124 )))
125
126 (((
127 ~1. Change Power IC to TPS22916
128 )))
129
130
131 (((
132 v1.3
133 )))
134
135 (((
136 ~1. Change JP3 from KF350-8P to KF350-11P, Add one extra interface for I2C and one extra interface for one-wire
137 )))
138
139
140 (((
141 v1.2
142 )))
143
144 (((
145 Release version ​​​​​
146 )))
147
148 = 2. Pin mapping and Power ON Device =
149
150 (((
151 The RS485-BL is powered on by 8500mAh battery. To save battery life, RS485-BL is shipped with power off. User can put the jumper to power on RS485-BL.
152 )))
153
154 [[image:1652953055962-143.png||height="387" width="728"]]
155
156
157 The Left TXD and RXD are TTL interface for external sensor. TTL level is controlled by 3.3/5v Jumper.
158
159 = 3. Operation Mode =
160
161 == 3.1 How it works? ==
162
163 (((
164 The RS485-BL is configured as LoRaWAN OTAA Class A mode by default. It has OTAA keys to join network. To connect a local LoRaWAN network, user just need to input the OTAA keys in the network server and power on the RS485-BL. It will auto join the network via OTAA.
165 )))
166
167 == 3.2 Example to join LoRaWAN network ==
168
169 Here shows an example for how to join the TTN V3 Network. Below is the network structure, we use [[LG308>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/140-lg308.html]] as LoRaWAN gateway here. 
170
171 [[image:1652953414711-647.png||height="337" width="723"]]
172
173 (((
174 The RS485-BL in this example connected to two RS485 devices for demonstration, user can connect to other RS485 devices via the same method.
175 )))
176
177 (((
178 The LG308 is already set to connect to [[TTN V3 network >>url:https://www.thethingsnetwork.org/]]. So what we need to now is only configure the TTN V3:
179 )))
180
181 (((
182 **Step 1**: Create a device in TTN V3 with the OTAA keys from RS485-BL.
183 )))
184
185 (((
186 Each RS485-BL is shipped with a sticker with unique device EUI:
187 )))
188
189 [[image:1652953462722-299.png]]
190
191 (((
192 User can enter this key in their LoRaWAN Server portal. Below is TTN V3 screen shot:
193 )))
194
195 (((
196 Add APP EUI in the application.
197 )))
198
199
200
201
202 [[image:image-20220519174512-1.png]]
203
204 [[image:image-20220519174512-2.png||height="328" width="731"]]
205
206 [[image:image-20220519174512-3.png||height="556" width="724"]]
207
208 [[image:image-20220519174512-4.png]]
209
210 You can also choose to create the device manually.
211
212 [[image:1652953542269-423.png||height="710" width="723"]]
213
214 Add APP KEY and DEV EUI
215
216 [[image:1652953553383-907.png||height="514" width="724"]]
217
218
219 (((
220 **Step 2**: Power on RS485-BL and it will auto join to the TTN V3 network. After join success, it will start to upload message to TTN V3 and user can see in the panel.
221 )))
222
223 [[image:1652953568895-172.png||height="232" width="724"]]
224
225 == 3.3 Configure Commands to read data ==
226
227 (((
228 There are plenty of RS485 and TTL level devices in the market and each device has different command to read the valid data. To support these devices in flexible, RS485-BL supports flexible command set. User can use [[AT Commands or LoRaWAN Downlink>>path:#AT_COMMAND]] Command to configure how RS485-BL should read the sensor and how to handle the return from RS485 or TTL sensors.
229 )))
230
231 === 3.3.1 onfigure UART settings for RS485 or TTL communication ===
232
233 RS485-BL can connect to either RS485 sensors or TTL sensor. User need to specify what type of sensor need to connect.
234
235 **~1. RS485-MODBUS mode:**
236
237 AT+MOD=1 ~/~/ Support RS485-MODBUS type sensors. User can connect multiply RS485 , Modbus sensors to the A / B pins.
238
239 **2. TTL mode:**
240
241 AT+MOD=2 ~/~/ Support TTL Level sensors, User can connect one TTL Sensor to the TXD/RXD/GND pins.
242
243 RS485-BL default UART settings is **9600, no parity, stop bit 1**. If the sensor has a different settings, user can change the RS485-BL setting to match.
244
245 (% border="1" style="background-color:#ffffcc; color:green; width:795px" %)
246 |(((
247 **AT Commands**
248 )))|(% style="width:285px" %)(((
249 **Description**
250 )))|(% style="width:347px" %)(((
251 **Example**
252 )))
253 |(((
254 AT+BAUDR
255 )))|(% style="width:285px" %)(((
256 Set the baud rate (for RS485 connection). Default Value is: 9600.
257 )))|(% style="width:347px" %)(((
258 (((
259 AT+BAUDR=9600
260 )))
261
262 (((
263 Options: (1200,2400,4800,14400,19200,115200)
264 )))
265 )))
266 |(((
267 AT+PARITY
268 )))|(% style="width:285px" %)(((
269 (((
270 Set UART parity (for RS485 connection)
271 )))
272
273 (((
274 Default Value is: no parity.
275 )))
276 )))|(% style="width:347px" %)(((
277 (((
278 AT+PARITY=0
279 )))
280
281 (((
282 Option: 0: no parity, 1: odd parity, 2: even parity
283 )))
284 )))
285 |(((
286 AT+STOPBIT
287 )))|(% style="width:285px" %)(((
288 (((
289 Set serial stopbit (for RS485 connection)
290 )))
291
292 (((
293 Default Value is: 1bit.
294 )))
295 )))|(% style="width:347px" %)(((
296 (((
297 AT+STOPBIT=0 for 1bit
298 )))
299
300 (((
301 AT+STOPBIT=1 for 1.5 bit
302 )))
303
304 (((
305 AT+STOPBIT=2 for 2 bits
306 )))
307 )))
308
309 === 3.3.2 Configure sensors ===
310
311 (((
312 Some sensors might need to configure before normal operation. User can configure such sensor via PC or through RS485-BL AT Commands (% style="color:#4f81bd" %)**AT+CFGDEV**.
313 )))
314
315 (((
316 When user issue an (% style="color:#4f81bd" %)**AT+CFGDEV**(%%) command, Each (% style="color:#4f81bd" %)**AT+CFGDEV**(%%) equals to send a command to the RS485 or TTL sensors. This command will only run when user input it and won’t run during each sampling.
317 )))
318
319 (% border="1" style="background-color:#ffffcc; color:green; width:806px" %)
320 |**AT Commands**|(% style="width:418px" %)**Description**|(% style="width:256px" %)**Example**
321 |AT+CFGDEV|(% style="width:418px" %)(((
322 This command is used to configure the RS485/TTL devices; they won’t be used during sampling.
323
324 AT+CFGDEV=xx xx xx xx xx xx xx xx xx xx xx xx,
325
326 mm: 0: no CRC, 1: add CRC-16/MODBUS in the end of this command
327 )))|(% style="width:256px" %)AT+CFGDEV=xx xx xx xx xx xx xx xx xx xx xx xx,m
328
329 Detail of AT+CFGDEV command see [[AT+CFGDEV detail>>path:#AT_CFGDEV]].
330
331 === 3.3.3 Configure read commands for each sampling ===
332
333 (((
334 RS485-BL is a battery powered device; it will sleep most of time. And wake up on each period and read RS485 / TTL sensor data and uplink.
335 )))
336
337 (((
338 During each sampling, we need to confirm what commands we need to send to the sensors to read data. After the RS485/TTL sensors send back the value, it normally includes some bytes and we only need a few from them for a shorten payload.
339 )))
340
341 (((
342 To save the LoRaWAN network bandwidth, we might need to read data from different sensors and combine their valid value into a short payload.
343 )))
344
345 (((
346 This section describes how to achieve above goals.
347 )))
348
349 (((
350 During each sampling, the RS485-BL can support 15 commands to read sensors. And combine the return to one or several uplink payloads.
351 )))
352
353 (((
354 **Command from RS485-BL to Sensor:**
355 )))
356
357 (((
358 RS485-BL can send out pre-set max 15 strings via **AT+COMMAD1**, **ATCOMMAND2**,…, to **AT+COMMANDF** . All commands are of same grammar.
359 )))
360
361 (((
362 **Handle return from sensors to RS485-BL**:
363 )))
364
365 (((
366 After RS485-BL send out a string to sensor, RS485-BL will wait for the return from RS485 or TTL sensor. And user can specify how to handle the return, by **AT+DATACUT or AT+SEARCH commands**
367 )))
368
369 * (((
370 **AT+DATACUT**
371 )))
372
373 (((
374 When the return value from sensor have fix length and we know which position the valid value we should get, we can use AT+DATACUT command.
375 )))
376
377 * (((
378 **AT+SEARCH**
379 )))
380
381 (((
382 When the return value from sensor is dynamic length and we are not sure which bytes the valid data is, instead, we know what value the valid value following. We can use AT+SEARCH to search the valid value in the return string.
383 )))
384
385 (((
386 **Define wait timeout:**
387 )))
388
389 (((
390 Some RS485 device might has longer delay on reply, so user can use AT+CMDDL to set the timeout for getting reply after the RS485 command is sent. For example, AT+CMDDL1=1000 to send the open time to 1000ms
391 )))
392
393 (((
394 After we got the valid value from each RS485 commands, we need to combine them together with the command **AT+DATAUP**.
395 )))
396
397 **Examples:**
398
399 Below are examples for the how above AT Commands works.
400
401 **AT+COMMANDx : **This command will be sent to RS485/TTL devices during each sampling, Max command length is 14 bytes. The grammar is:
402
403 (% border="1" class="table-bordered" style="background-color:#4f81bd; color:white; width:501px" %)
404 |(% style="width:498px" %)(((
405 **AT+COMMANDx=xx xx xx xx xx xx xx xx xx xx xx xx,m**
406
407 **xx xx xx xx xx xx xx xx xx xx xx xx: The RS485 command to be sent**
408
409 **m: 0: no CRC, 1: add CRC-16/MODBUS in the end of this command**
410 )))
411
412 For example, if we have a RS485 sensor. The command to get sensor value is: 01 03 0B B8 00 02 46 0A. Where 01 03 0B B8 00 02 is the Modbus command to read the register 0B B8 where stored the sensor value. The 46 0A is the CRC-16/MODBUS which calculate manually.
413
414 In the RS485-BL, we should use this command AT+COMMAND1=01 03 0B B8 00 02,1 for the same.
415
416 **AT+SEARCHx**: This command defines how to handle the return from AT+COMMANDx.
417
418 (% border="1" class="table-bordered" style="background-color:#4f81bd; color:white; width:580px" %)
419 |(% style="width:577px" %)(((
420 **AT+SEARCHx=aa,xx xx xx xx xx**
421
422 * **aa: 1: prefix match mode; 2: prefix and suffix match mode**
423 * **xx xx xx xx xx: match string. Max 5 bytes for prefix and 5 bytes for suffix**
424 )))
425
426 **Examples:**
427
428 1. For a return string from AT+COMMAND1: 16 0c 1e 56 34 2e 30 58 5f 36 41 30 31 00 49
429
430 If we set AT+SEARCH1=1,1E 56 34.      (max 5 bytes for prefix)
431
432 The valid data will be all bytes after 1E 56 34 , so it is (% style="background-color:yellow" %)**2e 30 58 5f 36 41 30 31 00 49**
433
434 [[image:1653271044481-711.png]]
435
436 1. For a return string from AT+COMMAND1:  16 0c 1e 56 34 2e 30 58 5f 36 41 30 31 00 49
437
438 If we set AT+SEARCH1=2, 1E 56 34+31 00 49
439
440 Device will search the bytes between 1E 56 34 and 31 00 49. So it is(% style="background-color:yellow" %) **2e 30 58 5f 36 41 30**
441
442 [[image:1653271276735-972.png]]
443
444 **AT+DATACUTx : **This command defines how to handle the return from AT+COMMANDx, max return length is 45 bytes.
445
446 (% style="background-color:#4f81bd; color:white; width:729px" %)
447 |(% style="width:726px" %)(((
448 **AT+DATACUTx=a,b,c**
449
450 * **a: length for the return of AT+COMMAND**
451 * **b:1: grab valid value by byte, max 6 bytes. 2: grab valid value by bytes section, max 3 sections.**
452 * **c: define the position for valid value.  **
453 )))
454
455 Examples:
456
457 * Grab bytes:
458
459 [[image:1653271581490-837.png||height="313" width="722"]]
460
461 * Grab a section.
462
463 [[image:1653271648378-342.png||height="326" width="720"]]
464
465 * Grab different sections.
466
467 [[image:1653271657255-576.png||height="305" width="730"]]
468
469 (((
470 (% style="color:red" %)**Note:**
471 )))
472
473 (((
474 AT+SEARCHx and AT+DATACUTx can be used together, if both commands are set, RS485-BL will first process AT+SEARCHx on the return string and get a temporary string, and then process AT+DATACUTx on this temporary string to get the final payload. In this case, AT+DATACUTx need to set to format AT+DATACUTx=0,xx,xx where the return bytes set to 0.
475 )))
476
477 (((
478 **Example:**
479 )))
480
481 (((
482 (% style="color:red" %)AT+COMMAND1=11 01 1E D0,0
483 )))
484
485 (((
486 (% style="color:red" %)AT+SEARCH1=1,1E 56 34
487 )))
488
489 (((
490 (% style="color:red" %)AT+DATACUT1=0,2,1~~5
491 )))
492
493 (((
494 (% style="color:red" %)Return string from AT+COMMAND1: 16 0c 1e 56 34 2e 30 58 5f 36 41 30 31 00 49
495 )))
496
497 (((
498 (% style="color:red" %)String after SEARCH command: 2e 30 58 5f 36 41 30 31 00 49
499 )))
500
501 (((
502 (% style="color:red" %)Valid payload after DataCUT command: 2e 30 58 5f 36
503 )))
504
505 [[image:1653271763403-806.png]]
506
507 === 3.3.4 Compose the uplink payload ===
508
509 (((
510 Through AT+COMMANDx and AT+DATACUTx we got valid value from each RS485 commands, Assume these valid value are RETURN1, RETURN2, .., to RETURNx. The next step is how to compose the LoRa Uplink Payload by these RETURNs. The command is **AT+DATAUP.**
511 )))
512
513 (((
514 (% style="color:#4f81bd" %)**Examples: AT+DATAUP=0**
515 )))
516
517 (((
518 Compose the uplink payload with value returns in sequence and send with (% style="color:red" %)**A SIGNLE UPLINK**.
519 )))
520
521 (((
522 Final Payload is
523 )))
524
525 (((
526 (% style="color:#4f81bd" %)Battery Info+PAYVER + VALID Value from RETURN1 + Valid Value from RETURN2 + … + RETURNx
527 )))
528
529 (((
530 Where PAYVER is defined by AT+PAYVER, below is an example screen shot.
531 )))
532
533 [[image:1653272787040-634.png||height="515" width="719"]]
534
535 (((
536 (% style="color:#4f81bd" %)**Examples: AT+DATAUP=1**
537 )))
538
539 (((
540 Compose the uplink payload with value returns in sequence and send with (% style="color:red" %)**Multiply UPLINKs**.
541 )))
542
543 (((
544 Final Payload is
545 )))
546
547 (((
548 (% style="color:#4f81bd" %)Battery Info+PAYVER + PAYLOAD COUNT + PAYLOAD# + DATA
549 )))
550
551 1. (((
552 Battery Info (2 bytes): Battery voltage
553 )))
554 1. (((
555 PAYVER (1 byte): Defined by AT+PAYVER
556 )))
557 1. (((
558 PAYLOAD COUNT (1 byte): Total how many uplinks of this sampling.
559 )))
560 1. (((
561 PAYLOAD# (1 byte): Number of this uplink. (from 0,1,2,3…,to PAYLOAD COUNT)
562 )))
563 1. (((
564 DATA: Valid value: max 6 bytes(US915 version here, Notice*!) for each uplink so each uplink <= 11 bytes. For the last uplink, DATA will might less than 6 bytes
565 )))
566
567 [[image:1653272817147-600.png||height="437" width="717"]]
568
569 So totally there will be 3 uplinks for this sampling, each uplink includes 6 bytes DATA
570
571 DATA1=RETURN1 Valid Value = (% style="background-color:#4f81bd; color:white" %) 20 20 0a 33 90 41
572
573 DATA2=1^^st^^ ~~ 6^^th^^ byte of Valid value of RETURN10= (% style="background-color:#4f81bd; color:white" %)02 aa 05 81 0a 20
574
575 DATA3=7^^th^^ ~~ 11^^th^^ bytes of Valid value of RETURN10 =(% style="background-color:#4f81bd; color:white" %) 20 20 20 2d 30
576
577 Below are the uplink payloads:
578
579 [[image:1653272901032-107.png]]
580
581 (% style="color:red" %)Notice: the Max bytes is according to the max support bytes in different Frequency Bands for lowest SF. As below:
582
583 ~* For AU915/AS923 bands, if UplinkDwell time=0, max 51 bytes for each uplink ( so 51 -5 = 46 max valid date)
584
585 * For AU915/AS923 bands, if UplinkDwell time=1, max 11 bytes for each uplink ( so 11 -5 = 6 max valid date).
586
587 * For US915 band, max 11 bytes for each uplink ( so 11 -5 = 6 max valid date).
588
589 ~* For all other bands: max 51 bytes for each uplink  ( so 51 -5 = 46 max valid date).
590
591 === 3.3.5 Uplink on demand ===
592
593 (((
594 Except uplink periodically, RS485-BL is able to uplink on demand. The server sends downlink command to RS485-BL and RS485 will uplink data base on the command.
595 )))
596
597 (((
598 Downlink control command:
599 )))
600
601 (((
602 **0x08 command**: Poll an uplink with current command set in RS485-BL.
603 )))
604
605 (((
606 **0xA8 command**: Send a command to RS485-BL and uplink the output from sensors.
607 )))
608
609 === 3.3.6 Uplink on Interrupt ===
610
611 Put the interrupt sensor between 3.3v_out and GPIO ext.
612
613 [[image:1653273818896-432.png]]
614
615 (((
616 AT+INTMOD=0  Disable Interrupt
617 )))
618
619 (((
620 AT+INTMOD=1  Interrupt trigger by rising or falling edge.
621 )))
622
623 (((
624 AT+INTMOD=2  Interrupt trigger by falling edge. ( Default Value)
625 )))
626
627 (((
628 AT+INTMOD=3  Interrupt trigger by rising edge.
629 )))
630
631 == 3.4 Uplink Payload ==
632
633 (% border="1" style="background-color:#4f81bd; color:white; width:850px" %)
634 |**Size(bytes)**|(% style="width:130px" %)**2**|(% style="width:93px" %)**1**|(% style="width:509px" %)**Length depends on the return from the commands**
635 |Value|(% style="width:130px" %)(((
636 (((
637 Battery(mV)
638 )))
639
640 (((
641 &
642 )))
643
644 (((
645 Interrupt _Flag
646 )))
647 )))|(% style="width:93px" %)(((
648 PAYLOAD_VER
649
650
651 )))|(% style="width:509px" %)If the valid payload is too long and exceed the maximum support payload length in server, server will show payload not provided in the LoRaWAN server.
652
653 Below is the decoder for the first 3 bytes. The rest bytes are dynamic depends on different RS485 sensors.
654
655 (((
656 function Decoder(bytes, port) {
657 )))
658
659 (((
660 ~/~/Payload Formats of RS485-BL Deceive
661 )))
662
663 (((
664 return {
665 )))
666
667 (((
668 ~/~/Battery,units:V
669 )))
670
671 (((
672 BatV:((bytes[0]<<8 | bytes[1])&0x7fff)/1000,
673 )))
674
675 (((
676 ~/~/GPIO_EXTI 
677 )))
678
679 (((
680 EXTI_Trigger:(bytes[0] & 0x80)? "TRUE":"FALSE",
681 )))
682
683 (((
684 ~/~/payload of version
685 )))
686
687 (((
688 Pay_ver:bytes[2],
689 )))
690
691 (((
692 };
693 )))
694
695 (((
696 }
697 )))
698
699 (((
700 TTN V3 uplink screen shot.
701 )))
702
703 [[image:1653274001211-372.png||height="192" width="732"]]
704
705 == 3.5 Configure RS485-BL via AT or Downlink ==
706
707 User can configure RS485-BL via [[AT Commands >>path:#_​Using_the_AT]]or LoRaWAN Downlink Commands
708
709 There are two kinds of Commands:
710
711 * **Common Commands**: They should be available for each sensor, such as: change uplink interval, reset device. For firmware v1.3, user can find what common commands it supports: http:~/~/wiki.dragino.com/index.php?title=End_Device_AT_Commands_and_Downlink_Commands
712
713 * **Sensor Related Commands**: These commands are special designed for RS485-BL.  User can see these commands below:
714
715 1.
716 11.
717 111. Common Commands:
718
719 They should be available for each of Dragino Sensors, such as: change uplink interval, reset device. For firmware v1.3, user can find what common commands it supports: [[http:~~/~~/wiki.dragino.com/index.php?title=End_Device_AT_Commands_and_Downlink_Commands>>url:http://wiki.dragino.com/index.php?title=End_Device_AT_Commands_and_Downlink_Commands]]
720
721
722 1.
723 11.
724 111. Sensor related commands:
725
726 ==== Choose Device Type (RS485 or TTL) ====
727
728 RS485-BL can connect to either RS485 sensors or TTL sensor. User need to specify what type of sensor need to connect.
729
730 * AT Command
731
732 **AT+MOD=1** ~/~/ Set to support RS485-MODBUS type sensors. User can connect multiply RS485 , Modbus sensors to the A / B pins.
733
734 **AT+MOD=2** ~/~/ Set to support TTL Level sensors, User can connect one TTL Sensor to the TXD/RXD/GND pins.
735
736
737 * Downlink Payload
738
739 **0A aa**     à same as AT+MOD=aa
740
741
742
743 ==== [[RS485 Debug Command>>path:#downlink_A8]] (AT+CFGDEV) ====
744
745 This command is used to configure the RS485 or TTL sensors; they won’t be used during sampling.
746
747 * AT Command
748
749 AT+CFGDEV=xx xx xx xx xx xx xx xx xx xx xx xx,m
750
751 m: 0: no CRC; 1: add CRC-16/MODBUS in the end of this command.
752
753
754
755 * Downlink Payload
756
757 Format: A8 MM NN XX XX XX XX YY
758
759 Where:
760
761 * MM: 1: add CRC-16/MODBUS ; 0: no CRC
762 * NN: The length of RS485 command
763 * XX XX XX XX: RS485 command total NN bytes
764 * YY: How many bytes will be uplink from the return of this RS485 command, if YY=0, RS485-BL will execute the downlink command without uplink; if YY>0, RS485-BL will uplink total YY bytes from the output of this RS485 command
765
766 **Example 1:**
767
768 To connect a Modbus Alarm with below commands.
769
770 * The command to active alarm is: 0A 05 00 04 00 01 4C B0. Where 0A 05 00 04 00 01 is the Modbus command to read the register 00 40 where stored the DI status. The 4C B0 is the CRC-16/MODBUS which calculate manually.
771
772 * The command to deactivate alarm is: 0A 05 00 04 00 00 8D 70. Where 0A 05 00 04 00 00 is the Modbus command to read the register 00 40 where stored the DI status. The 8D 70 is the CRC-16/MODBUS which calculate manually.
773
774 So if user want to use downlink command to control to RS485 Alarm, he can use:
775
776 **A8 01 06 0A 05 00 04 00 01 00**: to activate the RS485 Alarm
777
778 **A8 01 06 0A 05 00 04 00 00 00**: to deactivate the RS485 Alarm
779
780 A8 is type code and 01 means add CRC-16/MODBUS at the end, the 3^^rd^^ byte is 06, means the next 6 bytes are the command to be sent to the RS485 network, the final byte 00 means this command don’t need to acquire output.
781
782
783 **Example 2:**
784
785 Check TTL Sensor return:
786
787 [[image:file:///C:/Users/93456/AppData/Local/Temp/msohtmlclip1/01/clip_image024.png]]
788
789
790
791
792 ==== Set Payload version ====
793
794 This is the first byte of the uplink payload. RS485-BL can connect to different sensors. User can set the PAYVER field to tell server how to decode the current payload.
795
796 * AT Command:
797
798 AT+PAYVER: Set PAYVER field = 1
799
800
801 * Downlink Payload:
802
803 0xAE 01   à Set PAYVER field =  0x01
804
805 0xAE 0F   à Set PAYVER field =  0x0F
806
807
808 ==== Set RS485 Sampling Commands ====
809
810 AT+COMMANDx, AT+DATACUTx and AT+SEARCHx
811
812 These three commands are used to configure how the RS485-BL polling data from Modbus device. Detail of usage please see : [[polling RS485 device>>path:#polling_485]].
813
814
815 * AT Command:
816
817 AT+COMMANDx: Configure RS485 read command to sensor.
818
819 AT+DATACUTx: Configure how to handle return from RS485 devices.
820
821 AT+SEARCHx: Configure search command
822
823
824 * Downlink Payload:
825
826 0xAF downlink command can be used to set AT+COMMANDx or AT+DATACUTx.
827
828 Note: if user use AT+COMMANDx to add a new command, he also need to send AT+DATACUTx downlink.
829
830 Format: AF MM NN LL XX XX XX XX YY
831
832 Where:
833
834 * MM: the ATCOMMAND or AT+DATACUT to be set. Value from 01 ~~ 0F,
835 * NN: 0: no CRC; 1: add CRC-16/MODBUS ; 2: set the AT+DATACUT value.
836 * LL: The length of AT+COMMAND or AT+DATACUT command
837 * XX XX XX XX: AT+COMMAND or AT+DATACUT command
838 * YY: If YY=0, RS485-BL will execute the downlink command without uplink; if YY=1, RS485-BL will execute an uplink after got this command.
839
840 Example:
841
842 **AF 03 01 06 0A 05 00 04 00 01 00**: Same as AT+COMMAND3=0A 05 00 04 00 01,1
843
844 **AF 03 02 06 10 01 05 06 09 0A 00**: Same as AT+DATACUT3=**16**,**1**,**5+6+9+10**
845
846 **AF 03 02 06 0B 02 05 07 08 0A 00**: Same as AT+DATACUT3=**11**,**2**,**5~~7+8~~10**
847
848
849 0xAB downlink command can be used for set AT+SEARCHx
850
851 Example: **AB aa 01 03 xx xx xx** (03 here means there are total 3 bytes after 03) So
852
853 * AB aa 01 03 xx xx xx  same as AT+SEARCHaa=1,xx xx xx
854 * AB aa 02 03 xx xx xx 02 yy yy(03 means there are 3 bytes after 03, they are xx xx xx;02 means there are 2 bytes after 02, they are yy yy) so the commands
855
856 **AB aa 02 03 xx xx xx 02 yy yy**  same as **AT+SEARCHaa=2,xx xx xx+yy yy**
857
858
859 ==== Fast command to handle MODBUS device ====
860
861 AT+MBFUN is valid since v1.3 firmware version. The command is for fast configure to read Modbus devices. It is only valid for the devices which follow the [[MODBUS-RTU protocol>>url:https://www.modbustools.com/modbus.html]].
862
863 This command is valid since v1.3 firmware version
864
865
866 AT+MBFUN has only two value:
867
868 * AT+MBFUN=1: Enable Modbus reading. And get response base on the MODBUS return
869
870 AT+MBFUN=1, device can auto read the Modbus function code: 01, 02, 03 or 04. AT+MBFUN has lower priority vs AT+DATACUT command. If AT+DATACUT command is configured, AT+MBFUN will be ignore.
871
872 * AT+MBFUN=0: Disable Modbus fast reading.
873
874 Example:
875
876 * AT+MBFUN=1 and AT+DATACUT1/AT+DATACUT2 are not configure (0,0,0).
877 * AT+COMMAND1= 01 03 00 10 00 08,1 ~-~-> read slave address 01 , function code 03, start address 00 01, quantity of registers 00 08.
878 * AT+COMMAND2= 01 02 00 40 00 10,1 ~-~-> read slave address 01 , function code 02, start address 00 40, quantity of inputs 00 10.
879
880 [[image:file:///C:/Users/93456/AppData/Local/Temp/msohtmlclip1/01/clip_image025.png]]
881
882
883 [[image:file:///C:/Users/93456/AppData/Local/Temp/msohtmlclip1/01/clip_image026.png]]
884
885
886 * Downlink Commands:
887
888 A9 aa -à Same as AT+MBFUN=aa
889
890
891 ==== RS485 command timeout ====
892
893 Some Modbus device has slow action to send replies. This command is used to configure the RS485-BL to use longer time to wait for their action.
894
895 Default value: 0, range:  0 ~~ 5 seconds
896
897
898 * AT Command:
899
900 AT+CMDDLaa=hex(bb cc)
901
902 Example:
903
904 **AT+CMDDL1=1000** to send the open time to 1000ms
905
906
907 * Downlink Payload:
908
909 0x AA aa bb cc
910
911 Same as: AT+CMDDLaa=hex(bb cc)
912
913 Example:
914
915 0xAA 01 03 E8  à Same as **AT+CMDDL1=1000 ms**
916
917
918 ==== [[Uplink>>path:#downlink_A8]] payload mode ====
919
920 Define to use one uplink or multiple uplinks for the sampling.
921
922 The use of this command please see: [[Compose Uplink payload>>path:#DataUP]]
923
924 * AT Command:
925
926 AT+DATAUP=0
927
928 AT+DATAUP=1
929
930
931 * Downlink Payload:
932
933 0xAD 00   à Same as AT+DATAUP=0
934
935 0xAD 01   à Same as AT+DATAUP=1
936
937
938 ==== Manually trigger an Uplink ====
939
940 Ask device to send an uplink immediately.
941
942 * Downlink Payload:
943
944 0x08 FF, RS485-BL will immediately send an uplink.
945
946
947 ==== Clear RS485 Command ====
948
949 The AT+COMMANDx and AT+DATACUTx settings are stored in special location, user can use below command to clear them.
950
951
952 * AT Command:
953
954 **AT+CMDEAR=mm,nn**   mm: start position of erase ,nn: stop position of erase
955
956 Etc. AT+CMDEAR=1,10 means erase AT+COMMAND1/AT+DATACUT1 to AT+COMMAND10/AT+DATACUT10
957
958 Example screen shot after clear all RS485 commands. 
959
960
961
962 The uplink screen shot is:
963
964 [[image:file:///C:/Users/93456/AppData/Local/Temp/msohtmlclip1/01/clip_image023.png]]
965
966
967 * Downlink Payload:
968
969 0x09 aa bb same as AT+CMDEAR=aa,bb
970
971
972 ==== Set Serial Communication Parameters ====
973
974 Set the Rs485 serial communication parameters:
975
976 * AT Command:
977
978 Set Baud Rate:
979
980 AT+BAUDR=9600    ~/~/ Options: (1200,2400,4800,14400,19200,115200)
981
982
983 Set UART parity
984
985 AT+PARITY=0    ~/~/ Option: 0: no parity, 1: odd parity, 2: even parity
986
987
988 Set STOPBIT
989
990 AT+STOPBIT=0    ~/~/ Option: 0 for 1bit; 1 for 1.5 bit ; 2 for 2 bits
991
992
993 * Downlink Payload:
994
995 A7 01 aa bb: Same  AT+BAUDR=hex(aa bb)*100
996
997 Example:
998
999 * A7 01 00 60   same as AT+BAUDR=9600
1000 * A7 01 04 80  same as AT+BAUDR=115200
1001
1002 A7 02 aa: Same as  AT+PARITY=aa  (aa value: 00 , 01 or 02)
1003
1004 A7 03 aa: Same as  AT+STOPBIT=aa  (aa value: 00 , 01 or 02)
1005
1006
1007 ==== Control output power duration ====
1008
1009 User can set the output power duration before each sampling.
1010
1011 * AT Command:
1012
1013 Example:
1014
1015 AT+3V3T=1000 ~/~/ 3V3 output power will open 1s before each sampling.
1016
1017 AT+5VT=1000 ~/~/ +5V output power will open 1s before each sampling.
1018
1019
1020 * LoRaWAN Downlink Command:
1021
1022 07 01 aa bb  Same as AT+5VT=(aa bb)
1023
1024 07 02 aa bb  Same as AT+3V3T=(aa bb)
1025
1026
1027
1028
1029 1.
1030 11. Buttons
1031
1032 |**Button**|**Feature**
1033 |**RST**|Reboot RS485-BL
1034
1035 1.
1036 11. +3V3 Output
1037
1038 RS485-BL has a Controllable +3V3 output, user can use this output to power external sensor.
1039
1040 The +3V3 output will be valid for every sampling. RS485-BL will enable +3V3 output before all sampling and disable the +3V3 after all sampling. 
1041
1042
1043 The +3V3 output time can be controlled by AT Command.
1044
1045 **AT+3V3T=1000**
1046
1047 Means set +3v3 valid time to have 1000ms. So, the real +3v3 output will actually have 1000ms + sampling time for other sensors.
1048
1049
1050 By default, the AT+3V3T=0. This is a special case, means the +3V3 output is always on at any time
1051
1052
1053 1.
1054 11. +5V Output
1055
1056 RS485-BL has a Controllable +5V output, user can use this output to power external sensor.
1057
1058 The +5V output will be valid for every sampling. RS485-BL will enable +5V output before all sampling and disable the +5v after all sampling. 
1059
1060
1061 The 5V output time can be controlled by AT Command.
1062
1063 **AT+5VT=1000**
1064
1065 Means set 5V valid time to have 1000ms. So, the real 5V output will actually have 1000ms + sampling time for other sensors.
1066
1067
1068 By default, the AT+5VT=0. If the external sensor which require 5v and require more time to get stable state, user can use this command to increase the power ON duration for this sensor.
1069
1070
1071
1072
1073 1.
1074 11. LEDs
1075
1076 |**LEDs**|**Feature**
1077 |**LED1**|Blink when device transmit a packet.
1078
1079 1.
1080 11. Switch Jumper
1081
1082 |**Switch Jumper**|**Feature**
1083 |**SW1**|(((
1084 ISP position: Upgrade firmware via UART
1085
1086 Flash position: Configure device, check running status.
1087 )))
1088 |**SW2**|(((
1089 5V position: set to compatible with 5v I/O.
1090
1091 3.3v position: set to compatible with 3.3v I/O.,
1092 )))
1093
1094 +3.3V: is always ON
1095
1096 +5V: Only open before every sampling. The time is by default, it is AT+5VT=0.  Max open time. 5000 ms.
1097
1098 1. Case Study
1099
1100 User can check this URL for some case studies.
1101
1102 [[http:~~/~~/wiki.dragino.com/index.php?title=APP_RS485_COMMUNICATE_WITH_SENSORS>>url:http://wiki.dragino.com/index.php?title=APP_RS485_COMMUNICATE_WITH_SENSORS]]
1103
1104
1105
1106
1107 1. Use AT Command
1108 11. Access AT Command
1109
1110 RS485-BL supports AT Command set. User can use a USB to TTL adapter plus the 3.5mm Program Cable to connect to RS485-BL to use AT command, as below.
1111
1112 [[image:file:///C:/Users/93456/AppData/Local/Temp/msohtmlclip1/01/clip_image027.png]]
1113
1114
1115 In PC, User needs to set **serial tool**(such as [[putty>>url:https://www.chiark.greenend.org.uk/~~sgtatham/putty/latest.html]], SecureCRT) baud rate to **9600** to access to access serial console of RS485-BL. The default password is 123456. Below is the output for reference:
1116
1117 [[image:file:///C:/Users/93456/AppData/Local/Temp/msohtmlclip1/01/clip_image028.png]]
1118
1119
1120
1121 More detail AT Command manual can be found at [[AT Command Manual>>path:#AT_COMMAND]]
1122
1123
1124
1125 1.
1126 11. Common AT Command Sequence
1127 111. Multi-channel ABP mode (Use with SX1301/LG308)
1128
1129 If device has not joined network yet:
1130
1131 AT+FDR
1132
1133 AT+NJM=0
1134
1135 ATZ
1136
1137
1138 If device already joined network:
1139
1140 AT+NJM=0
1141
1142 ATZ
1143
1144 1.
1145 11.
1146 111. Single-channel ABP mode (Use with LG01/LG02)
1147
1148 AT+FDR   Reset Parameters to Factory Default, Keys Reserve
1149
1150 AT+NJM=0 Set to ABP mode
1151
1152 AT+ADR=0 Set the Adaptive Data Rate Off
1153
1154 AT+DR=5  Set Data Rate
1155
1156 AT+TDC=60000  Set transmit interval to 60 seconds
1157
1158 AT+CHS=868400000 Set transmit frequency to 868.4Mhz
1159
1160 AT+RX2FQ=868400000 Set RX2Frequency to 868.4Mhz (according to the result from server)
1161
1162 AT+RX2DR=5  Set RX2DR to match the downlink DR from server. see below
1163
1164 AT+DADDR=26 01 1A F1 Set Device Address to 26 01 1A F1, this ID can be found in the LoRa Server portal.
1165
1166 ATZ          Reset MCU
1167
1168 **Note:**
1169
1170 1. Make sure the device is set to ABP mode in the IoT Server.
1171 1. Make sure the LG01/02 gateway RX frequency is exactly the same as AT+CHS setting.
1172 1. Make sure SF / bandwidth setting in LG01/LG02 match the settings of AT+DR. refer [[this link>>url:http://www.dragino.com/downloads/index.php?dir=LoRa_Gateway/&file=LoRaWAN%201.0.3%20Regional%20Parameters.xlsx]] to see what DR means.
1173 1. The command AT+RX2FQ and AT+RX2DR is to let downlink work. to set the correct parameters, user can check the actually downlink parameters to be used. As below. Which shows the RX2FQ should use 868400000 and RX2DR should be 5
1174
1175 [[image:file:///C:/Users/93456/AppData/Local/Temp/msohtmlclip1/01/clip_image029.png]]
1176
1177
1178 1. FAQ
1179 11. How to upgrade the image?
1180
1181 The RS485-BL LoRaWAN Controller is shipped with a 3.5mm cable, the cable is used to upload image to RS485-BL to:
1182
1183 * Support new features
1184 * For bug fix
1185 * Change LoRaWAN bands.
1186
1187 Below shows the hardware connection for how to upload an image to RS485-BL:
1188
1189 [[image:file:///C:/Users/93456/AppData/Local/Temp/msohtmlclip1/01/clip_image030.png]]
1190
1191 **Step1:** Download [[flash loader>>url:https://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-programmers/flasher-stm32.html]].
1192
1193 **Step2**: Download the [[LT Image files>>url:http://www.dragino.com/downloads/index.php?dir=LT_LoRa_IO_Controller/LT33222-L/image/]].
1194
1195 **Step3: **Open flashloader; choose the correct COM port to update.
1196
1197
1198 |(((
1199 HOLD PRO then press the RST button, SYS will be ON, then click next
1200 )))
1201
1202 |(((
1203 Board detected
1204 )))
1205
1206 |(((
1207
1208 )))
1209
1210 [[image:file:///C:/Users/93456/AppData/Local/Temp/msohtmlclip1/01/clip_image031.png]] [[image:file:///C:/Users/93456/AppData/Local/Temp/msohtmlclip1/01/clip_image032.png]]
1211
1212
1213
1214 [[image:file:///C:/Users/93456/AppData/Local/Temp/msohtmlclip1/01/clip_image033.png]] [[image:file:///C:/Users/93456/AppData/Local/Temp/msohtmlclip1/01/clip_image034.png]]
1215
1216
1217 [[image:file:///C:/Users/93456/AppData/Local/Temp/msohtmlclip1/01/clip_image035.png]] [[image:file:///C:/Users/93456/AppData/Local/Temp/msohtmlclip1/01/clip_image036.png]]
1218
1219
1220 1.
1221 11. How to change the LoRa Frequency Bands/Region?
1222
1223 User can follow the introduction for [[how to upgrade image>>path:#upgrade_image]]. When download the images, choose the required image file for download.
1224
1225
1226
1227 1.
1228 11. How many RS485-Slave can RS485-BL connects?
1229
1230 The RS485-BL can support max 32 RS485 devices. Each uplink command of RS485-BL can support max 16 different RS485 command. So RS485-BL can support max 16 RS485 devices pre-program in the device for uplink. For other devices no pre-program, user can use the [[downlink message (type code 0xA8) to poll their info>>path:#downlink_A8]].
1231
1232
1233
1234
1235 1. Trouble Shooting     
1236 11. Downlink doesn’t work, how to solve it?
1237
1238 Please see this link for debug:
1239
1240 [[http:~~/~~/wiki.dragino.com/index.php?title=Main_Page#LoRaWAN_Communication_Debug>>url:http://wiki.dragino.com/index.php?title=Main_Page#LoRaWAN_Communication_Debug]] 
1241
1242
1243
1244 1.
1245 11. Why I can’t join TTN V3 in US915 /AU915 bands?
1246
1247 It might about the channels mapping. Please see for detail.
1248
1249 [[http:~~/~~/wiki.dragino.com/index.php?title=LoRaWAN_Communication_Debug#Notice_of_US915.2FCN470.2FAU915_Frequency_band>>url:http://wiki.dragino.com/index.php?title=LoRaWAN_Communication_Debug#Notice_of_US915.2FCN470.2FAU915_Frequency_band]]
1250
1251
1252
1253 1. Order Info
1254
1255 **Part Number: RS485-BL-XXX**
1256
1257 **XXX:**
1258
1259 * **EU433**: frequency bands EU433
1260 * **EU868**: frequency bands EU868
1261 * **KR920**: frequency bands KR920
1262 * **CN470**: frequency bands CN470
1263 * **AS923**: frequency bands AS923
1264 * **AU915**: frequency bands AU915
1265 * **US915**: frequency bands US915
1266 * **IN865**: frequency bands IN865
1267 * **RU864**: frequency bands RU864
1268 * **KZ865: **frequency bands KZ865
1269
1270 1. Packing Info
1271
1272 **Package Includes**:
1273
1274 * RS485-BL x 1
1275 * Stick Antenna for LoRa RF part x 1
1276 * Program cable x 1
1277
1278 **Dimension and weight**:
1279
1280 * Device Size: 13.5 x 7 x 3 cm
1281 * Device Weight: 105g
1282 * Package Size / pcs : 14.5 x 8 x 5 cm
1283 * Weight / pcs : 170g
1284
1285 1. Support
1286
1287 * Support is provided Monday to Friday, from 09:00 to 18:00 GMT+8. Due to different timezones we cannot offer live support. However, your questions will be answered as soon as possible in the before-mentioned schedule.
1288 * Provide as much information as possible regarding your enquiry (product models, accurately describe your problem and steps to replicate it etc) and send a mail to
1289
1290 [[support@dragino.com>>url:file:///D:/市场资料/说明书/LoRa/LT系列/support@dragino.com]]