Инструменты пользователя

Инструменты сайта


works:programmer:arduino:esp32-wifi-client

ESP32 Клиент WiFi

#include <WiFi.h>
 
static const char ssid[] = "__НАЗВАНИЕ_СЕТКИ__";
static const char pass[] = "__ПАРОЛЬ_СЕТКИ__";
static const char addr[] = "www.google.com";
 
static int keyIndex = 0;
 
void printWifiStatus();
 
WiFiClient cli;
 
void setup() {
  Serial.begin(115200);
  int stat = 900000;
  while (stat != WL_CONNECTED) {
    Serial.print("Connecting to: "); Serial.println(ssid);
    stat = WiFi.begin(ssid, pass);
    delay(10000);
  }
  Serial.println("AT+OK");
  printWifiStatus();
  Serial.println("\nStarting connection to server...");
  if (cli.connect(addr, 80)) {
    Serial.println("connected to server");
    // Make a HTTP request:
    cli.println("GET /search?q=arduino HTTP/1.1");
    cli.print("Host: ");
    cli.println(addr);
    cli.println("Connection: close");
    cli.println();
  }
 
}
 
void loop() {
  while (cli.available()) {
    char c = cli.read();
    Serial.write(c);
  }
  if (!cli.connected()) {
    Serial.println();
    Serial.println("disconnecting from server.");
    cli.stop();
    while (true);
  }
}
 
void printWifiStatus() {
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}
works/programmer/arduino/esp32-wifi-client.txt · Последнее изменение: 2019/12/12 05:20 — 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki