Я работал над модулем ESP и получил некоторые ошибки. Может ли кто-нибудь помочь устранить эти ошибки?
Код;
#include <Keypad.h>
#include <Servo.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <PubSubClient.h>
const char* ssid = "";//put your wifi network name here
const char* password = "";//put your wifi password here
const char* mqtt_server = "broker.hivemq.com";
WiFiClient espClient;
PubSubClient client(espClient);
const byte n_rows = 4;
const byte n_cols = 4;
char keys[n_rows][n_cols] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte colPins[n_rows] = {D3, D2, D1, D0};
byte rowPins[n_cols] = {D7, D6, D5, D4};
Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, n_rows, n_cols);
Servo myservo;
String passcode="";
String myPasscode="5432"; //предопределенный код доступа, изменить в соответствии с вашим желанием
void setup(){
Serial.begin(115200);
myservo.attach(15); //прикрепить сервопривод к контакту D8)
myservo.write(150);
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
}
void setup_wifi() {
delay(100);
// We start by connecting to a WiFi network
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());
}
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived in topic: ");
Serial.println(topic);
Serial.print("Message:");
String message;
for (int i = 0; i < length; i++) {
//Serial.print((char)payload[i]);
message+=(char)payload[i];
}
if(message==myPasscode){
publish("Approved");
dispatchMoney();
}else{
publish("Denied");
}
Serial.println();
Serial.println("-----------------------");
}
void publish(String msg){
char message[100];
msg.toCharArray(message,100);
client.publish("/ABC/ATM/ACK", message);
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected())
{
Serial.print("Attempting MQTT connection...");
// Create a random client ID
String clientId = "ESP8266Client-";
clientId += String(random(0xffff), HEX);
// Attempt to connect
//if you MQTT broker has clientID,username and password
//please change following line to if (client.connect(clientId,userName,passWord))
if (client.connect(clientId.c_str()))
{
Serial.println("connected");
//once connected to MQTT broker, subscribe command if any
client.subscribe("/ABC/ATM/RCV");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 6 seconds before retrying
delay(6000);
}
}
} //end reconnect()
void loop(){
if (!client.connected()) {
reconnect();
}
client.loop();
char myKey = myKeypad.getKey();
if (myKey != NULL){
if(myKey =='#'){
Serial.print("You entered: ");
Serial.println(passcode);
if(passcode == myPasscode){
Serial.println("Your are welcome");
dispatchMoney();
}else{
Serial.println("Password did not match");
}
passcode="";
}else{
passcode+=myKey;
}
delay(200);
}
}
void dispatchMoney() {
Serial.println("Dispatching money...");
myservo.write(90); //rotates the motor counterclockwise at slow speed
delay(5000);
myservo.write(150); //rotates the motor counterclockwise at slow speed
}
ОШИБКА:
sketch_apr28a.b:24:25: error: 'D3' was not declared in this scope
byte colPins[n_rows] = {D3, D2, D1, D0};
^
sketch_apr28a.b:24:29: error: 'D2' was not declared in this scope
byte colPins[n_rows] = {D3, D2, D1, D0};
^
sketch_apr28a.b:24:33: error: 'D1' was not declared in this scope
byte colPins[n_rows] = {D3, D2, D1, D0};
^
sketch_apr28a.b:24:37: error: 'D0' was not declared in this scope
byte colPins[n_rows] = {D3, D2, D1, D0};
^
sketch_apr28a.b:25:25: error: 'D7' was not declared in this scope
byte rowPins[n_cols] = {D7, D6, D5, D4};
^
sketch_apr28a.b:25:29: error: 'D6' was not declared in this scope
byte rowPins[n_cols] = {D7, D6, D5, D4};
^
sketch_apr28a.b:25:33: error: 'D5' was not declared in this scope
byte rowPins[n_cols] = {D7, D6, D5, D4};
^
sketch_apr28a.b:25:37: error: 'D4' was not declared in this scope
byte rowPins[n_cols] = {D7, D6, D5, D4};
^
sketch_apr28a.b:27:1: error: 'Keypad' does not name a type
Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, n_rows, n_cols);
^
C:\Users\Malini\Documents\Arduino\sketch_apr28a.b\sketch_apr28a.b.ino: In function 'void loop()':
sketch_apr28a.b:124:16: error: 'myKeypad' was not declared in this scope
char myKey = myKeypad.getKey();
^
Multiple libraries were found for "Servo.h"
Used: C:\Users\Malini\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\Servo
Not used: C:\Users\Malini\Documents\Arduino\libraries\ServoESP32
Not used: C:\Users\Malini\Downloads\Arduino\libraries\Servo
exit status 1
'D3' was not declared in this scope
@Anchana Vinod, 👍1
Обсуждение0
Смотрите также:
- AT-команда не отвечает на последовательный монитор
- Отправка данных Arduino в MySQL с помощью phpMyAdmin и XAMPP на Windows10
- Arduino выводит значения мусора на serial monitor с ESP8266
- ошибка: espcomm_upload_mem failed при загрузке скетча
- фатальная ошибка ESP8266WiFi.h: Такого файла или каталога нет
- Как подключить Wi-Fi Shield ESP-12E-ESP8266-UART-WIFI-Wireless-Shield к Arduino
- Получить данные с сайта с помощью ESP8266 с помощью AT-команд
- Захват изображений с OV7670 (без FIFO) с использованием Arduino Uno?
выберите плату Lolin (Wemos) или NodeMCU в меню "Сервис"., @Juraj