• Hi,
    For some odd reason the code is as follows; Just playing around and bumped into the issue.
    Is anyone else seeing this issue ? I am uploading directly to the ESP8266

    var wifi = require("Wifi");
    
    var server = "192.168.1.25";
    
    var mqtt = require("MQTT").create(server);
    mqtt.on('connected', function() {
      mqtt.subscribe("pcduino");
    });
    
    mqtt.on('publish', function (pub) {
      console.log("topic: "+pub.topic);
      console.log("message: "+pub.message);
    });
    
    
    wifi.stopAP();
    wifi.disconnect(); 
    wifi.scan(function(data){
    
      for(x in data)
      {
        console.log(data[x].ssid);
      }
    
      //wifi.connect("ABC", {password:"xyz"}, function(err){
      //  console.log("connected? err=", err, "info=", wifi.getIP());
      //});
    
      wifi.connect("Zain-E5577-0462", {password:"85887536"}, function(err){
        console.log("connected? err=", err, "info=", wifi.getIP());
        mqtt.connect({
          keep_alive: 60, // keep_alive[seconds]
          port: 1883, // port number
          clean_session: 1883, // port number
          username: "xyz", 
          password: "xyz", 
          protocol_name: "MQTT", // or MQIsdp, etc..
          protocol_level: 0, // protocol_level
        });
      });
    
    });
    

    Error As follows;

    Uncaught Error: Function "write" not found!
     at line 1 col 35
    ....log("Client connected");b.write(a.mqttConnect(a.clie­nt_id))...
                                  ^
    in function "d" called from line 3 col 143
    ..."close")});a.client=b};b?d():b=requir­e("net").connect({host:...
                                  ^
    in function "connect" called from line 1 col 184
    ...me:'MQTT',protocol_level:0});
                                  ^
    in function called from system
    
  • Same problem here. Could you find a solution?

  • I think this is related to module size. What build are you using on ESP8266?

    When the ESP8266 port started we had 1300 JSVars. We had to cut down the MQTT module to bare basics to get it to load and leave some space for application code.

    But there are now some ESP8266 builds out there with 1600 (even 1700 JSVars) and I do wonder if the core module would run in this - I haven't had opportunity to test.

    Maybe seek out one of the latest builds - with 1600/1700 JSVars, and try again or try this cut down MQTT module which has worked very well for myself and a couple of others.

    https://github.com/olliephillips/tinyMQT­T

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

[Uncaught Error: Function "write" not found!] MQTT on ESP8266

Posted by Avatar for NodePool @NodePool

Actions