How to pass connection options like username and password in mqtt - javascript

I am getting failed: Error during WebSocket handshake: net:: ERR_CONNECTION_RESET this error when I fixed mqttprops.
I tried using these props
mqttProps: {
host: "157.245.85.49:8084/mqtt",
username: "tolomoto",
password: "S36EeqD956UwGCYC",
},
or
mqttProps: {
protocol: "wss",
host: "wss://157.245.85.49:8084/mqtt",
port: "8084",
username: "tolomoto",
password: "S36EeqD956UwGCYC",
},
or
mqttProps: "ws://157.245.85.49:8084/mqtt"
or
mqttProps: "ws://tolomoto:S36EeqD956UwGCYC#157.245.85.49:8084/mqtt
Please tell me how to solve it.

Related

Switching from mqtts protocol to wss in nodeJS

I can connect to my MQTT broker, using mqtts protocol like this:
mqtt = require('mqtt')
let options = {
host: '0d9d5087c5b3492ea3d302aae8e5fd90.s2.eu.hivemq.cloud',
port: 8883,
path: '/mqtt',
clientId: 'mqttx_2d803d2743',
protocol: 'mqtts',
username: 'light29',
password: 'Mqtt29#!',
cleanSession: true,
}
// initialize the MQTT client
let client = mqtt.connect(options);
// setup the callbacks
client.on('connect', function () {
console.log('Connected');
});
client.on('error', function (error) {
console.log(error);
});
client.on('message', function (topic, message) {
// called each time a message is received
console.log('Received message:', topic, message.toString());
});
// subscribe to topic 'my/test/topic'
client.subscribe('mytest');
// publish message 'Hello' to topic 'my/test/topic'
client.publish('mytest', 'Hello');
This code, yields, as expected:
Connected
Received message: mytest Hello
Now, I would like to connect to this same broker but using wss protocol instead, thus I tried:
let options = {
host: '0d9d5087c5b3492ea3d302aae8e5fd90.s2.eu.hivemq.cloud',
port: 8884,
path: '/mqtt',
clientId: 'mqttx_2d803d2743',
protocol: 'wss',
username: 'light29',
password: 'Mqtt29#!',
cleanSession: true,
}
However, in this case, I got:
Error: connect ECONNREFUSED 127.0.0.1:8884
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
errno: -61,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 8884
}
I have finally managed to connect with these changes:
let options = {
username: 'light29',
password: 'Mqtt29#!',
}
// initialize the MQTT client
let client = mqtt.connect('wss://0d9d5087c5b3492ea3d302aae8e5fd90.s2.eu.hivemq.cloud:8884/mqtt', options);
Still, I do not know why explicitly passing protocol, host, port and path does solve it.
The problem in the original is that protocol in the options should be schema and should container URL schema e.g.
let options = {
host: '0d9d5087c5b3492ea3d302aae8e5fd90.s2.eu.hivemq.cloud',
port: 8883,
path: '/mqtt',
clientId: 'mqttx_2d803d2743',
schema: 'mqtts://',
username: 'light29',
password: 'Mqtt29#!',
cleanSession: true,
}
or
let options = {
host: '0d9d5087c5b3492ea3d302aae8e5fd90.s2.eu.hivemq.cloud',
port: 8883,
path: '/mqtt',
clientId: 'mqttx_2d803d2743',
schema: 'wss://',
username: 'light29',
password: 'Mqtt29#!',
cleanSession: true,
}
protocol is not a valid option.

Nodemailer error (Error: queryA EREFUSED)

