제 8 장 IOT 응용 실습
페이지 정보
작성자 관리자 댓글 4건 조회 2,012회 작성일 21-11-21 22:07본문
제 8 장 IOT 응용 실습
댓글목록
관리자님의 댓글
관리자 작성일
CREATE TABLE IF NOT EXISTS iot (
num int(11) NOT NULL AUTO_INCREMENT,
id char(15) NOT NULL,
name char(10) NOT NULL,
subject char(200) NOT NULL,
content text NOT NULL,
regist_day char(20) NOT NULL,
hit int(11) NOT NULL,
file_name char(40) DEFAULT NULL,
file_type char(40) DEFAULT NULL,
file_copied char(40) DEFAULT NULL,
PRIMARY KEY (num)
)
관리자님의 댓글
관리자 작성일
10/iot.php
<?php
$con = mysqli_connect("localhost", "user1", "12345", "sample");
$mb_id = trim($_POST['userid']);
$wr_password = trim($_POST['userpw']);
$wr_latitude = trim($_POST['latitude']);
$wr_longitude = trim($_POST['longitude']);
$wr_datetime = trim($_POST['datetime']);
if($mb_id == "" || $wr_password == "") {
echo "400";
exit;
}
$sql = "select id as mb_id, pass as mb_password, name as mb_name from members where id='$mb_id'";
$result = mysqli_query($con, $sql);
$mb = mysqli_fetch_array($result);
if (!(isset($mb['mb_id']) && $mb['mb_id']) || $wr_password != $mb['mb_password']) {
echo "401";
exit;
}
if($wr_latitude == "" || $wr_longitude == "") {
echo "402";
exit;
}
if($wr_datetime == "")
$wr_datetime = G5_TIME_YMDHIS;
$subject = $wr_datetime;
$content = "$wr_latitude , $wr_longitude";
$regist_day = date("Y-m-d (H:i)"); // 현재의 '년-월-일-시-분'을 저장
$userid = $mb['mb_id'];
$username = $mb['mb_name'];
$upfile_name = "";
$upfile_type = "";
$copied_file_name = "";
$sql = "insert into iot (id, name, subject, content, regist_day, hit, file_name, file_type, file_copied) ";
$sql .= "values('$userid', '$username', '$subject', '$content', '$regist_day', 0, ";
$sql .= "'$upfile_name', '$upfile_type', '$copied_file_name')";
mysqli_query($con, $sql); // $sql 에 저장된 명령 실행
echo "200";
exit;
?>
관리자님의 댓글
관리자 작성일
10/iot_list.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IOT데이터</title>
<link rel="stylesheet" type="text/css" href="./css/common.css">
<link rel="stylesheet" type="text/css" href="./css/board.css">
</head>
<body>
<header>
<?php include "header.php";?>
</header>
<section>
<div id="board_box">
<h3>
IOT > 목록보기
</h3>
<ul id="board_list">
<li>
<span class="col1">번호</span>
<span class="col3">아이디</span>
<span class="col2">위치</span>
<span class="col5">등록일</span>
</li>
<?php
if (isset($_GET["page"]))
$page = $_GET["page"];
else
$page = 1;
$sql = "select * from iot order by num desc";
$result = mysqli_query($con, $sql);
$total_record = mysqli_num_rows($result); // 전체 글 수
$scale = 10;
// 전체 페이지 수($total_page) 계산
if ($total_record % $scale == 0)
$total_page = floor($total_record/$scale);
else
$total_page = floor($total_record/$scale) + 1;
// 표시할 페이지($page)에 따라 $start 계산
$start = ($page - 1) * $scale;
$number = $total_record - $start;
for ($i=$start; $i<$start+$scale && $i < $total_record; $i++)
{
mysqli_data_seek($result, $i);
// 가져올 레코드로 위치(포인터) 이동
$row = mysqli_fetch_array($result);
// 하나의 레코드 가져오기
$num = $row["num"];
$id = $row["id"];
$name = $row["name"];
$subject = $row["subject"];
$content = $row["content"];
$regist_day = $row["regist_day"];
$hit = $row["hit"];
if ($row["file_name"])
$file_image = "<img src='./img/file.gif'>";
else
$file_image = " ";
?>
<li>
<span class="col1"><?=$number?></span>
<span class="col3"><?=$id?></span>
<span class="col2"><?=$content?></span>
<span class="col5"><?=$subject?></span>
</li>
<?php
$number--;
}
mysqli_close($con);
?>
</ul>
<ul id="page_num">
<?php
if ($total_page>=2 && $page >= 2)
{
$new_page = $page-1;
echo "<li><a href='iot_list.php?page=$new_page'>◀ 이전</a> </li>";
}
else
echo "<li> </li>";
// 게시판 목록 하단에 페이지 링크 번호 출력
for ($i=1; $i<=$total_page; $i++)
{
if ($page == $i) // 현재 페이지 번호 링크 안함
{
echo "<li><b> $i </b></li>";
}
else
{
echo "<li><a href='iot_list.php?page=$i'> $i </a><li>";
}
}
if ($total_page>=2 && $page != $total_page)
{
$new_page = $page+1;
echo "<li> <a href='iot_list.php?page=$new_page'>다음 ▶</a> </li>";
}
else
echo "<li> </li>";
?>
</ul> <!-- page -->
<ul class="buttons">
<li><button onclick="location.href='iot_list.php'">목록</button></li>
</ul>
</div> <!-- board_box -->
</section>
<footer>
<?php include "footer.php";?>
</footer>
</body>
</html>
관리자님의 댓글
관리자 작성일
10/iot_map.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IOT데이터 구글맵으로 보기</title>
<link rel="stylesheet" type="text/css" href="./css/common.css">
<link rel="stylesheet" type="text/css" href="./css/board.css">
</head>
<body>
<header>
<?php include "header.php";?>
</header>
<section>
<div id="board_box">
<h3>IOT > 맵으로 보기</h3>
<?php
$sql = "select * from iot order by subject desc";
$result = mysqli_query($con, $sql);
$total_record = mysqli_num_rows($result); // 전체 글 수
$ploylines = "[";
$loc_center = "{0, 0}";
$locations = "[";
for ($i=0; $i < $total_record; $i++){
mysqli_data_seek($result, $i);
// 가져올 레코드로 위치(포인터) 이동
$row = mysqli_fetch_array($result);
$subject = $row["subject"];
$content = $row["content"];
$latlng = explode(",",$content);
if($i == 0) $loc_center = "{lat: $latlng[0] , lng: $latlng[1]}";
$ploylines .= "{lat: $latlng[0] , lng: $latlng[1]},";
$locations .= "['$subject', $latlng[0], $latlng[1]],";
}
$ploylines .= "]";
$locations .= "]";
?>
<div id="map" style="width:100%; height: 500px;"></div>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=구글맵키&callback=initMap& region=kr"></script>
<script>
function initMap() {
var locations = <?= $locations;?>;
const myLatLng = <?= $loc_center;?>;
const map = new google.maps.Map(document.getElementById("map"), {
zoom: 14,
center: myLatLng,
});
const flightPlanCoordinates = <?= $ploylines;?>;
const flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2,
});
flightPath.setMap(map);
var infowindow = new google.maps.InfoWindow();
var marker, i;
for(i=0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1],locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker,i){
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker,i));
}
}
</script>
<br><br>
</div> <!-- board_box -->
</section>
<footer>
<?php include "footer.php";?>
</footer>
</body>
</html>