首页 > 解决方案 > Esp8266 和 Internet FTP 客户端的密码?

问题描述

一段时间以来,我一直试图为 ESP8266 制作一个简单的 FTP 客户端程序,但没有成功。

我想将光值时间 + lux=max 65535 发送到我的互联网主页。一个简单的数据。我如何从互联网上获取时间?这是第二个问题。

我可以将数据发送到这样的互联网地方,不需要密码,但我的互联网地方需要密码。

我使用 ESP8266 是因为我可以把它放在屋外,并使用光电源,为锂电池充电,两节 18650 电池并联。我会在白天以小时为间隔发送。还有其他程序,它获取数据并转换为连续数据文件。然后它将转到PC图形。这些其他东西已经工作了大约 15-20 年,但我在 esp8266 中还很新。

我从网上找到了这个程序。它可以工作,但我还需要我的 Internet 服务的密码。有人可以帮助我吗?

#include <ESP8266WiFi.h>
// SSID
const char* ssid     = "MyWifiid";
const char* password = "MyWifiPassword";
// Host
const char* host = "dweet.io";
void setup() {

  // Serial
  Serial.begin(115200);
  delay(10);

  // We start by connecting to a 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(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  
  delay(5000);

  Serial.print("connecting to ");
  Serial.println(host);

//Connect to the host server:

  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }

//Formulate the URI for the GET request we will send to the host server:

  // We now create a URI for the request
  String url = "/dweet/for/MyLight?Lux=65535";

//Send the GET request to the server and check whether the request has been received or if it has timed out:

  // Send request
  Serial.print("Requesting URL: ");
  Serial.println(url);
  
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" + 
               "Connection: close\r\n\r\n");
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      Serial.println(">>> Client Timeout !");
      client.stop();
      return;
    }
  }

//Read incoming data from the host server line by line and display the data on the serial monitor.

//Close the connection after all the data has been received from the server:

      // Read all the lines from the answer
      while(client.available()){
        String line = client.readStringUntil('\r');
        Serial.print(line);
      }

      // Close connecting
      Serial.println();
      Serial.println("closing connection");
    }

标签: c++ftppasswordsclientesp8266

解决方案


为了获得时间,您可以使用NTP。这是一个示例:NTPClient

如果您想在网页的开头进行身份验证,这里是SimpleAuthentication示例:身份验证

我希望我正确理解了这个问题。


推荐阅读