add: added mosquitto and front alerts

This commit is contained in:
Lukian 2025-04-26 16:49:29 +02:00
parent 78a6d26984
commit cb9a0c27b4
11 changed files with 948 additions and 10 deletions

39
front/src/App.tsx Normal file
View file

@ -0,0 +1,39 @@
import { useState } from "react"
import axios from "axios"
export default function App() {
const [text, setText] = useState("")
const [level, setLevel] = useState(1)
function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault()
axios
.post('/api/alert', {
sensor_id: 1,
text: text,
level: level
})
.then(() => {
setText("")
})
.catch((error) => {
console.error(error.response.data)
});
}
return (
<div>
<img src="/api/video" alt="" />
<form onSubmit={handleSubmit} >
<input type="text" name="text" id="text" onChange={(e) => setText(e.target.value)} value={text} />
<select name="level" id="level" onChange={(e) => setLevel(Number(e.target.value))} value={level}>
<option value={3}>High</option>
<option value={2}>Medium</option>
<option value={1}>Low</option>
</select>
<button type="submit">Submit alert</button>
</form>
</div>
)
}

View file

@ -1,9 +1,7 @@
import { createRoot } from 'react-dom/client'
import App from './App'
createRoot(document.getElementById('root')!).render(
<div>
<img src="/api/video" alt="" />
<img src="/api/video" alt="" />
<img src="/api/video" alt="" />
</div>
<App />
)