hello world for esp32-wrover

This post is based mostly on Installing ESP32 Board in Arduino IDE 2 (Windows, Mac OS X, Linux) | Random Nerd Tutorials it is a good resource to get started on verify the ESP32-WROVER is working.

The hardest part is to determine what are the connector chip and installing libraries into Arduino IDE. Refer to the shared link in the beginning of this post.

Code from DeepSeek for a complicated hello world, assuming to make the LED blinks in morse code:

#include <Arduino.h>

#define LED_PIN 2  // Built-in LED on GPIO 2

// Morse code representations for A-Z
const char* morseCodes[] = {
  ".-",    // A
  "-...",  // B
  "-.-.",  // C
  "-..",   // D
  ".",     // E
  "..-.",  // F
  "--.",   // G
  "....",  // H
  "..",    // I
  ".---",  // J
  "-.-",   // K
  ".-..",  // L
  "--",    // M
  "-.",    // N
  "---",   // O
  ".--.",  // P
  "--.-",  // Q
  ".-.",   // R
  "...",   // S
  "-",     // T
  "..-",   // U
  "...-",  // V
  ".--",   // W
  "-..-",  // X
  "-.--",  // Y
  "--.."   // Z
};

void setup() {
  pinMode(LED_PIN, OUTPUT);  // Set the LED pin as an output
  Serial.begin(115200);
}

void loop() {
  String message = "SOS";  // Message to transmit in Morse code
  message.toUpperCase();   // Convert message to uppercase

  // Transmit the message in Morse code
  for (int i = 0; i < message.length(); i++) {
    char currentChar = message[i];
    if (currentChar >= 'A' && currentChar <= 'Z') {
      transmitMorse(morseCodes[currentChar - 'A']);  // Transmit Morse code for the character
    } else if (currentChar == ' ') {
      delay(1400);  // Gap between words (7 units)
    }
    delay(600);  // Gap between letters (3 units)
  }

  delay(2000);  // Wait before repeating the message
}

// Function to transmit a Morse code pattern
void transmitMorse(const char* morseCode) {
  for (int i = 0; i < strlen(morseCode); i++) {
    if (morseCode[i] == '.') {
      blinkDot();  // Transmit a dot
    } else if (morseCode[i] == '-') {
      blinkDash();  // Transmit a dash
    }
    delay(200);  // Gap between dots/dashes (1 unit)
  }
}

// Function to blink a dot (short flash)
void blinkDot() {
  digitalWrite(LED_PIN, HIGH);  // Turn the LED on
  delay(200);                   // Dot duration (1 unit)
  digitalWrite(LED_PIN, LOW);   // Turn the LED off
}

// Function to blink a dash (long flash)
void blinkDash() {
  digitalWrite(LED_PIN, HIGH);  // Turn the LED on
  delay(600);                   // Dash duration (3 units)
  digitalWrite(LED_PIN, LOW);   // Turn the LED off
}

Code to connect to WiFi:

#include <WiFi.h>

// Replace with your network credentials
const char* ssid = "myhome4iot";
const char* password = "i have the longest wifi password ever";

void setup() {
  Serial.begin(115200);

  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  Serial.println("Connecting to Wi-Fi...");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }

  // Connection successful
  Serial.println("\nWi-Fi connected!");

  // Get and print network information
  IPAddress ip = WiFi.localIP();
  IPAddress gateway = WiFi.gatewayIP();
  IPAddress dns = WiFi.dnsIP();

  Serial.println("Network Information:");
  Serial.print("IP Address: ");
  Serial.println(ip);
  Serial.print("Gateway: ");
  Serial.println(gateway);
  Serial.print("DNS Server: ");
  Serial.println(dns);
}

void loop() {
  // Nothing to do here
}
Returning IP information of ESP32

Code to scan WiFi:

#include <WiFi.h>

void setup() {
  Serial.begin(115200);

  // Set ESP32 to station mode
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();  // Disconnect from any previous connection
  delay(100);

  Serial.println("Starting Wi-Fi scan...");
}

