When I am trying to insert a old timestamp
the values are not visible in influx DB
var newMsg = {};
var data_time = msg.payload.data.substr(16, 8);
var Temp = Number(hexTo8p8(msg.payload.data.substr(16 + 8, 4)));
var Humidity = Number(hexTo8p8(msg.payload.data.substr(16 + 8 + 4, 4)));
var data = msg.payload.data.substr(16, 8);
var data_length = msg.payload.data.length;
for (var i = 1; i <= 30; i++) {
data_time = msg.payload.data.substr(16 * i, 8);
Temp = Number(hexTo8p8(msg.payload.data.substr(24 * i, 4)));
Humidity = Number(hexTo8p8(msg.payload.data.substr(28 * i, 4)));
data = msg.payload.data.substr(16 * i, 8);
let UTC_ISO = new Date(parseInt(msg.payload.data.substr(16 * i, 8), 16) * 1000).toISOString();
let UTC_unix = parseInt(msg.payload.data.substr(16 * i, 8), 16);
var d = new Date(UTC_ISO);
var converted_payload = UTC_ISO.split(/\.|T/).slice(0, 2).join(" ");
let UTC_short = new Date(parseInt(msg.payload.data.substr(16 * i, 8), 16) * 1000).toDateString();
var checktime = 1546337502;
if (checktime > data_time) {
}
if (Temp == Humidity || Temp > 99 || Humidity > 99 || data_length < 40) {
}
else {
newMsg.payload = [{
device_mac: msg.payload.mac,
device_timestamp: new Date(UTC_unix * 1000).getTime(),
temp: Temp,
humidity: Humidity,
time: new Date(UTC_unix * 1000).getTime(),
timestamp: new Date(UTC_unix * 1000).getTime(),
},
{
device_mac: msg.payload.mac,
history: 1,
host: 1,
}];
node.send(newMsg);
}
}
return null;
function calculateDistance(rssi) {
let P = -69; // @TODO This value should come from MQTT message
let n = 3;
let d = Math.pow(10, ((P - rssi) / (10 * n))); //(n ranges from 2 to 4)
return d * 2;
}
function hexTo8p8(/** @type {string} */ value) {
let intValue = parseInt(value, 16);
let signed = (intValue & 0x8000) > 0 ? -1 / 10 : 1;
return signed * intValue / Math.pow(2, 8);
}
function int2float( /** @type {string} */value_int) {
// Create new Buffer based on array bytes
const buf = Buffer.from(value_int);
// swap the words
const temp0 = buf[0];
const temp1 = buf[1];
buf[0] = buf[2];
buf[1] = buf[3];
buf[2] = temp0;
buf[3] = temp1;
// Represent these bytes as 32-bit unsigned int
const value = buf.readInt32BE();
// save the value
msg.payload = value;
return msg;
}
Issue
Unable to restore old data using the old time stamp
[{"device_mac":"BC572900A06A","device_timestamp":1663470615000,"temp":31.15625,"humidity":53.91015625,"time":1663470615000,"timestamp":1663470615000},{"device_mac":"BC572900A06A","history":1,"host":1}]