scheme for saving sensor data
This commit is contained in:
parent
a44284b9b1
commit
5935064606
3 changed files with 23 additions and 1 deletions
|
@ -2,6 +2,7 @@ import { db } from "$lib/server/db";
|
|||
import * as table from "$lib/server/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import type { PageServerLoad } from "./$types";
|
||||
import { connect } from "mqtt";
|
||||
|
||||
export const load: PageServerLoad = async ({ params }) => {
|
||||
{
|
||||
|
|
|
@ -6,6 +6,7 @@ import { writable } from "svelte/store";
|
|||
// In a real application, you might want to store more data or
|
||||
// use a more robust way to manage messages, but for a basic example, this works.
|
||||
const latestMessage = writable("No message yet");
|
||||
const devices = writable([]);
|
||||
|
||||
let client = null;
|
||||
|
||||
|
@ -36,6 +37,7 @@ function connectMqtt() {
|
|||
const payload = message.toString();
|
||||
console.log(`Received message from topic "${topic}": ${payload}`);
|
||||
latestMessage.set(payload); // Update the Svelte store
|
||||
console.log(topic.split("/")[1]);
|
||||
});
|
||||
|
||||
client.on("error", (err) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue