• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Arduino + esp8266_01s
#1
Mam do was pytanie jak przekazac

Kod:
Serial.read()

na strone www poprzez

Kod:
server.on("/serial_read", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", "");
  });

Cały Kod
Kod:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include "pages.h"
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(2, 3); // RX | TX

#ifndef APSSID
#define APSSID "ESPap"
#define APPSK  "thereisnospoon"
#endif

/* Set these to your desired credentials. */
const char *ssid = APSSID;
const char *password = APPSK;
String readString;

AsyncWebServer server(80);

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

    // Start the software serial for communication with the ESP8266
    ESPserial.begin(9600);  

    Serial.println("");
    Serial.println("Remember to to set Both NL & CR in the serial monitor.");
    Serial.println("Ready");
    Serial.println("");  
  
  Serial.println();
  Serial.print("Configuring access point...");
  /* You can remove the password parameter if you want the AP to be open. */
  WiFi.softAP(ssid, password);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
        AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", ESP_HTML_HOMEPAGE, ESP_HTML_SIZE);
        response->addHeader("Content-Encoding","gzip");
        request->send(response);
  });
  server.on("/serial", HTTP_GET, [](AsyncWebServerRequest *request){
        AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", ESP_HTML_SERIAL, ESP_HTML_SIZE);
        response->addHeader("Content-Encoding","gzip");
        request->send(response);
  });
  server.on("/serial_read", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", "NARAZIE NIC");
  });

  server.begin();
  Serial.println("HTTP server started");
}


void loop() {
      // listen for communication from the ESP8266 and then write it to the serial monitor
    if ( ESPserial.available() )   {  Serial.write( ESPserial.read() );  }

    // listen for user input and send it to the ESP8266
    if ( Serial.available() )       {  ESPserial.write( Serial.read() );  }

}
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości