http://www.universalcard.byethost7.com是我的服务器。我保存index.php文件的地方。代码如下:
<?php
if(isset($_GET['username']) && isset($_GET['pin']) && isset($_GET['cost'])) {
$username = $_GET['username'];
$pin = $_GET['pin'];
$cost = $_GET['cost'];
$filecontent = "Username is: ".$username." and PIN is: ".$pin." and cost is: ".$cost."\n";
$filestatus = file_put_contents('uc.txt',$filecontent,FILE_APPEND);
if($filestatus != false )
{
echo "Data written to file..";
}else{
echo "Ohh sorry..";
}
} else {
echo "Something went wrong..";
}
?>
我想通过Arduino IDE向ESP8266发送GET请求。 在这个GET请求中,我发送3个变量'username','pin'和'cost'以及一些值(数据类型为String)。并且这些值附加到文件“uc.txt”。因此,当我使用浏览器发送请求时,值将附加到文本文件中。
但是当我尝试使用ESP8266发送时,它没有附加
Arduino代码低于
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
const char* ssid = "rainbow";
const char* password = "12345678";
const char* host = "universalcard.byethost7.com";
const int httpsPort = 443;
// Use web browser to view and copy
// SHA1 fingerprint of the certificate
//const char* fingerprint = "CF 05 98 89 CA FF 8E D8 5E 5C E0 C2 E4 F7 E6 C3 C7 50 DD 5C";
void setup() {
Serial.begin(115200);
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());
// Use WiFiClientSecure class to create TLS connection
WiFiClientSecure client;
Serial.print("connecting to ");
Serial.println(host);
if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
return;
}
String url = "/index.php?username=2bv14is114&pin=5555&cost=1111";
Serial.print("requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: BuildFailureDetectorESP8266\r\n" +
"Connection: close\r\n\r\n");
Serial.println("request sent");
while (client.connected()) {
String line = client.readStringUntil('\n');
if (line == "\r") {
Serial.println("headers received");
break;
}
}
String line = client.readStringUntil('\n');
if (line.startsWith("{\"state\":\"success\"")) {
Serial.println("esp8266/Arduino CI successfull!");
} else {
Serial.println("esp8266/Arduino CI has failed");
}
Serial.println("reply was:");
Serial.println("==========");
Serial.println(line);
Serial.println("==========");
Serial.println("closing connection");
}
void loop() {
}
串行监视器中的输出低于
答案 0 :(得分:0)