plese help me:
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include "Arduino.h"
#include <Servo.h>
Servo servoObject1;
Servo servoObject2;
Servo servoObject3;
const char* ssid ="xxxxxxxxx";
const char* password ="xxxxxxxxxx";
const char* mqtt_server ="192.168.178.33";
const int mqtt_port =1886;
WiFiClient espClient;
PubSubClient client(espClient);
void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network
Serial.println();
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 MQTTCallback(char* topic, byte* payload, unsigned int length) {
String Command = "";
for (int i = 0; i < length; i++) {
Command = Command + (char)payload[i];
}
int angle = Command.toInt();
if(strcmp(topic, "ServoControl/Servo1/Angle") == 0)
{
servoObject1.write(angle);
}
if(strcmp(topic, "ServoControl/Servo2/Angle") == 0)
{
servoObject2.write(angle);
}
if(strcmp(topic, "ServoControl/Servo3/Angle") == 0)
{
servoObject3.write(angle);
}
}
void reconnect() {
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Create a random client ID
String clientId = "ServoControl";
// Attempt to connect
if (client.connect(clientId.c_str())) {
Serial.println("connected");
client.subscribe("ServoControl/Servo1/Angle");
client.subscribe("ServoControl/Servo2/Angle");
client.subscribe("ServoControl/Servo3/Angle");
}
else
{
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void setup()
{
Serial.begin(115200);
servoObject1.attach(D2);
servoObject2.attach(D3);
servoObject3.attach(D4);
setup_wifi();
client.setServer(mqtt_server, mqtt_port);
reconnect();
client.setCallback(MQTTCallback);
}
void loop() {
if (!client.connected()) {
connectToMQTT();
}
//...
}
Arduino: 1.8.13 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"
C:\Users\Michael\Downloads\iobroker_servocontrol_release\iobroker_servocontrol_Orgi\iobroker_servocontrol_Orgi.ino: In function 'void loop()':
iobroker_servocontrol_Orgi:104:19: error: 'connectToMQTT' was not declared in this scope
connectToMQTT();
^
Mehrere Bibliotheken wurden für "Servo.h" gefunden
Benutzt: C:\Users\Michael\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\Servo
Nicht benutzt: C:\Arduino\libraries\Servo
Nicht benutzt: C:\Users\Michael\Documents\Arduino\libraries\Servo
exit status 1
'connectToMQTT' was not declared in this scope
Dieser Bericht wäre detaillierter, wenn die Option
"Ausführliche Ausgabe während der Kompilierung"
in Datei -> Voreinstellungen aktiviert wäre.