#include <WiFi.h>
#include <PubSubClient.h>
#include <ESP32Servo.h>
#include "callBack.h"

char clientId[50];
int servoPin = 2;


WiFiClient espClient;
PubSubClient client(espClient);


void setup()
{
  WiFi.mode(WIFI_STA);
  WiFi.begin("Wokwi-GUEST", "");
  
  client.setServer("broker.emqx.io", 1883);
  client.setCallback(callBack);
  Serial.begin(9600);
  servoMotor.attach(servoPin, 500, 2400);
  

}


void loop() 
{
  if (!client.connected()) {
    client.connect(clientId);
    Serial.println("ESP32 is Connected with MQTT!");
    client.subscribe("topicName/iot");
  }
  client.loop();

}