ねえ!これが私の最初の投稿です!すべての初心者がESP8266に慣れやすくするために作成することにしました。
つまり、ESP-01があります。
![](https://habrastorage.org/getpro/habr/upload_files/28a/848/6e2/28a8486e28b32a6f2bec6a53d9330345.jpg)
そしてUSB-UARTコンバーター。
![](https://habrastorage.org/getpro/habr/upload_files/671/b3b/250/671b3b250dd8476f76ee6dad5fee017e.jpg)
個人的には持っていますが、それは重要ではありません。
他のモジュールを使用することもできますが、接続図のみが変更されます。
ファームウェアを接続します:
![](https://habrastorage.org/getpro/habr/upload_files/4e2/1a4/432/4e21a44321946c3aff039ac3ecbfb24f.jpg)
すぐに落とし穴について言う必要があります。
GPIO0 EXT_RSBT 10.
, RTS DTR.
, ESP-01 – 3,3. 3,3.
3,3 USB-UART , 220 ESP-01.
lm1117-3,3. , ESP-01 ESPlorer Lua Arduino.
![](https://habrastorage.org/getpro/habr/upload_files/f95/e44/a16/f95e44a167c94f174b5b4bb60a3f40e2.jpg)
– Arduino IDE.
esp8266 .
.
, <> Generic ESP8266 Module.
.
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
boolean recievedFlag;
String strData, Link;
// WIFI
const char *ssid = "**************"; //
const char *password = "*************"; //
const char *host = "**********************************"; //
const int httpsPort = 443; // HTTPS= 443 HTTP = 80
const char fingerprint[] PROGMEM = "5B:FB:D1:D4:49:D3:0F:A9:C6:40:03:34:BA:E0:24:05:AA:D2:E2:01"; //
// t WIFI
void setup() {
delay(1000); //
Serial.begin(9600); // UART
WiFi.mode(WIFI_OFF); //
delay(1000); //
WiFi.mode(WIFI_STA); // ESP
WiFi.begin(ssid, password); //
Serial.println("");
Serial.print("Connecting"); // UART
//
while (WiFi.status() != WL_CONNECTED) {delay(500);
Serial.print(".");} // UART
Serial.println(""); //
Serial.print("Connected to "); // UART:
Serial.println(ssid); //
Serial.print("IP address: ");
Serial.println(WiFi.localIP()); //IP ESP
}
//
void transmit() {
WiFiClientSecure httpsClient; // WiFiClient
Serial.println(host); // UART: ,
Serial.printf("Using fingerprint '%s'\n", fingerprint); // .
httpsClient.setFingerprint(fingerprint); //
httpsClient.setTimeout(15000); // (15 )
delay(1000); //
Serial.print("HTTPS Connecting"); // UART:
int r=0; //
while((!httpsClient.connect(host, httpsPort)) && (r < 30))
{delay(100);Serial.print(".");r++;} // UART
if(r==30) {Serial.println("Connection failed");} // UART,
else {Serial.println("Connected to web");} // UART,
Link = "/get.php?" + strData; // GET
Serial.print("requesting URL: "); // UART GET
Serial.println(host+Link); // UART GET
httpsClient.print(String("GET ") + Link + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n"); // GET ESP
Serial.println("request sent"); // UART GET
while (httpsClient.connected()) //
{String line = httpsClient.readStringUntil('\n');
if (line == "\r") {Serial.println("headers received");break;}}
Serial.println("reply was:"); // UART
Serial.println("=========="); // UART
String line; //
while(httpsClient.available()){ //
line = httpsClient.readStringUntil('\n');
Serial.println(line);} // UART
Serial.println("=========="); // UART
Serial.println("closing connection");} // UART,
//
void loop() {
while (Serial.available() > 0) // UART
{ strData +=(char)Serial.read(); //
recievedFlag = true; delay(2); }; //
if (recievedFlag) //
{ Serial.println(strData); // UART
transmit(); //
strData =""; //
recievedFlag = false;} //
}
. .
: Wi-Fi / / UART.
:
const char fingerprint[] PROGMEM = "5B:FB:D1:D4:49:D3:0F:A9:C6:40:03:34:BA:E0:24:05:AA:D2:E2:01"; //
.
.. HTTPS « ».
: https://www.grc.com/fingerprints.htm
![](https://habrastorage.org/getpro/habr/upload_files/db8/f54/b66/db8f54b66329fa45612ee847e25b1617.png)
“Fingerprint Site”.
, .
:
![](https://habrastorage.org/getpro/habr/upload_files/8c1/ad7/756/8c1ad775630ca5519efb312d1b426b98.png)
! Esp .
«id=123456789» «». « » «9600 » .
![](https://habrastorage.org/getpro/habr/upload_files/93f/4a0/0ea/93f4a00eaef504477688a6d47b79d17a.png)
, .
«https://www.000webhost.com».
![](https://habrastorage.org/getpro/habr/upload_files/ab8/f60/7fc/ab8f607fc7f12edb6eb5ce08e35c3c1b.jpg)
. Get ( ).
.
« » …
![](https://habrastorage.org/getpro/habr/upload_files/48c/20f/5d7/48c20f5d75b979c37bf883ae0ebb5136.jpg)
… .
![](https://habrastorage.org/getpro/habr/upload_files/ff9/2b9/a59/ff92b9a59313281edc3cd448ddc9f828.png)
« ».
![](https://habrastorage.org/getpro/habr/upload_files/711/fcc/959/711fcc9592bafb0d3052c33495d25514.png)
«public_html».
![](https://habrastorage.org/getpro/habr/upload_files/164/f9e/23f/164f9e23f32faf1dc0b83ae233017f4d.png)
«New File» .
test.txt ( ).
«get.php» :
<?php
$var1= $_GET['id'];
$fileContent = "Registrated id= ".$var1."\n";
$fileStatus = file_put_contents('test.txt',$fileContent,FILE_APPEND);
if($fileStatus != false)
{
echo "SUCCESS: data written to file";
}
else
{
echo "FAIL: could not write to file";
}
?>
.
.
: «SUCCESS: data written to file».
test.txt….
![](https://habrastorage.org/getpro/habr/upload_files/e8c/33c/f87/e8c33cf879aa0d191477ca678ed8141b.png)
.
test.txt . « /test.txt».
![](https://habrastorage.org/getpro/habr/upload_files/8a8/c82/217/8a8c822177554705a423e440c436635e.png)
- .
. , , . , ..
. .. - . !