#define NAVETTE_UUID "DEADDEAD-F88F-0042-F88F-010203040506" // same UUID for all vehicles
#define FORCEGATEOPEN 0b01 // minor high bits = 0b01 => force gate to open
#define CLEARGATECALIBRATION 0b11 // minor high bits = 0b11 => clear gate calibration
#define STATE_SCAN 1 // STATE_SCAN : scanning iBeacon tram with UUID = NAVETTE_UUID. Opening door when the RSSI is high enough. Go to STATE_OPEN_GATE after opening the door.
#define STATE_OPEN_GATE 2 // STATE_OPEN_GATE : door is open. Keep the door open while receiving tram. Go to STATE_SCAN when not receiving tram after GO_TO_SCAN_STATE_DELAY
#define SCAN_TIME 2 // scan period in second
#define GO_TO_SCAN_STATE_DELAY 4 // if no trame was received during X sec, go to STATE_SCAN
#define DELAY_REJECT_TRAM 3 // if the last tram was received more than X seconds ago, the average RSSI is not computed and returns an average RSSI of -100
#define PULSE_DURATION 500 // pulse to open gate. duration in ms
#define DELAY_BETWEEN_PULSE 4 // to keep the gate open emit a pulse every X seconds
#define RSSI_THRESHOLD_OPEN_GATE -95 // if the average RSSI is above this threshold the gate can be open
// ***** definitions *****
intSTATE;// state of the system : can be either STATE_SCAN or STATE_OPEN_GATE
time_tt;// time is seconds
structRSSI{// table contening the RSSI and time of the last 2 trams. Used to compute the average RSSI.
intval=-100;
time_ttime=0;
}tabRSSI[2];
time_ttPulseGate=0;
// ***** open gate *****
voidopenGate(){
Serial.println(" OPENING GATE");//DEBUG
digitalWrite(RELAY1,HIGH);//activate relay1 for 0.5 sec
#define NAVETTE_UUID "DEADDEAD-F88F-0042-F88F-010203040506" // same UUID for all vehicles
#define FORCEGATEOPEN 0b01 // minor high bits = 0b01 => force gate to open
#define CLEARGATECALIBRATION 0b11 // minor high bits = 0b11 => clear gate calibration
#define STATE_SCAN 1 // STATE_SCAN : scanning iBeacon tram with UUID = NAVETTE_UUID. Opening door when the RSSI is high enough. Go to STATE_OPEN_GATE after opening the door.
#define STATE_OPEN_GATE 2 // STATE_OPEN_GATE : door is open. Keep the door open while receiving tram. Go to STATE_SCAN when not receiving tram after GO_TO_SCAN_STATE_DELAY
#define SCAN_TIME 2 // scan period in second
#define GO_TO_SCAN_STATE_DELAY 3 // if no trame was received during X sec, go to STATE_SCAN
#define DELAY_REJECT_TRAM 3 // if the last tram was received more than X seconds ago, the average RSSI is not computed and returns an average RSSI of -100
#define PULSE_DURATION 500 // pulse to open gate. duration in ms
#define DELAY_BETWEEN_PULSE 5 // to keep the gate open emit a pulse every X seconds
#define RSSI_THRESHOLD_OPEN_GATE -95 // if the average RSSI is above this threshold the gate can be open
#define SERIAL_BAUDRATE 115200
// ***** definitions *****
intSTATE;// state of the system : can be either STATE_SCAN or STATE_OPEN_GATE
time_tt;// time is seconds
structRSSI{// table contening the RSSI and time of the last 2 trams. Used to compute the average RSSI.
intval=-100;
time_ttime=0;
}tabRSSI[2];
time_ttPulseGate=0;
// ***** set up WiFi *****
voidsetUpWifi(){
WiFi.mode(WIFI_AP);
WiFi.softAP("gate01");
}
// ***** set up On The Air software upload *****
voidsetupOTA(){
// Port defaults to 3232
ArduinoOTA.setPort(3232);
// Hostname
ArduinoOTA.setHostname("gate01");
// Authentication
ArduinoOTA.setPassword("neOCampus");
ArduinoOTA.onStart([](){
Stringtype;
if(ArduinoOTA.getCommand()==U_FLASH)
type="sketch";
else// U_SPIFFS
type="filesystem";
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()