Skip to content

Commit 1069e4d

Browse files
committed
TRACE、LoRaWan868、UHF
1 parent 8c80855 commit 1069e4d

7 files changed

Lines changed: 277 additions & 468 deletions

File tree

examples/Unit/LoRaWAN868/LoRaWAN868.ino

Lines changed: 159 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -20,107 +20,107 @@ M5Canvas canvas(&display);
2020

2121
String waitRevice()
2222
{
23-
String recvStr;
24-
do
25-
{
26-
recvStr = Serial2.readStringUntil('\n');
27-
} while (recvStr.length() == 0);
28-
canvas.println(recvStr);
29-
return recvStr;
23+
String recvStr;
24+
do
25+
{
26+
recvStr = Serial2.readStringUntil('\n');
27+
} while (recvStr.length() == 0);
28+
canvas.println(recvStr);
29+
return recvStr;
3030
}
3131

3232
uint16_t ypos = 55;
3333

3434
void drawLineStr(String str, uint16_t color)
3535
{
36-
M5.Lcd.setTextColor(color);
37-
M5.Lcd.drawString(str, 10, ypos, 4);
38-
ypos += 32;
36+
M5.Lcd.setTextColor(color);
37+
M5.Lcd.drawString(str, 10, ypos, 4);
38+
ypos += 32;
3939
}
4040

4141

4242
void sendATCMD(String cmdStr)
4343
{
44-
Serial2.print(cmdStr);
45-
delay(100);
44+
Serial2.print(cmdStr);
45+
delay(100);
4646
}
4747

4848
int sendATCMDAndRevice(String cmdStr)
4949
{
50-
Serial2.print(cmdStr);
51-
delay(10);
52-
waitRevice();
53-
String recvStr = waitRevice();
54-
if (recvStr.indexOf("OK") != -1)
55-
{
56-
return 0;
57-
}
58-
else
59-
{
60-
return -1;
61-
}
50+
Serial2.print(cmdStr);
51+
delay(10);
52+
waitRevice();
53+
String recvStr = waitRevice();
54+
if (recvStr.indexOf("OK") != -1)
55+
{
56+
return 0;
57+
}
58+
else
59+
{
60+
return -1;
61+
}
6262
}
6363

