Skip to content

Instantly share code, notes, and snippets.

@alexastrum
Last active July 29, 2020 21:47
Show Gist options
  • Save alexastrum/e2b0372c6d9a7c399592d2b1fcaef38f to your computer and use it in GitHub Desktop.
Save alexastrum/e2b0372c6d9a7c399592d2b1fcaef38f to your computer and use it in GitHub Desktop.
#define WIFI_SSID ""
#define WIFI_PASSWORD ""
#define DEVICE_ID "TestDevice"
#include "config.h"
#include "display.h"
#include "wifi.h"
void setup()
{
setupDisplay();
setupWiFi();
}
void loop()
{
displaySuspend("All done!");
}
#include <WiFiNINA.h>
#include <utility/wifi_drv.h>
/**
* Re-initialize the WiFi driver.
* This is currently necessary to switch from BLE to WiFi.
*/
void resetWiFi() {
wiFiDrv.wifiDriverDeinit();
wiFiDrv.wifiDriverInit();
}
void connectToWiFi()
{
int status = WiFi.status();
if (status == WL_CONNECTED)
{
return;
}
displayStatus("Connecting to WiFi...");
WiFi.setHostname(DEVICE_ID);
while(true) {
status = WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
if (status == WL_CONNECTED) {
break;
}
displayError("Retrying in 5 seconds...");
delay(5000);
resetWiFi();
}
displayStatus("Connected to WiFi.");
}
void setupWiFi()
{
int status = WiFi.status();
if (status == WL_NO_SHIELD)
{
displaySuspend("WiFi shield missing!");
}
if (status == WL_NO_MODULE)
{
displaySuspend("Communication with WiFi module failed!");
}
if (WiFi.firmwareVersion() < WIFI_FIRMWARE_LATEST_VERSION)
{
displayStatus("Please upgrade WiFi firmware!");
}
connectToWiFi();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment