RUI3-Arduino-Library V1.0.1
RAKWireless library for communication over UART with RUI3 based WisDuo modules.
Loading...
Searching...
No Matches
rui3_at.h
Go to the documentation of this file.
1
13#ifndef _RUI3_H_
14#define _RUI3_H_
15#include "Arduino.h"
16
18#define NO_RESPONSE 255
19
21#define ARRAY_SIZE(array) (sizeof((array)) / sizeof((array[0])))
22
24#define CLASS_A 0
26#define CLASS_B 1
28#define CLASS_C 2
29
31#define LoRaWAN 1
33#define LoRaP2P 0
34
36#define OTAA 1
38#define ABP 0
39
41#define EU433 0
42#define CN470 1
43#define RU864 2
44#define IN865 3
45#define EU868 4
46#define US915 5
47#define AU915 6
48#define KR920 7
49#define AS923 8
50#define AS923_1 8
51#define AS923_2 9
52#define AS923_3 10
53#define AS923_4 11
54#define LA915 12
55
57#define CONF 1
59#define UNCONF 0
60
62#define LPM_LVL_1 1
64#define LPM_LVL_2 2
65
67#define LPM_OFF 0
69#define LPM_ON 1
70
71#define MAX_CMD_LEN (32)
72#define MAX_ARGUMENT 25
73
74// Debug output set to 0 to disable app debug output
75#ifndef DEBUG_MODE
76#define DEBUG_MODE 0
77#endif
78
79#if DEBUG_MODE > 0
80#define MYLOG(tag, ...) \
81 do \
82 { \
83 if (tag) \
84 Serial.printf("[%s] ", tag); \
85 Serial.printf(__VA_ARGS__); \
86 Serial.printf("\n"); \
87 Serial.flush(); \
88 } while (0)
89#else
90#define MYLOG(...)
91#endif
92
94typedef struct _stParam
95{
97 int argc;
99
101typedef struct _p2p_settings
102{
103 uint32_t freq; // Frequency in Hz, 150000000-960000000 Hz
104 uint16_t sf; // Spreading factor 6 - 12
105 uint16_t bw; // Bandwidth 0=125kHz, 1=250kHz, 2=500kHz, 3=7.8kHz, 4=10.4kHz, 5=15.63kHz, 6=20.83kHz, 7=31.25kHz, 8=41.67kHz, 9=62.5kHz
106 uint16_t cr; // Coding Rate 0 = 4/5, 1 = 4/6, 2 = 4/7, 3 = 4/8
107 uint16_t ppl; // Preamble length 2-65535
108 uint16_t txp; // TX power 5 - 22
110
111// #define DEBUG_MODE
112
120class RUI3
121{
122public:
140 RUI3(Stream &serial1, Stream &serial = Serial);
141
161 bool setLPM(int mode);
162
185 uint8_t getLPM(void);
186
206 bool setLPMLevel(int mode);
207
230 uint8_t getLPMLevel(void);
231
252 bool setWorkingMode(int mode);
253
276 uint8_t getWorkingMode(void);
277
297 bool setDataRate(int rate);
298
321 uint8_t getDataRate(void);
322
342 bool setClass(int classMode);
343
366 uint8_t getClass(void);
367
401 bool setRegion(int region);
402
425 uint8_t getRegion(void);
426
446 bool setJoinMode(int mode);
447
470 uint8_t getJoinMode(void);
471
492 bool setConfirmed(int type);
493
517 uint8_t getConfirmed(void);
518
543 bool initOTAA(String devEUI, String appEUI, String appKEY);
544
575 bool getDevEUI(char *eui, uint16_t array_len);
576
607 bool getAppEUI(char *eui, uint16_t array_len);
608
639 bool getAppKey(char *key, uint16_t array_len);
640
665 bool initABP(String devADDR, String nwksKEY, String appsKEY);
666
688 uint32_t getDevAddress(void);
689
720 bool getAppsKey(char *key, uint16_t array_len);
721
752 bool getNwsKey(char *key, uint16_t array_len);
753
777 bool joinLoRaNetwork(int timeout = 15);
778
804 bool getVersion(void);
805
831 bool getJoinStatus(void);
832
843 String getChannelList(void);
844
878 bool sendData(int port, char *datahex);
879
923
968
1001 bool sendP2PData(char *datahex);
1002
1023 bool setP2PCAD(bool enable);
1024
1043 bool getP2PCAD(void);
1044
1071 bool recvResponse(uint32_t timeout = 10000);
1072
1119 void recvRX(uint32_t timeout);
1120
1129 void flushRX(uint32_t timeout = 5000);
1130
1149 bool sleep(int mode);
1150
1194 void reset(void);
1195
1207 bool setUARTConfig(int Baud);
1208
1236 bool sendRawCommand(char *command);
1237
1265 bool byteArrayToAscii(char *b_array, char *a_array, uint16_t b_array_len, uint16_t a_array_len);
1266
1299 bool asciiArrayToByte(char *b_array, char *a_array, uint16_t b_array_len, uint16_t a_array_len);
1300
1302 char ret[1024] = {0};
1303
1305
1306private:
1307 Stream &_serial;
1308
1309 Stream &_serial1;
1310
1311 String _devADDR = "00112233";
1312
1313 String _devEUI = "60C5A8FFFE000001";
1314
1315 String _appEUI = "60C5A8FFFE000001";
1316
1317 String _nwksKEY = "60C5A8FFFE00000160C5A8FFFE000001";
1318
1319 String _appKEY = "60C5A8FFFE00000160C5A8FFFE000001";
1320
1321 String _appsKEY = "60C5A8FFFE00000160C5A8FFFE000001";
1322};
1323#endif // _RUI3_H_
Definition rui3_at.h:121
bool setRegion(int region)
Set the LoRaWAN Region See AT+BAND
Definition rui3_at.cpp:159
uint32_t getDevAddress(void)
Get the DevAddr See AT+DEVADDR
Definition rui3_at.cpp:606
bool initABP(String devADDR, String nwksKEY, String appsKEY)
Set credentials for ABP join mode Before using this command, you must call setJoinMode(1)
Definition rui3_at.cpp:552
bool getP2P(p2p_settings *p2p_settings)
Get current P2P settings See AT+P2P
Definition rui3_at.cpp:898
bool setP2PCAD(bool enable)
Enable or disable P2P Channel Activitity Detection See AT+CAD
Definition rui3_at.cpp:971
uint8_t getLPM(void)
Get Low power mode status See AT+LPM
Definition rui3_at.cpp:282
bool initOTAA(String devEUI, String appEUI, String appKEY)
Set LoRaWAN credentials for OTAA join mode Before using this command, you must call setJoinMode(0)
Definition rui3_at.cpp:438
bool asciiArrayToByte(char *b_array, char *a_array, uint16_t b_array_len, uint16_t a_array_len)
Convert a ASCII HEX string array into a byte array.
Definition rui3_at.cpp:1043
bool getAppEUI(char *eui, uint16_t array_len)
Get the App EUI See AT+APPEUI
Definition rui3_at.cpp:515
char ret[1024]
Char array with the last response from the WisDuo module.
Definition rui3_at.h:1302
bool setClass(int classMode)
Set the LoRaWAN device Class See AT+CLASS
Definition rui3_at.cpp:100
bool getP2PCAD(void)
Get CAD status (enabled/disabled)
Definition rui3_at.cpp:994
uint8_t getWorkingMode(void)
Get the Working Mode status See AT+NWM
Definition rui3_at.cpp:368
bool getDevEUI(char *eui, uint16_t array_len)
Get the DevEUI See AT+DEVEUI
Definition rui3_at.cpp:496
bool setConfirmed(int type)
Set package transmission mode In confirmed mode, the LNS will acknowledge the packet,...
Definition rui3_at.cpp:657
bool setDataRate(int rate)
Set the Data Rate See AT+DR
Definition rui3_at.cpp:62
bool setJoinMode(int mode)
Set network join mode OTAA or ABP See AT+NJM
Definition rui3_at.cpp:381
bool sleep(int mode)
Set the module in sleep mode. not required if low power mode is enabled) When the module is in sleep ...
Definition rui3_at.cpp:244
bool byteArrayToAscii(char *b_array, char *a_array, uint16_t b_array_len, uint16_t a_array_len)
Convert a byte array into a ASCII HEX string array.
Definition rui3_at.cpp:1029
bool recvResponse(uint32_t timeout=10000)
Get response to an AT command from the device The last response to an AT command is stored in **RUI...
Definition rui3_at.cpp:714
uint8_t getJoinMode(void)
Get the network join mode See AT+NJM
Definition rui3_at.cpp:410
bool sendData(int port, char *datahex)
Send data in LoRaWAN mode See AT+SEND
Definition rui3_at.cpp:697
bool setUARTConfig(int Baud)
Change RUI3 communication baud rate See AT+BAUD
Definition rui3_at.cpp:1007
bool getNwsKey(char *key, uint16_t array_len)
Get the NwsKey See AT+NWKSKEY
Definition rui3_at.cpp:639
bool getAppsKey(char *key, uint16_t array_len)
Get the AppsKey See AT+APPSKEY
Definition rui3_at.cpp:621
bool sendRawCommand(char *command)
Send a raw command to the RUI3 module. See RUI3 AT command manual
Definition rui3_at.cpp:1015
bool joinLoRaNetwork(int timeout=15)
Join the network See AT+JOIN
Definition rui3_at.cpp:423
bool setLPMLevel(int mode)
Set the LPM level See AT+LPMLVL
Definition rui3_at.cpp:299
void recvRX(uint32_t timeout)
Get RX packet after LoRaWAN TX or LoRa P2P receive command The last received RX packet is stored in...
Definition rui3_at.cpp:764
void flushRX(uint32_t timeout=5000)
Flush the RX buffer in case there is something left.
Definition rui3_at.cpp:847
bool sendP2PData(char *datahex)
Send a data packet over LoRa P2P See AT+PSEND
Definition rui3_at.cpp:955
uint8_t getLPMLevel(void)
Get the current LPM level See AT+LPMLVL
Definition rui3_at.cpp:319
void reset(void)
Reset the RUI3 module Communication with the module will be lost See ATZ
Definition rui3_at.cpp:336
uint8_t getClass(void)
Get the class See AT+CLASS
Definition rui3_at.cpp:131
bool initP2P(p2p_settings *p2p_settings)
Initialize LoRa P2P mode See AT+P2P
Definition rui3_at.cpp:882
uint8_t getRegion(void)
Get the Region See AT+BAND
Definition rui3_at.cpp:226
bool getJoinStatus(void)
Get the Join Status See AT+NJS
Definition rui3_at.cpp:38
bool getVersion(void)
Get the firmware version number of the module. See AT+VER
Definition rui3_at.cpp:32
stParam param
Definition rui3_at.h:1304
bool setLPM(int mode)
Enable/Disable Low power mode See AT+LPM
Definition rui3_at.cpp:263
bool setWorkingMode(int mode)
Set the device to LoRaWAN mode or LoRa P2P mode See AT+NWM When switching the device mode,...
Definition rui3_at.cpp:342
uint8_t getConfirmed(void)
Get the Confirmed/Unconfirmed packet status In confirmed mode, the LNS will acknowledge the packet,...
Definition rui3_at.cpp:684
uint8_t getDataRate(void)
Get the data rate See AT+DR
Definition rui3_at.cpp:82
bool getAppKey(char *key, uint16_t array_len)
Get the AppKey See AT+APPKEY
Definition rui3_at.cpp:534
String getChannelList(void)
Get the current channel list settings This feature works only in Regions US915, AU915 or CN470 Se...
Definition rui3_at.cpp:51
char command[1024]
Definition rui3_at.cpp:20
#define MAX_ARGUMENT
Definition rui3_at.h:72
struct _p2p_settings p2p_settings
struct _stParam stParam
Definition rui3_at.h:102
uint16_t bw
Definition rui3_at.h:105
uint16_t cr
Definition rui3_at.h:106
uint16_t txp
Definition rui3_at.h:108
uint16_t ppl
Definition rui3_at.h:107
uint16_t sf
Definition rui3_at.h:104
uint32_t freq
Definition rui3_at.h:103
Definition rui3_at.h:95
int argc
Definition rui3_at.h:97
char * argv[MAX_ARGUMENT]
Definition rui3_at.h:96