added Wifi-Settings to WebUI and Config
This commit is contained in:
parent
26ec46eb0e
commit
b723a80d46
@ -13,7 +13,7 @@
|
||||
#include "struct2json.h"
|
||||
|
||||
{% for var_name, var_info in structs.items() -%}
|
||||
void generateJsonObject_{{ var_name }}(JsonObject& data)
|
||||
void generateJsonObject_{{ var_name }}(JsonObject data)
|
||||
{
|
||||
{% for field_name, field_type in var_info['fields'].items() -%}
|
||||
data["{{ field_name }}"] = {{ var_name }}.{{ field_name }};
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include "config.h"
|
||||
|
||||
{% for var_name, var_info in structs.items() -%}
|
||||
void generateJsonObject_{{ var_name }}(JsonObject& data);
|
||||
void generateJsonObject_{{ var_name }}(JsonObject data);
|
||||
{% endfor %}
|
||||
|
||||
#endif /* _STRUCT2JSON_H_ */
|
||||
|
@ -318,11 +318,6 @@
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="col text-center">
|
||||
<button id="gpssave" class="btn-wsevent btn btn-outline-primary">Speichern</button>
|
||||
</div>
|
||||
</div>
|
||||
</p>
|
||||
</div>
|
||||
<!-- Div Group Source:GPS Settings-->
|
||||
@ -430,7 +425,42 @@
|
||||
</div>
|
||||
</div>
|
||||
</p>
|
||||
<!-- Div Group Lube Settings-->
|
||||
<!-- Div Group LED Settings-->
|
||||
<!-- Div Group WiFi Settings-->
|
||||
<hr />
|
||||
<p>
|
||||
<h4>WiFi Einstellungen</h4>
|
||||
<div class="form-group row">
|
||||
<label for="wifi-ssid" class="control-label col-4">WiFi SSID</label>
|
||||
<div class="col-8">
|
||||
<select id="wifi-ssid" class="set-wsevent data-wifi-ssid select form-control">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="wifi-pass" class="control-label col-4">WiFi Passwort</label>
|
||||
<div class="col-8">
|
||||
<div class="input-group" id="show_hide_password">
|
||||
<input id="wifi-pass" type="password" minlength="8" maxlength="63" class="set-wsevent data-pulserev form-control">
|
||||
<div class="input-group-addon">
|
||||
<a href=""><i class="fa fa-eye-slash" aria-hidden="true"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="wifi-conavailable" class="control-label col-4">automatisch verbinden</label>
|
||||
<div class="col-8">
|
||||
<div class="form-check">
|
||||
<input class="set-wsevent data-wifi-conavailable form-check-input" type="checkbox" id="wifi-conavailable">
|
||||
<label class="form-check-label" for="wifi-conavailable">
|
||||
LED blinken
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</p>
|
||||
<!-- Div Group WiFi Settings-->
|
||||
<!-- Div Group Save Button-->
|
||||
<hr />
|
||||
<p>
|
||||
|
@ -1,6 +1,19 @@
|
||||
$(document).ready(function(){
|
||||
$('.navbar-nav a').on('click', function(){
|
||||
$('.navbar-collapse').collapse('hide');
|
||||
$(document).ready(function () {
|
||||
$(".navbar-nav a").on("click", function () {
|
||||
$(".navbar-collapse").collapse("hide");
|
||||
});
|
||||
|
||||
$("#show_hide_password a").on("click", function (event) {
|
||||
event.preventDefault();
|
||||
if ($("#show_hide_password input").attr("type") == "text") {
|
||||
$("#show_hide_password input").attr("type", "password");
|
||||
$("#show_hide_password i").addClass("fa-eye-slash");
|
||||
$("#show_hide_password i").removeClass("fa-eye");
|
||||
} else if ($("#show_hide_password input").attr("type") == "password") {
|
||||
$("#show_hide_password input").attr("type", "text");
|
||||
$("#show_hide_password i").removeClass("fa-eye-slash");
|
||||
$("#show_hide_password i").addClass("fa-eye");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -11,6 +24,3 @@ document
|
||||
var nextSibling = e.target.nextElementSibling;
|
||||
nextSibling.innerText = fileName;
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
@ -79,6 +79,7 @@ typedef struct
|
||||
char wifi_ap_password[64];
|
||||
char wifi_client_ssid[33];
|
||||
char wifi_client_password[64];
|
||||
bool wifi_autoconnect;
|
||||
uint32_t checksum;
|
||||
} LubeConfig_t;
|
||||
|
||||
@ -94,6 +95,7 @@ const LubeConfig_t LubeConfig_defaults = {
|
||||
QUOTE(WIFI_AP_PASSWORD),
|
||||
QUOTE(WIFI_SSID_CLIENT),
|
||||
QUOTE(WIFI_PASSWORD_CLIENT),
|
||||
true,
|
||||
0};
|
||||
|
||||
void InitEEPROM();
|
||||
@ -108,6 +110,7 @@ uint32_t Checksum_EEPROM(uint8_t const *data, size_t len);
|
||||
void dumpEEPROM(uint16_t memoryAddress, uint16_t length);
|
||||
void MovePersistencePage_EEPROM(boolean reset);
|
||||
uint32_t ConfigSanityCheck(bool autocorrect = false);
|
||||
bool validateWiFiString(char *string, size_t size);
|
||||
|
||||
extern LubeConfig_t LubeConfig;
|
||||
extern persistenceData_t PersistenceData;
|
||||
|
@ -3,10 +3,10 @@
|
||||
*
|
||||
* @brief Header file for converting structs to JSON objects.
|
||||
*
|
||||
* @note This file is auto-generated by a script on 2024-01-25 14:30:32.
|
||||
* @note This file is auto-generated by a script on 2024-01-30 20:29:34.
|
||||
*
|
||||
* @author Marcel Peterkau
|
||||
* @date 25.01.2024
|
||||
* @date 30.01.2024
|
||||
*/
|
||||
|
||||
#ifndef _STRUCT2JSON_H_
|
||||
@ -17,10 +17,10 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
void generateJsonObject_LubeConfig(JsonObject& data);
|
||||
void generateJsonObject_PersistenceData(JsonObject& data);
|
||||
void generateJsonObject_LubeConfig(JsonObject data);
|
||||
void generateJsonObject_PersistenceData(JsonObject data);
|
||||
|
||||
|
||||
#endif /* _STRUCT2JSON_H_ */
|
||||
|
||||
// CODEGENERATOR_CHECKSUM: 4bb0dc037057aafd9688aacedfaae5c97c9de79dbbd0e139d982208053f74fa8
|
||||
// CODEGENERATOR_CHECKSUM: 59f35aadffd0bbef253210ea2fbaaf9a515553a2e3cc9bf4cfa2819b63c969ce
|
@ -492,6 +492,78 @@ uint32_t ConfigSanityCheck(bool autocorrect)
|
||||
if (autocorrect)
|
||||
LubeConfig.CANSource = LubeConfig_defaults.CANSource;
|
||||
}
|
||||
|
||||
if (!validateWiFiString(LubeConfig.wifi_ap_ssid, sizeof(LubeConfig.wifi_ap_ssid)))
|
||||
{
|
||||
SET_BIT(setting_reset_bits, 14);
|
||||
if (autocorrect)
|
||||
strncpy(LubeConfig.wifi_ap_ssid, LubeConfig_defaults.wifi_ap_ssid, sizeof(LubeConfig.wifi_ap_ssid));
|
||||
}
|
||||
|
||||
if (!validateWiFiString(LubeConfig.wifi_ap_password, sizeof(LubeConfig.wifi_ap_password)))
|
||||
{
|
||||
SET_BIT(setting_reset_bits, 15);
|
||||
if (autocorrect)
|
||||
strncpy(LubeConfig.wifi_ap_password, LubeConfig_defaults.wifi_ap_password, sizeof(LubeConfig.wifi_ap_password));
|
||||
}
|
||||
|
||||
if (!validateWiFiString(LubeConfig.wifi_client_ssid, sizeof(LubeConfig.wifi_client_ssid)))
|
||||
{
|
||||
SET_BIT(setting_reset_bits, 16);
|
||||
if (autocorrect)
|
||||
strncpy(LubeConfig.wifi_client_ssid, LubeConfig_defaults.wifi_client_ssid, sizeof(LubeConfig.wifi_client_ssid));
|
||||
}
|
||||
|
||||
if (!validateWiFiString(LubeConfig.wifi_client_password, sizeof(LubeConfig.wifi_client_password)))
|
||||
{
|
||||
SET_BIT(setting_reset_bits, 17);
|
||||
if (autocorrect)
|
||||
strncpy(LubeConfig.wifi_client_password, LubeConfig_defaults.wifi_client_password, sizeof(LubeConfig.wifi_client_password));
|
||||
}
|
||||
// Return the bitmask indicating which settings need to be reset
|
||||
return setting_reset_bits;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Validates whether a given string contains only characters allowed in WiFi SSIDs and passwords.
|
||||
*
|
||||
* This function checks each character in the provided string to ensure
|
||||
* that it contains only characters allowed in WiFi SSIDs and passwords.
|
||||
* It considers characters from 'A' to 'Z', 'a' to 'z', '0' to '9', as well as
|
||||
* the following special characters: ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~
|
||||
*
|
||||
* @param string Pointer to the string to be validated.
|
||||
* @param size Size of the string including the null-terminator.
|
||||
* @return true if the string contains only allowed characters or is NULL,
|
||||
* false otherwise.
|
||||
*/
|
||||
bool validateWiFiString(char *string, size_t size)
|
||||
{
|
||||
if (string == NULL)
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < size; i++)
|
||||
{
|
||||
char c = string[i];
|
||||
if (c == '\0')
|
||||
{
|
||||
// Reached the end of the string, all characters were valid WiFi characters.
|
||||
return true;
|
||||
}
|
||||
if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
|
||||
(c >= '0' && c <= '9') || c == '!' || c == '"' || c == '#' ||
|
||||
c == '$' || c == '%' || c == '&' || c == '\'' || c == '(' ||
|
||||
c == ')' || c == '*' || c == '+' || c == ',' || c == '-' ||
|
||||
c == '.' || c == '/' || c == ':' || c == ';' || c == '<' ||
|
||||
c == '=' || c == '>' || c == '?' || c == '@' || c == '[' ||
|
||||
c == '\\' || c == ']' || c == '^' || c == '_' || c == '`' ||
|
||||
c == '{' || c == '|' || c == '}' || c == '~'))
|
||||
{
|
||||
// Found a character that is not a valid WiFi character.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// If the loop completes without finding a null terminator, the string is invalid.
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -3,16 +3,16 @@
|
||||
*
|
||||
* @brief Implementation file for converting structs to JSON objects.
|
||||
*
|
||||
* @note This file is auto-generated by a script on 2024-01-25 14:30:32.
|
||||
* @note This file is auto-generated by a script on 2024-01-30 20:29:34.
|
||||
*
|
||||
* @author Marcel Peterkau
|
||||
* @date 25.01.2024
|
||||
* @date 30.01.2024
|
||||
*/
|
||||
|
||||
|
||||
#include "struct2json.h"
|
||||
|
||||
void generateJsonObject_LubeConfig(JsonObject& data)
|
||||
void generateJsonObject_LubeConfig(JsonObject data)
|
||||
{
|
||||
data["EEPROM_Version"] = LubeConfig.EEPROM_Version;
|
||||
data["DistancePerLube_Default"] = LubeConfig.DistancePerLube_Default;
|
||||
@ -36,10 +36,11 @@ void generateJsonObject_LubeConfig(JsonObject& data)
|
||||
data["wifi_ap_password"] = LubeConfig.wifi_ap_password;
|
||||
data["wifi_client_ssid"] = LubeConfig.wifi_client_ssid;
|
||||
data["wifi_client_password"] = LubeConfig.wifi_client_password;
|
||||
data["wifi_autoconnect"] = LubeConfig.wifi_autoconnect;
|
||||
data["checksum"] = LubeConfig.checksum;
|
||||
}
|
||||
|
||||
void generateJsonObject_PersistenceData(JsonObject& data)
|
||||
void generateJsonObject_PersistenceData(JsonObject data)
|
||||
{
|
||||
data["writeCycleCounter"] = PersistenceData.writeCycleCounter;
|
||||
data["tankRemain_microL"] = PersistenceData.tankRemain_microL;
|
||||
@ -51,4 +52,4 @@ void generateJsonObject_PersistenceData(JsonObject& data)
|
||||
|
||||
|
||||
|
||||
// CODEGENERATOR_CHECKSUM: 4bb0dc037057aafd9688aacedfaae5c97c9de79dbbd0e139d982208053f74fa8
|
||||
// CODEGENERATOR_CHECKSUM: 59f35aadffd0bbef253210ea2fbaaf9a515553a2e3cc9bf4cfa2819b63c969ce
|
@ -307,6 +307,10 @@ void WebserverEERestore_Callback(AsyncWebServerRequest *request, const String &f
|
||||
LubeConfig.LED_Mode_Flash = json["config"]["LED_Mode_Flash"].as<bool>();
|
||||
LubeConfig.LED_Max_Brightness = json["config"]["LED_Max_Brightness"].as<uint8_t>();
|
||||
LubeConfig.LED_Min_Brightness = json["config"]["LED_Min_Brightness"].as<uint8_t>();
|
||||
strncpy(LubeConfig.wifi_ap_ssid, json["config"]["wifi_ap_ssid"].as<const char *>(), sizeof(LubeConfig.wifi_ap_ssid));
|
||||
strncpy(LubeConfig.wifi_ap_password, json["config"]["wifi_ap_password"].as<const char *>(), sizeof(LubeConfig.wifi_ap_password));
|
||||
strncpy(LubeConfig.wifi_client_ssid, json["config"]["wifi_client_ssid"].as<const char *>(), sizeof(LubeConfig.wifi_client_ssid));
|
||||
strncpy(LubeConfig.wifi_client_password, json["config"]["wifi_client_password"].as<const char *>(), sizeof(LubeConfig.wifi_client_password));
|
||||
|
||||
PersistenceData.writeCycleCounter = json["persis"]["writeCycleCounter"].as<uint16_t>();
|
||||
PersistenceData.tankRemain_microL = json["persis"]["tankRemain_microL"].as<uint32_t>();
|
||||
@ -346,7 +350,7 @@ void WebServerEEJSON_Callback(AsyncWebServerRequest *request)
|
||||
{
|
||||
AsyncResponseStream *response = request->beginResponseStream("application/json");
|
||||
JsonDocument json;
|
||||
JsonObject info = json.to<JsonObject>();
|
||||
JsonObject info = json["info"].to<JsonObject>();
|
||||
|
||||
char buffer[16];
|
||||
|
||||
@ -357,12 +361,12 @@ void WebServerEEJSON_Callback(AsyncWebServerRequest *request)
|
||||
snprintf_P(buffer, sizeof(buffer), "%s", constants.GitHash);
|
||||
info["Git-Hash"] = buffer;
|
||||
|
||||
JsonObject config = json.to<JsonObject>();
|
||||
JsonObject config = json["config"].to<JsonObject>();
|
||||
generateJsonObject_LubeConfig(config);
|
||||
JsonObject persis = json.to<JsonObject>();
|
||||
JsonObject persis = json["persis"].to<JsonObject>();
|
||||
generateJsonObject_PersistenceData(persis);
|
||||
|
||||
JsonObject eepart = json.to<JsonObject>();
|
||||
JsonObject eepart = json["eepart"].to<JsonObject>();
|
||||
sprintf(buffer, "0x%04X", globals.eePersistanceAdress);
|
||||
eepart["PersistanceAddress"] = buffer;
|
||||
|
||||
@ -513,7 +517,7 @@ void Websocket_HandleButtons(uint8_t *data)
|
||||
void Websocket_HandleSettings(uint8_t *data)
|
||||
{
|
||||
char identifier[32];
|
||||
char value[32];
|
||||
char value[63];
|
||||
|
||||
parseWebsocketString((char *)data, identifier, sizeof(identifier), value, sizeof(value));
|
||||
|
||||
@ -568,6 +572,14 @@ void Websocket_HandleSettings(uint8_t *data)
|
||||
{
|
||||
LubeConfig.LED_Mode_Flash = value[0] == '1' ? true : false;
|
||||
}
|
||||
else if (strcmp(identifier, "wifi-ssid") == 0)
|
||||
{
|
||||
strncpy(LubeConfig.wifi_client_ssid, value, sizeof(LubeConfig.wifi_client_ssid));
|
||||
}
|
||||
else if (strcmp(identifier, "wifi-password") == 0)
|
||||
{
|
||||
strncpy(LubeConfig.wifi_client_password, value, sizeof(LubeConfig.wifi_client_password));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug_pushMessage("Got unknown Settings-id and value '%s' from ws-client\n", identifier);
|
||||
@ -704,7 +716,9 @@ void Websocket_RefreshClientData_Static(uint32_t client_id, bool send_mapping)
|
||||
"showimpulse;"
|
||||
"showgps;"
|
||||
"showcan;"
|
||||
"bleedingpulses;";
|
||||
"bleedingpulses;"
|
||||
"wifi-ssid;"
|
||||
"wifi-password;";
|
||||
|
||||
if (client_id > 0)
|
||||
webSocket.text(client_id, mapping);
|
||||
@ -733,6 +747,8 @@ void Websocket_RefreshClientData_Static(uint32_t client_id, bool send_mapping)
|
||||
temp.concat(String(LubeConfig.SpeedSource == SOURCE_GPS ? "1" : "0") + ";");
|
||||
temp.concat(String(LubeConfig.SpeedSource == SOURCE_CAN ? "1" : "0") + ";");
|
||||
temp.concat(String(LubeConfig.BleedingPulses) + ";");
|
||||
temp.concat(String(LubeConfig.wifi_client_ssid) + ";");
|
||||
temp.concat(String(LubeConfig.wifi_client_password) + ";");
|
||||
|
||||
for (uint32_t i = 0; i < SpeedSourceString_Elements; i++)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user