c++ - 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");
}
解决方案
推荐阅读
- java - 如何使用 Apache Flink 从 Cassandra 读取数据?
- java - Chronicle:反序列化期间未初始化对象
- php - 在 Laravel 中通过内部 with() 排序
- scala - Gatling 将数据从 feeder 传递到 exec
- ios - UIView 弹簧动画是否使用缓动曲线选项?
- three.js - 在 ThreeJS 中获取对象的全局旋转位置
- stream - HERE.OLP:如何“订阅通知”到目录?
- firefox - 如何在 Firefox 中监控 websocket 帧
- html - 如何..获取在AngularJS + HTML中检查的值“值”的检查行的总和
- powercli - PowerCli 获取存储 I/O 控制状态