Closed tringler closed 6 years ago
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>
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?
It has been solved by npm install socket.io --save
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
I changed var mqttclient = mqtt.createClient(mqttport, mqttbroker);
to var mqttclient = mqtt.connect(mqttport, mqttbroker);
Take a look at: https://github.com/mqttjs/MQTT.js/issues/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)
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)
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
Why is this closed? Current code as of today does not run, I have the same errors @tringler has.
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) {
Hello,
I'm receiving the error
Cannot find module socket.io
when I try to start the mqtt panel even I installed socket.io vianpm -g install socket.io
Any idea how to get rid of this error? Here you are the full error message:
Thanks in Advance, Thomas