ค่าไม่แสดงที่ web server ครับ

ESP 8266 เชื่อมต่อกับ เน็ตของโทรศัพท์ครับ Run ได้ปกติ แต่ค่าไม่แสดงที่ Google หรือ web server ครับ แก้ไขยังไงครับ


#include <ESP8266WiFi.h>

#define echoPin D7 // Echo Pin
#define trigPin D6 // Trigger Pin
 int LED = D5; 


const char* ssid = "book";
const char* password = "book1518";

double readCmDistance()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
//Return calculate the distance (in cm) based on the speed of sound.
return pulseIn(echoPin, HIGH)/58.2;
}

WiFiServer server(80);    
void setup() {
  pinMode(LED,OUTPUT);
  pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
  Serial.begin(115200);
  delay(10);

  // prepare GPIO2
  pinMode(5, OUTPUT);
  digitalWrite(5, 0);

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    digitalWrite(LED,HIGH);
  }
  Serial.println("");
  Serial.println("WiFi connected");

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.println(WiFi.localIP());
}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  // Wait until the client sends some data
  Serial.println("new client");
  unsigned long timeout = millis() + 3000;
  while (!client.available() && millis() < timeout) {
    delay(1);
  }
  if (millis() > timeout) {
    Serial.println("timeout");
    client.flush();
    client.stop();
    return;
  }

  // Read the first line of the request
  String req = client.readStringUntil('\r');
  Serial.println(req);
  client.flush();

  // Match the request
  int val;
  if (req.indexOf("/gpio/0") != -1) {
    val = 0;
  } else if (req.indexOf("/gpio/1") != -1) {
    val = 1;
  } else {
    Serial.println("invalid request");
    client.stop();
    return;
  }

  // Set GPIO2 according to the request
  digitalWrite(5, val);

  client.flush();

  // Prepare the response
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\n\r\ ";
  s += "\n";
  if (val) s += "" + String(readCmDistance()) + " cm.\n";

  // Send the response to the client
  client.print(s);
  delay(1);
  Serial.println("Client disconnected");

  // The client will actually be disconnected
  // when the function returns and 'client' object is detroyed
}

ทำตามตัวอย่างไหนมาครับ ถ้าต่อเน็ตโทรศัพท์ทั่วไปไม่น่าได้เพราะไอพีเป็นแบบ private ไม่งั้นลองเชื่อมเน็ต wifi จากที่เดียวกันกับ พีซีน่าจะได้อยู่ลองดูครับ

ตอนนี้ย้ายมาทำเป็น WiFimanager แล้วครับ จะเซ็ทให้ web server IP กลางทำยังไงหรอครับ

#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino

//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>         //https://github.com/tzapu/WiFiManager


void setup() {
    // put your setup code here, to run once:
    Serial.begin(115200);

    //WiFiManager
    //Local intialization. Once its business is done, there is no need to keep it around
    WiFiManager wifiManager;
    //reset saved settings
    //wifiManager.resetSettings();
    
    //set custom ip for portal
    //wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));

    //fetches ssid and pass from eeprom and tries to connect
    //if it does not connect it starts an access point with the specified name
    //here  "AutoConnectAP"
    //and goes into a blocking loop awaiting configuration
    wifiManager.autoConnect("AutoConnectAP");
    //or use this for auto generated name ESP + ChipID
    //wifiManager.autoConnect();

    
    //if you get here you have connected to the WiFi
    Serial.println("connected...yeey :)");
}

void loop() {
    // put your main code here, to run repeatedly:
    
}

ใช้เน็ตอะไรต่อ มือถือหรือว่าเน็ตบ้าน

เน็ตมือถือครับ

ต้องการใช้ภายในบ้านเอง หรือว่าดูจากนอกบ้านผ่านมือถือก็ได้?

ผ่านมือถือได้ด้วยครับ

ถ้าใช้ เน็ตมือถือไม่สามารถเจาะวงแลนเข้ามาได้ครับ ต้องเป็นเน็ตบ้านเท่านั้น อยากรู้เพิ่มเติมให้ศ฿กษาเรื่อง DDNS ของแต่ระเจ้าของเน็ตบ้านจะมีให้ใช้ ส่วนการใช้มือถืออาจต้องไปวิ่งผ่านตัวกลางอย่าง broker แต่ก็อาจมีข้อจำกัดลองหาข้อมูลดูครับ

wifimanager เชื่อมต่อกับเน็ตบ้าน เน็ตวิทยาลัย แล้วจะส่ง IP ที่ได้รับมา แล้วมันมีวิธีเซ็ท ค่า IP ที่จะเป้น web server รึป่าวครับ

จะเอา ESP เป็น server หรือ

ทำ ESP8266 ให้เป้น access point แล้วแสดงผลที่ web server อะไรแบบนี้อะครับ

ถ้าทำใช้ภายในวงแลนเดียวก็ได้อะครับ