/* ESP32 WiFi Scanning example */

#include "WiFi.h"
#include "MQTT.h"
const char* ssid = "Wokwi-GUEST";
const char* password = "";
WiFiClient net;
MQTTClient client;
void setup() {
  Serial.begin(115200);
  Serial.println("Connecting to WiFi");
  WiFi.begin(ssid,password,6);
  client.begin("public.cloud.shiftr.io",net);

  while(WiFi.status()!=WL_CONNECTED);{
    Serial.println(".");
    delay(1000);
  }
  while(!client.connect("arduino", "public", "public")){
    Serial.println(".");
    delay(1000);
  }

}
 
void messageReceived(String &topic, String &payload) {
  Serial.println("incoming: " + topic + " - " + payload);

  // Note: Do not use the client in the callback to publish, subscribe or
  // unsubscribe as it may cause deadlocks when other things arrive while
  // sending and receiving acknowledgments. Instead, change a global variable,
  // or push to a queue and handle it in the loop after calling `client.loop()`.
}
void loop() {
 client.subscribe("/hello");
 client.onMessage(messageReceived);
 delay(500);
}