LoginSignup
0
0

More than 5 years have passed since last update.

wemosで生http

Last updated at Posted at 2018-07-17

概要

wemosで生httpリクエストを表示してみた。

結果

GET /test HTTP/1.1
Host: 192.168.11.14
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: ja,en-US;q=0.9,en;q=0.8

サンプルコード

#include <ESP8266WiFi.h>

const char * ssid = "001D736531AA_G";
const char * password = "";
WiFiServer server(80);
void setup() 
{
    Serial.begin(115200);
    delay(10);
    pinMode(2, OUTPUT);
    digitalWrite(2, 0);
    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(500);
        Serial.print(".");
    }
    Serial.println("");
    Serial.println("WiFi connected");
    server.begin();
    Serial.println("Server started");
    Serial.println(WiFi.localIP());
}
void loop()
{
    WiFiClient client = server.available();
    if (!client)
    {
        return;
    }
    Serial.println("new client");
    while (!client.available())
    {
        delay(1);
    }
    String req = client.readStringUntil('\0');
    client.flush();
    String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>";
    s += "<body><textarea rows=10 cols=80>";
    s += req;
    s += "</textarea></body></html>\r\n\r\n";
    client.print(s);
    delay(1);
    Serial.println("Client disonnected");
}




以上。

0
0
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
0
0