ESP8266 ESP-01 引脚:
电路原理图 :
*笔记 :
请在 Arduino TX 和 ESP8266 ESP-01 RX 之间制作分压器。
阿杜诺素描:
int output1=0;
void setup() {
// put your setup code here, to run once:
pinMode(8,OUTPUT);//FOR output1
Serial.begin(115200);
int connectionSuccess=0;
while(connectionSuccess==0)
{
Serial.println("AT+RST\r\n");
delay(2000);
while(Serial.available()>0)
{
char c=Serial.read();
}
Serial.println("AT+CWMODE=1\r\n");
delay(2000);
while(Serial.available()>0)
{
char c=Serial.read();
}
Serial.println("AT+CWJAP=\"TP-Link_F338\",\"20955250\"\r\n");
delay(5000);
while(Serial.available()>0)
{
//char c=Serial.read();
if(Serial.find('K')==true)
{
connectionSuccess=1;
}
}
}
}
void loop() {
// put your main code here, to run repeatedly:
String requestGet="GET /index.php HTTP/1.0\r\nHost: switchonthelamp.atwebpages.com\r\nAccept: */*\r\nContent-Type: text/html; charset=UTF-8\r\n";
Serial.println("AT+CIPSTART=\"TCP\",\"switchonthelamp.atwebpages.com\",80\r\n");
delay(1000);
while(Serial.available()>0)
{
char c=Serial.read();
}
Serial.println("AT+CIPSEND="+String(requestGet.length()+2)+"\r\n");
delay(100);
while(Serial.available()>0)
{
char c=Serial.read();
}
//RECEIVE DATA FROM SERVER AND SEARCH FOR KEY BETWEEN TWO HASH TAG
//----------------------------------------------------------------
int firstHash=0;
int secondHash=0;
String tempText;
Serial.println(requestGet);
char arrayByte[1000];
int saizHuruf=Serial.readBytesUntil('^',arrayByte,1000);
for(int i=0;i {
char a=arrayByte[i];
tempText+=a;
if(a=='#'&&firstHash==0)
{
firstHash=i;
}
if(a=='#'&&firstHash!=0)
{
secondHash=i;
}
}
if(firstHash!=0&&secondHash!=0)
{
String result=tempText.substring(firstHash,secondHash+1);
Serial.println(result);
//OUTPUT 1
int output1temp=(String(result.charAt(1))).toInt();
if(output1temp!=output1)
{
output1=output1temp;
if(output1==1)
{
digitalWrite(8,HIGH);
}
else
{
digitalWrite(8,LOW);
}
}
//OUTPUT 1
}
//----------------------------------------------------------------
//RECEIVE DATA FROM SERVER AND SEARCH FOR KEY BETWEEN TWO HASH TAG
delay(1000);
Serial.println("AT+CIPCLOSE\r\n");
delay(2000);
while(Serial.available()>0)
{
char c=Serial.read();
}
delay(1000);
}
;i++)>
*笔记 :
完整的项目文件(在此处下载):
https://drive.google.com/file/d/1V2NW7Xp4ljk0WP4gY0RyByy4EovzFpKk/view?usp=sharing
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
全部0条评论
快来发表一下你的评论吧 !