2023-06-06 16:43:04 +02:00
|
|
|
#include <WiFi.h>
|
|
|
|
|
#include "configuration.h"
|
2023-06-08 06:58:10 +02:00
|
|
|
#include "wifi_utils.h"
|
2023-06-06 17:21:59 +02:00
|
|
|
#include "display.h"
|
2023-06-06 16:43:04 +02:00
|
|
|
|
|
|
|
|
extern Configuration Config;
|
|
|
|
|
extern WiFi_AP *currentWiFi;
|
|
|
|
|
extern int myWiFiAPIndex;
|
|
|
|
|
extern int myWiFiAPSize;
|
2023-06-08 23:09:05 +02:00
|
|
|
extern int stationMode;
|
2023-06-06 16:43:04 +02:00
|
|
|
|
|
|
|
|
namespace WIFI_Utils {
|
|
|
|
|
|
2023-06-08 23:09:05 +02:00
|
|
|
void startWiFi() {
|
2023-06-06 16:43:04 +02:00
|
|
|
int status = WL_IDLE_STATUS;
|
|
|
|
|
WiFi.mode(WIFI_STA);
|
|
|
|
|
WiFi.disconnect();
|
|
|
|
|
delay(500);
|
|
|
|
|
unsigned long start = millis();
|
2023-06-06 17:21:59 +02:00
|
|
|
show_display("", "Connecting to Wifi:", currentWiFi->ssid + " ...", 0);
|
2023-06-06 16:43:04 +02:00
|
|
|
Serial.print("\nConnecting to '"); Serial.print(currentWiFi->ssid); Serial.println("' WiFi ...");
|
|
|
|
|
WiFi.begin(currentWiFi->ssid.c_str(), currentWiFi->password.c_str());
|
|
|
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
|
|
|
Serial.print('.');
|
|
|
|
|
delay(1000);
|
|
|
|
|
if ((millis() - start) > 15000){
|
|
|
|
|
if(myWiFiAPIndex >= (myWiFiAPSize-1)) {
|
|
|
|
|
myWiFiAPIndex = 0;
|
|
|
|
|
} else {
|
|
|
|
|
myWiFiAPIndex++;
|
|
|
|
|
}
|
|
|
|
|
currentWiFi = &Config.wifiAPs[myWiFiAPIndex];
|
|
|
|
|
start = millis();
|
|
|
|
|
Serial.print("\nConnect to WiFi '"); Serial.print(currentWiFi->ssid); Serial.println("' ...");
|
2023-06-06 17:21:59 +02:00
|
|
|
show_display("", "Connect to Wifi:", currentWiFi->ssid + " ...", 0);
|
2023-06-06 16:43:04 +02:00
|
|
|
WiFi.begin(currentWiFi->ssid.c_str(), currentWiFi->password.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Serial.print("Connected as ");
|
|
|
|
|
Serial.println(WiFi.localIP());
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-08 23:09:05 +02:00
|
|
|
void setup() {
|
|
|
|
|
if (stationMode == 1 || stationMode == 2) {
|
|
|
|
|
if (stationMode==1) {
|
2023-06-08 01:34:18 +02:00
|
|
|
Serial.println("stationMode ---> iGate (only Rx)");
|
|
|
|
|
} else {
|
|
|
|
|
Serial.println("stationMode ---> iGate (Rx + Tx)");
|
|
|
|
|
}
|
2023-06-08 23:09:05 +02:00
|
|
|
startWiFi();
|
|
|
|
|
btStop();
|
|
|
|
|
} else if (stationMode == 3 || stationMode == 4) {
|
|
|
|
|
if (stationMode == 3) {
|
|
|
|
|
Serial.println("stationMode ---> DigiRepeater (Rx freq == Tx freq)");
|
|
|
|
|
} else {
|
|
|
|
|
Serial.println("stationMode ---> DigiRepeater (Rx freq != Tx freq)");
|
|
|
|
|
}
|
|
|
|
|
WiFi.mode(WIFI_OFF);
|
2023-06-08 01:34:18 +02:00
|
|
|
btStop();
|
|
|
|
|
} else {
|
2023-06-08 23:09:05 +02:00
|
|
|
Serial.println("stationMode ---> NOT VALID, check '/data/igate_conf.json'");
|
|
|
|
|
show_display("stationMode Not Valid", "change it on : /data/", "igate_conf.json", 0);
|
2023-06-08 01:34:18 +02:00
|
|
|
while (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 16:43:04 +02:00
|
|
|
}
|