6464
void setup()
6565
{
66-
M5.begin();
67-
Serial2.begin(115200, SERIAL_8N1, 16, 17);
68-
Serial2.flush();
69-
delay(100);
70-
display.begin();
71-
display.setTextSize(2);
72-
canvas.setColorDepth(1); // mono color
73-
canvas.createSprite(display.width(), display.height());
74-
canvas.setTextSize((float)canvas.width() / 160);
75-
canvas.setTextScroll(true);
76-
77-
sendATCMD("AT?\r");
78-
delay(100);
79-
Serial2.flush();
80-
sendATCMDAndRevice("AT+ILOGLVL=0\r");
81-
sendATCMDAndRevice("AT+CSAVE\r");
82-
sendATCMDAndRevice("AT+IREBOOT=0\r");
83-
display.println("LoraWan Rebooting");
84-
delay(2000);
85-
display.println("LoraWan config");
86-
sendATCMDAndRevice("AT+CJOINMODE=0\r");
87-
sendATCMDAndRevice("AT+CDEVEUI=00BB9DA5B97ADDF6\r");
88-
sendATCMDAndRevice("AT+CAPPEUI=70B3D57ED004247E\r");//70B3D57ED003B699
89-
sendATCMDAndRevice("AT+CAPPKEY=27DFE264CA33AC1957C005EB48BA4723\r");
90-
sendATCMDAndRevice("AT+CULDLMODE=2\r");
91-
sendATCMDAndRevice("AT+CCLASS=2\r");
92-
sendATCMDAndRevice("AT+CWORKMODE=2\r");
93-
sendATCMDAndRevice("AT+CNBTRIALS=0,5\r");
94-
sendATCMDAndRevice("AT+CNBTRIALS=1,5\r");
95-
96-
// TX Freq
97-
// 868.1 - SF7BW125 to SF12BW125
98-
// 868.3 - SF7BW125 to SF12BW125 and SF7BW250
99-
// 868.5 - SF7BW125 to SF12BW125
100-
// 867.1 - SF7BW125 to SF12BW125
101-
// 867.3 - SF7BW125 to SF12BW125
102-
// 867.5 - SF7BW125 to SF12BW125
103-
// 867.7 - SF7BW125 to SF12BW125
104-
// 867.9 - SF7BW125 to SF12BW125
105-
// 868.8 - FSK
106-
107-
sendATCMDAndRevice("AT+CFREQBANDMASK=0001\r");
108-
109-
//869.525 - SF9BW125 (RX2) | 869525000
110-
//sendATCMDAndRevice("AT+CRXP=0,0,869525000\r");
111-
112-
sendATCMDAndRevice("AT+CSAVE\r");
113-
114-
sendATCMDAndRevice("AT+CJOIN=1,0,10,8\r");
66+
M5.begin();
67+
Serial2.begin(115200, SERIAL_8N1, 16, 17);
68+
Serial2.flush();
69+
delay(100);
70+
display.begin();
71+
display.setTextSize(2);
72+
canvas.setColorDepth(1); // mono color
73+
canvas.createSprite(display.width(), display.height());
74+
canvas.setTextSize((float)canvas.width() / 160);
75+
canvas.setTextScroll(true);
76+
77+
sendATCMD("AT?\r");
78+
delay(100);
79+
Serial2.flush();
80+
sendATCMDAndRevice("AT+ILOGLVL=0\r");
81+
sendATCMDAndRevice("AT+CSAVE\r");
82+
sendATCMDAndRevice("AT+IREBOOT=0\r");
83+
display.println("LoraWan Rebooting");
84+
delay(2000);
85+
display.println("LoraWan config");
86+
sendATCMDAndRevice("AT+CJOINMODE=0\r");
87+
sendATCMDAndRevice("AT+CDEVEUI=00BB9DA5B97ADDF6\r");
88+
sendATCMDAndRevice("AT+CAPPEUI=70B3D57ED004247E\r");//70B3D57ED003B699
89+
sendATCMDAndRevice("AT+CAPPKEY=27DFE264CA33AC1957C005EB48BA4723\r");
90+
sendATCMDAndRevice("AT+CULDLMODE=2\r");
91+
sendATCMDAndRevice("AT+CCLASS=2\r");
92+
sendATCMDAndRevice("AT+CWORKMODE=2\r");
93+
sendATCMDAndRevice("AT+CNBTRIALS=0,5\r");
94+
sendATCMDAndRevice("AT+CNBTRIALS=1,5\r");
95+
96+
// TX Freq
97+
// 868.1 - SF7BW125 to SF12BW125
98+
// 868.3 - SF7BW125 to SF12BW125 and SF7BW250
99+
// 868.5 - SF7BW125 to SF12BW125
100+
// 867.1 - SF7BW125 to SF12BW125
101+
// 867.3 - SF7BW125 to SF12BW125
102+
// 867.5 - SF7BW125 to SF12BW125
103+
// 867.7 - SF7BW125 to SF12BW125
104+
// 867.9 - SF7BW125 to SF12BW125
105+
// 868.8 - FSK
106+
107+
sendATCMDAndRevice("AT+CFREQBANDMASK=0001\r");
108+
109+
//869.525 - SF9BW125 (RX2) | 869525000
110+
//sendATCMDAndRevice("AT+CRXP=0,0,869525000\r");
111+
112+
sendATCMDAndRevice("AT+CSAVE\r");
113+
114+
sendATCMDAndRevice("AT+CJOIN=1,0,10,8\r");
115115
}
116116

117117
enum systemstate
118118
{
119-
kIdel = 0,
120-
kJoined,
121-
kSending,
122-
kWaitSend,
123-
kEnd,
119+
kIdel = 0,
120+
kJoined,
121+
kSending,
122+
kWaitSend,
123+
kEnd,
124124
};
125125
int system_fsm = kIdel;
126126

