diff --git a/software/firmware/source/SoftRF/src/driver/WiFi.cpp b/software/firmware/source/SoftRF/src/driver/WiFi.cpp index 3af5d16fe..ef5dcb47c 100644 --- a/software/firmware/source/SoftRF/src/driver/WiFi.cpp +++ b/software/firmware/source/SoftRF/src/driver/WiFi.cpp @@ -129,20 +129,68 @@ void WiFi_setup() // Print hostname. Serial.println("Hostname: " + host_name); - Serial.print(F("Setting soft-AP configuration ... ")); - WiFi.config(local_IP, gateway, gateway, subnet); - Serial.println(F("Ready")); + if (station_ssid.length() > 0) { + // ... Try to connect to WiFi station. + WiFi.begin(station_ssid.c_str(), station_psk.c_str()); + + // ... Pritn new SSID + Serial.print(F("new SSID: ")); + Serial.println(WiFi.SSID()); + + Serial.println(F("Wait for WiFi connection.")); + + // ... Give Wi-Fi 10-20 seconds to connect to station. + unsigned long startTime = millis(); + while (WiFi.status() != WL_CONNECTED && + millis() - startTime < WIFI_STA_TIMEOUT) + { + Serial.write('.'); Serial.flush(); + //Serial.print(WiFi.status()); + delay(500); + } + Serial.println(); - Serial.print(F("Setting soft-AP ... ")); - Serial.println(WiFi.beginAP(host_name.c_str(), ap_default_psk) == WL_AP_LISTENING ? - F("Ready") : F("Failed!")); + // Check connection + if (WiFi.status() == WL_CONNECTED) { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + +#if !defined(ARDUINO_RASPBERRY_PI_PICO) + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); +#endif /* ARDUINO_RASPBERRY_PI_PICO */ + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); + } else { + Serial.println(F("Can not connect to WiFi station. Go into AP mode.")); + } + } - Serial.print(F("IP address: ")); - Serial.println(WiFi.softAPIP()); + if (WiFi.status() != WL_CONNECTED) { + // Go into software AP mode. + Serial.print(F("Setting soft-AP configuration ... ")); + WiFi.config(local_IP, gateway, gateway, subnet); + Serial.println(F("Ready")); - SoC->WiFi_set_param(WIFI_PARAM_TX_POWER, WIFI_TX_POWER_MED); // 10 dBm - SoC->WiFi_set_param(WIFI_PARAM_DHCP_LEASE_TIME, WIFI_DHCP_LEASE_HRS); - delay(10); + SoC->WiFi_set_param(WIFI_PARAM_TX_POWER, WIFI_TX_POWER_MED); // 10 dBm + SoC->WiFi_set_param(WIFI_PARAM_DHCP_LEASE_TIME, WIFI_DHCP_LEASE_HRS); + + Serial.print(F("Setting soft-AP ... ")); + Serial.println(WiFi.beginAP(host_name.c_str(), ap_default_psk) == WL_AP_LISTENING ? + F("Ready") : F("Failed!")); + + delay(10); + +// Serial.print(F("IP address: ")); +// Serial.println(WiFi.softAPIP()); + } Uni_Udp.begin(RFlocalPort); Serial.print(F("UDP server has started at port: ")); diff --git a/software/firmware/source/SoftRF/src/platform/RP2040.cpp b/software/firmware/source/SoftRF/src/platform/RP2040.cpp index 389439dd0..a16087fa6 100644 --- a/software/firmware/source/SoftRF/src/platform/RP2040.cpp +++ b/software/firmware/source/SoftRF/src/platform/RP2040.cpp @@ -224,6 +224,10 @@ static void RP2040_msc_flush_cb (void) } #endif /* ARDUINO_ARCH_MBED */ +#if defined(ARDUINO_RASPBERRY_PI_PICO) && !defined(EXCLUDE_WIFI) +SPIClassRP2040 SPI0(spi0, PIN_SPI0_MISO, PIN_SPI0_SS, PIN_SPI0_SCK, PIN_SPI0_MOSI); +#endif /* EXCLUDE_WIFI */ + static void RP2040_setup() { #if !defined(ARDUINO_ARCH_MBED) @@ -279,6 +283,9 @@ static void RP2040_setup() #if defined(ARDUINO_RASPBERRY_PI_PICO) RP2040_board = RP2040_RPIPICO; +#if !defined(EXCLUDE_WIFI) + WiFi.setPins(PIN_SPI0_SS, D26, D24, D20, &SPI0); +#endif /* EXCLUDE_WIFI */ #elif defined(ARDUINO_RASPBERRY_PI_PICO_W) RP2040_board = rp2040.isPicoW() ? RP2040_RPIPICO_W : RP2040_RPIPICO; #endif /* ARDUINO_RASPBERRY_PI_PICO */ @@ -601,7 +608,7 @@ static uint32_t RP2040_maxSketchSpace() static void RP2040_WiFi_set_param(int ndx, int value) { -#if !defined(EXCLUDE_WIFI) +#if !defined(EXCLUDE_WIFI) && !defined(USE_ARDUINO_WIFI) switch (ndx) { case WIFI_PARAM_TX_POWER: @@ -630,7 +637,7 @@ static void RP2040_WiFi_set_param(int ndx, int value) #endif /* EXCLUDE_WIFI */ } -#if !defined(EXCLUDE_WIFI) +#if !defined(EXCLUDE_WIFI) && !defined(USE_ARDUINO_WIFI) #include #endif /* EXCLUDE_WIFI */ @@ -641,7 +648,7 @@ union rp2040_ip { static void RP2040_WiFi_transmit_UDP(int port, byte *buf, size_t size) { -#if !defined(EXCLUDE_WIFI) +#if !defined(EXCLUDE_WIFI) && !defined(USE_ARDUINO_WIFI) union rp2040_ip ipv4; IPAddress ClientIP; ipv4.addr = (uint32_t) WiFi.localIP(); @@ -677,7 +684,7 @@ static void RP2040_WiFi_transmit_UDP(int port, byte *buf, size_t size) static void RP2040_WiFiUDP_stopAll() { -#if !defined(EXCLUDE_WIFI) +#if !defined(EXCLUDE_WIFI) && !defined(USE_ARDUINO_WIFI) WiFiUDP::stopAll(); #endif /* EXCLUDE_WIFI */ } @@ -685,7 +692,7 @@ static void RP2040_WiFiUDP_stopAll() static bool RP2040_WiFi_hostname(String aHostname) { bool rval = false; -#if !defined(EXCLUDE_WIFI) +#if !defined(EXCLUDE_WIFI) && !defined(USE_ARDUINO_WIFI) if (RP2040_board == RP2040_RPIPICO_W) { WiFi.hostname(aHostname.c_str()); rval = true; @@ -696,7 +703,7 @@ static bool RP2040_WiFi_hostname(String aHostname) static int RP2040_WiFi_clients_count() { -#if !defined(EXCLUDE_WIFI) +#if !defined(EXCLUDE_WIFI) && !defined(USE_ARDUINO_WIFI) WiFiMode_t mode = WiFi.getMode(); switch (mode) diff --git a/software/firmware/source/SoftRF/src/platform/RP2040.h b/software/firmware/source/SoftRF/src/platform/RP2040.h index d9d8ad1df..047b1b15c 100644 --- a/software/firmware/source/SoftRF/src/platform/RP2040.h +++ b/software/firmware/source/SoftRF/src/platform/RP2040.h @@ -230,13 +230,21 @@ struct rst_info { #define USE_WIFI_CUSTOM true #include #define Serial_setDebugOutput(x) ({}) -#define WIFI_STA_TIMEOUT 20000 +#define WIFI_STA_TIMEOUT 20000 /* Experimental */ #define ENABLE_PROL //#define ENABLE_BT_VOICE #else #define EXCLUDE_WIFI +//#define EXCLUDE_OTA +//#define USE_ARDUINO_WIFI +//#define USE_WIFI_NINA false +//#define USE_WIFI_CUSTOM true +//#include +//#define Serial_setDebugOutput(x) ({}) +//#define WIFI_STA_TIMEOUT 20000 + #define EXCLUDE_BLUETOOTH #endif /* ARDUINO_RASPBERRY_PI_PICO_W */ diff --git a/software/firmware/source/SoftRF/src/platform/SAMD.cpp b/software/firmware/source/SoftRF/src/platform/SAMD.cpp index 075fc0244..2fd3d9dd7 100644 --- a/software/firmware/source/SoftRF/src/platform/SAMD.cpp +++ b/software/firmware/source/SoftRF/src/platform/SAMD.cpp @@ -70,7 +70,9 @@ Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIX_NUM, SOC_GPIO_PIN_LED, NEO_GRB + NEO_KHZ800); #endif /* EXCLUDE_LED_RING */ +#if defined(EXCLUDE_WIFI) char UDPpacketBuffer[4]; // Dummy definition to satisfy build sequence +#endif /* EXCLUDE_WIFI */ static struct rst_info reset_info = { .reason = REASON_DEFAULT_RST, diff --git a/software/firmware/source/SoftRF/src/ui/Web.cpp b/software/firmware/source/SoftRF/src/ui/Web.cpp index 96b52134a..d1193338b 100644 --- a/software/firmware/source/SoftRF/src/ui/Web.cpp +++ b/software/firmware/source/SoftRF/src/ui/Web.cpp @@ -678,7 +678,23 @@ void handleSettings() { server.sendHeader(String(F("Cache-Control")), String(F("no-cache, no-store, must-revalidate"))); server.sendHeader(String(F("Pragma")), String(F("no-cache"))); server.sendHeader(String(F("Expires")), String(F("-1"))); +#if !defined(USE_ARDUINO_WIFI) server.send ( 200, "text/html", Settings_temp ); +#else + char *content = Settings_temp; + size_t bytes_left = strlen(Settings_temp); + size_t chunk_size; + + server.setContentLength(bytes_left); + server.send(200, String(F("text/html")), ""); + + do { + chunk_size = bytes_left > JS_MAX_CHUNK_SIZE ? JS_MAX_CHUNK_SIZE : bytes_left; + server.sendContent(content, chunk_size); + content += chunk_size; + bytes_left -= chunk_size; + } while (bytes_left > 0) ; +#endif /* USE_ARDUINO_WIFI */ SoC->swSer_enableRx(true); free(Settings_temp); }