Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
eue
Commits
937e73fb
Commit
937e73fb
authored
Mar 01, 2021
by
KangMin An
Browse files
Arduino DataSending & Server Receiving & Get API.
parent
0a410e3a
Changes
2
Show whitespace changes
Inline
Side-by-side
server/package.json
View file @
937e73fb
...
...
@@ -26,6 +26,7 @@
"express"
:
"^4.17.1"
,
"helmet"
:
"^4.1.1"
,
"morgan"
:
"^1.10.0"
,
"node-fetch"
:
"^2.6.1"
,
"pug"
:
"^3.0.0"
},
"devDependencies"
:
{
...
...
server/src/controllers/dataController.js
View file @
937e73fb
import
routes
from
"
../routes
"
;
import
fetch
from
"
node-fetch
"
;
export
const
getDataInput
=
(
req
,
res
)
=>
{
console
.
log
(
req
.
query
);
if
(
req
.
query
.
type
===
"
Out
"
)
{
// 외부 데이터 수집기
const
{
query
:
{
id
,
type
,
lat
,
lng
},
}
=
req
;
// OpenWeatherAPI로 부터 지역의 날씨 정보획득
fetch
(
`https://api.openweathermap.org/data/2.5/weather?lat=
${
lat
}
&lon=
${
lng
}
&appid=
${
process
.
env
.
OPENWEATHERMAP_API_KEY
}
`
)
.
then
((
response
)
=>
response
.
json
())
.
then
((
json
)
=>
{
const
temp
=
json
.
main
.
temp
;
const
humi
=
json
.
main
.
humidity
;
const
press
=
json
.
main
.
pressure
;
const
wind_speed
=
json
.
wind
.
speed
;
console
.
log
(
id
,
type
,
lat
,
lng
,
temp
,
humi
,
press
,
wind_speed
);
});
}
else
{
// 내부 데이터 수집기 동작
const
{
query
:
{
id
,
type
,
temp
,
humi
,
lights
},
}
=
req
;
console
.
log
(
id
,
type
,
temp
,
humi
,
lights
);
}
res
.
status
(
200
).
send
(
"
<p>OK</p>
"
);
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment