ESP8266之烧写arduino的程序到ESP8266板做客户端并与数据交互-Arduino中文社区 - Powered by Discuz! Archiver

李德凯 发表于 2018-4-20 19:41

ESP8266之烧写arduino的程序到ESP8266板做客户端并与数据交互

本帖最后由 李德凯 于 2020-1-13 08:20 编辑

总操作流程:



[*]1、下安装

[*]2、烧写
[*]3、测试

下安装安装时路径不要改,这是对应arduino ide中的路径

https://pan.baidu.com/s/1ZAKDMQ9ojpurD2UM8BtwAA


[*]成功标识:



vscode-resource://file///d%3A/CCN/3.%E5%B5%8C%E5%85%A5%E5%BC%8F/1.arduino%28arduino%20uno%20r3%20%29/03.arduino%E4%B9%8Bwifi%20ESP8266/02.ESP8266%E4%B9%8B%E5%AD%A6%E4%B9%A0/image/1-1.png烧写
各器件链接
[*]使用usb转串口链接esp8266

vscode-resource://file///d%3A/CCN/3.%E5%B5%8C%E5%85%A5%E5%BC%8F/1.arduino%28arduino%20uno%20r3%20%29/03.arduino%E4%B9%8Bwifi%20ESP8266/02.ESP8266%E4%B9%8B%E5%AD%A6%E4%B9%A0/image/1-2.png烧写程序
[*]arduino id 配置

vscode-resource://file///d%3A/CCN/3.%E5%B5%8C%E5%85%A5%E5%BC%8F/1.arduino%28arduino%20uno%20r3%20%29/03.arduino%E4%B9%8Bwifi%20ESP8266/02.ESP8266%E4%B9%8B%E5%AD%A6%E4%B9%A0/image/1-3.png
[*]写程序



#include <ESP8266WiFi.h>
WiFiClient client;
const char *ssid   = "TP-LINK888";//要加入路由的wifi名
const char *password = "QwE@123@*~*";//要加入路由的wifi密码
const char *host = "192.168.0.102";//服务器IP
const int httpPort =8234;//服务器端口号
void setup() {
Serial.begin(115200);
delay(10);
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());
while (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    delay(500);
}
Serial.print("connecting to ");
Serial.println(host);
client.write("successfully\r\n");//绑定apikey,修改成你自己的apikey
delay(10);
}

void loop() {

//接收信息
while(client.available()){
    String line = client.readStringUntil('\r');
   Serial.println(line);
}
//发送信息
while(Serial.available()){
    String line = Serial.readStringUntil('\r');
    client.println(line);
}

}






vscode-resource://file///d%3A/CCN/3.%E5%B5%8C%E5%85%A5%E5%BC%8F/1.arduino%28arduino%20uno%20r3%20%29/03.arduino%E4%B9%8Bwifi%20ESP8266/02.ESP8266%E4%B9%8B%E5%AD%A6%E4%B9%A0/image/1-4.png
[*]烧写失败,拔出usb转串口重插

测试
串口/网络助手调试
https://pan.baidu.com/s/1m5MAc4ZON0x-nsT-WQAr7g


[*]制作服务端

vscode-resource://file///d%3A/CCN/3.%E5%B5%8C%E5%85%A5%E5%BC%8F/1.arduino%28arduino%20uno%20r3%20%29/03.arduino%E4%B9%8Bwifi%20ESP8266/02.ESP8266%E4%B9%8B%E5%AD%A6%E4%B9%A0/image/1-6.png各器件链接
[*]使用usb转串口链接esp8266

vscode-resource://file///d%3A/CCN/3.%E5%B5%8C%E5%85%A5%E5%BC%8F/1.arduino%28arduino%20uno%20r3%20%29/03.arduino%E4%B9%8Bwifi%20ESP8266/02.ESP8266%E4%B9%8B%E5%AD%A6%E4%B9%A0/image/1-5.png
[*]串口助手调试


先开启服务端,再插入“usb转串口”




vscode-resource://file///d%3A/CCN/3.%E5%B5%8C%E5%85%A5%E5%BC%8F/1.arduino%28arduino%20uno%20r3%20%29/03.arduino%E4%B9%8Bwifi%20ESP8266/02.ESP8266%E4%B9%8B%E5%AD%A6%E4%B9%A0/image/1-7.gif
页: [1]
查看完整版本: ESP8266之烧写arduino的程序到ESP8266板做客户端并与数据交互