void loop() {
  // Scan for nearby Wi-Fi networks
  int numNetworks = WiFi.scanNetworks();

  if (numNetworks == 0) {
    Serial.println("No networks found.");
  } else {
    Serial.print(numNetworks);
    Serial.println(" networks found:");
    for (int i = 0; i < numNetworks; i++) {
      // Print SSID and RSSI for each network
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.print(WiFi.SSID(i));  // SSID
      Serial.print(" (");
      Serial.print(WiFi.RSSI(i));  // Signal strength (RSSI)
      Serial.print(" dBm)");
      Serial.print(" [");
      Serial.print(getEncryptionType(WiFi.encryptionType(i)));  // Encryption type
      Serial.println("]");
    }
  }

  Serial.println("-----------------------------");
  delay(10000);  // Wait 10 seconds before scanning again
}

// Function to convert encryption type to a human-readable string
String getEncryptionType(wifi_auth_mode_t encryptionType) {
  switch (encryptionType) {
    case WIFI_AUTH_OPEN:
      return "Open";
    case WIFI_AUTH_WEP:
      return "WEP";
    case WIFI_AUTH_WPA_PSK:
      return "WPA";
    case WIFI_AUTH_WPA2_PSK:
      return "WPA2";
    case WIFI_AUTH_WPA_WPA2_PSK:
      return "WPA/WPA2";
    case WIFI_AUTH_WPA2_ENTERPRISE:
      return "WPA2 Enterprise";
    case WIFI_AUTH_WPA3_PSK:
      return "WPA3";
    case WIFI_AUTH_WPA2_WPA3_PSK:
      return "WPA2/WPA3";
    default:
      return "Unknown";
  }
}

Unfortunately, due to the ESP32-WROVER hardware limitation, any modern 5GHz WiFi will not be able to be scanned or detected. On top of that, the stock ESP32-WROVER-IE needs to have a actual wifi cable to extend its range.

WiFi range is too short to scan a large area as well as limitation of WiFi hardware/chip

Making your windows RDP accessible from your home network

It is simple to make your computer in your home LAN accessible from internet.

The pre-requisite would be understanding how Network Address Translation works. To make the dynamic IP of ISP provide to your home internet access, feel free to research into finding Dynamic DNS providers. This will make it easier than using websites like whatismyip.com . And you just need to fire up the RDP client, and use the Dynamic DNS FQDN which will be always pointing to your static IP.

Depending on the network equipment used in your home or provided by your Internet Service Provider (ISP), you may need to look for NAT or in my case IPv4 port mapping.

The screenshot above, shows how to create a NAT mapping or a IPv4 port mapping for a computer with LAN IP, 192.168.100.12, take note that the port of RDP is 3389 and the protocol used is TCP. Hence, the internal port must be numbered 3389.

External port set to 3389 are for the sake of simplicity.

If there are more host in your LAN need to be accessible from the internet remotely using RDP, there is no need to change the default port of RDP of your host.

Instead, use the known port that is not blocked by your ISP. Example assuming that higher port numbers are not blocked by your ISP, you could use 13389, or 23389, or 33389 or 43389, or 53389 or 63389, as long as it is not more than 65535 or lesser than 1024. Those port number can be used as the External port number, while maintaining the internal port number to 3389.

Connect to SSH using customed port from UBuntu Terminal

Scope and conditions :

  1. SSH service is running on remote server.
  2. SSH is binded to IP address 10.10.10.10.
  3. SSH service is running on Port 9394 or customed port (SSH default port 22).
  4. There is no firewall on your computer or your network. Continue reading

Nuts about NAT

Unlike actual mailing or house addresses, public IP addresses is more easily depleted.

Each host in a computer network or Internet in this case, requires public IP address to identify itself in the Internet. IP Simplified : It is used as a unique Identity for computers to communicate and interact in the Internet.

IP Address is a highlighted on the first statement is getting more rare. Due to this limitation, many users needs to share a single Internet public IP… Continue reading