Last active
June 9, 2022 02:13
-
-
Save Terny22/50e65c427be349f89c9c8150dfd20af4 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
var mqtt = require('mqtt'); | |
const ACCESS_TOKEN = process.argv[2]; | |
var client = mqtt.connect('mqtt://demo.thingsboard.io',{ | |
username: ACCESS_TOKEN | |
}); | |
var waterData = { | |
waterIncrement: Math.random(), | |
water: 11583 | |
} | |
client.on('connect', function () { | |
console.log('connected'); | |
console.log('Uploading water data once per minute...'); | |
setInterval(publishTelemetry, 60000); | |
}); | |
function publishTelemetry() { | |
waterData.waterIncrement = Math.random(); | |
waterData.water += waterData.waterIncrement; | |
client.publish('v1/devices/me/telemetry', JSON.stringify(waterData)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment