Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

color and sequence configurable in web interface, port number for mqtt server #26

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions data/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,73 @@
</div>
</div>

<div class="form-group">
<label for="touchRingActiveColor" class="col-md-4 control-label">Touch Ring Active: LED Color</label>
<div class="col-md-4">
<select id="touchRingActiveColor" name="touchRingActiveColor" class="select form-control">
<option value="1" %TOUCH_RING_ACTIVE_COLOR_1%>Red</option>
<option value="2" %TOUCH_RING_ACTIVE_COLOR_2%>Blue</option>
<option value="3" %TOUCH_RING_ACTIVE_COLOR_3%>Purple</option>
<option value="4" %TOUCH_RING_ACTIVE_COLOR_4%>Green</option>
<option value="5" %TOUCH_RING_ACTIVE_COLOR_5%>Yellow</option>
<option value="6" %TOUCH_RING_ACTIVE_COLOR_6%>Cyan</option>
<option value="7" %TOUCH_RING_ACTIVE_COLOR_7%>White</option>
</select>
<small class="text-muted">Not all versions of the R503 sensor supports all colors. Older ones only red, blue and purple!</small>
</div>
</div>
<div class="form-group">
<label for="touchRingActiveSequence" class="col-md-4 control-label">Touch Ring Active: LED Sequence</label>
<div class="col-md-4">
<label class="radio-inline">
<input type="radio" name="touchRingActiveSequence" value="4" %TOUCH_RING_ACTIVE_SEQUENCE_4%>
Off
</label>
<label class="radio-inline">
<input type="radio" name="touchRingActiveSequence" value="3" %TOUCH_RING_ACTIVE_SEQUENCE_3%>
On
</label>
<label class="radio-inline">
<input type="radio" name="touchRingActiveSequence" value="1" %TOUCH_RING_ACTIVE_SEQUENCE_1%>
Breath
</label>
<label class="radio-inline">
<input type="radio" name="touchRingActiveSequence" value="2" %TOUCH_RING_ACTIVE_SEQUENCE_2%>
Blink
</label>
</div>
</div>
<div class="form-group">
<label for="scanColor" class="col-md-4 control-label">Scan fingerprint: LED Color</label>
<div class="col-md-4">
<select id="scanColor" name="scanColor" class="select form-control">
<option value="1" %SCAN_COLOR_1%>Red</option>
<option value="2" %SCAN_COLOR_2%>Blue</option>
<option value="3" %SCAN_COLOR_3%>Purple</option>
<option value="4" %SCAN_COLOR_4%>Green</option>
<option value="5" %SCAN_COLOR_5%>Yellow</option>
<option value="6" %SCAN_COLOR_6%>Cyan</option>
<option value="7" %SCAN_COLOR_7%>White</option>
</select>
<small class="text-muted">Not all versions of the R503 sensor supports all colors. Older ones only red, blue and purple!</small>
</div>
</div>
<div class="form-group">
<label for="matchColor" class="col-md-4 control-label">Matching fingerprint: LED Color</label>
<div class="col-md-4">
<select id="matchColor" name="matchColor" class="select form-control">
<option value="1" %MATCH_COLOR_1%>Red</option>
<option value="2" %MATCH_COLOR_2%>Blue</option>
<option value="3" %MATCH_COLOR_3%>Purple</option>
<option value="4" %MATCH_COLOR_4%>Green</option>
<option value="5" %MATCH_COLOR_5%>Yellow</option>
<option value="6" %MATCH_COLOR_6%>Cyan</option>
<option value="7" %MATCH_COLOR_7%>White</option>
</select>
<small class="text-muted">Not all versions of the R503 sensor supports all colors. Older ones only red, blue and purple!</small>
</div>
</div>

<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="btnSaveSettings"></label>
Expand Down
12 changes: 9 additions & 3 deletions src/FingerprintManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void FingerprintManager::updateTouchState(bool touched)
// check if sensor or ring is touched
if (touched) {
// turn touch indicator on:
finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_RED, 0);
finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, scanColor, 0);
} else {
// turn touch indicator off:
setLedRingReady();
Expand Down Expand Up @@ -189,7 +189,7 @@ Match FingerprintManager::scanFingerprint() {
match.returnCode = finger.fingerSearch();
if (match.returnCode == FINGERPRINT_OK) {
// found a match!
finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_PURPLE);
finger.LEDcontrol(FINGERPRINT_LED_ON, 0, matchColor);

match.scanResult = ScanResult::matchFound;
match.matchId = finger.fingerID;
Expand Down Expand Up @@ -457,7 +457,7 @@ void FingerprintManager::setLedRingWifiConfig() {

void FingerprintManager::setLedRingReady() {
if (!ignoreTouchRing)
finger.LEDcontrol(FINGERPRINT_LED_BREATHING, 250, FINGERPRINT_LED_BLUE);
finger.LEDcontrol(touchRingActiveSequence, 250, touchRingActiveColor);
else
finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_BLUE); // just an indicator for me to see if touch ring is active or not
}
Expand Down Expand Up @@ -558,3 +558,9 @@ void FingerprintManager::importSensorDB() {

}

void FingerprintManager::configTouchRingActive(uint8_t color, uint8_t sequence, uint8_t scanColor, uint8_t matchColor ) {
this->touchRingActiveColor = color;
this->touchRingActiveSequence = sequence;
this->scanColor = scanColor;
this->matchColor = matchColor;
}
5 changes: 5 additions & 0 deletions src/FingerprintManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class FingerprintManager {
uint8_t writeNotepad(uint8_t pageNumber, const char *text, uint8_t length);
uint8_t readNotepad(uint8_t pageNumber, char *text, uint8_t length);

uint8_t touchRingActiveColor = 2;
uint8_t touchRingActiveSequence = 1;
uint8_t scanColor = 1;
uint8_t matchColor = 2;


public:
Expand All @@ -67,6 +71,7 @@ class FingerprintManager {
String getPairingCode();
bool setPairingCode(String pairingCode);

void configTouchRingActive(uint8_t color, uint8_t sequence, uint8_t scanColor, uint8_t matchColor);
bool deleteAll();


Expand Down
8 changes: 8 additions & 0 deletions src/SettingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ bool SettingsManager::loadAppSettings() {
appSettings.sensorPin = preferences.getString("sensorPin", "00000000");
appSettings.sensorPairingCode = preferences.getString("pairingCode", "");
appSettings.sensorPairingValid = preferences.getBool("pairingValid", false);
appSettings.touchRingActiveColor = preferences.getShort("ringActCol", 2);
appSettings.touchRingActiveSequence = preferences.getShort("ringActSeq", 1);
appSettings.scanColor = preferences.getShort("scanColor", 1);
appSettings.matchColor = preferences.getShort("matchColor", 3);
preferences.end();
return true;
} else {
Expand Down Expand Up @@ -52,6 +56,10 @@ void SettingsManager::saveAppSettings() {
preferences.putString("sensorPin", appSettings.sensorPin);
preferences.putString("pairingCode", appSettings.sensorPairingCode);
preferences.putBool("pairingValid", appSettings.sensorPairingValid);
preferences.putShort("ringActCol", appSettings.touchRingActiveColor);
preferences.putShort("ringActSeq", appSettings.touchRingActiveSequence);
preferences.putShort("scanColor", appSettings.scanColor);
preferences.putShort("matchColor", appSettings.matchColor);
preferences.end();
}

Expand Down
4 changes: 4 additions & 0 deletions src/SettingsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ struct AppSettings {
String ntpServer = "pool.ntp.org";
String sensorPin = "00000000";
String sensorPairingCode = "";
int8_t touchRingActiveColor = 2;
int8_t touchRingActiveSequence = 1;
int8_t scanColor = 1;
int8_t matchColor = 3;
bool sensorPairingValid = false;
};

Expand Down
84 changes: 79 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const char* WifiConfigSsid = "FingerprintDoorbell-Config"; // SSID used for WiFi
const char* WifiConfigPassword = "12345678"; // password used for WiFi when in Access Point mode for configuration. Min. 8 chars needed!
IPAddress WifiConfigIp(192, 168, 4, 1); // IP of access point in wifi config mode

const char* Selected = "selected"; // password used for WiFi when in Access Point mode for configuration. Min. 8 chars needed!
const char* Checked = "checked"; // password used for WiFi when in Access Point mode for configuration. Min. 8 chars needed!

const long gmtOffset_sec = 0; // UTC Time
const int daylightOffset_sec = 0; // UTC Time
const int doorbellOutputPin = 19; // pin connected to the doorbell (when using hardware connection instead of mqtt to ring the bell)
Expand Down Expand Up @@ -137,6 +140,56 @@ String processor(const String& var){
return settingsManager.getAppSettings().mqttRootTopic;
} else if (var == "NTP_SERVER") {
return settingsManager.getAppSettings().ntpServer;
} else if (var == "TOUCH_RING_ACTIVE_COLOR_1") {
return (settingsManager.getAppSettings().touchRingActiveColor == 1) ? Selected : "";
} else if (var == "TOUCH_RING_ACTIVE_COLOR_2") {
return (settingsManager.getAppSettings().touchRingActiveColor == 2) ? Selected : "";
} else if (var == "TOUCH_RING_ACTIVE_COLOR_3") {
return (settingsManager.getAppSettings().touchRingActiveColor == 3) ? Selected : "";
} else if (var == "TOUCH_RING_ACTIVE_COLOR_4") {
return (settingsManager.getAppSettings().touchRingActiveColor == 4) ? Selected : "";
} else if (var == "TOUCH_RING_ACTIVE_COLOR_5") {
return (settingsManager.getAppSettings().touchRingActiveColor == 5) ? Selected : "";
} else if (var == "TOUCH_RING_ACTIVE_COLOR_6") {
return (settingsManager.getAppSettings().touchRingActiveColor == 6) ? Selected : "";
} else if (var == "TOUCH_RING_ACTIVE_COLOR_7") {
return (settingsManager.getAppSettings().touchRingActiveColor == 7) ? Selected : "";
} else if (var == "TOUCH_RING_ACTIVE_SEQUENCE_4") {
return (settingsManager.getAppSettings().touchRingActiveSequence == 4) ? Checked : "";
} else if (var == "TOUCH_RING_ACTIVE_SEQUENCE_3") {
return (settingsManager.getAppSettings().touchRingActiveSequence == 3) ? Checked : "";
} else if (var == "TOUCH_RING_ACTIVE_SEQUENCE_1") {
return (settingsManager.getAppSettings().touchRingActiveSequence == 1) ? Checked : "";
} else if (var == "TOUCH_RING_ACTIVE_SEQUENCE_2") {
return (settingsManager.getAppSettings().touchRingActiveSequence == 2) ? Checked : "";
} else if (var == "SCAN_COLOR_1") {
return (settingsManager.getAppSettings().scanColor == 1) ? Selected : "";
} else if (var == "SCAN_COLOR_2") {
return (settingsManager.getAppSettings().scanColor == 2) ? Selected : "";
} else if (var == "SCAN_COLOR_3") {
return (settingsManager.getAppSettings().scanColor == 3) ? Selected : "";
} else if (var == "SCAN_COLOR_4") {
return (settingsManager.getAppSettings().scanColor == 4) ? Selected : "";
} else if (var == "SCAN_COLOR_5") {
return (settingsManager.getAppSettings().scanColor == 5) ? Selected : "";
} else if (var == "SCAN_COLOR_6") {
return (settingsManager.getAppSettings().scanColor == 6) ? Selected : "";
} else if (var == "SCAN_COLOR_7") {
return (settingsManager.getAppSettings().scanColor == 7) ? Selected : "";
} else if (var == "MATCH_COLOR_1") {
return (settingsManager.getAppSettings().matchColor == 1) ? Selected : "";
} else if (var == "MATCH_COLOR_2") {
return (settingsManager.getAppSettings().matchColor == 2) ? Selected : "";
} else if (var == "MATCH_COLOR_3") {
return (settingsManager.getAppSettings().matchColor == 3) ? Selected : "";
} else if (var == "MATCH_COLOR_4") {
return (settingsManager.getAppSettings().matchColor == 4) ? Selected : "";
} else if (var == "MATCH_COLOR_5") {
return (settingsManager.getAppSettings().matchColor == 5) ? Selected : "";
} else if (var == "MATCH_COLOR_6") {
return (settingsManager.getAppSettings().matchColor == 6) ? Selected : "";
} else if (var == "MATCH_COLOR_7") {
return (settingsManager.getAppSettings().matchColor == 7) ? Selected : "";
}

return String();
Expand Down Expand Up @@ -357,6 +410,10 @@ void startWebserver(){
settings.mqttPassword = request->arg("mqtt_password");
settings.mqttRootTopic = request->arg("mqtt_rootTopic");
settings.ntpServer = request->arg("ntpServer");
settings.touchRingActiveColor = request->arg("touchRingActiveColor").toInt();
settings.touchRingActiveSequence = request->arg("touchRingActiveSequence").toInt();
settings.scanColor = request->arg("scanColor").toInt();
settings.matchColor = request->arg("matchColor").toInt();
settingsManager.saveAppSettings(settings);
request->redirect("/");
shouldReboot = true;
Expand Down Expand Up @@ -446,7 +503,6 @@ void startWebserver(){

}


void mqttCallback(char* topic, byte* message, unsigned int length) {
Serial.print("Message arrived on topic: ");
Serial.print(topic);
Expand Down Expand Up @@ -614,6 +670,17 @@ void reboot()
ESP.restart();
}

void splitIpAndPort(String mqttServerConfigString, const char* &mqttHostname, u16_t &mqttPort) {
s8_t positionOfColon = mqttServerConfigString.indexOf(":");

if (positionOfColon >= 0) {
mqttHostname = mqttServerConfigString.substring(0 , positionOfColon).c_str();
mqttPort = mqttServerConfigString.substring(positionOfColon + 1).toInt();
} else {
mqttHostname = mqttServerConfigString.c_str();
mqttPort = 1883;
}
}

void setup()
{
Expand Down Expand Up @@ -658,12 +725,17 @@ void setup()
notifyClients("Error: No MQTT Broker is configured! Please go to settings and enter your server URL + user credentials.");
} else {
delay(5000);

const char* mqttHostname;
u16_t mqttPort;
splitIpAndPort(settingsManager.getAppSettings().mqttServer , mqttHostname, mqttPort);

IPAddress mqttServerIp;
if (WiFi.hostByName(settingsManager.getAppSettings().mqttServer.c_str(), mqttServerIp))
if (WiFi.hostByName(mqttHostname, mqttServerIp))
{
mqttConfigValid = true;
Serial.println("IP used for MQTT server: " + mqttServerIp.toString());
mqttClient.setServer(mqttServerIp , 1883);
Serial.println("IP used for MQTT server: " + mqttServerIp.toString() + ":" + mqttPort) ;
mqttClient.setServer(mqttServerIp , mqttPort);
mqttClient.setCallback(mqttCallback);
connectMqttClient();
}
Expand All @@ -672,8 +744,10 @@ void setup()
notifyClients("MQTT Server '" + settingsManager.getAppSettings().mqttServer + "' not found. Please check your settings.");
}
}
if (fingerManager.connected)
if (fingerManager.connected) {
fingerManager.configTouchRingActive(settingsManager.getAppSettings().touchRingActiveColor,settingsManager.getAppSettings().touchRingActiveSequence,settingsManager.getAppSettings().scanColor,settingsManager.getAppSettings().matchColor);
fingerManager.setLedRingReady();
}
else
fingerManager.setLedRingError();
} else {
Expand Down