diff --git a/api/index.js b/api/index.js index a227fc39b93ee6a610381c298ae0e4a343fedac9..f740836d86df56e570ddd3ec2e4dc25de06dd3a0 100644 --- a/api/index.js +++ b/api/index.js @@ -138,18 +138,17 @@ app.post('/entry', (req, res) => { let id_tag = req.body.id_tag; let time_stamp = new Date(); time_stamp.setHours(time_stamp.getHours() + 1); - console.log(req.body); if (!id_tag) { res.status(http_status_codes_1.default.BAD_REQUEST).send({ error: "Missing argument" }); - console.log("error no tag"); return; } const query = "INSERT INTO `entry`(`time_stamp`, `id_tag`) VALUES (?,?)"; exports.db.query(query, [time_stamp, id_tag], (err, result) => { if (err) { res.status(http_status_codes_1.default.INTERNAL_SERVER_ERROR).send({ error: "Something wrong append" }); + return; } - res.status(http_status_codes_1.default.OK).send(); + res.status(http_status_codes_1.default.OK).end(); }); }); app.listen(port, () => { diff --git a/api/index.ts b/api/index.ts index 5cefb2141bbc37289a70e6db2a39cbc0aaa938f2..1159760416597e98181f1f06a0ac1350d732422a 100644 --- a/api/index.ts +++ b/api/index.ts @@ -158,8 +158,7 @@ app.get('/entry', (req: Request, res: Response) => { } res.json(result); - } - ) + }) }) app.get('/test', (req: Request, res: Response) => { @@ -174,11 +173,8 @@ app.post('/entry', (req: Request, res: Response) => { let time_stamp = new Date(); time_stamp.setHours(time_stamp.getHours() + 1) - console.log(req.body) - if(!id_tag) { res.status(StatusCode.BAD_REQUEST).send({error:"Missing argument"}) - console.log("error no tag") return } @@ -186,10 +182,11 @@ app.post('/entry', (req: Request, res: Response) => { db.query(query, [time_stamp, id_tag], (err, result) => { if (err) { - res.status(StatusCode.INTERNAL_SERVER_ERROR).send({error: "Something wrong append"}); + res.status(StatusCode.INTERNAL_SERVER_ERROR).send({error:"Something wrong append"}); + return } - res.status(StatusCode.OK).send(); + res.status(StatusCode.OK).end(); }) }) diff --git a/detection_tag/tag_detection.py b/detection_tag/tag_detection.py new file mode 100644 index 0000000000000000000000000000000000000000..2ff8cea232eb8657a8f826bc7253d8d07092bb9f --- /dev/null +++ b/detection_tag/tag_detection.py @@ -0,0 +1,31 @@ +# code provenant de Jovani + +import serial +from time import sleep +import requests + +# Send data to API +def sendAPI(tag): + url = 'http://localhost:8000/entry' + myobj = {'id_tag': tag} + + x = requests.post(url, json = myobj) + + print(x.text) + +sendAPI("19040563") + +receiver = serial.Serial('/dev/ttyACM0', 115200) + +while(True): + rx=0 + sleep(0.5) + bytes_data = [0x01, 0x46, 0x46, 0x05, 0x05, 0x0d] + receiver.write(bytes_data) + receiver.timeout = 0.5 + rx = receiver.read(size=17) + + if (rx != b'\x01ff\x020000000000\x03\x00\r'): + print(rx) + # Les données ne sont pas encore filtrée correctemenent, on doit nettoyer et récupérer juste l'ID du tag + sendAPI(rx) \ No newline at end of file diff --git a/frontend/src/lib/Entry.svelte b/frontend/src/lib/Entry.svelte index 317182641235e5a26986cd2890def4240bee652d..d707ebf5665e9bd76f0fff6f4160e669a3522519 100644 --- a/frontend/src/lib/Entry.svelte +++ b/frontend/src/lib/Entry.svelte @@ -30,6 +30,7 @@ getEntries(year_selected); function sendEntry() { + console.log("get entries"); let body_data = { id_tag: "19040562" }; @@ -42,6 +43,7 @@ }, }).then(function (response) { if (!response.ok) return Promise.reject(response.status); + getEntries(year_selected); return response.json(); }) .then(function (data) { @@ -50,17 +52,23 @@ .catch(function (error) { console.log("Error: " + error); }); + } + </script> <div class="container"> <h1>Classement {year_selected}</h1> - <select name="" id="" bind:value={year_selected} on:change={selectYear}> - {#each editions as edition} - <option value={edition.year}>{edition.year}</option> - {/each} - </select> + <form action=""> + <select name="" id="" bind:value={year_selected} on:change={selectYear}> + {#each editions as edition} + <option value={edition.year}>{edition.year}</option> + {/each} + </select> + + <button on:click={sendEntry}>Add entry</button> + </form> <table> <tr> @@ -90,8 +98,6 @@ </tr> {/each} </table> - - <button on:click={sendEntry}>Add entry</button> </div> <style> diff --git a/frontend/src/lib/Team.svelte b/frontend/src/lib/Team.svelte index 4a417eb6a935e8f44f4c988c19565f47cc4674cb..c84531f9b2fe670708d699f23fc071cbf434f9e3 100644 --- a/frontend/src/lib/Team.svelte +++ b/frontend/src/lib/Team.svelte @@ -3,10 +3,11 @@ let teams = []; let availableTags = []; + let year_selected = new Date().getFullYear(); - let TEAMS_URL = "http://localhost:8000/teams/tag?year=2022"; + let TEAMS_URL = "http://localhost:8000/teams/tag?year="; function getTeams() { - fetch(TEAMS_URL) + fetch(TEAMS_URL+year_selected) .then((response) => response.json()) .then((teams_data) => { teams = teams_data; @@ -33,7 +34,6 @@ let team_name = ""; let team_participants = ""; let tag_selected = ""; - let year_selected = new Date().getFullYear(); // Send data function save() {