Skip to content

Commit 27fb013

Browse files
committed
add some features
1 parent 17ec960 commit 27fb013

File tree

4 files changed

+117
-97
lines changed

4 files changed

+117
-97
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ online simulation with [circuito.io](https://www.circuito.io/static/reply/index.
2727

2828
Components Pins | ESP Pins
2929
------------ | ------------
30-
Ultrasonic one Trig pin | P23
31-
Ultrasonic one Echo pin | P22
30+
Ultrasonic one Trig pin | P33
31+
Ultrasonic one Echo pin | P25
3232
Ultrasonic one VCC pin | 5v
3333
Ultrasonic one GND pin | gnd
3434
Ultrasonic two Trig pin | 17
3535
Ultrasonic two Echo pin | 16
3636
Ultrasonic two VCC pin | 5v
3737
Ultrasonic two GND pin | gnd
38-
First servo input pin | 19
38+
First servo input pin | 32
3939
First servo VCC pin | 5v
4040
First servo GND pin | gnd
41-
Second servo input pin | 18
41+
Second servo input pin | 19
4242
Second servo VCC pin | 5v
4343
Second servo GND pin | gnd
4444

code/code.ino

Lines changed: 53 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,49 @@
22
#include <ESP32Servo.h>
33
#include "webpage.h"
44
#include "server.h"
5+
#include <WiFi.h>
6+
#include <WebServer.h>
57

6-
#include <WiFi.h> // standard library
7-
#include <WebServer.h> // standard library
8-
9-
//input output define
10-
8+
//input output pins
119
#define ULTRA_ONE_TRIG_PIN 33 // ESP32 pin GIOP23 connected to Ultrasonic Sensor's TRIG pin
1210
#define ULTRA_ONE_ECHO_PIN 25 // ESP32 pin GIOP22 connected to Ultrasonic Sensor's ECHO pin
1311
#define ULTRA_TWO_TRIG_PIN 17
1412
#define ULTRA_TWO_ECHO_PIN 16
1513
#define PIN_LED 2 //On board LED
16-
#define PIN_OUTPUT 26 // connected to nothing but an example of a digital write from the web page
14+
#define PIN_OUTPUT 26
1715
#define ENTRY_SERVO_PIN 32
1816
#define EXIT_SERVO_PIN 19
1917

18+
//wifi variables
2019
#define USE_INTRANET
2120
#define AP_SSID "Parking-System"
2221
#define AP_PASS "pass12345"
22+
// variable for the IP reported when you connect to your homes intranet (during debug mode)
23+
IPAddress Actual_IP;
24+
// definitions of your desired intranet created by the ESP32
25+
IPAddress PageIP(192, 168, 1, 1);
26+
IPAddress gateway(192, 168, 1, 1);
27+
IPAddress subnet(255, 255, 255, 0);
28+
IPAddress ip;
2329

2430

25-
int servoPosi = 0;
2631

2732

28-
bool LED0 = false, SomeOutput = false;
33+
bool status_led = true, system_status = true;
2934
int entry_gate_distance = 0;
3035
int exit_gate_distance = 0;
31-
3236
uint32_t SensorUpdate = 0;
33-
3437
int cars_num = 0;
3538

36-
39+
//servos variables
3740
Servo entry_gate_servo; // create servo object to control a servo
3841
Servo exit_gate_servo; // create servo object to control a servo
3942
bool entry_open = false;
4043
bool exit_open = false;
41-
42-
4344
int entry_servo_pos = 0;
4445
int exit_servo_pos = 0;
4546

47+
// time variables
4648
int moveTime = 10;
4749
unsigned long int entry_open_time = 0;
4850
unsigned long int entry_moving_time = 0;
@@ -52,22 +54,13 @@ unsigned long int exit_moving_time = 0;
5254

5355
// the XML array size needs to be bigger that your maximum expected size. 2048 is way too big for this example
5456
char XML[2048];
55-
5657
// just some buffer holder for char operations
5758
char buf[32];
5859

59-
// variable for the IP reported when you connect to your homes intranet (during debug mode)
60-
IPAddress Actual_IP;
61-
62-
// definitions of your desired intranet created by the ESP32
63-
IPAddress PageIP(192, 168, 1, 1);
64-
IPAddress gateway(192, 168, 1, 1);
65-
IPAddress subnet(255, 255, 255, 0);
66-
IPAddress ip;
6760

6861

6962

70-
// gotta create a server
63+
// create a server
7164
WebServer server(80);
7265

7366
void setup() {
@@ -87,8 +80,8 @@ void setup() {
8780
pinMode(PIN_LED, OUTPUT);
8881

8982
// turn off led
90-
LED0 = false;
91-
digitalWrite(PIN_LED, LED0);
83+
// status_led = false;
84+
digitalWrite(PIN_LED, status_led);
9285

9386
// configure the trigger pin to output mode
9487
pinMode(ULTRA_ONE_TRIG_PIN, OUTPUT);
@@ -102,9 +95,8 @@ void setup() {
10295
disableCore0WDT();
10396

10497

105-
// just an update to progress
98+
// setup the server
10699
Serial.println("starting server");
107-
// // if you have this #define USE_INTRANET, you will connect to your home intranet, again makes debugging easier
108100
WiFi.softAP(AP_SSID, AP_PASS);
109101
delay(100);
110102
WiFi.softAPConfig(PageIP, gateway, subnet);
@@ -115,16 +107,14 @@ void setup() {
115107
printWifiStatus();
116108

117109

118-
// these calls will handle data coming back from your web page
119-
// this one is a page request, upon ESP getting / string the web page will be sent
110+
//handle server requests
120111
server.on("/", SendWebsite);
121112
server.on("/xml", SendXML);
122113

123114
// upon ESP getting /UPDATE_SLIDER string, ESP will execute the UpdateSlider function
124115
// same notion for the following .on calls
125116
// add as many as you need to process incoming strings from your web page
126117
// as you can imagine you will need to code some javascript in your web page to send such strings
127-
// this process will be documented in the SuperMon.h web page code
128118
server.on("/UPDATE_SLIDER", UpdateSlider);
129119
server.on("/BUTTON_0", ProcessButton_0);
130120
server.on("/BUTTON_1", ProcessButton_1);
@@ -133,10 +123,10 @@ void setup() {
133123
}
134124

135125
void loop() {
136-
// in my example here every 50 ms, i measure some analog sensor data (my finger dragging over the pins
137-
// and process accordingly
138-
// analog input can be from temperature sensors, light sensors, digital pin sensors, etc.
139126

127+
if(system_status)
128+
{
129+
140130
//Serial.println("Reading Sensors");
141131
SensorUpdate = millis();
142132
exit_gate_distance = get_distance(ULTRA_TWO_TRIG_PIN, ULTRA_TWO_ECHO_PIN);
@@ -158,8 +148,7 @@ void loop() {
158148

159149
Serial.print("Cars Number: ");
160150
Serial.println(cars_num);
161-
Serial.print("Cars Number: ");
162-
Serial.println(exit_gate_distance);
151+
163152

164153

165154
//Entry Gate Moving control
@@ -206,7 +195,7 @@ void loop() {
206195
exit_moving_time = millis();
207196
}
208197
}
209-
198+
}
210199
server.handleClient();
211200
}
212201

@@ -227,7 +216,7 @@ void UpdateSlider() {
227216

228217
// now send it back
229218
strcpy(buf, "");
230-
sprintf(buf, "%d", servoPosi);
219+
sprintf(buf, "%d", 20);
231220
sprintf(buf, buf);
232221
server.send(200, "text/plain", buf); //Send web page
233222

@@ -237,37 +226,30 @@ void UpdateSlider() {
237226
// now process button_0 press from the web site. Typical applications are the used on the web client can
238227
// turn on / off a light, a fan, disable something etc
239228
void ProcessButton_0() {
240-
LED0 = !LED0;
241-
digitalWrite(PIN_LED, LED0);
242-
Serial.print("Button 0 "); Serial.println(LED0);
229+
system_status=!system_status;
230+
status_led = !status_led;
231+
digitalWrite(PIN_LED, status_led);
232+
Serial.print("Button 0 "); Serial.println(status_led);
243233
server.send(200, "text/plain", ""); //Send web page
244234

245235
}
246236
// same notion for processing button_1
247237
void ProcessButton_1() {
248238
// just a simple way to toggle a LED on/off. Much better ways to do this
249239
Serial.println("Button 1 press");
250-
SomeOutput = !SomeOutput;
251240

252-
// digitalWrite(PIN_OUTPUT, SomeOutput);
253-
Serial.print("Button 1 "); Serial.println(LED0);
241+
// server.send(200, "text/plain", ""); //Send web page
254242

255-
// regardless if you want to send stuff back to client or not
256-
// you must have the send line--as it keeps the page running
257-
// if you don't want feedback from the MCU--or send all data via XML use this method
258-
// sending feeback
259-
server.send(200, "text/plain", ""); //Send web page
260-
261-
// if you want to send feed back immediataly
262-
// note you must have proper code in the java script to read this data stream
263-
/*
264-
if (some_process) {
265-
server.send(200, "text/plain", "SUCCESS"); //Send web page
243+
if (!entry_open&&!exit_open) {
244+
cars_num=0;
245+
Serial.println("Cars number reset.");
246+
server.send(200, "text/plain", "true"); //Send web page
247+
266248
}
267-
else {
268-
server.send(200, "text/plain", "FAIL"); //Send web page
249+
else{
250+
server.send(200, "text/plain", "false"); //Send web page
269251
}
270-
*/
252+
271253
}
272254

273255

@@ -290,34 +272,33 @@ void SendXML() {
290272
// send distance_cm
291273
sprintf(buf, "<B0>%d</B0>\n", cars_num);
292274
strcat(XML, buf);
293-
// send Volts0
294-
// sprintf(buf, "<V0>%d</V0>\n", cars_num);
295-
// strcat(XML, buf);
296-
// send bits1
275+
297276
sprintf(buf, "<B1>%d</B1>\n", entry_gate_distance);
298277
strcat(XML, buf);
299-
// // send Volts1
300-
// sprintf(buf, "<V1>%d</V1>\n", entry_gate_distance);
301-
// strcat(XML, buf);
278+
279+
280+
sprintf(buf, "<B2>%d</B2>\n", exit_gate_distance);
281+
strcat(XML, buf);
282+
302283
// show led0 status
303-
if (LED0) {
284+
if (status_led) {
304285
strcat(XML, "<LED>1</LED>\n");
305286
}
306287
else {
307288
strcat(XML, "<LED>0</LED>\n");
308289
}
309-
if (SomeOutput) {
310-
strcat(XML, "<SWITCH>1</SWITCH>\n");
311-
}
312-
else {
313-
strcat(XML, "<SWITCH>0</SWITCH>\n");
314-
}
290+
// if (!entry_open&&!exit_open) {
291+
// strcat(XML, "<SWITCH>true</SWITCH>\n");
292+
// }
293+
// else {
294+
// strcat(XML, "<SWITCH>false</SWITCH>\n");
295+
// }
315296

316297
strcat(XML, "</Data>\n");
317298
// wanna see what the XML code looks like?
318299
// actually print it to the serial monitor and use some text editor to get the size
319300
// then pad and adjust char XML[2048]; above
320-
Serial.println(XML);
301+
// Serial.println(XML);
321302

322303
// you may have to play with this value, big pages need more porcessing time, and hence
323304
// a longer timeout that 200 ms

0 commit comments

Comments
 (0)