sorry for my english
I am using nodemailer and when querying through the api it gives this error:
Error: queryA EREFUSED smtp.gmail.com
at QueryReqWrap.onresolve [as oncomplete] (dns.js:210:19) {
errno: undefined,
code: 'EDNS',
syscall: 'queryA',
hostname: 'smtp.gmail.com',
command: 'CONN'
}
My code:
this.transporter = nodemailer.createTransport({
service: 'gmail'
auth: {
user: mygmail#gmail.com,
pass: mypass,
},
})
UPD: I connected the phone to the Internet instead of my LAN cable, checked, everything worked. There was no error, I connected the LAN back, disconnected the phone, this error appeared again
Make sure that Less secure app access is on in your Gmail account:
Less secure app access > ON
Then fix your code:
this.transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: email,
pass: password
}
});
You can use the built-in service in the Nodemailer and make your code simpler with this one.
this.transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: mygmail#gmail.com,
pass: mypass,
},
})
Please make sure you have disabled 2-Step verification.

Why does couchDB gives me not authorized error when trying to create views

I am using couchDB and when ever i try to create views it is giving me this error
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
code: 'EUNAUTHORIZED',
body: {
error: 'unauthorized',
reason: 'You are not a db or server admin.'
}
}
I am using Node-Couchdb and i am passing the credentials like this
const NodeCouchDb = require('node-couchdb')
require("dotenv-flow").config();
const couch = new NodeCouchDb({
host: process.env.DB_HOST,
protocol: process.env.DB_PROTOCOL,
port: process.env.DB_PORT
})
const couchAuth = new NodeCouchDb({
auth: {
user: process.env.DB_USER_NAME,
pass: process.env.PASSWORD
}
})
module.exports = {
couch
}
Your code is creating two instances of NodeCouchDB, couch and couchAuth where
couch points to server specified by envars without credentials
couchAuth points to the default server (127.0.0.1:5984) with credentials specified by envars
You need to combine parameters, for example
const NodeCouchDb = require("node-couchdb");
const couch = new NodeCouchDb({
host: process.env.DB_HOST,
protocol: process.env.DB_PROTOCOL,
port: process.env.DB_PORT,
auth: {
user: process.env.DB_USER_NAME,
pass: process.env.PASSWORD,
},
});
module.exports = {
couch
};

Zoho with NodeMailer not working error code: 'EDNS'

I try to send an email with Nodemailer and always get the same error:
hostname: 'smtp.zoho.com',
secure: true,
port: 465,
auth: {
user: 'maria#mydomain.my',
pass: 'apppassgenerated'
}
});
I tried too:
service: 'Zoho',
auth: {
user: 'maria#mydomain.my',
pass: 'apppassgenerated'
}
});
I always get: { Error: queryA EREFUSED smtp.zoho.com
at QueryReqWrap.onresolve [as oncomplete] (dns.js:213:19)
errno: 'EREFUSED',
code: 'EDNS',
syscall: 'queryA',
hostname: 'smtp.zoho.com',
command: 'CONN' }
Ok, It was because I was using free plan of Google Functions. If you want to integrate external tools you have to pay 🤷‍♂️

auth0 login to database sql server failed

I want to connect to my SQL SERVER database using this javascript code (code in https://manage.auth0.com on cloud):
function login(email, password, callback) {
var connection = sqlserver.connect({
userName: 'username',
password: 'mypassword',
server: 'TUN040474\\dblocal',
options: {
database: 'myDB',
rowCollectionOnRequestCompletion: true
}
});
I obtained this error:
connection to TUN040474\dblocal:1433 - failed Error: getaddrinfo ENOTFOUND TUN040474\dblocal TUN040474\dblocal:1433
After googling (https://community.auth0.com/t/custom-database-defining-the-server/6277) I understood that I have to do theese two steps:
configure my FireWall by adding rule for port 1433 for any IP Address
in my function replace server 'TUN040474\dblocal' by the Ip Address of my host because the code is in the cloud.
So I did them. But it still not working and i obtained this error:
"timeout : failed to connect to 41.224.17.185:1433 in 15000ms"
i have tried all ip addresses in ipconfig
this is the new code
function login(email, password, callback) {
var connection = sqlserver.connect({
userName: 'username',
password: 'mypassword',
server: '41.224.17.185', // I tried all ip addresses in ipconfig
options: {
database: 'myDB',
rowCollectionOnRequestCompletion: true
}
});
Is there anyone who has had this problem and solved it?

Categories

Resources