Created
April 18, 2022 21:17
-
-
Save atimin/b774b56ee4655a2c82892746237acb2d 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 {Client} = require('reduct-js'); | |
const client = new Client('http://localhost:8383'); | |
client.getBucket('mqtt').then(async (bucket) => { | |
let data = await bucket.read('mqtt_data'); | |
console.log('Last record: %s', data); | |
// Get data for the last hour | |
const stopTime = BigInt(Date.now() * 1000); | |
const startTime = stopTime - 3_600_000_000n; | |
const records = await bucket.list('mqtt_data', startTime, stopTime); | |
for (const record of records) { | |
data = await bucket.read('mqtt_data', record.timestamp); | |
console.log('Found record "%s" with timestamp "%d"', data, record.timestamp); | |
} | |
}).catch(error => console.error(error)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment