You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is free and unencumbered software released into the public domain.
2
+
3
+
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
4
+
5
+
In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
6
+
7
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+
9
+
For more information, please refer to <http://unlicense.org/>
// print the SSID of the network you're attached to:
38
+
Serial.print("SSID: ");
39
+
Serial.println(WiFi.SSID());
40
+
41
+
// print the MAC address of the router you're attached to:
42
+
byte bssid[6];
43
+
WiFi.BSSID(bssid);
44
+
Serial.print("BSSID: ");
45
+
printMacAddress(bssid);
46
+
47
+
// print the received signal strength:
48
+
long rssi = WiFi.RSSI();
49
+
Serial.print("signal strength (RSSI):");
50
+
Serial.println(rssi);
51
+
52
+
// print the encryption type:
53
+
byte encryption = WiFi.encryptionType();
54
+
Serial.print("Encryption Type:");
55
+
Serial.println(encryption, HEX);
56
+
Serial.println();
57
+
}
58
+
59
+
60
+
voidconnectToWiFi() {
61
+
62
+
if (WiFi.status() == WL_NO_MODULE) {
63
+
Serial.println("Communication with WiFi module failed!");
64
+
// block further activity
65
+
while(true);
66
+
}
67
+
68
+
// info about your adapter
69
+
String firmware_version = WiFi.firmwareVersion();
70
+
71
+
Serial.print("WiFi Firmware Version: ");
72
+
Serial.println(firmware_version);
73
+
if ( firmware_version < WIFI_FIRMWARE_LATEST_VERSION) {
74
+
Serial.print("Latest available version: ");
75
+
Serial.println(WIFI_FIRMWARE_LATEST_VERSION);
76
+
Serial.println("Please upgrade your firmware.");
77
+
}
78
+
79
+
80
+
Serial.print("Connecting to ");
81
+
Serial.println(SSID);
82
+
83
+
WiFi.begin(SSID, PWD);
84
+
85
+
while (WiFi.status() != WL_CONNECTED) {
86
+
Serial.print(".");
87
+
delay(500);
88
+
// we can even make the ESP32 to sleep
89
+
}
90
+
91
+
Serial.print("Connected. IP: ");
92
+
Serial.println(WiFi.localIP());
93
+
printCurrentNet();
94
+
}
95
+
96
+
97
+
98
+
voidset_threshold(Request &req, Response &res) {
99
+
char seconds_char[64];
100
+
req.query("seconds", seconds_char, 64);
101
+
102
+
if (strlen(seconds_char) != NULL){
103
+
threshold_pour = atoi(seconds_char);
104
+
res.print("You have reset the threshold! Please make sure that this is safe, as it aims to prevent overflow due to mistyping the query parameter. The threshold is now set to: ");
105
+
res.print(threshold_pour);
106
+
} else {
107
+
res.print("Please specify amount of seconds in query parameter; threshold?seconds=10 e.g..");
108
+
}
109
+
}
110
+
111
+
voidget_threshold(Request &req, Response &res) {
112
+
res.print("The threshold is: ");
113
+
res.print(threshold_pour);
114
+
res.print(" seconds.");
115
+
}
116
+
117
+
voidpour_tea(Request &req, Response &res) {
118
+
char seconds_char[64];
119
+
req.query("seconds", seconds_char, 64);
120
+
int pouring_delay = atoi(seconds_char);
121
+
122
+
if (strlen(seconds_char) != NULL && pouring_delay <= threshold_pour ){
123
+
//release breaks
124
+
digitalWrite(brakePin, LOW);
125
+
126
+
//set work duty for the motor, Duty is the amount of power it is getting from 0 to 256.
127
+
analogWrite(pwmPin, 256);
128
+
129
+
delay(pouring_delay*1000); // convert miliseconds to seconds
130
+
131
+
//activate breaks
132
+
digitalWrite(brakePin, HIGH);
133
+
134
+
//set work duty for the motor to 0 (off)
135
+
analogWrite(pwmPin, 0);
136
+
// Serial.println(req.JSON());
137
+
res.print("Poured Tea in: ");
138
+
res.print(pouring_delay);
139
+
res.print(" seconds!");
140
+
} elseif (pouring_delay > threshold_pour) {
141
+
res.print("Exceeded safety threshold for pouring. Change threshold in firmware or use endpoint /flush and set minutes");
142
+
}
143
+
else {
144
+
res.print("Please specify amount of seconds in query parameter; pour_tea?seconds=10 e.g..");
145
+
}
146
+
}
147
+
148
+
voidflush(Request &req, Response &res) {
149
+
char minutes_char[64];
150
+
req.query("minutes", minutes_char, 64);
151
+
152
+
if (strlen(minutes_char) != NULL){
153
+
//release breaks
154
+
digitalWrite(brakePin, LOW);
155
+
156
+
//set work duty for the motor, Duty is the amount of power it is getting from 0 to 256.
157
+
analogWrite(pwmPin, 256);
158
+
159
+
int pouring_delay = atoi(minutes_char);
160
+
delay(pouring_delay*1000*60); // convert miliseconds to seconds
161
+
162
+
//activate breaks
163
+
digitalWrite(brakePin, HIGH);
164
+
165
+
//set work duty for the motor to 0 (off)
166
+
analogWrite(pwmPin, 0);
167
+
// Serial.println(req.JSON());
168
+
res.print("Poured Tea in: ");
169
+
res.print(pouring_delay);
170
+
res.print(" minutes!");
171
+
} else {
172
+
res.print("Please specify amount of seconds in query parameter; flush?minutes=1 e.g..");
0 commit comments