113 lines
2.8 KiB
Plaintext
113 lines
2.8 KiB
Plaintext
#mosquitto conf file docs
|
|
https://mosquitto.org/man/mosquitto-conf-5.html
|
|
|
|
#conf file
|
|
allow_anonymous false #must have user
|
|
connection_messages true #log client connect and disconnect
|
|
password_file /etc/mosquitto/passwd #speicyf path to password file
|
|
max_connections 5 #demo purpose
|
|
listener 8883 #port for tls
|
|
certfile /home/mpuser/letsencrypt-copy/live/mqtt.teeseng.uk-0001/cert.pem
|
|
cafile /home/mpuser/letsencrypt-copy/live/mqtt.teeseng.uk-0001/fullchain.pem
|
|
keyfile /home/mpuser/letsencrypt-copy/live/mqtt.teeseng.uk-0001/privkey.pem
|
|
|
|
|
|
|
|
#mosquitt.conf
|
|
pid_file /run/mosquitto/mosquitto.pid
|
|
|
|
persistence true
|
|
persistence_location /var/lib/mosquitto/
|
|
|
|
log_type all
|
|
log_facility 5
|
|
log_dest file /var/log/mosquitto/mosquitto.log
|
|
|
|
https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-the-mosquitto-mqtt-messaging-broker-on-ubuntu-18-04
|
|
|
|
|
|
let ormQuery = {};
|
|
let whereClause = {};
|
|
//let whereNest = {};
|
|
//let whereDate = {};
|
|
|
|
buildFuncs = {
|
|
month: function(query){
|
|
const validMonths = [
|
|
"1",
|
|
"2",
|
|
"3",
|
|
"4",
|
|
"5",
|
|
"6",
|
|
"7",
|
|
"8",
|
|
"9",
|
|
"10",
|
|
"11",
|
|
"12",
|
|
];
|
|
if (validMonths.includes(query.month)) {
|
|
whereClause = {
|
|
where: sequelize.where(
|
|
sequelize.fn("MONTH", sequelize.col("createdAt")),
|
|
query.month
|
|
),
|
|
};
|
|
} else {
|
|
query.month = getMonthFromString(query.month);
|
|
whereClause = {
|
|
where: sequelize.where(
|
|
sequelize.fn("MONTH", sequelize.col("createdAt")),
|
|
query.month
|
|
),
|
|
};
|
|
}
|
|
},
|
|
week: function(query){
|
|
whereClause.week = sequelize.where(
|
|
sequelize.fn("WEEK", sequelize.col("createdAt")),
|
|
query.week
|
|
);
|
|
},
|
|
sensorid: function (query){
|
|
whereClause.sensorid = sequelize.where(
|
|
sequelize.col("sensorid"),
|
|
query.sensorid
|
|
);
|
|
}
|
|
}
|
|
|
|
function getData(queryString)
|
|
for(let query in queryString){
|
|
if(buildFuncs[query]); buildFuncs[query](queryString)
|
|
|
|
if (!whereClause) {
|
|
return await sensorDataModel.findAll(ormQuery);
|
|
} else if (whereClause) {
|
|
console.log(whereClause);
|
|
//console.log(whereNest);
|
|
//console.log(whereDate);
|
|
console.log(query);
|
|
console.log(ormQuery);
|
|
|
|
return await sensorDataModel.findAll({
|
|
//limit default value if query.limit is undefined or not provided
|
|
limit: query.limit,
|
|
//The operators Op.and, Op.or and Op.not can be used to create arbitrarily complex nested logical comparisons.
|
|
//https://sequelize.org/docs/v6/core-concepts/model-querying-basics/#examples-with-opand-and-opor
|
|
where: {
|
|
//[Op.and]: [whereNest, whereClause],
|
|
[Op.and]: [whereClause],
|
|
createdAt: {
|
|
//https://stackoverflow.com/questions/43115151/sequelize-query-to-find-all-records-that-falls-in-between-date-range
|
|
[Op.between]: [whereClause.startdate, whereClause.enddate],
|
|
},
|
|
},
|
|
|
|
//only use where clause to lookup based on condition that i put into whereClause
|
|
...ormQuery,
|
|
});
|
|
}
|
|
}
|
|
} |