|
TB上买的ESP8266模块,线路连接没有问题,有数据能传输,但是我冉伟不正上,我用串口监视程序运行,串口打印两次,网络调试助手才显示一次数据。下面是图和代码。串口监视器每显示两次数据,网络调试助手才显示一次数据。请问这是什么原因。
#include <SoftwareSerial.h>
#define WIFI_TX 7 // ESP8266
#define WIFI_RX 6
SoftwareSerial wifi(WIFI_RX, WIFI_TX); //RX, TX
void wifiConfig();
void wifiSend();
void getWifiSerialData();
String _comdata_wifi = ""; //for incoming wifi serial data
void setup()
{
Serial.begin(9600);
wifi.begin(115200);
Serial.println("system is ready!");
delay(1000);
wifiConfig();
}
void loop() {
wifiSend();
delay(1000);
/*
getWifiSerialData();
if(Serial.available())
{
String order = "";
while (Serial.available())
{
char cc = (char)Serial.read();
order += cc;
delay(2);
}
order.trim();
wifi.println(order);
}
if(_comdata_wifi!="")
{
Serial.println(_comdata_wifi);
_comdata_wifi = String("");
}
*/
}
void getWifiSerialData()
{
while (wifi.available() > 0)
{
_comdata_wifi += char(wifi.read()); //get wifi data
delay(4);
}
}
void wifiConfig()
{
wifi.println("AT+RST");
delay(600);
wifi.println("AT+CWMODE=2");
delay(600);
wifi.println("AT+RST");
delay(600);
wifi.println("AT+CIPMUX=1");
delay(600);
wifi.println("AT+CIPSERVER=1,8080");
delay(600);
//Serial.println("wifiConfig");
}
void wifiSend()
{
Serial.println("wifiSend!");
wifi.println("AT+CIPSEND=0,14");
wifi.println("0123456789");
delay(1000);
// wifi.println("AT+CIPCLOSE");
// delay(1000);
}
|
-
-
|