Skip to content

Instantly share code, notes, and snippets.

@prohazko2
Created November 27, 2020 19:06
Show Gist options
  • Save prohazko2/8d52cacdffb5aa819e630d872cad828f to your computer and use it in GitHub Desktop.
Save prohazko2/8d52cacdffb5aa819e630d872cad828f to your computer and use it in GitHub Desktop.
const cert = `
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
`;
const key = `
-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----
`;
const mqtt = require("mqtt").connect("mqtt://192.168.1.129", {
clientId: "mqtt-prohazko-xxx",
});
mqtt.on("connect", () => {
console.log("connect");
});
mqtt.on("error", (err) => {
console.log(err);
});
mqtt.on("message", (topic, message) => {
console.log(`${new Date().toISOString()}: [${topic}] ${message.toString()}`);
send();
});
setInterval(send, 5 * 60 * 1000);
function send() {
const rand = (Math.random() * 30).toFixed(2);
mqtt.publish("base/state/temperature", rand);
}
const repl = require("repl").start({ prompt: " > " });
repl.context.send = send;
repl.context.mqtt = mqtt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment