使用注意事項:
選擇 ESP32 Dev Module
燒錄時先壓住RST鈕,等開始跑燒錄程序時放開RST,就可以燒錄了。
參考資料:
ESP32 HTTP GET with Arduino IDE
ESP32 Web Server 網路伺服器手機上網遙控兩個 LED
Arduino建立Web Server做一個HTML客製化網頁,讓Wifi用戶連入
ESP32 Guide 2024 | Choosing and Using an ESP32 Board
『DOIT ESP32 DEVKIT V1 BOARD (WI-FI AND BLUETOOTH)』範例介紹01 (2022/01/20)
2022-01-20 Jash.Liao Comments 0 Comment
『DOIT ESP32 DEVKIT V1 Board (Wi-Fi and Bluetooth)』範例介紹01 (2022/01/20)
資料來源: https://randomnerdtutorials.com/getting-started-with-esp32/
WiFiScan – 無線網路掃描
https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/
ESP32 Pinout – 腳位介紹
https://randomnerdtutorials.com/esp32-pinout-reference-gpios/
ESP32 Inputs Outputs – 基本輸出入
https://randomnerdtutorials.com/esp32-digital-inputs-outputs-arduino/
ESP32 PWM –
https://randomnerdtutorials.com/esp32-pwm-arduino-ide/
ESP32 Analog Inputs –
https://randomnerdtutorials.com/esp32-adc-analog-read-arduino-ide/
ESP32 Interrupts Timers –
https://randomnerdtutorials.com/esp32-pir-motion-sensor-interrupts-timers/
ESP32 Deep Sleep –
https://randomnerdtutorials.com/esp32-deep-sleep-arduino-ide-wake-up-sources/
ESP32 Web Server – 連接區網WIFI後,建立網頁伺服器,提供內建簡單網頁控制燈號亮滅
https://randomnerdtutorials.com/esp32-web-server-arduino-ide/
ESP32 LoRa
ESP32 BLE
ESP32 BLE Client-Server
ESP32 Bluetooth
ESP32 MQTT
ESP32 ESP-NOW
ESP32 Wi-Fi – 兩塊板子 一個當AP+Web Server,另一個當 Web Client 進行http 通訊
https://randomnerdtutorials.com/esp32-client-server-wi-fi/
ESP32 WebSocket
ESP32 ESP-MESH
ESP32 Email
ESP32 Text Messages
ESP32 HTTP GET POST – 連接區網WIFI後,使用ESP32作為 Web Client 透過呼叫已知Web API 傳送對應資訊到Server上
https://randomnerdtutorials.com/esp32-http-get-post-arduino/
HTTP GET Web APIs – 連接區網WIFI後,使用ESP32作為 Web Client 透過呼叫已知Web API 傳送對應資訊到Server上並取回對回傳值 (天氣 API)
https://randomnerdtutorials.com/esp32-http-get-open-weather-map-thingspeak-arduino/
HTTP POST Web APIs – 連接區網WIFI後,使用ESP32作為 Web Client 透過呼叫已知Web API 傳送對應資訊到Server上並取回對回傳值 (IFTT API)
https://randomnerdtutorials.com/esp32-http-post-ifttt-thingspeak-arduino/
Server-Sent Events –
---------------------------------------------------------------------------------------------
『WEMOS D1 R1 WIFI UNO』和『DOIT ESP32 DEVKIT V1 BOARD』(ARDUINO) 與 簡單 PHP HTTP GET通訊
2022-01-21 Jash.Liao Comments 0 Comment
『WEMos D1 R1 WiFi UNO』和『DOIT ESP32 DEVKIT V1 BOARD』(Arduino) 與 簡單 PHP Http Get通訊
資料來源: https://randomnerdtutorials.com/esp32-http-get-post-arduino/
https://github.com/jash-git/IOT-Smart-Application-Design-Practice-Class-Project-2022
https://github.com/jash-git/Jash-good-idea-20220101-001/tree/main/Arduino_Base64_C_lib_Project/Arduino%E5%92%8CPHP%E9%80%9A%E8%A8%8A%E6%9C%83%E5%8B%95%E7%A8%8B%E5%BC%8F%E5%82%99%E4%BB%BD
『PHP』
<?php
$val = $_GET['string'];
$bf = fopen("test.txt","a+");
fwrite ($bf,$val."\r\n");
fclose($bf);
echo "get data=";
if(($val%2)==0)
{
echo 0;
}
else
{
echo 1;
}
?>
『WEMos D1 R1 WiFi UNO』
/*
* This sketch sends data via HTTP GET requests to data.sparkfun.com service.
*
* You need to get streamId and privateKey at data.sparkfun.com and paste them
* below. Or just customize this script to talk to other HTTP servers.
*
*/
#include <ESP8266WiFi.h>
const char* ssid = "jash_TStar";
const char* password = "asd700502";
const char* host = "192.168.0.191";
const char* streamId = "....................";
const char* privateKey = "....................";
int Blue=D4;//D4 有連接WIFI指示燈
int Green=D5;//D5 命令對應燈
int Red=D6;//D6 命令對應燈
void setup() {
//---
//設定燈號腳位工作模式
pinMode(Blue, OUTPUT);
pinMode(Green, OUTPUT);
pinMode(Red, OUTPUT);
//---設定燈號腳位工作模式
//---
//等待取得網路IP時,設定三燈全亮
digitalWrite(Blue, HIGH);
digitalWrite(Green, HIGH);
digitalWrite(Red, HIGH);
//---等待取得網路IP時,設定三燈全亮
Serial.begin(9600);
delay(50);
// 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(50);
Serial.print(".");
}
//---
//取得網路IP時,所有燈熄滅
digitalWrite(Blue, LOW);//digitalWrite(Blue, HIGH);
digitalWrite(Green, LOW);
digitalWrite(Red, LOW);
//---取得網路IP時,所有燈熄滅
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(1000);
}
int value = 0;
void loop() {
value=random(10,50);
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 8080;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
client.stop();
digitalWrite(Blue, HIGH);
return;
}
else
{
digitalWrite(Blue, LOW);
}
// We now create a URI for the request
//String url = "/php_code/val.php";
String url = "/jash_web/val2DB.php";
url += "?string=";
url += value;
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
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(5sec)!");
Serial.println("");
client.stop();
digitalWrite(Blue, HIGH);
return;
}
else
{
digitalWrite(Blue, LOW);
}
}
// Read all the lines of the reply from server and print them to Serial
while(client.available())
{
String line = client.readStringUntil('\r');
int index=line.indexOf("get data=");//搜尋資料列
if(index!=-1)
{
digitalWrite(Blue, LOW);
//----
//過濾不需要資料
int value=line.length();
char Buf[100];
line.toCharArray(Buf, 100);
line="";
//Serial.println(value);
for(int i=0;i<value;i++)
{
if((Buf[i]>=48)&&(Buf[i]<=57))//只留數字範圍
{
line+=Buf[i];
}
}
//----過濾不需要資料
switch(line.toInt())
{
case 0:
Serial.println("Red on & Green off");
digitalWrite(Red, HIGH);
digitalWrite(Green,LOW);
break;
case 1:
Serial.println("Red off & Green on");
digitalWrite(Red, LOW);
digitalWrite(Green,HIGH);
break;
}
break;
}
}
client.stop();
Serial.println("closing connection");
Serial.println("");
delay(1000);
}
『DOIT ESP32 DEVKIT V1 BOARD』
/*
Rui Santos
Complete project details at Complete project details at https://RandomNerdTutorials.com/esp32-http-get-post-arduino/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include <WiFi.h>
#include <HTTPClient.h>
int value = 0;
const char* ssid = "jash_TStar";
const char* password = "asd700502";
//Your Domain name with URL path or IP address with path
String serverName = "http://192.168.0.191:8080/jash_web/val2DB.php";
//String serverName = "http://192.168.0.191:8080/php_code/val.php";
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastTime = 0;
// Timer set to 10 minutes (600000)
//unsigned long timerDelay = 600000;
// Set timer to 5 seconds (5000)
unsigned long timerDelay = 5000;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
Serial.println("Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.");
}
void loop() {
//Send an HTTP POST request every 10 minutes
if ((millis() - lastTime) > timerDelay) {
//Check WiFi connection status
if(WiFi.status()== WL_CONNECTED){
HTTPClient http;
value=random(10,50);
String serverPath = serverName;
serverPath += "?string=";
serverPath += value;
// Your Domain name with URL path or IP address with path
http.begin(serverPath.c_str());
// Send HTTP GET request
int httpResponseCode = http.GET();
if (httpResponseCode>0) {
//Serial.print("HTTP Response code: ");
//Serial.println(httpResponseCode);
String line = http.getString();
Serial.println(line);
int index=line.indexOf("get data=");//搜尋資料列
if(index!=-1)
{
//----
//過濾不需要資料
int value=line.length();
char Buf[100];
line.toCharArray(Buf, 100);
line="";
//Serial.println(value);
for(int i=0;i<value;i++)
{
if((Buf[i]>=48)&&(Buf[i]<=57))//只留數字範圍
{
line+=Buf[i];
}
}
//----過濾不需要資料
switch(line.toInt())
{
case 0:
Serial.println("Red on & Green off");
//digitalWrite(Red, HIGH);
//digitalWrite(Green,LOW);
break;
case 1:
Serial.println("Red off & Green on");
//digitalWrite(Red, LOW);
//digitalWrite(Green,HIGH);
break;
}//switch
}//if(index!=-1)
}//if (httpResponseCode>0)
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
lastTime = millis();
}
}