You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var mqtt = require('mqtt-scripts')
var io = require("socket.io");
var express = require("express");
var app = express();
app.use(express.static('www'));
var server = app.listen(3333);
var webSockerIO = io.listen(server);
const deviceName = "Kiosk-1";
let orderId = 0
let orderDetail = "nothing"
webSockerIO.on('connection', function (socket) {
mqtt.subscribe("device/kiosk/2", (topic, val) => {
console.log(topic)
console.log(val)
var data = val;
if (data.method === "set") {
switch (data.cmd) {
case "orderId":
orderId = data.orderId;
socket.emit('mqtt', { 'msg': {'orderId': orderId} });
break;
case "orderDetail":
orderDetail = data.orderDetail;
break;
}
} else {
switch (data.cmd) {
case "ping":
socket.emit('mqtt', { 'msg': 'pong' });
data.ping = "pong";
break;
case "orderId":
data.orderId = orderId;
break;
case "order":
data.order = deviceName;
break;
}
}
mqtt.publish("ResponseTopic", JSON.stringify(data));
});
});
error
> [email protected] start /Users/austin/Documents/company/edgeX/mqtt-device-simulator-kiosk
> node index.js && mqtt-scripts -u 'mqtt://10.99.253.133' -v 'debug' -d ./
2020-08-31 18:21:29.243 <info> mqtt-scripts 1.2.2 starting
2020-08-31 18:21:29.581 <info> mqtt connected mqtt://127.0.0.1
/Users/austin/Documents/company/edgeX/mqtt-device-simulator-kiosk/index.js:17
mqtt.subscribe("device/kiosk/2", (topic, val) => {
^
TypeError: mqtt.subscribe is not a function
at Namespace.<anonymous> (/Users/austin/Documents/company/edgeX/mqtt-device-simulator-kiosk/index.js:17:10)
at Namespace.emit (events.js:315:20)
at Namespace.EventEmitter.emit (domain.js:482:12)
at Namespace.emit (/Users/austin/Documents/company/edgeX/mqtt-device-simulator-kiosk/node_modules/socket.io/lib/namespace.js:213:10)
at /Users/austin/Documents/company/edgeX/mqtt-device-simulator-kiosk/node_modules/socket.io/lib/namespace.js:181:14
at processTicksAndRejections (internal/process/task_queues.js:79:11)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node index.js && mqtt-scripts -u 'mqtt://10.99.253.133' -v 'debug' -d ./`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/austin/.npm/_logs/2020-08-31T10_21_32_982Z-debug.log
The text was updated successfully, but these errors were encountered:
How to use it with express and socketio ?
package.json
index.js
error
The text was updated successfully, but these errors were encountered: