Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SensorDataCollectorAppServer_IOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Miklósi Máté
SensorDataCollectorAppServer_IOS
Commits
e7f16a72
Commit
e7f16a72
authored
1 year ago
by
miklosimate
Browse files
Options
Downloads
Patches
Plain Diff
File transfer Start
parent
11ed0583
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
index.js
+46
-1
46 additions, 1 deletion
index.js
with
46 additions
and
1 deletion
index.js
+
46
−
1
View file @
e7f16a72
...
...
@@ -4,6 +4,7 @@ const path = require('path');
const
ip
=
require
(
'
ip
'
);
const
app
=
express
();
const
server
=
http
.
createServer
(
app
);
const
fs
=
require
(
'
fs
'
)
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'
public
'
)));
app
.
use
(
express
.
json
());
// Use express.json() to parse JSON bodies
...
...
@@ -82,6 +83,51 @@ app.post('/am-i-ok/:deviceID', (req, res) => {
console
.
log
(
'
Sent JSON:
'
,
responseToSend
);
});
app
.
post
(
'
/json/:deviceID
'
,
(
req
,
res
)
=>
{
const
deviceID
=
req
.
params
.
deviceID
;
console
.
log
(
`Json incoming form:
${
deviceID
}
`
)
let
responseToSend
const
measurementsFolderPath
=
path
.
join
(
__dirname
,
'
measurements
'
,
deviceID
);
// Check if the folder exists, if not create it
if
(
!
fs
.
existsSync
(
measurementsFolderPath
))
{
fs
.
mkdirSync
(
measurementsFolderPath
,
{
recursive
:
true
});
}
// Get filename from request body
console
.
log
(
"
The body of the request is:
"
)
console
.
log
(
req
.
body
)
console
.
log
(
"
The paramteres are:
"
)
console
.
log
(
req
.
params
)
const
{
filename
,
...
jsonData
}
=
req
.
body
;
console
.
log
(
"
The filename shold be:
"
,
filename
)
// Generate unique filename if not provided
const
fileName
=
filename
||
deviceID
+
'
.json
'
;
// Path to save the file
const
filePath
=
path
.
join
(
measurementsFolderPath
,
fileName
);
// Write JSON data to the file
fs
.
writeFile
(
filePath
,
JSON
.
stringify
(
jsonData
,
null
,
2
),
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
'
Error saving file:
'
,
err
);
responseToSend
=
{
error
:
err
}
return
res
.
status
(
500
).
json
(
responseToSend
);
}
else
{
console
.
log
(
'
File saved successfully:
'
,
filePath
);
responseToSend
=
{
error
:
''
}
return
res
.
status
(
200
).
json
(
responseToSend
);
}
});
console
.
log
(
'
Sent JSON:
'
,
responseToSend
);
});
app
.
post
(
'
/ready/:deviceID
'
,
(
req
,
res
)
=>
{
const
deviceID
=
req
.
params
.
deviceID
;
...
...
@@ -91,7 +137,6 @@ app.post('/ready/:deviceID', (req, res) => {
console
.
log
(
`Received "ready" message from device
${
deviceID
}
`
);
// Update the device state to "Ready"
connectedDevices
[
deviceID
].
state
=
'
Ready
'
;
}
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment