pdf-icon

Arduino Quick Start

2. Devices & Examples

Air Quality Wi-Fi Information

Air Quality Wi-Fi related APIs and example program.

Example

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#include <M5Unified.h>
#include <WiFi.h>

void setup() {
  // Initialize M5Unified
  M5.begin();
  // Clear screen once – black background
  M5.Lcd.fillScreen(TFT_BLACK);
  // Set text properties
  M5.Lcd.setTextSize(1);
  M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
  // Scan for Wi-Fi networks
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);
  int n = WiFi.scanNetworks();
  // Print results to the screen
  M5.Lcd.setCursor(0, 0);
  M5.Lcd.printf("Found %d networks\n\n", n);
  for (int i = 0; i < n; i++) {
    // Long SSIDs will wrap automatically
    M5.Lcd.printf("%2d: %s\n    (%d dBm)\n\n",
                  i + 1,
                  WiFi.SSID(i).c_str(),
                  WiFi.RSSI(i));
    delay(50);
  }
}

void loop() {
  M5.update();
  // To refresh periodically, place code here
}

After uploading, press the reset button to see the following:

On This Page