I'm trying to use the Meteor package perak:meteor-mqtt-collection to connect to CloudMQTT, but am unsure about how to interpret the syntax for the mqttConnect function:
Collection.mqttConnect(uri, topics, options, mqttOptions)
"where mqttOptions is an object that is supplied to mqtt.connect([url],options) in the MQTT.js library for configuring the underlying options of the MQTT.js-client. See the docs."
So far my Meteor test-code looks like this:
Goals = new Meteor.Collection('dbGoals');
if (Meteor.isClient) {
Goals.insert({
topic: "goals",
message: "Hello world from Meteor Web Client",
broadcast: true
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
Goals.mqttConnect("m10.cloudmqtt.com", ["goals"], {
insert: true,
raw: true
},
{ servers: [{ host: 'm10.cloudmqtt.com', port: 12310 }],
clientId:"uniqueIdforEachMqttClient",
username: "myMqttUserName",
password: "myMqttUserPass",
clean:false
});
And gets the following error:
C:\Users\user\AppData\Local\.meteor\packages\meteor-tool\1.1.10\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:245
throw(ex);
^
TypeError: Cannot call method 'replace' of null
at Object.connect (C:\Users\user\AppData\Local\.meteor\packages\perak_mqtt-collection\1.0.4\npm\node_modules\mqtt\lib\connect\index.js:62:35)
at [object Object].Mongo.Collection.mqttConnect (packages/perak_mqtt-collection/packages/perak_mqtt-collection.js:37:1)
at E:\Data\Projects\Project2016\design\sw\mqttColl\.meteor\local\build\programs\server\boot.js:249:5
at mqttColl.js:25:11
=> Exited with code: 8
=> Your application is crashing.
The line mqttColl.js:25:11 is:
Goals.mqttConnect("m10.cloudmqtt.com", "goals", {
I know the object with my servers: options works with MQTT.js running on Node and CloudMQTT, but I'm not sure that I've got the mqttConnect() function parameters entered correctly for the perak Meteor package. For starters, it seems unlikely that the MQTT broker's URL would be needed in multiple places nor that the topic goals should be in brackets, but I'm just not clear on the parameter syntax.
Any suggestions?
You should add protocol into the URL: mqtt://m10.cloudmqtt.com.
Related
I am trying to connect an Azure Function to a SQL-Database that I also created in Azure. Sounds pretty simple and Microsoft even has a pretty good POC tutorial for it. However, in my case the Azure Function is dropping "entryPoint" errors that I am not able to resolve.
I checked some other stackoverflow discussions (Can't connect Node.js server to Azure SQL Database) and googled the hell out of it. Unfortunately it seems like none of this is helping. I updated the "function.json" to set my entryPoint as shown below.
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"access": "listen",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"entryPoint": "index",
"direction": "out",
"name": "res"
}
]
}
My index.js code is a very trivial try to connect to the database and tell me about the success.
var Connection = require('tedious').Connection;
var config = {
userName: 'XXXX',
password: 'XXXX!',
server: 'XXXX.database.windows.net',
// If you are on Microsoft Azure, you need this:
options: {encrypt: true, database: 'XXXXX'}
};
var connection = new Connection(config);
connection.on('connect', function(err) {
// If no error, then good to proceed.
console.log("Connected");
});
Normally this should connect to the database and print a "Connected" to the console but somehow it shows this error:
[Error] Executed 'Functions.TediousTest' (Failed, Id=XXXXXXX)
node exited with code 1
[error] Worker was unable to load function TediousTest: 'Unable to determine function entry point. If multiple functions are exported, you must indicate the entry point, either by naming it 'run' or 'index', or by naming it explicitly via the 'entryPoint' metadata property.',[error] Worker XXXXXX uncaught exception: ReferenceError: executeStatement is not defined
Hopefully this is enough information to understand my problem. The database has no special firewall etc. at the moment. Besides it seems like the code snippet isn't even able to get in touch with the firewall. Thanks in advance.
I believe you haven't exported your function properly based on the error message - basically missed the module.exports line.
I guess your code looks something like this
...
async function TediousTest() {
...
}
If so, just add this line to the end
module.exports = TediousTest;
im currently doing the quick-start of domino-db and when i tried to create a document i got an internal error with the error message "bulkNote request failed with Proton code 65561".
Do you know what the problem is and is it possible to check some logs of proton to see what went wrong.
const serverConfig = {
hostName : 'XXXXXXX.de', // Host name of and port are valid
connection: {
port: 'XXXX',
},
};
const databaseConfig = {
filePath: 'node-demo.nsf', // The database file name
};
useServer(serverConfig)
.then((server) => server.useDatabase(databaseConfig))
.then((database) => database.createDocument({
document: {
Form: 'Contact',
FirstName: 'Aaron',
LastName: 'Aardman',
City: 'Arlington',
State: 'MA',
},
}))
.catch(console.error);
edit:
The error appears every time i access a document(document.read, bulkReadDocuments) not only by the creation of a document.
Here's the definition of that error code (from errorcodes.js):
65561: { id: 'INVALID_SQN', msg: 'Invalid or missing protocol sequence number.' },
This suggests you are using the Beta version of domino-db with the latest release of Proton. Proton now checks the protocol sequence number for every request -- to make sure it's not an incompatible request from a newer client. The Beta version of domino-db did not send the sequence number.
Please check your app and make sure it's using the latest version of domino-db.
I'm trying to create a kik bot, but I keep getting this error anytime I try and run it "Uncaught ReferenceError: request is not defined". I have installed node and the kik package but that seems not to be working here is my Javascript:
request.post({
url: "https://api.kik.com/v1/config",
auth: {
user: "<my-user-name>",
pass: "<my-api-key>"
},
json: {
"webhook": "<link>",
"features": {
"receiveReadReceipts": false,
"receiveIsTyping": false,
"manuallySendReadReceipts": false,
"receiveDeliveryReceipts": false
},
"staticKeyboard": {
"type": "suggested",
"responses": [
{
"body": "Start",
"type": "text"
},
{
"body": "Help",
"type": "text"
}
]
}
}
}, callback);
I've been trying to looking into this but came up with nothing. Could it be a Node problem?
Thank you in advance!!
From the conversation we had, I thought I put the answer here for future references.
That piece of code is supposed to be run on NodeJS in commandline, not a browser.
You need to setup a node environment, install the required dependencies using npm or whatever you like. Then run the code in node.
$ npm install request to install request.
var request = require('request') to require the installed library.
Also you need to modify the code and provide proper a callback function. You can read requests documentation here.
I consistently get a SequelizeConnectionRefusedError when trying to connect to a MySQL database on my server.
The login credentials are correct, the port is open, everything seems good (and works like a charm in the dev environment).
Sorry for the scarce background information, but I'm dumbfounded here - I really don't know what could be causing this problem.
This is my output from mysql --version
mysql Ver 14.14 Distrib 5.5.43, for debian-linux-gnu (x86_64) using readline 6.3
And this is the code I'm using to initialize Sequelize. The table I want it to use doesn't exist yet, but I'm fairly sure that hasn't got anything to do with this problem. I've tried logging in with the root user as well, but no dice - I still get the same error.
var sequelize = new Sequelize("database", username, password, {
host: "localhost",
dialect: "mysql",
port: 3306,
define: {
paranoid: true
}
});
var Model = sequelize.define("Model", {
md5: {type: Sequelize.STRING(128)},
ip: {type: Sequelize.STRING(256)},
url: {type: Sequelize.STRING(1024)}
});
sequelize.sync();
This is running on Ubuntu 14.04, where node is being run behind Passenger (although the error appears if I run the application with node directly as well). I'm running nginx and PHP on the same server, where another PHP application is connecting to the database, if that's of any relevance.
What could be causing this problem?
I tried to connect to the database directly with the MySQL module as well, but that gave me the same error. When looking for solutions to the same problem, but related to the MySQL module rather than Sequelize, I found this: connect ECONNREFUSED - node js , sql.
What I needed was to supply the mysql module with a socketPath key. Here's how I changed my code to make it work:
var sequelize = new Sequelize("database", username, password, {
host: "localhost",
dialect: "mysql",
logging: function () {},
pool: {
max: 5,
min: 0,
idle: 10000
},
dialectOptions: {
socketPath: "/var/run/mysqld/mysqld.sock"
},
define: {
paranoid: true
}
});
I'm on a project using a stack that includes PostgreSQL, NodeJS, SailsJS, and BackboneJS. I pulled the client and server repos from git and I navigate into the server for the project and try to run it:
sails lift
Then I get this error:
/Users/$USER/Documents/Code/$APP/config/adapters.js:39
host: mc.dbSettings.host,
TypeError: Cannot read property 'host' of undefined
Where mc is a var that is set to point to another mainConfig.js file using a require statement. Opening that file I see that dbSettings is defined as:
dbSettings: {
host: "localhost",
user: "_appName_",
password: "_password_",
dbName: "_appDB_"
},
and sails cannot initialize because there is no localhost, or it doesn't know what it is? Please help.
If you're requireing a file and getting an "undefined" error trying to access its contents, it's possible you haven't exported the file contents properly. Your config file should look something like:
module.exports = {
dbSettings: {
host: "localhost",
user: "_appName_",
password: "_password_",
dbName: "_appDB_"
},
...
};
Note the module.exports. If that's missing, or if it's namespaced (like module.exports.foo) or if that dbSettings object is nested inside something else, it won't work.
dbSettings is undefined. So that must mean that it's not being found by SailJS. If you are using v.1.0 then you need to define your settings in connections.js instead of adapters.js. I'm assuming Sails will not be able to find your configuration otherwise.