server modify and arduino sketch editting
parent
da1f7743f0
commit
eedaaa0b51
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -1,2 +1,36 @@
|
|||
void setup(){}
|
||||
void loop(){}
|
||||
// imports
|
||||
#include <SPI.h>
|
||||
#include <MFRC522.h>
|
||||
|
||||
|
||||
// Pin Setting
|
||||
#define RST_PIN1 9
|
||||
#define SS_PIN1 10
|
||||
|
||||
#define RST_PIN2 5
|
||||
#define SS_PIN2 6
|
||||
|
||||
#define RST_PIN3 2
|
||||
#define SS_PIN3 3
|
||||
|
||||
// RFID-Module Instances
|
||||
MFRC522 mfrc522_1(SS_PIN1, RST_PIN1);
|
||||
MFRC522 mfrc522_2(SS_PIN2, RST_PIN2);
|
||||
MFRC522 mfrc522_3(SS_PIN3, RST_PIN3);
|
||||
|
||||
// Setup
|
||||
void setup() {
|
||||
// Serial Begin
|
||||
Serial.begin(9600);
|
||||
// SPI start
|
||||
SPI.begin();
|
||||
|
||||
// Initialisation of Modules
|
||||
mfrc522_1.PCD_Init();
|
||||
mfrc522_2.PCD_Init();
|
||||
mfrc522_3.PCD_Init();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// reading of triple signal
|
||||
}
|
||||
|
|
|
@ -3,22 +3,81 @@ const express = require('express');
|
|||
const http = require('http');
|
||||
const schedule = require('node-schedule');
|
||||
const axios = require('axios');
|
||||
const { SerialPort } = require('serialport');
|
||||
const { ReadlineParser } = require('@serialport/parser-readline');
|
||||
const fs = require('fs');
|
||||
const cors = require('cors');
|
||||
|
||||
|
||||
// Start Express and define port
|
||||
const app = express();
|
||||
const serverPort = 3000;
|
||||
|
||||
// Shedule Format (* * * * *) (Sec(0-59), Min(0-59), Hours(0-23), Day (1-31), Month (0-11))
|
||||
// Set Cors Policy
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
app.use(express.static('public'));
|
||||
|
||||
// Setting of Port of Arduino
|
||||
const arduinoPort = new SerialPort({
|
||||
path: 'COM3',
|
||||
baudRate: 9600
|
||||
});
|
||||
|
||||
const job = schedule.scheduleJob('*/15 * * * *', () => {
|
||||
const clientURL = 'http://localhost:80';
|
||||
// Server and Client information
|
||||
const clientURL = 'http://localhost:80';
|
||||
|
||||
axios.get(clientURL)
|
||||
.then((response) => {
|
||||
})
|
||||
.catch((error) => {
|
||||
});
|
||||
// fetching data from Serialport: Getting Card Information which is in the middle
|
||||
function waitForData() {
|
||||
return new Promise((resolve) => {
|
||||
const parser = arduinoPort.pipe(new ReadlineParser({ delimiter: '\r\n' }));
|
||||
parser.once('data', (data) => {
|
||||
resolve(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// fetching data from Serialport: Getting Hand Information of the Player
|
||||
function waitForData(playerid) {
|
||||
return "coming soon!"
|
||||
}
|
||||
|
||||
// Get Request for Playerhand
|
||||
app.get('/cardinmyhand/:playerid', async (req, res) => {
|
||||
try {
|
||||
const playerid = req.params.playerid;
|
||||
const data = await waitForData(playerid); // Warte auf Daten von der seriellen Schnittstelle
|
||||
res.send(data); // Sende die Daten an den Client
|
||||
} catch (error) {
|
||||
res.status(500).send('Fehler beim Lesen der Daten');
|
||||
}
|
||||
});
|
||||
|
||||
// Get Request for Card in the middle
|
||||
app.get('/cardinthemiddle', async (req, res) => {
|
||||
try {
|
||||
const data = await waitForData(); // Warte auf Daten von der seriellen Schnittstelle
|
||||
res.send(data); // Sende die Daten an den Client
|
||||
} catch (error) {
|
||||
res.status(500).send('Fehler beim Lesen der Daten');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// // Shedule Format (* * * * *) (Sec(0-59), Min(0-59), Hours(0-23), Day (1-31), Month (0-11))
|
||||
// const job = schedule.scheduleJob('*/15 * * * *', () => {
|
||||
|
||||
|
||||
// axios.get(clientURL)
|
||||
// .then((response) => {
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// });
|
||||
// });
|
||||
|
||||
// Port Definition
|
||||
app.listen(3000, () => {
|
||||
console.log('Backend-Server running on port 3000...');
|
||||
app.listen(serverPort, () => {
|
||||
console.log(`Server läuft auf http://localhost:${serverPort}`);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue