今日も暖かったですね。皆様、如何お過ごしでしょうか。
さて表題ですが、”今日の名言”と訳すそうです。
RFC 865ってインターネットの超黎明期に提案された様です。※ RFCの意味は、本記事の末尾にあります。
1983年5月のタイムスタンプが付いています。
私の社会人2年目の年です。
なんか遊び心があって良いですね。
今回のサンプルコード(C言語)は、TCP Clientのスケッチをちょっと弄りました。
SSIDとPASSWORDは、皆さん個人の環境に合わせて下さい。
const char* host = "djxmmx.net"; // A "quote of the day" service site
const uint16_t port = 17; // Port 17
が接続条件になります。
"We want a few mad people now. See where the sane ones have landed us!"
George Bernard Shaw (1856-1950)
なのが返ってきました。どの様な意味なのでしょうか。まだ火曜日だというのに、悩んで今夜は眠れない
Google先生翻訳
私たちは今、数人の狂った人々が欲しいです。正気の人が着陸した場所を見る
(マンネリ化した状態に於いて)常識を打ち破れ の様な意味でしょうか
George Bernard Shawって、あのシェークスピア以来のアイルランド出身の天才劇作家とのことです。
私は、その分野には詳しくありません。
さてと、レガシー感の漂う”IoT版おみくじみ”たいな感じのサンプルコードです。
/*
RFC 865 Quote of the Day Protocol(QOTD)
This sketch establishes a TCP connection to a "quote of the day" service.
and it prints received data.
Last update 2020/11/16 modified for ESP8266 ESP-12F by jk1brk
*/
#include <ESP8266WiFi.h>
#ifndef STASSID
#define STASSID "SSID"
#define STAPSK "PASSWORD"
#endif
#define LED_BUILTIN2 14 // LED_BUILTIN2 GPIO14
const char* ssid = STASSID;
const char* password = STAPSK;
const char* host = "djxmmx.net"; // A "quote of the day" service site
const uint16_t port = 17; // Port 17
void setup() {
Serial.begin(115200);
// Prepare LED
pinMode(LED_BUILTIN2, OUTPUT); // LED_BUILTIN2 OUTPUT
digitalWrite(LED_BUILTIN2, 0); // LED_BUILTIN2 OFF
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to AP: ");
Serial.println(ssid);
/* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
would try to act as both a client and an access-point and could cause
network-issues with your other WiFi-devices on your WiFi-network. */
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("WiFi connected to AP ");
// Channel & Receive Signal Strangth Indicater(dbm)
Serial.printf("Ch: %d, RSSI: %ddBm
", WiFi.channel(), WiFi.RSSI());
Serial.print("Client IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
Serial.print("connecting to server & port: ");
Serial.print(host);
Serial.print(':');
Serial.println(port);
// Use WiFiClient class to create TCP connections
WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
delay(5000);
return;
}
// wait for data to be available
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
delay(60000);
return;
}
}
// Read all the lines of the reply from server and print them to Serial
Serial.println("receiving from remote server...");
// not testing 'client.connected()' since we do not need to send data here
digitalWrite(LED_BUILTIN2, 1); // LED_BUILTIN2 ON
while (client.available()) {
char ch = static_cast<char>(client.read());
Serial.print(ch);
}
digitalWrite(LED_BUILTIN2, 0); // LED_BUILTIN2 OFF
// Close the connection
Serial.println();
Serial.println("closing connection");
client.stop();
delay(300000); // execute once every 5 minutes, don't flood remote service
}
【参照記事】