Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WioTerminalWifiConnect.cpp
#include "rpcWiFi.h"
#include <WiFiClientSecure.h>
#include"TFT_eSPI.h"
TFT_eSPI tft;
const char* ssid = "yourNetworkName";
const char* password = "yourNetworkPassword";
int connectingSeconds = 0;
WiFiClientSecure client;
void setup() {
tft.begin();
tft.setRotation(3);
tft.fillScreen(TFT_BLACK);
tft.setTextSize(2);
tft.setCursor(40, 50);
tft.print("El Bruno - @elbruno");
tft.setCursor(40, 75);
tft.print("Connecting to Wi-Fi..");
// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
WiFi.begin(ssid, password);
// attempt to connect to Wifi network:
while (WiFi.status() != WL_CONNECTED) {
connectingSeconds++;
tft.setCursor(40, 100);
tft.print("Seconds waiting: ");
tft.setCursor((40 + tft.textWidth("Seconds waiting: ")), 100);
tft.print(connectingSeconds);
// wait 1 second for re-trying
delay(1000);
WiFi.begin(ssid, password);
}
tft.setCursor(40, 125);
tft.print("Connected!");
tft.setCursor(40, 150);
tft.print("IP: ");
tft.setCursor((40 + tft.textWidth("IP: ")), 150);
tft.print(WiFi.localIP());
}
void loop() {
// do nothing
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment