Wiki source code of Point to Point Communication for RS485-LN
Last modified by Xiaoling on 2022/07/04 11:22
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | **Table of Contents:** | ||
2 | |||
3 | {{toc/}} | ||
4 | |||
5 | |||
6 | |||
7 | |||
8 | |||
9 | |||
10 | |||
11 | = **1. point to point** = | ||
12 | |||
13 | == **1.1 Overview** == | ||
14 | |||
15 | ((( | ||
16 | [[image:1656901825798-483.png]] | ||
17 | |||
18 | |||
19 | |||
20 | == **1.2 Configure** == | ||
21 | |||
22 | |||
23 | (% style="color:blue" %)**A's configuration: ** **B's configuration:** | ||
24 | |||
25 | AT+GROUPMOD=0 AT+GROUPMOD=0 | ||
26 | |||
27 | AT+GROUPID=12345678 AT+GROUPID=12345678 | ||
28 | |||
29 | AT+TXCHS=868700000 AT+TXCHS=869000000 | ||
30 | |||
31 | AT+RXCHS=869000000 AT+RXCHS=868700000 | ||
32 | |||
33 | AT+CFGDEV=01 03 00 00 00 04,1 AT+CFGDEV=01 03 00 00 00 02,1 | ||
34 | |||
35 | or or | ||
36 | |||
37 | AT+COMMAND=01 03 00 00 00 04,1 AT+COMMAND=01 03 00 00 00 02,1 | ||
38 | ))) | ||
39 | |||
40 | |||
41 | |||
42 | == **1.3 Serial port display** == | ||
43 | |||
44 | |||
45 | [[image:image-20220704103422-2.png||height="430" width="817"]] | ||
46 | |||
47 | ((( | ||
48 | A sends a command to B to query B's RS485 sensor data and display it on A's upper computer. | ||
49 | ))) | ||
50 | |||
51 | ((( | ||
52 | Similarly, B sends a command to A to query A's RS485 sensor data and display it on B's upper computer. | ||
53 | ))) | ||
54 | |||
55 | |||
56 | [[image:image-20220704103502-3.png]] | ||
57 | |||
58 | ((( | ||
59 | If the sender does not get the ACK reply from the receiver, it will retransmit up to 4 times, each interval is 10 seconds, and the UplinkCounter of the retransmission will not increase. (Retransmission only occurs when using the AT+CFGDEV command or triggering an external interrupt) | ||
60 | ))) | ||
61 | |||
62 | |||
63 | |||
64 | = **2. Point To Mult-Point ** = | ||
65 | |||
66 | == **2.1 Overview** == | ||
67 | |||
68 | |||
69 | [[image:1656901541427-229.png]] | ||
70 | |||
71 | |||
72 | == **2.2 Configure** == | ||
73 | |||
74 | |||
75 | (% style="color:blue" %)**Configuration of the TX group:** | ||
76 | |||
77 | AT+GROUPMOD=0,2 | ||
78 | |||
79 | AT+GROUPID=12345678 | ||
80 | |||
81 | AT+TXCHS=868700000 | ||
82 | |||
83 | AT+RXCHS=869000000 | ||
84 | |||
85 | AT+CFGDEV=01 03 00 00 00 02,1 | ||
86 | |||
87 | or | ||
88 | |||
89 | AT+COMMAND=01 03 00 00 00 02,1 | ||
90 | |||
91 | |||
92 | (% style="color:blue" %)**Configuration for RX group number 1:** | ||
93 | |||
94 | AT+GROUPMOD=1,1 | ||
95 | |||
96 | AT+GROUPID=12345678 | ||
97 | |||
98 | AT+TXCHS=869000000 | ||
99 | |||
100 | AT+RXCHS=868700000 | ||
101 | |||
102 | |||
103 | (% style="color:blue" %)**Configuration for RX group number 2:** | ||
104 | |||
105 | AT+GROUPMOD=1,2 | ||
106 | |||
107 | AT+GROUPID=12345678 | ||
108 | |||
109 | AT+TXCHS=869000000 | ||
110 | |||
111 | AT+RXCHS=868700000 | ||
112 | |||
113 | |||
114 | |||
115 | == **2.3 Serial port display** == | ||
116 | |||
117 | (% id="cke_bm_79849S" style="display:none" %) [[image:1656901280202-290.png]] | ||
118 | |||
119 | |||
120 | [[image:image-20220704103658-4.png||height="495" width="852"]] | ||
121 | |||
122 | ((( | ||
123 | The TX group sends broadcast data to the RX group. After the RX group receives the data, it will reply to the TX group in order from small to large.(% style="display:none" %) | ||
124 | ))) | ||
125 | |||
126 | (% style="display:none" %) (%%) | ||
127 | |||
128 | |||
129 | [[image:image-20220704103658-5.png]] | ||
130 | |||
131 | ((( | ||
132 | If the sender does not get the ACK reply from the receiver, it will retransmit up to 4 times, each interval is 30 seconds, and the UplinkCounter of the retransmission will not increase.(Retransmission only occurs when using the AT+CFGDEV command or triggering an external interrupt) | ||
133 | ))) | ||
134 | |||
135 | (% style="display:none" %) (%%) | ||
136 | |||
137 | (% style="display:none" %) (%%) | ||
138 | |||
139 | = **3. AT command** = | ||
140 | |||
141 | (% style="display:none" %) (%%) (% style="display:none" %) | ||
142 | |||
143 | ((( | ||
144 | (% style="color:#037691" %)**ATZ** (%%)**: ** Trig a reset of the MCU | ||
145 | ))) | ||
146 | |||
147 | ((( | ||
148 | (% style="color:#037691" %)**AT+FDR** (%%)**:** Reset Parameters to Factory Default, Keys Reserve | ||
149 | ))) | ||
150 | |||
151 | ((( | ||
152 | (% style="color:#037691" %)**AT+FCU** (%%)**:** Get or Set the Frame Co(% style="display:none" %) (%%)unter Uplink | ||
153 | ))) | ||
154 | |||
155 | ((( | ||
156 | (% style="color:#037691" %)**AT+FCD** (%%)**:** Get or Set the Frame Counter Downlink | ||
157 | ))) | ||
158 | |||
159 | ((( | ||
160 | (% style="color:#037691" %)**AT+TXP** (%%)**:** Get or Set the transmit power, the maximum is 20dBm (default is 14dBm) | ||
161 | ))) | ||
162 | |||
163 | ((( | ||
164 | (% style="color:#037691" %)**AT+SYNC** (%%)**:** Get or Set the Sync word [1:0x34,0:0x12] (default is 1) | ||
165 | ))) | ||
166 | |||
167 | ((( | ||
168 | (% style="color:#037691" %)**AT+PMB** (%%)**: **Get or Set the preamble (default:8) | ||
169 | ))) | ||
170 | |||
171 | ((( | ||
172 | (% style="color:#037691" %)**AT+TXCHS **(%%)**:** Get or Set the transmit frequency of TX (default:868700000) | ||
173 | ))) | ||
174 | |||
175 | ((( | ||
176 | (% style="color:#037691" %)**AT+TXSF **(%%)**:** Get or Set the spreading factor of TX (7 to 12) (default:12) | ||
177 | ))) | ||
178 | |||
179 | ((( | ||
180 | (% style="color:#037691" %)**AT+RXCHS **(%%)**:** Get or Set the transmit frequency of RX (default:869000000) | ||
181 | ))) | ||
182 | |||
183 | ((( | ||
184 | (% style="color:#037691" %)**AT+RXSF **(%%)**:** Get or Set the spreading factor of RX (7 to 12) (default:12) | ||
185 | ))) | ||
186 | |||
187 | ((( | ||
188 | (% style="color:#037691" %)**AT+BW **(%%)**: **Get or Set the bandwidth [0:125khz,1:250khz,2:500khz] (default:0) | ||
189 | ))) | ||
190 | |||
191 | ((( | ||
192 | (% style="color:#037691" %)**AT+CR **(%%)**: **Get or Set the coding rate [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] (default:1) | ||
193 | ))) | ||
194 | |||
195 | ((( | ||
196 | (% style="color:#037691" %)**AT+TDC **(%%)**:** Get or set the application data transmission interval in ms(default 10 minutes) | ||
197 | ))) | ||
198 | |||
199 | ((( | ||
200 | (% style="color:#037691" %)**AT+VER **(%%)**:** Get firmware version number | ||
201 | ))) | ||
202 | |||
203 | ((( | ||
204 | (% style="color:#037691" %)**AT+SEND **(%%)**: **Set Custom sent hex data | ||
205 | ))) | ||
206 | |||
207 | ((( | ||
208 | (% style="color:#037691" %)**AT+GROUPMOD **(%%)**: **Set or Get the grouping (% style="display:none" %) (%%)mode of the device (default: 0) | ||
209 | ))) | ||
210 | |||
211 | ((( | ||
212 | ((( | ||
213 | (% style="color:#037691" %)**AT+GROUPID **(%%)**: **Set or Get the password for (% style="display:none" %) (%%)matching between TX group and RX group, which can be composed of numbers or characters (default: 12345678)(% style="display:none" %) | ||
214 | |||
215 | ((( | ||
216 | (% style="color:#037691" %)**AT+INTMOD **(%%)**:** Get or Set the trigger interrupt mode | ||
217 | ))) | ||
218 | |||
219 | ((( | ||
220 | (% style="color:#037691" %)**AT+BAUDR **(%%)**:** Get or set the baud rate of rs485. (default: 9600) | ||
221 | ))) | ||
222 | |||
223 | ((( | ||
224 | (% style="color:#037691" %)**AT+DATABIT **(%%)**:** Get or Set databit(7:7 bits,8:8 bits) of rs485 (default: 8) | ||
225 | ))) | ||
226 | |||
227 | ((( | ||
228 | (% style="color:#037691" %)**AT+PARITY **(%%)**: **Get or Set parity(0:none,1:odd,2:even) of rs485(default: 0) | ||
229 | ))) | ||
230 | |||
231 | ((( | ||
232 | (% style="color:#037691" %)**AT+STOPBIT **(%%)**: **Get or Set stopbit(0:1 bit,1:1.5 bit,2:2 bit) of rs485(default: 0) | ||
233 | ))) | ||
234 | |||
235 | ((( | ||
236 | (% style="color:#037691" %)**AT+CMDDL **(%%)**:** Get or Set the delay waiting time after receiving RS485 command (default: 400) | ||
237 | ))) | ||
238 | |||
239 | ((( | ||
240 | (% style="color:#037691" %)**AT+CRCCHECK **(%%)**:** Get or set to receive and verify RS485 sensor data (0: Disable,1:CRC16_MODBUS) (default: 1) | ||
241 | ))) | ||
242 | |||
243 | ((( | ||
244 | (% style="color:#037691" %)**AT+SCHEDULE **(%%)**:** Each TDC sends command data to the receiver. | ||
245 | ))) | ||
246 | |||
247 | ((( | ||
248 | (% style="color:#037691" %)**AT+CFGDEV **(%%)**:** Instantly send RS485 commands to the receiver. | ||
249 | ))) | ||
250 | |||
251 | ((( | ||
252 | (% style="color:#037691" %)**AT+RS485 **(%%)**: **Send commands to the local RS485 device. | ||
253 | ))) | ||
254 | |||
255 | ((( | ||
256 | (% style="color:#037691" %)**AT+MOD **(%%)**:** Get or set the host send mode.(default: 0) | ||
257 | ))) | ||
258 | ))) | ||
259 | ))) | ||
260 | |||
261 | ((( | ||
262 | |||
263 | ))) | ||
264 | |||
265 | ((( | ||
266 | |||
267 | ))) | ||
268 | |||
269 | ((( | ||
270 | (% style="color:#4f81bd" %)**Example 1:** | ||
271 | ))) | ||
272 | |||
273 | ((( | ||
274 | **AT+SEND=01020304 **will send a payload of 01020304 | ||
275 | ))) | ||
276 | |||
277 | ((( | ||
278 | |||
279 | |||
280 | |||
281 | ))) | ||
282 | |||
283 | ((( | ||
284 | ((( | ||
285 | (% style="color:#4f81bd" %)**Example 2: ** | ||
286 | ))) | ||
287 | |||
288 | ((( | ||
289 | **AT+INTMOD=aa** (0:Disable,1:falling or rising,2:falling,3:rising) (default: 2) | ||
290 | ))) | ||
291 | ))) | ||
292 | |||
293 | ((( | ||
294 | ((( | ||
295 | RS485-LN support external Interrupt uplink since hardware v1.2 release. | ||
296 | ))) | ||
297 | |||
298 | [[image:image-20220704104958-6.png]] | ||
299 | |||
300 | ((( | ||
301 | Connect the Interrupt pin to RS485-LN INT port and connect the GND pin to V- port. When there is a high voltage (Max 24v) on INT pin. Device will send an lora packet. | ||
302 | ))) | ||
303 | ))) | ||
304 | |||
305 | ((( | ||
306 | |||
307 | |||
308 | |||
309 | ))) | ||
310 | |||
311 | ((( | ||
312 | ((( | ||
313 | (% style="color:#4f81bd" %)**Example 3: ** | ||
314 | ))) | ||
315 | |||
316 | ((( | ||
317 | **AT+SCHEDULE: **This command will be sent to Group RX during each transmission, Max command length is 14 bytes. The grammar is: | ||
318 | ))) | ||
319 | |||
320 | ((( | ||
321 | AT+SCHEDULE =xx xx xx xx xx xx xx xx xx xx xx xx,m | ||
322 | ))) | ||
323 | |||
324 | ((( | ||
325 | xx xx xx xx xx xx xx xx xx xx xx xx: The RS485 command to be sent | ||
326 | ))) | ||
327 | |||
328 | ((( | ||
329 | m: 0: no CRC, 1: add CRC-16/MODBUS in the end of this command | ||
330 | ))) | ||
331 | |||
332 | ((( | ||
333 | 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. | ||
334 | ))) | ||
335 | ))) | ||
336 | |||
337 | ((( | ||
338 | |||
339 | ))) | ||
340 | |||
341 | ((( | ||
342 | |||
343 | ))) | ||
344 | |||
345 | ((( | ||
346 | ((( | ||
347 | (% style="color:#4f81bd" %)**Example 4: ** | ||
348 | ))) | ||
349 | |||
350 | ((( | ||
351 | **AT+CFGDEV :** This command will be sent to Group RX. | ||
352 | ))) | ||
353 | |||
354 | ((( | ||
355 | The grammar is: | ||
356 | ))) | ||
357 | |||
358 | ((( | ||
359 | AT+CFGDEV =xx xx xx xx xx xx xx xx xx xx xx xx,m | ||
360 | ))) | ||
361 | |||
362 | ((( | ||
363 | xx xx xx xx xx xx xx xx xx xx xx xx: The RS485 command to be sent | ||
364 | ))) | ||
365 | |||
366 | ((( | ||
367 | m: 0: no CRC, 1: add CRC-16/MODBUS in the end of this command. | ||
368 | ))) | ||
369 | ))) | ||
370 | |||
371 | ((( | ||
372 | |||
373 | |||
374 | |||
375 | ((( | ||
376 | (% style="color:#4f81bd" %)**Example 5:**(%%)** ** | ||
377 | ))) | ||
378 | ))) | ||
379 | |||
380 | ((( | ||
381 | **AT+RS485:** This command will be sent to local RS485 device. | ||
382 | ))) | ||
383 | |||
384 | ((( | ||
385 | The grammar is: | ||
386 | ))) | ||
387 | |||
388 | ((( | ||
389 | AT+RS485 =xx xx xx xx xx xx xx xx xx xx xx xx,m | ||
390 | ))) | ||
391 | |||
392 | ((( | ||
393 | xx xx xx xx xx xx xx xx xx xx xx xx: The RS485 command to be sent | ||
394 | ))) | ||
395 | |||
396 | ((( | ||
397 | m: 0: no CRC, 1: add CRC-16/MODBUS in the end of this command. | ||
398 | ))) | ||
399 | |||
400 | |||
401 | |||
402 | ((( | ||
403 | (% style="color:#4f81bd" %)**Example 6:** | ||
404 | ))) | ||
405 | |||
406 | ((( | ||
407 | **AT+MOD=0** Commands are transparently transmitted through UART. | ||
408 | ))) | ||
409 | |||
410 | ((( | ||
411 | **AT+MOD=1,500** Commands are transparently transmitted through RS485. 500 ms after the first character is received from RS485, all characters are commands. | ||
412 | ))) | ||
413 | |||
414 | |||
415 | |||
416 | ((( | ||
417 | (% style="color:#4f81bd" %)**Example 7:** | ||
418 | ))) | ||
419 | |||
420 | ((( | ||
421 | **AT+GROUPMOD=0** Set to point to point mode | ||
422 | ))) | ||
423 | |||
424 | ((( | ||
425 | **AT+GROUPMOD=0,aa** Set the TX group that controls the number of aa (The maximum value of aa is 8) | ||
426 | ))) | ||
427 | |||
428 | ((( | ||
429 | **AT+GROUPMOD=1,bb** Set to the RX group controlled by the TX group, numbered bb(The maximum value of bb is 8) | ||
430 | ))) | ||
431 | |||
432 | |||
433 | ((( | ||
434 | **AT+GROUPMOD=0,2** Set to control the TX group of the two RX groups | ||
435 | ))) | ||
436 | |||
437 | ((( | ||
438 | **AT+GROUPMOD=1,1** Set the RX group numbered 1 | ||
439 | ))) | ||
440 | |||
441 | ((( | ||
442 | **AT+GROUPMOD=1,2** Set the RX group numbered 2 | ||
443 | ))) | ||
444 | |||
445 | |||
446 | |||
447 | = **4. Data Format** = | ||
448 | |||
449 | |||
450 | ((( | ||
451 | 8 bytes of GROUPID +n payload + 4 bytes of checksum | ||
452 | ))) | ||
453 | |||
454 | |||
455 | ((( | ||
456 | Payload(S12, SF11, SF10 maximum length is 59, SF9 maximum length is 123, SF8, SF7 maximum length is 230): | ||
457 | ))) | ||
458 | |||
459 | (% border="1" cellspacing="10" style="background-color:#f7faff; color:black; width:430px" %) | ||
460 | |=(% style="width: 60px;" %)**Size (bytes)**|=(% style="width: 60px;" %)**1**|=(% style="width: 60px;" %)**1**|=(% style="width: 60px;" %)**1**|=(% style="width: 80px;" %)**1**|=(% style="width: 100px;" %)**payloadsize** | ||
461 | |(% style="width:100px" %)**Value**|(% style="width:71px" %)address|(% style="width:71px" %)request|(% style="width:49px" %)ACK|(% style="width:99px" %)payloadsize|(% style="width:139px" %)((( | ||
462 | command data or | ||
463 | |||
464 | return data | ||
465 | ))) | ||
466 | |||
467 | ((( | ||
468 | (% style="color:#037691" %)**The first byte: **(%%)00 is the broadcast address, 01-08 is the RX group number | ||
469 | ))) | ||
470 | |||
471 | ((( | ||
472 | (% style="color:#037691" %)**The second byte:**(%%) send request when not 0, not request when it is 0 | ||
473 | ))) | ||
474 | |||
475 | ((( | ||
476 | (% style="color:#037691" %)**The third byte:**(%%) ACK returned to the sender. | ||
477 | ))) | ||
478 | |||
479 | ((( | ||
480 | (% style="color:#037691" %)**The fourth byte:**(%%) The command length of the sender or the data length of the RS485 sensor returned by the receiver. | ||
481 | ))) | ||
482 | |||
483 | ((( | ||
484 | (% style="color:#037691" %)**The Fifth byte:**(%%) RS485 command or RS485 return data. | ||
485 | ))) | ||
486 | |||
487 | |||
488 | ((( | ||
489 | |||
490 | ))) |