Last active
July 29, 2020 21:47
-
-
Save alexastrum/e2b0372c6d9a7c399592d2b1fcaef38f to your computer and use it in GitHub Desktop.
Firebase IoT https://medium.com/@alexastrum/connect-arduino-nano-33-iot-to-firebase-rtdb-in-5-minutes-347ec6917da5 #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define WIFI_SSID "" | |
#define WIFI_PASSWORD "" | |
#define DEVICE_ID "TestDevice" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "config.h" | |
#include "display.h" | |
#include "wifi.h" | |
void setup() | |
{ | |
setupDisplay(); | |
setupWiFi(); | |
} | |
void loop() | |
{ | |
displaySuspend("All done!"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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