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
f22309e2
Commit
f22309e2
authored
Mar 07, 2021
by
KangMin An
Browse files
Arduino Update.
parent
937e73fb
Changes
2
Show whitespace changes
Inline
Side-by-side
arduino/code/main
/main
.ino
→
arduino/code/main
_inside/main_inside
.ino
View file @
f22309e2
...
@@ -26,7 +26,6 @@ String SSPW = "Wifi_SSPW"; // Wifi - SSPW
...
@@ -26,7 +26,6 @@ String SSPW = "Wifi_SSPW"; // Wifi - SSPW
String
EUEIP
=
"EUE_IP"
;
// Web Server - IP
String
EUEIP
=
"EUE_IP"
;
// Web Server - IP
int
EUEPORT
=
8081
;
// Web Server - Port
int
EUEPORT
=
8081
;
// Web Server - Port
// 함수 선언부
void
connectESP
();
void
connectESP
();
void
connectWifi
();
void
connectWifi
();
void
sendData
(
String
vars
);
void
sendData
(
String
vars
);
...
@@ -77,30 +76,52 @@ void setup() {
...
@@ -77,30 +76,52 @@ void setup() {
void
loop
()
{
void
loop
()
{
String
input
=
""
;
String
input
=
""
;
// 사용자 ID
String
ID
=
"Admin"
;
// 측정기 분류(IN / OUT)
String
type_
=
"In"
;
// 사용자 장소의 위도(Latitude), 경도(Longitude)
float
lati
=
37.241706
;
String
str_lati
=
String
(
lati
,
6
);
float
lng
=
131.864889
;
String
str_lng
=
String
(
lng
,
6
);
// DHT11 모듈의 측정 event
sensors_event_t
event
;
sensors_event_t
event
;
// 온도
dht
.
temperature
().
getEvent
(
&
event
);
dht
.
temperature
().
getEvent
(
&
event
);
float
temp
=
event
.
temperature
;
float
temp
=
event
.
temperature
;
String
str_Temp
=
String
(
temp
);
String
str_Temp
=
String
(
temp
);
// 습도
dht
.
humidity
().
getEvent
(
&
event
);
dht
.
humidity
().
getEvent
(
&
event
);
float
humi
=
event
.
relative_humidity
;
float
humi
=
event
.
relative_humidity
;
String
str_Humi
=
String
(
humi
);
String
str_Humi
=
String
(
humi
);
// 광도
int
lights
=
analogRead
(
CDS_A
);
int
lights
=
analogRead
(
CDS_A
);
String
str_Lights
=
String
(
lights
);
String
str_Lights
=
String
(
lights
);
String
ID
=
"Admin"
;
input
+=
"id="
+
ID
;
input
+=
"id="
+
ID
;
input
+=
"&type="
+
type_
;
input
+=
"&lat="
+
str_lati
;
input
+=
"&lng="
+
str_lng
;
input
+=
"&temp="
+
str_Temp
;
input
+=
"&temp="
+
str_Temp
;
input
+=
"&humi="
+
str_Humi
;
input
+=
"&humi="
+
str_Humi
;
input
+=
"&lights="
+
str_Lights
;
input
+=
"&lights="
+
str_Lights
;
Serial
.
println
(
input
);
Serial
.
println
(
input
);
// 데이터 전송
sendData
(
input
);
sendData
(
input
);
// 1분마다 전송 진행
delay
(
60000
);
}
}
//
함수 정의부
//
ESP모듈 연결
void
connectESP
(){
void
connectESP
(){
esp
.
println
(
"AT"
);
esp
.
println
(
"AT"
);
Serial
.
println
(
"AT Sent"
);
Serial
.
println
(
"AT Sent"
);
...
@@ -111,30 +132,36 @@ void connectESP(){
...
@@ -111,30 +132,36 @@ void connectESP(){
Serial
.
println
(
"OK Command Received."
);
Serial
.
println
(
"OK Command Received."
);
}
}
// 공유기와 연결
void
connectWifi
(){
void
connectWifi
(){
String
cmd
=
"AT+CWMODE=1"
;
// Client로 설정
// ESP8266 모듈 Client로 설정
String
cmd
=
"AT+CWMODE=1"
;
esp
.
println
(
cmd
);
esp
.
println
(
cmd
);
Serial
.
println
(
"Set ESP8266 to client."
);
Serial
.
println
(
"Set ESP8266 to client."
);
// 공유기와 연결
Serial
.
println
(
"Connecting to Wifi..."
);
Serial
.
println
(
"Connecting to Wifi..."
);
cmd
=
"AT+CWJAP=
\"
"
+
SSID
+
"
\"
,"
+
SSPW
+
"
\"
"
;
cmd
=
"AT+CWJAP=
\"
"
+
SSID
+
"
\"
,"
+
SSPW
+
"
\"
"
;
esp
.
println
(
cmd
);
esp
.
println
(
cmd
);
// 연결 확인
while
(
!
esp
.
find
(
"OK"
));
while
(
!
esp
.
find
(
"OK"
));
Serial
.
println
(
"Wifi Connected"
);
Serial
.
println
(
"Wifi Connected"
);
// 연결된 공유기 확인
cmd
=
"AT+CWJAP?"
;
cmd
=
"AT+CWJAP?"
;
esp
.
println
(
cmd
);
esp
.
println
(
cmd
);
Serial
.
write
(
esp
.
read
());
Serial
.
write
(
esp
.
read
());
}
}
void
sendData
(
String
input
){
void
sendData
(
String
input
){
// ESP 모듈을 통해 Server
로 데이터 전송
// ESP 모듈을 통해 Server
와 연결
esp
.
println
(
"AT+CIPSTART=
\"
TCP
\"
,
\"
"
+
EUEIP
+
"
\"
,"
+
EUEPORT
);
esp
.
println
(
"AT+CIPSTART=
\"
TCP
\"
,
\"
"
+
EUEIP
+
"
\"
,"
+
EUEPORT
);
if
(
esp
.
find
(
"Error"
)){
if
(
esp
.
find
(
"Error"
)){
Serial
.
println
(
"AT+CIPSTART Error..."
);
Serial
.
println
(
"AT+CIPSTART Error..."
);
}
}
// 서버로 전송할 데이터 작성
String
vars
=
input
;
String
vars
=
input
;
String
msg
=
"GET /data/input?"
;
String
msg
=
"GET /data/input?"
;
...
@@ -144,13 +171,14 @@ void sendData(String input){
...
@@ -144,13 +171,14 @@ void sendData(String input){
esp
.
println
(
msg
.
length
());
esp
.
println
(
msg
.
length
());
delay
(
2000
);
delay
(
2000
);
// 데이터 전송
if
(
esp
.
find
(
">"
)){
if
(
esp
.
find
(
">"
)){
esp
.
print
(
msg
);
esp
.
print
(
msg
);
Serial
.
println
(
"Data sent."
);
Serial
.
println
(
"Data sent."
);
delay
(
1000
);
delay
(
1000
);
}
}
// 서버와 연결 종료
Serial
.
println
(
"Connection Closed."
);
Serial
.
println
(
"Connection Closed."
);
esp
.
println
(
"AT+CIPCLOSE"
);
esp
.
println
(
"AT+CIPCLOSE"
);
delay
(
5000
);
}
}
arduino/code/main_outside/main_outside.ino
0 → 100644
View file @
f22309e2
#include <SoftwareSerial.h>
#define ESPPIN_TX 2 // ESP 8266 모듈의 TX 핀
#define ESPPIN_RX 3 // ESP 8266 모듈의 RX 핀
SoftwareSerial
esp
(
ESPPIN_TX
,
ESPPIN_RX
);
String
SSID
=
"Wifi_SSID"
;
// Wifi - SSID
String
SSPW
=
"Wifi_SSPW"
;
// Wifi - SSPW
String
EUEIP
=
"EUE_IP"
;
// Web Server - IP
int
EUEPORT
=
8081
;
// Web Server - Port
void
connectESP
();
void
connectWifi
();
void
sendData
(
String
vars
);
void
setup
()
{
Serial
.
begin
(
9600
);
// Serial monitor의 통신 속도 9600으로 설정
esp
.
begin
(
9600
);
// esp모듈의 통신 속도 9600으로 설정
connectESP
();
// ESP 모듈 탐색
connectWifi
();
// ESP 모듈 wifi 연결
}
void
loop
()
{
String
input
=
""
;
// 사용자 ID
String
ID
=
"Admin"
;
// 측정기 분류(IN / OUT)
String
type_
=
"Out"
;
// 지역의 위도(Latitude), 경도(Longitude)
float
lati
=
37.241706
;
String
str_lati
=
String
(
lati
,
6
);
float
lng
=
131.864889
;
String
str_lng
=
String
(
lng
,
6
);
input
+=
"id="
+
ID
;
input
+=
"&type="
+
type_
;
input
+=
"&lat="
+
str_lati
;
input
+=
"&lng="
+
str_lng
;
Serial
.
println
(
input
);
// 데이터 전송
sendData
(
input
);
// 1분마다 전송 진행
delay
(
60000
);
}
// ESP모듈 연결
void
connectESP
(){
esp
.
println
(
"AT"
);
Serial
.
println
(
"AT Sent"
);
while
(
!
esp
.
find
(
"OK"
)){
esp
.
println
(
"AT"
);
Serial
.
println
(
"ESP8266 Not Found."
);
}
Serial
.
println
(
"OK Command Received."
);
}
// 공유기와 연결
void
connectWifi
(){
// ESP8266 모듈 Client로 설정
String
cmd
=
"AT+CWMODE=1"
;
esp
.
println
(
cmd
);
Serial
.
println
(
"Set ESP8266 to client."
);
// 공유기와 연결
Serial
.
println
(
"Connecting to Wifi..."
);
cmd
=
"AT+CWJAP=
\"
"
+
SSID
+
"
\"
,"
+
SSPW
+
"
\"
"
;
esp
.
println
(
cmd
);
// 연결 확인
while
(
!
esp
.
find
(
"OK"
));
Serial
.
println
(
"Wifi Connected"
);
// 연결된 공유기 확인
cmd
=
"AT+CWJAP?"
;
esp
.
println
(
cmd
);
Serial
.
write
(
esp
.
read
());
}
void
sendData
(
String
input
){
// ESP 모듈을 통해 Server로 데이터 전송
esp
.
println
(
"AT+CIPSTART=
\"
TCP
\"
,
\"
"
+
EUEIP
+
"
\"
,"
+
EUEPORT
);
if
(
esp
.
find
(
"Error"
)){
Serial
.
println
(
"AT+CIPSTART Error..."
);
}
// 서버로 전송할 데이터 작성
String
vars
=
input
;
String
msg
=
"GET /data/input?"
;
msg
+=
vars
;
msg
+=
" HTTP/1.0
\r\n\r\n
"
;
esp
.
print
(
"AT+CIPSEND="
);
esp
.
println
(
msg
.
length
());
delay
(
2000
);
// 데이터 전송
if
(
esp
.
find
(
">"
)){
esp
.
print
(
msg
);
Serial
.
println
(
"Data sent."
);
delay
(
1000
);
}
// 서버와 연결 종료
Serial
.
println
(
"Connection Closed."
);
esp
.
println
(
"AT+CIPCLOSE"
);
}
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