Skip to content

Commit d24b649

Browse files
Update Wireless Stick Lite factory test example
1 parent f49c0a6 commit d24b649

File tree

1 file changed

+62
-33
lines changed

1 file changed

+62
-33
lines changed

examples/Factory_Test/Wireless_Stick_Lite_FactoryTest/Wireless_Stick_Lite_FactoryTest.ino

Lines changed: 62 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11

22
/*.........................................................................................
3-
* HelTec Automation(TM) WIFI_LoRa_32 factory test code, witch includ
3+
* HelTec Automation(TM) Wireless Stick Lite factory test code, witch include
44
* follow functions:
55
*
6+
* - Node A search WiFi and send WiFi AP number to another node B via LoRa, Node B
7+
* will send a string "abc" back to Node A, if Node A received "abc", test pass.
8+
*
69
* - Basic serial port test(in baud rate 115200);
710
*
811
* - LED blink test;
@@ -26,7 +29,8 @@
2629

2730
String packet;
2831
uint64_t chipid;
29-
bool receiveflag = false; // software flag for LoRa receiver, received data makes it true.
32+
bool IsACKRecvied = false;
33+
3034

3135
void WIFISetUp(void)
3236
{
@@ -36,7 +40,7 @@ void WIFISetUp(void)
3640
delay(1000);
3741
WiFi.mode(WIFI_STA);
3842
WiFi.setAutoConnect(true);
39-
WiFi.begin("WiFi SSID","WiFi password");
43+
WiFi.begin("WiFi SSID","WIFI password");
4044
delay(100);
4145

4246
byte count = 0;
@@ -64,20 +68,8 @@ void setup()
6468
{
6569
Heltec.begin(false /*DisplayEnable Enable*/, true /*LoRa Enable*/, true /*Serial Enable*/, true /*LoRa use PABOOST*/, 868E6 /*LoRa RF working band*/);
6670

67-
pinMode(25,OUTPUT);
68-
69-
pinMode(Vext,OUTPUT);
70-
digitalWrite(Vext, LOW); //// OLED USE Vext as power supply, must turn ON Vext before OLED init
71-
delay(50);
72-
7371
WIFISetUp();
7472

75-
LoRa.beginPacket();
76-
LoRa.print(WiFi.scanNetworks());
77-
LoRa.print(" networks found");
78-
LoRa.endPacket();
79-
Serial.printf("LoRa data sent success!\r\n");
80-
8173
// register the receive callback
8274
LoRa.onReceive(onReceive);
8375

@@ -87,28 +79,65 @@ void setup()
8779

8880
void loop()
8981
{
90-
if(receiveflag)
91-
{
92-
chipid=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes).
93-
Serial.printf("ESP32ChipID=%04X",(uint16_t)(chipid>>32));//print High 2 bytes
94-
Serial.printf("%08X\r\n",(uint32_t)chipid);//print Low 4bytes.
82+
unsigned char WiFiCount = 0;
9583

96-
receiveflag = false;
97-
}
98-
//delay(1000);
84+
if(!IsACKRecvied) //Scan native WiFi
85+
{
86+
WiFiCount = WiFi.scanNetworks();
87+
88+
LoRa.beginPacket();
89+
LoRa.print("H");//data header
90+
LoRa.print(WiFiCount);
91+
LoRa.endPacket();
92+
Serial.printf("%d", WiFiCount);
93+
Serial.printf(" WiFi found\r\n");
94+
}
95+
96+
// If received LoRa package with WIFI information, send ACK to node
97+
98+
else if((packet[0] == 'H') && (packet[1] >= 0x31))
99+
{
100+
packet = "";
101+
102+
digitalWrite(LED,LOW);
103+
104+
Serial.printf("Received WiFi packet number.\r\n");
105+
106+
LoRa.beginPacket();
107+
LoRa.print("abc");
108+
LoRa.endPacket();
109+
delay(10);
110+
111+
Serial.printf("LoRa sent 'abc' done.\r\n");
112+
}
113+
114+
else if((packet[0] == 'a') && (packet[1] == 'b') && (packet[2] == 'c')) // If received ACK package == "abc", test pass and print ChipID
115+
{
116+
packet = "";
117+
118+
digitalWrite(LED,HIGH);
119+
120+
chipid=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes).
121+
Serial.printf("ESP32ChipID=%04X",(uint16_t)(chipid>>32));//print High 2 bytes
122+
Serial.printf("%08X\r\n",(uint32_t)chipid);//print Low 4bytes.
123+
124+
digitalWrite(LED,HIGH);
125+
}
126+
127+
LoRa.receive();
128+
delay(2000);
99129
}
100130

101131
void onReceive(int packetSize)//LoRa receiver interrupt service
102132
{
103-
packet = "";
133+
packet = "";
104134

105-
while (LoRa.available())
106-
{
107-
packet += (char) LoRa.read();
108-
}
109-
if((packet[0] == 'a')&&(packet[1] == 'b')&&(packet[2] == 'c'))
110-
{
111-
digitalWrite(25,HIGH);
112-
receiveflag = true;
113-
}
135+
while (LoRa.available())
136+
{
137+
packet += (char) LoRa.read();
138+
}
139+
Serial.println(packet);
140+
Serial.println(LoRa.packetRssi());
141+
142+
IsACKRecvied = true;
114143
}

0 commit comments

Comments
 (0)