2019年10月23日星期三

Arduino ESP32 TCP Socket Server

Arduino ESP32 TCP Socket Server



Simple code
#include <WiFi.h>
const char* ssid = "WiFiSSID";
const char* password =  "WiFiPassword";

WiFiServer wifiServer(8000);

void setup() {

  Serial.begin(115200);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }
  Serial.println("Connected to the WiFi network");
  Serial.println(WiFi.localIP());
  wifiServer.begin();
}
void loop() {
 
  WiFiClient client = wifiServer.available();
  if (client) {
    while (client.connected()) {

      //      while (client.available()>0) {
      //        char c = client.read();
      //        client.write(c);
      //      }
      client.println(analogRead(0));
      //delay(10);
    }
    client.stop();
    Serial.println("Client disconnected");
  }
}


沒有留言:

發佈留言

打賞按讚