how to connect the mqtt server

Posted on
  • I use the mosca to run a mqtt server,and use the esp32 as a mqtt client ,but the client can not connect the server,the server and the client are in different network,so how can i set up the host ?var ssid="wangnuan";
    var password="wang1234";
    var wifi=require('Wifi');
    var host='xxxxxxxx';

    var options={

    client_id : "random",
    keep_alive: 60,
    port: 1883,
    clean_session: true,
    username: "test",
    password: "12345678",
    protocol_name: "esp32",
    protocol_level: 4,

    wifi.connect(ssid, {password: password}, function() {
    console.log('Connected to Wifi. IP address is:', wifi.getIP().ip);
    console.log("Connected to access point");
    var mqtt = require("MQTT").create(host);
    mqtt.on("connected", function() {

    console.log("MQTT connected");
    mqtt.on('publish', function (pub) {
      console.log("topic: "+pub.topic);
      console.log("message: "+pub.message);

    console.log("Doing a connect");

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

how to connect the mqtt server

Posted by Avatar for user81749 @user81749