IoT project on Remotely control Led using MQTTbox Server client with ESP8266-12e Wi-Fi Board

Поделиться
HTML-код
  • Опубликовано: 24 янв 2025

Комментарии • 11

  • @michaelreis6095
    @michaelreis6095 4 года назад +1

    It worked lol, thanks alot

  • @adityapandya8098
    @adityapandya8098 3 года назад

    Thank You so much

  • @ericsheffield3549
    @ericsheffield3549 4 года назад +1

    Hmmm.....interesting

  • @ΒΑΣΙΛΕΙΟΣΚΑΡΑΓΙΑΝΝΗΣ-π2λ

    Hello can someone help me with some issue in mqttbox ??

  • @ivinkuriakose8377
    @ivinkuriakose8377 4 года назад +2

    cant find the code.

    • @spr9827
      @spr9827 4 года назад

      ayyo pavam

    • @padeiro3582
      @padeiro3582 4 года назад

      /*Modified by
      * Technical Team,REES52
      */
      #include
      #include
      // Define NodeMCU D2 pin connect to Piezo LedPin
      #define ledPin D2
      // Update these with values suitable for your network.
      const char* ssid = "Tenda_FB6CA0"; //enter your wifi id
      const char* password = "9898986969"; //enter your wi-fi passowrd
      const char* mqtt_server = "broker.mqttdashboard.com";
      //const char* mqtt_server = "iot.eclipse.org";
      WiFiClient espClient;
      PubSubClient client(espClient);
      long lastMsg = 0;
      char msg[50];
      int value = 0;
      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(".");
      }
      randomSeed(micros());
      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("Command from MQTT broker is : [");
      Serial.print(topic);
      int p =(char)payload[0]-'0';
      // if MQTT comes a 0 turn off LED on D2
      if(p==0)
      {
      digitalWrite(ledPin, LOW);
      Serial.println(" Turn Off ledPin! ");
      }
      // if MQTT comes a 1, turn on ledPin on pin D2
      if(p==1)
      {
      digitalWrite(ledPin, HIGH);
      Serial.println(" Turn On ledPin! ");
      }
      Serial.println();
      } //end callback
      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.publish("outTopic","hello world");
      //resubscribe
      client.subscribe("REES52Command");
      } 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 setup() {
      Serial.begin(115200);
      setup_wifi();
      client.setServer(mqtt_server, 1883);

      pinMode(ledPin, OUTPUT);
      digitalWrite(ledPin, LOW);
      }
      void loop() {
      if (!client.connected()) {
      reconnect();
      }
      client.setCallback(callback);
      client.loop();
      }

  • @BedangLamboy
    @BedangLamboy 3 года назад

    code is not available on link

  • @padeiro3582
    @padeiro3582 4 года назад +1

    Galera, achei o código do vídeo, créditos da criadora do vídeo.
    /*Modified by
    * Technical Team,REES52
    */
    #include
    #include
    // Define NodeMCU D2 pin connect to Piezo LedPin
    #define ledPin D2
    // Update these with values suitable for your network.
    const char* ssid = "Tenda_FB6CA0"; //enter your wifi id
    const char* password = "9898986969"; //enter your wi-fi passowrd
    const char* mqtt_server = "broker.mqttdashboard.com";
    //const char* mqtt_server = "iot.eclipse.org";
    WiFiClient espClient;
    PubSubClient client(espClient);
    long lastMsg = 0;
    char msg[50];
    int value = 0;
    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(".");
    }
    randomSeed(micros());
    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("Command from MQTT broker is : [");
    Serial.print(topic);
    int p =(char)payload[0]-'0';
    // if MQTT comes a 0 turn off LED on D2
    if(p==0)
    {
    digitalWrite(ledPin, LOW);
    Serial.println(" Turn Off ledPin! ");
    }
    // if MQTT comes a 1, turn on ledPin on pin D2
    if(p==1)
    {
    digitalWrite(ledPin, HIGH);
    Serial.println(" Turn On ledPin! ");
    }
    Serial.println();
    } //end callback
    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.publish("outTopic","hello world");
    //resubscribe
    client.subscribe("REES52Command");
    } 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 setup() {
    Serial.begin(115200);
    setup_wifi();
    client.setServer(mqtt_server, 1883);

    pinMode(ledPin, OUTPUT);
    digitalWrite(ledPin, LOW);
    }
    void loop() {
    if (!client.connected()) {
    reconnect();
    }
    client.setCallback(callback);
    client.loop();
    }

  • @beatrizmulinari7609
    @beatrizmulinari7609 4 года назад +1

    cant find the code. Can you provide again, please?