-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.ino
106 lines (66 loc) ยท 2.37 KB
/
test.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Arduino_JSON - Version: Latest
#include <SoftwareSerial.h>
#include <Arduino_JSON.h>
#include <Servo.h>
#include <WiFi.h>
const char* ssid = "wifiAddress";
const char* password = "password";
#define motorPinNum = 8; // ์๋ณด๋ชจํฐ ํ ๋ฒํธ ์ง์
Servo motor;
void setup() {
Serial.begin(115200);
motor.attach(motorPinNum); // ์๋ณด๋ชจํฐ ํ ๋ฒํธ ์ค์
delay(100);
motor.write(0); // ์๋ณด๋ชจํฐ 0๋ ์์น๋ก ์ด๊ธฐํ
delay(100);
// motor.detach();
delay(4000);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi ........");
}
Serial.println("Connected to the WiFi ");
}
void loop() {
if ((WiFi.status() == WL_CONNECTED)) { // ์์ดํ์ด ์ฐ๊ฒฐ ํ์ธ
HTTPClient http; // http ํต์ ์ ์ํ ํด๋ผ์ด์ธํธ
// QR ์ฝ๋ ์ค์บ
// QR ์ฝ๋ ์ค์บ ๋ฐ์ดํฐ ์ ์ก
http.begin("http://localhost:8080/api/orders/varify"); // ์๋ฒ ์์ฒญ URL
http.addHeader("Content-Type", "Application/Json"); // RequestBody ๋ฐ์ดํฐ ํ์ ์ง์
int httpCode = http.POST(); // http Method ์ง์
if (httCode > 0) { // ์๋ต ์ฝ๋๊ฐ ์๋ค๋ฉด
String response = http.getString(); // ResponseBody ์ ์ฅ
StaticJsonBuffer<500> JSonBuffer; // JSON์ผ๋ก ํ์ฑํ๊ธฐ ์ํ ์ ์ฅ ๊ณต๊ฐ
JsonObject& root = JSONBuffer.parseObject(response); // JSON์ผ๋ก ํ์ฑํด์ entity์ ์ ์ฅ
String result = root["data"];
if (result == "OPEN") {
// ์ ๊ธฐ์ ํธ๋ก ๋ชจํฐ ๋์ํ๊ธฐ
Serial.println("Success authorization ...... ");
motor.write(180); // ๋ฌธ ์ด๊ธฐ
delay(3000); // ๋ฌธ ์ฌ๋ ๋์ ์๊ฐ ์ง์ฐ
motor.write(0); // ๋ฌธ ๋ซ๊ธฐ
} else {
//
Serial.println("Reject user ........ ");
}
/*
{
"postId": 1,
"id": 1,
"name": "id labore ex et quam laborum",
"email": "Eliseo@gardner.biz",
"body": "laudantium enim quasi est quidem magnam voluptate ipsam eos\ntempora quo necessitatibus\ndolor quam autem quasi\nreiciendis et nam sapiente accusantium"
},
*/
} else {
Serial.println("Error on HTTP Request.......");
Serial.println("httpCode : " + httpCode);
}
http.end();
} else {
Serial.println("Error in WiFi connection ...... ");
}
delay(10000);
}