我正在尝试使用ESP8266模块,并且我使用了esp8266wifi.h。 但这不起作用:(您能帮我吗?这是我的代码。我试图找到多个“ ESP8266WiFi.h”库,但找不到多个库。
#include "ESP8266WiFi.h"
#include "WiFiUDP.h"
const char* ssid = "your ssid";
const char* password = "your password";
WiFiUDP Udp;
unsigned int localUdpPort = 4210;
char incomingPacket[255];
char replyPacket[] = "Hi there! Got the message.";
void setup() {
Serial.begin(115200);
connectWifi();
Udp.begin(localUdpPort);
}
void loop() {
int packetSize = Udp.parsePacket();
if(packetSize){
Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
int len = Udp.read(incomingPacket, 255);
if (len > 0)
{
incomingPacket[len] = 0;
}
Serial.printf("UDP packet contents: %s\n", incomingPacket);
// send back a reply, to the IP address and port we got the packet from
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(replyPacket);
Udp.endPacket();
delay(1000); // Need a delay otherwise the data is not sent Was 3000
}
}
void connectWifi(){
Serial.print("Connecting to ");
Serial.print(ssid);
WiFi.disconnect(true);
delay(1000);
WiFi.begin(ssid, password);
while(WiFi.status() != WL_CONNECTED){
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP Address: ");
Serial.print(WiFi.localIP());
Serial.println("");
}
这是我的错误信息。您能告诉我“ queue.h”是什么意思吗?我找不到。
Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Uno"
Multiple libraries were found for "ESP8266WiFi.h"
In file included from C:\Program Files (x86)\Arduino\libraries\ESP8266WiFi\src/ESP8266WiFi.h:33:0,
Used: C:\Program
from C:\Users\user\Desktop\sketch_dec18b\sketch_dec18b\sketch_dec18b.ino:1:
C:\Program Files (x86)\Arduino\libraries\ESP8266WiFi\src/ESP8266WiFiType.h:26:10: fatal error:
queue.h: No such file or directory
#include <queue.h>
^~~~~~~~~
compilation terminated.
exit status 1
Error compiling for board Arduino/Genuino Uno.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
答案 0 :(得分:3)
您提到您想将ESP8266用作独立模块(而不是作为第二个MCU,由AT命令控制),但根据日志,编译器正在尝试为Arduino / Genuino Uno开发板进行翻译。 我认为第一步应该是检查板设置并安装必要的软件包,如果所需的软件包不可用。