kopia lustrzana https://github.com/sh123/esp32_loraprs
Added wifi reconnection
rodzic
ec9a86fce6
commit
d9ba503c43
25
loraprs.cpp
25
loraprs.cpp
|
@ -30,6 +30,8 @@ void LoraPrs::setupWifi(String wifiName, String wifiKey)
|
|||
if (wifiName.length() != 0) {
|
||||
Serial.print("WIFI connecting to " + wifiName);
|
||||
|
||||
WiFi.setHostname("loraprs");
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(wifiName.c_str(), wifiKey.c_str());
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
|
@ -41,6 +43,19 @@ void LoraPrs::setupWifi(String wifiName, String wifiKey)
|
|||
}
|
||||
}
|
||||
|
||||
void LoraPrs::reconnectWifi() {
|
||||
|
||||
Serial.print("WIFI re-connecting...");
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED || WiFi.localIP() == IPAddress(0,0,0,0)) {
|
||||
WiFi.reconnect();
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println("ok");
|
||||
}
|
||||
|
||||
void LoraPrs::setupLora(int loraFreq)
|
||||
{
|
||||
Serial.print("LoRa init...");
|
||||
|
@ -77,12 +92,16 @@ void LoraPrs::setupBt(String btName)
|
|||
|
||||
void LoraPrs::loop()
|
||||
{
|
||||
if (WiFi.status() != WL_CONNECTED && wifiName_.length() != 0) {
|
||||
reconnectWifi();
|
||||
}
|
||||
if (serialBt_.available()) {
|
||||
onBtReceived();
|
||||
}
|
||||
if (LoRa.parsePacket()) {
|
||||
onLoraReceived();
|
||||
}
|
||||
delay(10);
|
||||
}
|
||||
|
||||
void LoraPrs::onAprsReceived(String aprsMessage)
|
||||
|
@ -114,9 +133,9 @@ void LoraPrs::onLoraReceived()
|
|||
serialBt_.write((uint8_t)buf[i]);
|
||||
}
|
||||
onAprsReceived(buf + " " +
|
||||
String(LoRa.packetRssi()) + ", " +
|
||||
String(LoRa.packetSnr()) + "dB, " +
|
||||
String(LoRa.packetFrequencyError()) + "ppm\n");
|
||||
"RSSI: " + String(LoRa.packetRssi()) + ", " +
|
||||
"SNR: " + String(LoRa.packetSnr()) + "dB, " +
|
||||
"ERR: " + String(LoRa.packetFrequencyError()) + "Hz\n");
|
||||
delay(50);
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ private:
|
|||
void setupWifi(String wifiName, String wifiKey);
|
||||
void setupLora(int loraFreq);
|
||||
void setupBt(String btName);
|
||||
|
||||
void reconnectWifi();
|
||||
|
||||
void onLoraReceived();
|
||||
void onBtReceived();
|
||||
|
|
Ładowanie…
Reference in New Issue