Skip to content

Instantly share code, notes, and snippets.

@klinquist
Last active March 25, 2023 01:21
Show Gist options
  • Save klinquist/711358c08da3e5cba41999576e89b74e to your computer and use it in GitHub Desktop.
Save klinquist/711358c08da3e5cba41999576e89b74e to your computer and use it in GitHub Desktop.
Stream Rheem water heater data
// Stream data from Rheem hybrid water heaters.
// Run "npm install async-mqtt axios" to install dependencies
// Then execute via "node streamWaterHeaterData.js"
// Written by Kris Linquist
const axios = require('axios')
const MQTT = require("async-mqtt");
const rheem_username = '';
const rheem_password = '';
//To obtain these credentials, connect to your water heater's wifi and go to https://192.168.10.1/cred
const rheem_deviceName = '';
const rheem_activeKey = '';
const rheem_systemKey = 'e2e699cb0bb0bbb88fc8858cb5a401';
const rheem_systemSecret = 'E2E699CB0BE6C6FADDB1B0BC9A20';
(async function () {
console.log('Getting auth token')
let user = await axios.post('https://rheem.clearblade.com/api/v/1/user/auth', {
email: rheem_username,
password: rheem_password
}, {
headers: {
'ClearBlade-SystemKey': rheem_systemKey,
'ClearBlade-SystemSecret': rheem_systemSecret,
'Content-Type': 'application/json'
}
})
console.log('got user token, getting location')
let location = await axios.post(`https://rheem.clearblade.com/api/v/1/code/${rheem_systemKey}/getLocation`, null, {
headers: {
'ClearBlade-UserToken': user.data.user_token,
'Content-Type': 'application/json',
'ClearBlade-SystemKey': rheem_systemKey,
'ClearBlade-SystemSecret': rheem_systemSecret
}
})
let mac = location.data.results.locations[0].equiptments[0].mac_address;
let serialnumber = location.data.results.locations[0].equiptments[0].serial_number;
let deviceTopic = `device/${mac}/${serialnumber}/4736/reported`
console.log('got device ID from location, getting device token')
let auth = await axios.post(`https://rheem.clearblade.com/api/v/2/devices/${rheem_systemKey}/auth`, {
deviceName: rheem_deviceName,
activeKey: rheem_activeKey
})
console.log('Using token to connect to MQTT')
const client = await MQTT.connectAsync("mqtt://rheem.clearblade.com", {
username: auth.data.deviceToken,
password: rheem_systemKey
})
console.log('Conected.')
try {
await client.subscribe(deviceTopic)
} catch (err) {
console.log('Error subscribing: ' + err)
}
client.on('message', function (topic, message) {
console.log(`Message topic ${topic}`)
console.log(message.toString())
})
client.on('disconnect', function () {
console.log('disconnected')
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment