GithubHelp home page GithubHelp logo

Cannot find module 'socket.io' about mqtt-panel HOT 9 CLOSED

fabaff avatar fabaff commented on September 9, 2024
Cannot find module 'socket.io'

from mqtt-panel.

Comments (9)

otrab avatar otrab commented on September 9, 2024 1

Hi @tringler I think you use bad the mqtt method

check this
https://github.com/mqttjs/MQTT.js/blob/master/examples/client/simple-both.js

whit this I can run ./runner.sh

from mqtt-panel.

fabaff avatar fabaff commented on September 9, 2024

Can you try to change

    <script type="text/javascript" src="http://localhost:3000/socket.io/socket.io.js"></script>

to something like

    <script type="text/javascript" src="js/socket.io.min.js"></script>

from mqtt-panel.

tringler avatar tringler commented on September 9, 2024

Changed to <script type="text/javascript" src="js/socket.io.min.js"></script> in index.html, but running into the same behaviour. How can I test if the module socket.io is accessible by your script?

from mqtt-panel.

tringler avatar tringler commented on September 9, 2024

It has been solved by npm install socket.io --save

from mqtt-panel.

tringler avatar tringler commented on September 9, 2024

It stops now with:

var mqttclient = mqtt.createClient(mqttport, mqttbroker);
                      ^

TypeError: mqtt.createClient is not a function
    at Object.<anonymous> (/etc/mqtt-panel/server.js:15:23)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:423:7)
    at startup (bootstrap_node.js:147:9)
    at bootstrap_node.js:538:3

from mqtt-panel.

tringler avatar tringler commented on September 9, 2024

I changed var mqttclient = mqtt.createClient(mqttport, mqttbroker); to var mqttclient = mqtt.connect(mqttport, mqttbroker);

Take a look at: mqttjs/MQTT.js#247

Now it stops with:

TypeError: Parameter "url" must be a string, not number
    at Url.parse (url.js:81:11)
    at Object.urlParse [as parse] (url.js:75:5)
    at Object.connect (/etc/mqtt-panel/node_modules/mqtt/lib/connect/index.js:52:22)
    at Object.<anonymous> (/etc/mqtt-panel/server.js:15:23)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)

from mqtt-panel.

tringler avatar tringler commented on September 9, 2024

Changed var io = socket.listen(3000); to var io = socket.listen('http://localhost:3000');

Now it stops with:

/etc/mqtt-panel/node_modules/engine.io/lib/server.js:424
  var listeners = server.listeners('request').slice(0);
                         ^

TypeError: server.listeners is not a function
    at Server.attach (/etc/mqtt-panel/node_modules/engine.io/lib/server.js:424:26)
    at Function.attach (/etc/mqtt-panel/node_modules/engine.io/lib/engine.io.js:124:10)
    at Server.listen.Server.attach (/etc/mqtt-panel/node_modules/socket.io/lib/index.js:240:21)
    at new Server (/etc/mqtt-panel/node_modules/socket.io/lib/index.js:52:17)
    at Function.Server [as listen] (/etc/mqtt-panel/node_modules/socket.io/lib/index.js:40:41)
    at Object.<anonymous> (/etc/mqtt-panel/server.js:14:17)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)

from mqtt-panel.

falkTX avatar falkTX commented on September 9, 2024

Why is this closed?
Current code as of today does not run, I have the same errors @tringler has.

from mqtt-panel.

falkTX avatar falkTX commented on September 9, 2024

The current change makes it work for me:

diff --git a/server.js b/server.js
index 4af2095..96838e7 100644
--- a/server.js
+++ b/server.js
@@ -9,10 +9,10 @@ var socket = require('socket.io');
 //var firmata = require('firmata');
 
 var mqttbroker = 'localhost';
-var mqttport = 1883;
+var mqttport = '1883';
 
 var io = socket.listen(3000);
-var mqttclient = mqtt.createClient(mqttport, mqttbroker);
+var mqttclient = mqtt.connect('tcp://' + mqttbroker + ':' + mqttport);
 
 // Subscribe to topic
 io.sockets.on('connection', function (socket) {

from mqtt-panel.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.