@@ -131,93 +131,93 @@ int loraWanupLinkReviceCNT = 0;
131131

132132
void loop()
133133
{
134-
String recvStr = waitRevice();
135-
if (recvStr.indexOf("+CJOIN:") != -1)
136-
{
137-
if (recvStr.indexOf("OK") != -1)
138-
{
139-
canvas.println("[ INFO ] JOIN IN SUCCESSFUL");
140-
system_fsm = kJoined;
141-
}
142-
else
143-
{
144-
canvas.println("[ INFO ] JOIN IN FAIL");
145-
system_fsm = kIdel;
146-
}
147-
}
148-
else if (recvStr.indexOf("OK+RECV") != -1)
149-
{
150-
if (system_fsm == kJoined)
151-
{
152-
system_fsm = kSending;
153-
}
154-
else if (system_fsm == kWaitSend)
155-
{
156-
system_fsm = kEnd;
157-
char strbuff[128];
158-
loraWanupLinkReviceCNT ++;
159-
160-
//if(( loraWanSendCNT < 5 )&&( loraWanSendNUM == 8 ))
161-
//{
162-
// loraWanupLinkReviceCNT ++;
163-
// sprintf(strbuff,"SEND CNT: %d (%d/%d)",loraWanSendCNT,loraWanupLinkReviceCNT,loraWanupLinkCNT);
164-
// M5.Lcd.fillRect(0,183,320,32,TFT_BLACK);
165-
// M5.Lcd.setTextColor(TFT_GREEN);
166-
// M5.Lcd.drawString(strbuff, 10, 183, 4);
167-
// //drawLineStr(strbuff, TFT_GREEN);
168-
//
169-
//}
170-
//else
171-
//{
172-
// sprintf(strbuff,"FAILD NUM:%d CNT:%d (%d/%d)",loraWanSendNUM,loraWanSendCNT,loraWanupLinkReviceCNT,loraWanupLinkCNT);
173-
// M5.Lcd.fillRect(0,183,320,32,TFT_BLACK);
174-
// M5.Lcd.setTextColor(TFT_RED);
175-
// M5.Lcd.drawString(strbuff, 10, 183, 4);
176-
// drawLineStr(strbuff, TFT_RED);
177-
//}
178-
delay(500);
179-
system_fsm = kSending;
180-
}
181-
}
182-
else if(recvStr.indexOf("OK+SEND") != -1)
134+
String recvStr = waitRevice();
135+
if (recvStr.indexOf("+CJOIN:") != -1)
136+
{
137+
if (recvStr.indexOf("OK") != -1)
183138
{
184-
String snednum = recvStr.substring(8);
185-
canvas.printf(" [ INFO ] SEND NUM %s \r\n",snednum.c_str());
186-
loraWanSendNUM = snednum.toInt();
139+
canvas.println("[ INFO ] JOIN IN SUCCESSFUL");
140+
system_fsm = kJoined;
187141
}
188-
else if(recvStr.indexOf("OK+SENT") != -1)
142+
else
189143
{
190-
String snedcnt = recvStr.substring(8);
191-
canvas.printf(" [ INFO ] SEND CNT %s \r\n",snedcnt.c_str());
192-
loraWanSendCNT = snedcnt.toInt();
144+
canvas.println("[ INFO ] JOIN IN FAIL");
145+
system_fsm = kIdel;
193146
}
194-
else if(recvStr.indexOf("ERR+SENT") != -1)
147+
}
148+
else if (recvStr.indexOf("OK+RECV") != -1)
149+
{
150+
if (system_fsm == kJoined)
195151
{
196-
char strbuff[128];
197-
String ErrorCodeStr = recvStr.substring(9);
198-
sprintf(strbuff,"ERROR Code:%d (%d/%d)",ErrorCodeStr.toInt(),loraWanupLinkReviceCNT,loraWanupLinkCNT);
199-
canvas.println(strbuff);
200-
delay(500);
201-
202152
system_fsm = kSending;
203153
}
204-
else if(recvStr.indexOf("+CLINKCHECK:") != -1)
205-
{
206-
String checkStr = recvStr.substring(String("+CLINKCHECK:").length());
207-
208-
char strbuff[128];
209-
sprintf(strbuff,"%s (%d/%d)",checkStr.c_str(),loraWanupLinkReviceCNT,loraWanupLinkCNT);
210-
canvas.println(strbuff);
211-
212-
}
213-
214-
if (system_fsm == kSending)
154+
else if (system_fsm == kWaitSend)
215155
{
216-
canvas.println("LoraWan Sending");
217-
sendATCMD("AT+CLINKCHECK=1\r");
218-
loraWanupLinkCNT ++;
219-
system_fsm = kWaitSend;
156+
system_fsm = kEnd;
157+
char strbuff[128];
158+
loraWanupLinkReviceCNT ++;
159+
160+
//if(( loraWanSendCNT < 5 )&&( loraWanSendNUM == 8 ))
161+
//{
162+
// loraWanupLinkReviceCNT ++;
163+
// sprintf(strbuff,"SEND CNT: %d (%d/%d)",loraWanSendCNT,loraWanupLinkReviceCNT,loraWanupLinkCNT);
164+
// M5.Lcd.fillRect(0,183,320,32,TFT_BLACK);
165+
// M5.Lcd.setTextColor(TFT_GREEN);
166+
// M5.Lcd.drawString(strbuff, 10, 183, 4);
167+
// //drawLineStr(strbuff, TFT_GREEN);
168+
//
169+
//}
170+
//else
171+
//{
172+
// sprintf(strbuff,"FAILD NUM:%d CNT:%d (%d/%d)",loraWanSendNUM,loraWanSendCNT,loraWanupLinkReviceCNT,loraWanupLinkCNT);
173+
// M5.Lcd.fillRect(0,183,320,32,TFT_BLACK);
174+
// M5.Lcd.setTextColor(TFT_RED);
175+
// M5.Lcd.drawString(strbuff, 10, 183, 4);
176+
// drawLineStr(strbuff, TFT_RED);
177+
//}
178+
delay(500);
179+
system_fsm = kSending;
220180
}
221-
canvas.pushSprite(0, 0);
222-
delay(10);
223-
}
181+
}
182+
else if(recvStr.indexOf("OK+SEND") != -1)
183+
{
184+
String snednum = recvStr.substring(8);
185+
canvas.printf(" [ INFO ] SEND NUM %s \r\n",snednum.c_str());
186+
loraWanSendNUM = snednum.toInt();
187+
}
188+
else if(recvStr.indexOf("OK+SENT") != -1)
189+
{
190+
String snedcnt = recvStr.substring(8);
191+
canvas.printf(" [ INFO ] SEND CNT %s \r\n",snedcnt.c_str());
192+
loraWanSendCNT = snedcnt.toInt();
193+
}
194+
else if(recvStr.indexOf("ERR+SENT") != -1)
195+
{
196+
char strbuff[128];
197+
String ErrorCodeStr = recvStr.substring(9);
198+
sprintf(strbuff,"ERROR Code:%d (%d/%d)",ErrorCodeStr.toInt(),loraWanupLinkReviceCNT,loraWanupLinkCNT);
199+
canvas.println(strbuff);
200+
delay(500);
201+
202+
system_fsm = kSending;
203+
}
204+
else if(recvStr.indexOf("+CLINKCHECK:") != -1)
205+
{
206+
String checkStr = recvStr.substring(String("+CLINKCHECK:").length());
207+
208+
char strbuff[128];
209+
sprintf(strbuff,"%s (%d/%d)",checkStr.c_str(),loraWanupLinkReviceCNT,loraWanupLinkCNT);
210+
canvas.println(strbuff);
211+
212+
}
213+
214+
if (system_fsm == kSending)
215+
{
216+
canvas.println("LoraWan Sending");
217+
sendATCMD("AT+CLINKCHECK=1\r");
218+
loraWanupLinkCNT ++;
219+
system_fsm = kWaitSend;
220+
}
221+
canvas.pushSprite(0, 0);
222+
delay(10);
223+
}

0 commit comments

Comments
 (0)