import { useState } from 'react' import viteLogo from '/vite.svg' import './App.css' import mqtt from "precompiled-mqtt"; function App() { const [count, setCount] = useState(0) const topic = "value/#"; const brokerUrl = 'wss://random.pigne.org:443'; const sensorDataUrl = '/sensors_data.json'; const sensors = {}; const client = mqtt.connect(brokerUrl); client.on('connect', () => { console.log(`Connected to MQTT broker ${brokerUrl}`); client.subscribe(topic, (err) => { if (err) { console.error('Error subscribing to topic', err); } else { console.log(`Subscribed to topic ${topic}`); } }); }); client.on('message', (topic, message) => { const sensorData = JSON.parse(message.toString()); console.log(`Received sensor data from topic ${topic}:`, sensorData); // Update state with sensor data here }); //client.on('message', (topic,value) => {console.log(topic, JSON.parse(value.toString()))}) return (
Vite logo

Vite + React

Edit src/App.jsx and save to test HMR

Click on the Vite and React logos to learn more

) } export default App