#WioTerminal – Connecting to Wifi 📶, display local IP and get ready for Azure ☁️ scenarios !

Hi !

Another fast post to cover a super important scenario:

Connect to a Wifi network in the Wio Terminal.

The code and implementation are extremely simple for this, and with a couple of lines of code, we can connect and also display the local IP.

WioTerminal Connect to Wifi and display IP

Source Code

As usual, the full code is below and some notes

  • The Wifi mode must be set to STA and also must be disconnected before starting a new connection.
  • I added a counter to display how much time takes to connect to the WiFi network.
  • This can also be used for a timeout control.
  • I also display the IP address assigned to the device.
#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
}

Now we are connected, so we can start to interact with Azure resources !

Happy coding!

Greetings

El Bruno


References


¿Con ganas de ponerte al día?

En Lemoncode te ofrecemos formación online impartida por profesionales que se baten el cobre en consultoría:

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: