Fix: Convert timestamp to WIB (UTC+7) timezone
This commit is contained in:
parent
5dd7cb1e1a
commit
59d89ae7a5
|
|
@ -173,7 +173,12 @@ async function insertSensorData(data) {
|
||||||
async function getLatestSensorData() {
|
async function getLatestSensorData() {
|
||||||
try {
|
try {
|
||||||
const [rows] = await pool.query(
|
const [rows] = await pool.query(
|
||||||
'SELECT * FROM sensor_data ORDER BY timestamp DESC LIMIT 1'
|
`SELECT
|
||||||
|
id, suhu, berat, target, relay1, relay2, relay3, relay4, status,
|
||||||
|
CONVERT_TZ(timestamp, '+00:00', '+07:00') as timestamp
|
||||||
|
FROM sensor_data
|
||||||
|
ORDER BY timestamp DESC
|
||||||
|
LIMIT 1`
|
||||||
);
|
);
|
||||||
return rows[0] || null;
|
return rows[0] || null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -186,7 +191,12 @@ async function getLatestSensorData() {
|
||||||
async function getSensorDataHistory(limit = 50) {
|
async function getSensorDataHistory(limit = 50) {
|
||||||
try {
|
try {
|
||||||
const [rows] = await pool.query(
|
const [rows] = await pool.query(
|
||||||
'SELECT * FROM sensor_data ORDER BY timestamp DESC LIMIT ?',
|
`SELECT
|
||||||
|
id, suhu, berat, target, relay1, relay2, relay3, relay4, status,
|
||||||
|
CONVERT_TZ(timestamp, '+00:00', '+07:00') as timestamp
|
||||||
|
FROM sensor_data
|
||||||
|
ORDER BY timestamp DESC
|
||||||
|
LIMIT ?`,
|
||||||
[limit]
|
[limit]
|
||||||
);
|
);
|
||||||
return rows;
|
return rows;
|
||||||
|
|
@ -218,7 +228,12 @@ async function insertStatusHistory(message) {
|
||||||
async function getStatusHistory(limit = 50) {
|
async function getStatusHistory(limit = 50) {
|
||||||
try {
|
try {
|
||||||
const [rows] = await pool.query(
|
const [rows] = await pool.query(
|
||||||
'SELECT * FROM status_history ORDER BY timestamp DESC LIMIT ?',
|
`SELECT
|
||||||
|
id, message,
|
||||||
|
CONVERT_TZ(timestamp, '+00:00', '+07:00') as timestamp
|
||||||
|
FROM status_history
|
||||||
|
ORDER BY timestamp DESC
|
||||||
|
LIMIT ?`,
|
||||||
[limit]
|
[limit]
|
||||||
);
|
);
|
||||||
return rows;
|
return rows;
|
||||||
|
|
|
||||||
|
|
@ -146,6 +146,10 @@ mqttClient.on('message', async (topic, message) => {
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(msg);
|
const data = JSON.parse(msg);
|
||||||
|
|
||||||
|
// Get current time in WIB (UTC+7)
|
||||||
|
const now = new Date();
|
||||||
|
const wibTime = new Date(now.getTime() + (7 * 60 * 60 * 1000));
|
||||||
|
|
||||||
// Update latestData dengan data dari ESP32
|
// Update latestData dengan data dari ESP32
|
||||||
latestData = {
|
latestData = {
|
||||||
suhu: data.suhu || 0,
|
suhu: data.suhu || 0,
|
||||||
|
|
@ -156,7 +160,7 @@ mqttClient.on('message', async (topic, message) => {
|
||||||
relay3: latestData.relay3 || false,
|
relay3: latestData.relay3 || false,
|
||||||
relay4: latestData.relay4 || false,
|
relay4: latestData.relay4 || false,
|
||||||
status: latestData.status, // Keep current status
|
status: latestData.status, // Keep current status
|
||||||
timestamp: new Date().toISOString()
|
timestamp: wibTime.toISOString()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Save to database
|
// Save to database
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue