Skip to content
Snippets Groups Projects
Commit 2c2d1d23 authored by ExtraDev's avatar ExtraDev
Browse files

try to detect tag (not fonctionnal) and send it to the API (fonctionnal)

parent b82fbea8
No related branches found
No related tags found
No related merge requests found
...@@ -138,18 +138,17 @@ app.post('/entry', (req, res) => { ...@@ -138,18 +138,17 @@ app.post('/entry', (req, res) => {
let id_tag = req.body.id_tag; let id_tag = req.body.id_tag;
let time_stamp = new Date(); let time_stamp = new Date();
time_stamp.setHours(time_stamp.getHours() + 1); time_stamp.setHours(time_stamp.getHours() + 1);
console.log(req.body);
if (!id_tag) { if (!id_tag) {
res.status(http_status_codes_1.default.BAD_REQUEST).send({ error: "Missing argument" }); res.status(http_status_codes_1.default.BAD_REQUEST).send({ error: "Missing argument" });
console.log("error no tag");
return; return;
} }
const query = "INSERT INTO `entry`(`time_stamp`, `id_tag`) VALUES (?,?)"; const query = "INSERT INTO `entry`(`time_stamp`, `id_tag`) VALUES (?,?)";
exports.db.query(query, [time_stamp, id_tag], (err, result) => { exports.db.query(query, [time_stamp, id_tag], (err, result) => {
if (err) { if (err) {
res.status(http_status_codes_1.default.INTERNAL_SERVER_ERROR).send({ error: "Something wrong append" }); 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, () => { app.listen(port, () => {
......
...@@ -158,8 +158,7 @@ app.get('/entry', (req: Request, res: Response) => { ...@@ -158,8 +158,7 @@ app.get('/entry', (req: Request, res: Response) => {
} }
res.json(result); res.json(result);
} })
)
}) })
app.get('/test', (req: Request, res: Response) => { app.get('/test', (req: Request, res: Response) => {
...@@ -174,11 +173,8 @@ app.post('/entry', (req: Request, res: Response) => { ...@@ -174,11 +173,8 @@ app.post('/entry', (req: Request, res: Response) => {
let time_stamp = new Date(); let time_stamp = new Date();
time_stamp.setHours(time_stamp.getHours() + 1) time_stamp.setHours(time_stamp.getHours() + 1)
console.log(req.body)
if(!id_tag) { if(!id_tag) {
res.status(StatusCode.BAD_REQUEST).send({error:"Missing argument"}) res.status(StatusCode.BAD_REQUEST).send({error:"Missing argument"})
console.log("error no tag")
return return
} }
...@@ -187,9 +183,10 @@ app.post('/entry', (req: Request, res: Response) => { ...@@ -187,9 +183,10 @@ app.post('/entry', (req: Request, res: Response) => {
db.query(query, [time_stamp, id_tag], (err, result) => { db.query(query, [time_stamp, id_tag], (err, result) => {
if (err) { 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();
}) })
}) })
......
# 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
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
getEntries(year_selected); getEntries(year_selected);
function sendEntry() { function sendEntry() {
console.log("get entries");
let body_data = { let body_data = {
id_tag: "19040562" id_tag: "19040562"
}; };
...@@ -42,6 +43,7 @@ ...@@ -42,6 +43,7 @@
}, },
}).then(function (response) { }).then(function (response) {
if (!response.ok) return Promise.reject(response.status); if (!response.ok) return Promise.reject(response.status);
getEntries(year_selected);
return response.json(); return response.json();
}) })
.then(function (data) { .then(function (data) {
...@@ -50,18 +52,24 @@ ...@@ -50,18 +52,24 @@
.catch(function (error) { .catch(function (error) {
console.log("Error: " + error); console.log("Error: " + error);
}); });
} }
</script> </script>
<div class="container"> <div class="container">
<h1>Classement {year_selected}</h1> <h1>Classement {year_selected}</h1>
<form action="">
<select name="" id="" bind:value={year_selected} on:change={selectYear}> <select name="" id="" bind:value={year_selected} on:change={selectYear}>
{#each editions as edition} {#each editions as edition}
<option value={edition.year}>{edition.year}</option> <option value={edition.year}>{edition.year}</option>
{/each} {/each}
</select> </select>
<button on:click={sendEntry}>Add entry</button>
</form>
<table> <table>
<tr> <tr>
<th>Ordre</th> <th>Ordre</th>
...@@ -90,8 +98,6 @@ ...@@ -90,8 +98,6 @@
</tr> </tr>
{/each} {/each}
</table> </table>
<button on:click={sendEntry}>Add entry</button>
</div> </div>
<style> <style>
......
...@@ -3,10 +3,11 @@ ...@@ -3,10 +3,11 @@
let teams = []; let teams = [];
let availableTags = []; 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() { function getTeams() {
fetch(TEAMS_URL) fetch(TEAMS_URL+year_selected)
.then((response) => response.json()) .then((response) => response.json())
.then((teams_data) => { .then((teams_data) => {
teams = teams_data; teams = teams_data;
...@@ -33,7 +34,6 @@ ...@@ -33,7 +34,6 @@
let team_name = ""; let team_name = "";
let team_participants = ""; let team_participants = "";
let tag_selected = ""; let tag_selected = "";
let year_selected = new Date().getFullYear();
// Send data // Send data
function save() { function save() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment