diff --git a/index.html b/index.html index 9b921b0d976fa662331b5322ad650fc8ca0cd5ff..8a776c6441159c9c160aceec4e5364d44bd18dbf 100644 --- a/index.html +++ b/index.html @@ -1,3 +1,4 @@ +<!-- //This file was written by chatGPT (3.5) with many iterations and manual corrections. --> <!DOCTYPE html> <html lang="en"> <head> @@ -142,38 +143,6 @@ console.error('Error fetching devices:', error); } } - - async function handleStillHereMessageAndRefresh(deviceID) { - try { - const response = await fetch(`/stillHere/${deviceID}`, { - method: 'POST', - }); - - const data = await response.json(); - - // Refresh the device list after receiving "stillHere" message - await populateDeviceList(); - } catch (error) { - console.error('Error handling stillHere message:', error); - } - } - - - async function handleReadyMessageAndRefresh(deviceID) { - try { - const response = await fetch(`/ready/${deviceID}`, { - method: 'POST', - }); - - const data = await response.json(); - - // Refresh the device list after receiving "ready" message - await populateDeviceList(); - } catch (error) { - console.error('Error handling ready message:', error); - } - } - // Populate device list on page load populateDeviceList(); </script> diff --git a/index.js b/index.js index 1e90d8c697dbf8d0688331ea8703f628df354c56..3939aecd8840bb33dfb3f9207533a035709f763c 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,7 @@ app.get('/list', (req, res) => { res.sendFile(path.join(__dirname, 'list.html')); }); -// Add route to get server info +//This function was written by chatGPT (3.5), the rest of the code and the "Write me the route for server info" input was given. app.get('/server-info', (req, res) => { const serverInfo = { ip: ip.address(), @@ -36,8 +36,7 @@ app.get('/server-info', (req, res) => { }; res.json(serverInfo); }); - -// POST route for handling "init" messages +//This function was written by chatGPT (3.5) with many iterations and manual corrections. app.post('/init', (req, res) => { console.log(`Received "init" message\n`); //If the measurement parameters has not been set yet @@ -67,6 +66,7 @@ app.post('/init', (req, res) => { // POST route for checking "am-i-ok" messages +//This function was written by chatGPT (3.5) with many iterations and manual corrections. app.post('/am-i-ok/:deviceID', (req, res) => { const deviceID = req.params.deviceID; let responseToSend @@ -85,7 +85,7 @@ app.post('/am-i-ok/:deviceID', (req, res) => { } console.log('Sent JSON:', responseToSend); }); - +//This function was written by chatGPT (3.5) with many iterations and manual corrections. app.post('/json/:deviceID/:f_n', (req, res) => { const deviceID = req.params.deviceID; const f_n = req.params.f_n; @@ -139,7 +139,7 @@ app.post('/ready/:deviceID', (req, res) => { connectedDevices[deviceID].state = 'Ready'; } }); - +//This function was written by chatGPT (3.5) with many iterations and manual corrections. app.post('/stillHere/:deviceID', (req, res) => { const deviceID = req.params.deviceID; // Check if the device is registered @@ -169,7 +169,7 @@ function generateDeviceID() { // Generate a unique device ID (you can use a more robust method if needed) return Date.now().toString(36) + Math.random().toString(36).substr(2, 5); } - +//This function was written by chatGPT (3.5) app.get('/get-devices', (req, res) => { const devicesList = Object.keys(connectedDevices).map(deviceID => { return { @@ -181,6 +181,7 @@ app.get('/get-devices', (req, res) => { res.json(devicesList); }); +//This function was written by chatGPT (3.5) manual corrections was needed. app.post('/set-server-config', (req, res) => { // Handle the POST request to set server configuration const { NumberOfMeasurements, Intervals, Delay } = req.body; diff --git a/list.html b/list.html index 11faa6eef31a23246ebb05885aba2d8467a3ab99..609975d77ce0917cc29a0aafcb0bdbac809bbfbd 100644 --- a/list.html +++ b/list.html @@ -1,3 +1,4 @@ +<!-- //This file was written by chatGPT (3.5) with many iterations and manual corrections. --> <!DOCTYPE html> <html lang="en"> <head>