Created
November 27, 2020 19:06
-
-
Save prohazko2/8d52cacdffb5aa819e630d872cad828f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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