最終更新日:2023/3/10
インクルードするライブラリですが、Ethernet3を使用します。このライブラリは安定していると思います。
TM1637用のポートは確保します。
/* Chat Server A simple server that distributes any incoming messages to all connected clients. To use telnet to your device's IP address and type. You can see the client's input in the serial monitor as well. Using an Arduino Wiznet Ethernet shield. Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 * Analog inputs attached to pins A0 through A5 (optional) created 18 Dec 2009 by David A. Mellis modified 9 Apr 2012 by Tom Igoe */ #include <SPI.h> #include <Ethernet3.h> // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network. // gateway and subnet are optional: byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192, 168, 1, 177); IPAddress gateway(192, 168, 1, 1); IPAddress subnet(255, 255, 0, 0); // telnet defaults to port 23 EthernetServer server(23); boolean alreadyConnected = false; // whether or not the client was connected previously void setup() { // initialize the ethernet device Ethernet.begin(mac, ip, subnet, gateway); // start listening for clients server.begin(); // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } Serial.print("Chat server address:"); Serial.println(Ethernet.localIP()); } void loop() { // wait for a new client: EthernetClient client = server.available(); // when the client sends the first byte, say hello: if (client) { if (!alreadyConnected) { // clead out the input buffer: client.flush(); Serial.println("We have a new client"); client.println("Hello, client!"); alreadyConnected = true; } if (client.available() > 0) { // read the bytes incoming from the client: char thisChar = client.read(); // echo the bytes back to the client: server.write(thisChar); // echo the bytes to the server as well: Serial.write(thisChar); } } } |
|
/* * 2023/03/10 T.Wanibe * Chat Server * 着信メッセージを接続されているすべてのクライアントに配信する単純なサーバー。 * W5500-EVB-PICOをターゲットとしています * 回路: * ピン 16..21に接続されたイーサネットchip * 最大1044480バイトのフラッシュメモリのうち、スケッチが61292バイト(5%)を使っています。 * 最大262144バイトのRAMのうち、グローバル変数が7944バイト(3%)を使っていて、ローカル変数で254200バイト使うことができます。 */ #include <SPI.h> #include <Ethernet3.h> #define SPI_SCK 18 #define SPI_RX 16 #define SPI_TX 19 #define SPI_CS 17 #define NICReset 20 #define HTTPport 80 #define TELNETport 23 #define SerialRate 115200 // コントローラの MAC アドレスと IP アドレスを以下に入力します。 // IP アドレスは、ローカル ネットワークによって異なります。 byte mac[] = {0x00,0x08,0xDC,0x54,0x4D,0xE0}; //WIZNET byte ip[] = {192, 168, 0, 210}; byte gateway[] = {192, 168, 0, 1}; byte subnet[] = {255, 255, 255, 0}; // telnet defaults to port 23 EthernetServer server(TELNETport); boolean alreadyConnected = false; // whether or not the client was connected previously //------------- void setup() { pinMode(SPI_CS,OUTPUT); pinMode(NICReset,OUTPUT); // イーサネット接続とサーバーを開始します。 SPI.setSCK(SPI_SCK); SPI.setRX(SPI_RX); SPI.setTX(SPI_TX); SPI.setCS(SPI_CS); SPI.begin(); // Ethernet.init(pin)を使用してCSピンを設定できます Ethernet.setCsPin(SPI_CS); Ethernet.setRstPin(NICReset); digitalWrite(NICReset,LOW); delay(10); digitalWrite(NICReset,HIGH); Ethernet.init(SPI_CS); // イーサネット デバイスを初期化する Ethernet.begin(mac, ip, subnet, gateway); // start listening for clients server.begin(); // Open serial communications and wait for port to open: Serial.begin(SerialRate); while (!Serial) { ; // シリアルポートが接続されるのを待ちます。 } Serial.print("Chat server address:"); Serial.println(Ethernet.localIP()); } //------------- void loop() { // 新しいクライアントを待ちます: EthernetClient client = server.available(); // クライアントが最初のバイトを送信したら、こんにちはと言ってください: if (client) { if (!alreadyConnected) { // 入力バッファをクリアします: client.flush(); Serial.println("We have a new client"); client.println("Hello, client!"); alreadyConnected = true; } if (client.available() > 0) { // クライアントから受信したバイトを読み取ります。 char thisChar = client.read(); // バイトをクライアントにエコー バックします。 server.write(thisChar); //バイトをサーバーにもエコーします。 Serial.write(thisChar); } } } |
本ソフトウエアは、あなたに対して何も保証しません。本ソフトウエアの関係者(他の利用者も含む)は、あなたに対して一切責任を負いません。
あなたが、本ソフトウエアを利用(コンパイル後の再利用など全てを含む)する場合は、自己責任で行う必要があります。本ソフトウエアの著作権はToolsBoxに帰属します。
本ソフトウエアをご利用の結果生じた損害について、ToolsBoxは一切責任を負いません。
ToolsBoxはコンテンツとして提供する全ての文章、画像等について、内容の合法性・正確性・安全性等、において最善の注意をし、作成していますが、保証するものではありません。
ToolsBoxはリンクをしている外部サイトについては、何ら保証しません。
ToolsBoxは事前の予告無く、本ソフトウエアの開発・提供を中止する可能性があります。
Microsoft、Windows、WindowsNTは米国Microsoft Corporationの米国およびその他の国における登録商標です。
Windows Vista、Windows XPは、米国Microsoft Corporation.の商品名称です。
LabVIEW、National Instruments、NI、ni.comはNational Instrumentsの登録商標です。
I2Cは、NXP Semiconductors社の登録商標です。
その他の企業名ならびに製品名は、それぞれの会社の商標もしくは登録商標です。
すべての商標および登録商標は、それぞれの所有者に帰属します。