6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

M5Stack(ESP32)のWiFiサーバーにPCからtelnetで繋いでSerialとtelnetでリモートエコーを受け取る

Last updated at Posted at 2019-02-20

ArduinoにM5Stackのboard定義をインストールすると一緒に入ってくるM5Stack-Core-ESP32用のサンプルスケッチのSimpleWifiServerはWebサーバーとして振る舞ってますが、もっと原始的にPCからtelnetで繋いでPCから送信した文字をSerialからリモートエコーさせて動作を確認するスケッチを作ったので共有します。

これをESPに書き込んで

#include <WiFi.h>

const char* ssid     = "yourssid";
const char* password = "yourpassword";
const int port = 3232;

WiFiServer server(port);

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

    Serial.print("Connecting to ");
    Serial.println(ssid);

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
        delay(100);
        Serial.print(".");
    }

    Serial.println("");
    Serial.println("WiFi connected.");
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());
    Serial.print("Server port: ");
    Serial.println(port);
        
    server.begin();

}

void loop(){
 WiFiClient client = server.available();
  if (client) {
    Serial.println("New Client.");

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        client.write(c);
      }
    }
    
    client.stop();
    Serial.println("Client Disconnected.");
  }
}

シリアルコンソールを開くとIPとかポートが表示されるので(WiFiに接続できてれば)

Connecting to yourssid
....................
WiFi connected.
IP address: 192.168.1.8
Server port: 3232

> telnet 192.168.1.8 3232

あとはコマンドラインからtelnetで接続してキーボードを叩けば同じ文字がシリアルコンソールとtelnetのコンソールに表示されます。

6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?