Commit 937e73fb authored by KangMin An's avatar KangMin An
Browse files

Arduino DataSending & Server Receiving & Get API.

parent 0a410e3a
......@@ -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": {
......
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>");
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment