|
實體圖
WIFI 模組
ANDROID APP
手機圖示
ARDUINO 以下為程式要燒錄到esp8266,
SW_USER_AP.ino.rar
(1003 Bytes, 下載次數: 39)
#include <ESP8266WiFi.h>//鐵門控制 USER AP端 LO_ON
const char* ssid = "SW_USE";// wifi名稱
const char* password = "12345678";//wifi 登入密碼(要超過8位數才有效)
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
// pinMode(A0, INPUT);
pinMode(2, OUTPUT);
digitalWrite(2, 1);
pinMode(14, OUTPUT);//UP
digitalWrite(14, 1);
pinMode(12, OUTPUT);//STOP
digitalWrite(12, 1);
pinMode(13, OUTPUT);//DOWN
digitalWrite(13, 1);
// prepare GPIO15 LOCK
//pinMode(15, OUTPUT);
//digitalWrite(15, 0);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
// Serial.println(ssid);
WiFi.softAP(ssid,password);//啟用 APWiFi.softAP(ssid, password);
// IPAddress myIP = WiFi.softAPIP();
// IPAddress myIP(192.168.2.21);
WiFi.begin();
server.begin();
WiFi.mode(WIFI_AP);// 必須加上才會顯示 WIFI SSID
}
int val=0;
int va2;
void loop() {
// Check if a client has connected
WiFiClient client = server.available();// 監聽是否有用戶端傳送請求
if (!client) {
return;
}
// Serial.println(millis());
// Wait until the client sends some data
while(!client.available()){ //*************************
delay(10);
if (!client.available())
break;
}
// Read the first line of the request
client.setTimeout(200); // 時間內沒有讀取完成則跳離讀取
String req = client.readStringUntil('\r');
Serial.print(req);
if(val==0){
if (req.indexOf("UPON") != -1)
val = 1;
if (req.indexOf("STOP") != -1)
val = 2;
if (req.indexOf("DOWN") != -1)
val = 3;
if (req.indexOf("LOCK") != -1)
val = 4;}
else
{return;}
if(val==1)
{ digitalWrite(14, 0);delay(200);digitalWrite(14, 1);}
if(val==2)
{ digitalWrite(12, 0);delay(200);digitalWrite(12, 1);}
if(val==3)
{ digitalWrite(13, 0);delay(200);digitalWrite(13, 1);}
if(val==4)
{ digitalWrite(12, 0);delay(200);}
val=0;
}
以上提供給有興趣的人~~~
|
評分
-
21
查看全部評分
-
|