Last active
August 17, 2018 02:54
-
-
Save Terny22/b9e050e2c561cd7f109a2836f905085f 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 energyData = { | |
energyIncrement: Math.random(), | |
energy: 19546 | |
} | |
client.on('connect', function () { | |
console.log('connected'); | |
console.log('Uploading energy data once per minute...'); | |
setInterval(publishTelemetry, 60000); | |
}); | |
function publishTelemetry() { | |
energyData.energyIncrement = Math.random(); | |
energyData.energy += energyData.energyIncrement; | |
client.publish('v1/devices/me/telemetry', JSON.stringify(energyData)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment