#include "esp_http_server.h"
+#include "defines.h"
#include "ClassLogFile.h"
#include "server_help.h"
+#include "interface_mqtt.h"
+#include "server_GPIO.h"
#include "Helper.h"
#include "miniz.h"
@@ -53,17 +56,17 @@ struct file_server_data {
char scratch[SCRATCH_BUFSIZE];
};
-static const char *TAG = "file_server";
+static const char *TAG_FILESERVER = "file_server";
/* Handler to redirect incoming GET request for /index.html to /
* This can be overridden by uploading file with same name */
-static esp_err_t index_html_get_handler(httpd_req_t *req)
-{
- httpd_resp_set_status(req, "307 Temporary Redirect");
- httpd_resp_set_hdr(req, "Location", "/");
- httpd_resp_send(req, NULL, 0); // Response body can be empty
- return ESP_OK;
-}
+// static esp_err_t index_html_get_handler(httpd_req_t *req)
+// {
+// httpd_resp_set_status(req, "307 Temporary Redirect");
+// httpd_resp_set_hdr(req, "Location", "/");
+// httpd_resp_send(req, NULL, 0); // Response body can be empty
+// return ESP_OK;
+// }
/* Send HTTP response with a run-time generated html consisting of
* a list of all files and folders under the requested path.
@@ -95,7 +98,7 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const
printf("entrypath: <%s>\n", entrypath);
if (!dir) {
- ESP_LOGE(TAG, "Failed to stat dir : %s", dirpath);
+ ESP_LOGE(TAG_FILESERVER, "Failed to stat dir : %s", dirpath);
/* Respond with 404 Not Found */
httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, "Directory does not exist");
return ESP_FAIL;
@@ -115,7 +118,7 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const
if (chunksize > 0){
if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) {
fclose(fd);
- ESP_LOGE(TAG, "File sending failed!");
+ ESP_LOGE(TAG_FILESERVER, "File sending failed!");
return ESP_FAIL;
}
}
@@ -154,11 +157,11 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const
strlcpy(entrypath + dirpath_len, entry->d_name, sizeof(entrypath) - dirpath_len);
printf("Entrypath: %s\n", entrypath);
if (stat(entrypath, &entry_stat) == -1) {
- ESP_LOGE(TAG, "Failed to stat %s : %s", entrytype, entry->d_name);
+ ESP_LOGE(TAG_FILESERVER, "Failed to stat %s : %s", entrytype, entry->d_name);
continue;
}
sprintf(entrysize, "%ld", entry_stat.st_size);
- ESP_LOGI(TAG, "Found %s : %s (%s bytes)", entrytype, entry->d_name, entrysize);
+ ESP_LOGI(TAG_FILESERVER, "Found %s : %s (%s bytes)", entrytype, entry->d_name, entrysize);
/* Send chunk of HTML file containing table entries with file name and size */
httpd_resp_sendstr_chunk(req, "uri);
- const char filename = 'log_current.txt';
+ const char* filename = "log_current.txt";
- printf("uri: %s, filename: %s, filepath: %s\n", req->uri, &filename, filepath);
+ printf("uri: %s, filename: %s, filepath: %s\n", req->uri, filename, filepath);
std::string currentfilename = LogFile.GetCurrentFileName();
fd = OpenFileAndWait(currentfilename.c_str(), "r");
if (!fd) {
- ESP_LOGE(TAG, "Failed to read existing file : %s", filepath);
+ ESP_LOGE(TAG_FILESERVER, "Failed to read existing file : %s", filepath);
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to read existing file");
return ESP_FAIL;
@@ -226,8 +229,8 @@ static esp_err_t logfileact_get_handler(httpd_req_t *req)
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
-// ESP_LOGI(TAG, "Sending file : %s (%ld bytes)...", &filename, file_stat.st_size);
- set_content_type_from_file(req, &filename);
+// ESP_LOGI(TAG_FILESERVER, "Sending file : %s (%ld bytes)...", &filename, file_stat.st_size);
+ set_content_type_from_file(req, filename);
/* Retrieve the pointer to scratch buffer for temporary storage */
char *chunk = ((struct file_server_data *)req->user_ctx)->scratch;
@@ -239,7 +242,7 @@ static esp_err_t logfileact_get_handler(httpd_req_t *req)
/* Send the buffer contents as HTTP response chunk */
if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) {
fclose(fd);
- ESP_LOGE(TAG, "File sending failed!");
+ ESP_LOGE(TAG_FILESERVER, "File sending failed!");
/* Abort sending file */
httpd_resp_sendstr_chunk(req, NULL);
/* Respond with 500 Internal Server Error */
@@ -252,7 +255,7 @@ static esp_err_t logfileact_get_handler(httpd_req_t *req)
/* Close file after sending complete */
fclose(fd);
- ESP_LOGI(TAG, "File sending complete");
+ ESP_LOGI(TAG_FILESERVER, "File sending complete");
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
@@ -284,7 +287,7 @@ static esp_err_t download_get_handler(httpd_req_t *req)
if (!filename) {
- ESP_LOGE(TAG, "Filename is too long");
+ ESP_LOGE(TAG_FILESERVER, "Filename is too long");
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Filename too long");
return ESP_FAIL;
@@ -297,11 +300,11 @@ static esp_err_t download_get_handler(httpd_req_t *req)
if (buf_len > 1) {
char buf[buf_len];
if (httpd_req_get_url_query_str(req, buf, buf_len) == ESP_OK) {
- ESP_LOGI(TAG, "Found URL query => %s", buf);
+ ESP_LOGI(TAG_FILESERVER, "Found URL query => %s", buf);
char param[32];
/* Get value of expected key from query string */
if (httpd_query_key_value(buf, "readonly", param, sizeof(param)) == ESP_OK) {
- ESP_LOGI(TAG, "Found URL query parameter => readonly=%s", param);
+ ESP_LOGI(TAG_FILESERVER, "Found URL query parameter => readonly=%s", param);
readonly = param && strcmp(param,"true")==0;
}
}
@@ -316,7 +319,7 @@ static esp_err_t download_get_handler(httpd_req_t *req)
/* If file not present on SPIFFS check if URI
* corresponds to one of the hardcoded paths */
- ESP_LOGE(TAG, "Failed to stat file : %s", filepath);
+ ESP_LOGE(TAG_FILESERVER, "Failed to stat file : %s", filepath);
/* Respond with 404 Not Found */
httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, "File does not exist");
return ESP_FAIL;
@@ -324,7 +327,7 @@ static esp_err_t download_get_handler(httpd_req_t *req)
fd = OpenFileAndWait(filepath, "r");
if (!fd) {
- ESP_LOGE(TAG, "Failed to read existing file : %s", filepath);
+ ESP_LOGE(TAG_FILESERVER, "Failed to read existing file : %s", filepath);
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to read existing file");
return ESP_FAIL;
@@ -332,7 +335,7 @@ static esp_err_t download_get_handler(httpd_req_t *req)
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- ESP_LOGI(TAG, "Sending file : %s (%ld bytes)...", filename, file_stat.st_size);
+ ESP_LOGI(TAG_FILESERVER, "Sending file : %s (%ld bytes)...", filename, file_stat.st_size);
set_content_type_from_file(req, filename);
/* Retrieve the pointer to scratch buffer for temporary storage */
@@ -345,7 +348,7 @@ static esp_err_t download_get_handler(httpd_req_t *req)
/* Send the buffer contents as HTTP response chunk */
if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) {
fclose(fd);
- ESP_LOGE(TAG, "File sending failed!");
+ ESP_LOGE(TAG_FILESERVER, "File sending failed!");
/* Abort sending file */
httpd_resp_sendstr_chunk(req, NULL);
/* Respond with 500 Internal Server Error */
@@ -358,7 +361,7 @@ static esp_err_t download_get_handler(httpd_req_t *req)
/* Close file after sending complete */
fclose(fd);
- ESP_LOGI(TAG, "File sending complete");
+ ESP_LOGI(TAG_FILESERVER, "File sending complete");
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
@@ -385,13 +388,13 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
/* Filename cannot have a trailing '/' */
if (filename[strlen(filename) - 1] == '/') {
- ESP_LOGE(TAG, "Invalid filename : %s", filename);
+ ESP_LOGE(TAG_FILESERVER, "Invalid filename : %s", filename);
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Invalid filename");
return ESP_FAIL;
}
if (stat(filepath, &file_stat) == 0) {
- ESP_LOGE(TAG, "File already exists : %s", filepath);
+ ESP_LOGE(TAG_FILESERVER, "File already exists : %s", filepath);
/* Respond with 400 Bad Request */
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "File already exists");
return ESP_FAIL;
@@ -399,7 +402,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
/* File cannot be larger than a limit */
if (req->content_len > MAX_FILE_SIZE) {
- ESP_LOGE(TAG, "File too large : %d bytes", req->content_len);
+ ESP_LOGE(TAG_FILESERVER, "File too large : %d bytes", req->content_len);
/* Respond with 400 Bad Request */
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST,
"File size must be less than "
@@ -411,13 +414,13 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
fd = OpenFileAndWait(filepath, "w");
if (!fd) {
- ESP_LOGE(TAG, "Failed to create file : %s", filepath);
+ ESP_LOGE(TAG_FILESERVER, "Failed to create file : %s", filepath);
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to create file");
return ESP_FAIL;
}
- ESP_LOGI(TAG, "Receiving file : %s...", filename);
+ ESP_LOGI(TAG_FILESERVER, "Receiving file : %s...", filename);
/* Retrieve the pointer to scratch buffer for temporary storage */
char *buf = ((struct file_server_data *)req->user_ctx)->scratch;
@@ -429,7 +432,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
while (remaining > 0) {
- ESP_LOGI(TAG, "Remaining size : %d", remaining);
+ ESP_LOGI(TAG_FILESERVER, "Remaining size : %d", remaining);
/* Receive the file part by part into a buffer */
if ((received = httpd_req_recv(req, buf, MIN(remaining, SCRATCH_BUFSIZE))) <= 0) {
if (received == HTTPD_SOCK_ERR_TIMEOUT) {
@@ -442,7 +445,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
fclose(fd);
unlink(filepath);
- ESP_LOGE(TAG, "File reception failed!");
+ ESP_LOGE(TAG_FILESERVER, "File reception failed!");
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to receive file");
return ESP_FAIL;
@@ -455,7 +458,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
fclose(fd);
unlink(filepath);
- ESP_LOGE(TAG, "File write failed!");
+ ESP_LOGE(TAG_FILESERVER, "File write failed!");
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to write file to storage");
return ESP_FAIL;
@@ -468,7 +471,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
/* Close file upon upload completion */
fclose(fd);
- ESP_LOGI(TAG, "File reception complete");
+ ESP_LOGI(TAG_FILESERVER, "File reception complete");
std::string directory = std::string(filepath);
size_t zw = directory.find("/");
@@ -496,6 +499,13 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
httpd_resp_set_status(req, "303 See Other");
httpd_resp_set_hdr(req, "Location", directory.c_str());
httpd_resp_sendstr(req, "File uploaded successfully");
+
+ if (strcmp(filepath, CONFIG_FILE) == 0) {
+ printf("New config foung. Reload handler.");
+ gpio_handler_deinit();
+ MQTTdestroy();
+ }
+
return ESP_OK;
}
@@ -567,19 +577,19 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
/* Filename cannot have a trailing '/' */
if (filename[strlen(filename) - 1] == '/') {
- ESP_LOGE(TAG, "Invalid filename : %s", filename);
+ ESP_LOGE(TAG_FILESERVER, "Invalid filename : %s", filename);
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Invalid filename");
return ESP_FAIL;
}
if (stat(filepath, &file_stat) == -1) {
- ESP_LOGE(TAG, "File does not exist : %s", filename);
+ ESP_LOGE(TAG_FILESERVER, "File does not exist : %s", filename);
/* Respond with 400 Bad Request */
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "File does not exist");
return ESP_FAIL;
}
- ESP_LOGI(TAG, "Deleting file : %s", filename);
+ ESP_LOGI(TAG_FILESERVER, "Deleting file : %s", filename);
/* Delete file */
unlink(filepath);
@@ -623,7 +633,7 @@ void delete_all_in_directory(std::string _directory)
std::string filename;
if (!dir) {
- ESP_LOGE(TAG, "Failed to stat dir : %s", _directory.c_str());
+ ESP_LOGE(TAG_FILESERVER, "Failed to stat dir : %s", _directory.c_str());
return;
}
@@ -632,7 +642,7 @@ void delete_all_in_directory(std::string _directory)
if (!(entry->d_type == DT_DIR)){
if (strcmp("wlan.ini", entry->d_name) != 0){ // auf wlan.ini soll nicht zugegriffen werden !!!
filename = _directory + "/" + std::string(entry->d_name);
- ESP_LOGI(TAG, "Deleting file : %s", filename.c_str());
+ ESP_LOGI(TAG_FILESERVER, "Deleting file : %s", filename.c_str());
/* Delete file */
unlink(filename.c_str());
}
@@ -722,19 +732,19 @@ void register_server_file_uri(httpd_handle_t server, const char *base_path)
/* Validate file storage base path */
if (!base_path) {
// if (!base_path || strcmp(base_path, "/spiffs") != 0) {
- ESP_LOGE(TAG, "File server base_path not set");
+ ESP_LOGE(TAG_FILESERVER, "File server base_path not set");
// return ESP_ERR_INVALID_ARG;
}
if (server_data) {
- ESP_LOGE(TAG, "File server already started");
+ ESP_LOGE(TAG_FILESERVER, "File server already started");
// return ESP_ERR_INVALID_STATE;
}
/* Allocate memory for server data */
server_data = (file_server_data *) calloc(1, sizeof(struct file_server_data));
if (!server_data) {
- ESP_LOGE(TAG, "Failed to allocate memory for server data");
+ ESP_LOGE(TAG_FILESERVER, "Failed to allocate memory for server data");
// return ESP_ERR_NO_MEM;
}
strlcpy(server_data->base_path, base_path,
diff --git a/code/components/jomjol_fileserver_ota/server_ota.cpp b/code/components/jomjol_fileserver_ota/server_ota.cpp
index 6c69ae1e..39f4d7e9 100644
--- a/code/components/jomjol_fileserver_ota/server_ota.cpp
+++ b/code/components/jomjol_fileserver_ota/server_ota.cpp
@@ -12,7 +12,7 @@
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_event.h"
-#include "esp_event_loop.h"
+#include "esp_event.h"
#include "esp_log.h"
#include
#include "esp_http_client.h"
@@ -28,6 +28,7 @@
#include "server_tflite.h"
#include "server_file.h"
+#include "server_GPIO.h"
#include "ClassLogFile.h"
@@ -46,6 +47,7 @@ static char ota_write_data[BUFFSIZE + 1] = { 0 };
#define OTA_URL_SIZE 256
+static const char *TAGPARTOTA = "server_ota";
static void infinite_loop(void)
@@ -60,14 +62,14 @@ static void infinite_loop(void)
-static bool ota_example_task(std::string fn)
+static bool ota_update_task(std::string fn)
{
esp_err_t err;
/* update handle : set by esp_ota_begin(), must be freed via esp_ota_end() */
esp_ota_handle_t update_handle = 0 ;
const esp_partition_t *update_partition = NULL;
- ESP_LOGI(TAGPARTOTA, "Starting OTA example");
+ ESP_LOGI(TAGPARTOTA, "Starting OTA update");
const esp_partition_t *configured = esp_ota_get_boot_partition();
const esp_partition_t *running = esp_ota_get_running_partition();
@@ -374,7 +376,9 @@ esp_err_t handler_ota_update(httpd_req_t *req)
const char* resp_str;
- if (ota_example_task(fn))
+ KillTFliteTasks();
+ gpio_handler_deinit();
+ if (ota_update_task(fn))
{
resp_str = "Firmware Update Successfull!
You can restart now.";
}
@@ -400,8 +404,6 @@ void hard_restart() {
void task_reboot(void *pvParameter)
{
-
-
while(1)
{
vTaskDelay(5000 / portTICK_PERIOD_MS);
@@ -413,12 +415,14 @@ void task_reboot(void *pvParameter)
}
void doReboot(){
- LogFile.WriteToFile("Reboot - now");
- KillTFliteTasks();
+ ESP_LOGI(TAGPARTOTA, "Reboot in 5sec");
+ LogFile.WriteToFile("Reboot in 5sec");
xTaskCreate(&task_reboot, "reboot", configMINIMAL_STACK_SIZE * 64, NULL, 10, NULL);
+ // KillTFliteTasks(); // kills itself
+ gpio_handler_destroy();
vTaskDelay(5000 / portTICK_PERIOD_MS);
esp_restart();
- hard_restart();
+ hard_restart();
}
diff --git a/code/components/jomjol_fileserver_ota/server_ota.h b/code/components/jomjol_fileserver_ota/server_ota.h
index e227d146..415e5fd9 100644
--- a/code/components/jomjol_fileserver_ota/server_ota.h
+++ b/code/components/jomjol_fileserver_ota/server_ota.h
@@ -4,8 +4,6 @@
//#include "ClassControllCamera.h"
-static const char *TAGPARTOTA = "server_ota";
-
void register_server_ota_sdcard_uri(httpd_handle_t server);
void CheckOTAUpdate();
void doReboot();
diff --git a/code/components/jomjol_flowcontroll/ClassFlowAnalog.cpp b/code/components/jomjol_flowcontroll/ClassFlowAnalog.cpp
index c38d15b5..91cf5fc6 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowAnalog.cpp
+++ b/code/components/jomjol_flowcontroll/ClassFlowAnalog.cpp
@@ -359,7 +359,11 @@ bool ClassFlowAnalog::doNeuralNetwork(string time)
string zwcnn = "/sdcard" + cnnmodelfile;
zwcnn = FormatFileName(zwcnn);
printf(zwcnn.c_str());printf("\n");
- tflite->LoadModel(zwcnn);
+ if (!tflite->LoadModel(zwcnn)) {
+ printf("Can't read model file /sdcard%s\n", cnnmodelfile.c_str());
+ delete tflite;
+ return false;
+ }
tflite->MakeAllocate();
#endif
diff --git a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp
index 10013455..7cc091e1 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp
+++ b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp
@@ -210,7 +210,7 @@ bool ClassFlowControll::doFlow(string time)
int repeat = 0;
#ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("ClassFlowAnalog::doFlow - Start");
+ LogFile.WriteHeapInfo("ClassFlowControll::doFlow - Start");
#endif
for (int i = 0; i < FlowControll.size(); ++i)
@@ -239,7 +239,7 @@ bool ClassFlowControll::doFlow(string time)
}
#ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("ClassFlowAnalog::doFlow");
+ LogFile.WriteHeapInfo("ClassFlowControll::doFlow");
#endif
}
@@ -475,7 +475,7 @@ int ClassFlowControll::CleanTempFolder() {
esp_err_t ClassFlowControll::SendRawJPG(httpd_req_t *req)
{
- return flowmakeimage->SendRawJPG(req);
+ return flowmakeimage != NULL ? flowmakeimage->SendRawJPG(req) : ESP_FAIL;
}
@@ -487,6 +487,12 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
esp_err_t result = ESP_FAIL;
bool Dodelete = false;
+ if (flowalignment == NULL)
+ {
+ printf("Can't continue, flowalignment is NULL\n");
+ return ESP_FAIL;
+ }
+
if (_fn == "alg.jpg")
{
_send = flowalignment->ImageBasis;
@@ -518,7 +524,9 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
if (htmlinfo[i]->image_org)
_send = htmlinfo[i]->image_org;
}
+ delete htmlinfo[i];
}
+ htmlinfo.clear();
htmlinfo = GetAllAnalog();
for (int i = 0; i < htmlinfo.size(); ++i)
@@ -533,7 +541,9 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
if (htmlinfo[i]->image_org)
_send = htmlinfo[i]->image_org;
}
+ delete htmlinfo[i];
}
+ htmlinfo.clear();
if (_send)
{
diff --git a/code/components/jomjol_flowcontroll/ClassFlowDigit.cpp b/code/components/jomjol_flowcontroll/ClassFlowDigit.cpp
index dad5fcfe..0c214a63 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowDigit.cpp
+++ b/code/components/jomjol_flowcontroll/ClassFlowDigit.cpp
@@ -307,7 +307,12 @@ bool ClassFlowDigit::doNeuralNetwork(string time)
CTfLiteClass *tflite = new CTfLiteClass;
string zwcnn = FormatFileName("/sdcard" + cnnmodelfile);
printf(zwcnn.c_str());printf("\n");
- tflite->LoadModel(zwcnn);
+ if (!tflite->LoadModel(zwcnn)) {
+ printf("Can't read model file /sdcard%s\n", cnnmodelfile.c_str());
+ delete tflite;
+ return false;
+ }
+
tflite->MakeAllocate();
#endif
diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp
index d4ad7bbe..4748b0d7 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp
+++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp
@@ -1,6 +1,8 @@
+#include
#include "ClassFlowMQTT.h"
#include "Helper.h"
+#include "time_sntp.h"
#include "interface_mqtt.h"
#include "ClassFlowPostProcessing.h"
@@ -16,6 +18,8 @@ void ClassFlowMQTT::SetInitialParameter(void)
maintopic = "";
mainerrortopic = "";
+ topicUptime = "";
+ topicFreeMem = "";
clientname = "watermeter";
OldValue = "";
flowpostprocessing = NULL;
@@ -106,7 +110,7 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
}
}
- if ((uri.length() > 0) && (maintopic.length() > 0))
+ if (!MQTTisConnected() && (uri.length() > 0) && (maintopic.length() > 0))
{
mainerrortopic = maintopic + "/connection";
MQTTInit(uri, clientname, user, password, mainerrortopic, 60);
@@ -132,6 +136,16 @@ bool ClassFlowMQTT::doFlow(string zwtime)
MQTTPublish(mainerrortopic, "connected");
+ zw = maintopic + "/" + "uptime";
+ char uptimeStr[11];
+ sprintf(uptimeStr, "%ld", (long)getUpTime());
+ MQTTPublish(zw, uptimeStr);
+
+ zw = maintopic + "/" + "freeMem";
+ char freeheapmem[11];
+ sprintf(freeheapmem, "%zu", esp_get_free_heap_size());
+ MQTTPublish(zw, freeheapmem);
+
if (flowpostprocessing)
{
std::vector NUMBERS = flowpostprocessing->GetNumbers();
@@ -158,7 +172,7 @@ bool ClassFlowMQTT::doFlow(string zwtime)
zw = namenumber + "rate";
MQTTPublish(zw, resultrate);
- zw = namenumber + "timestamp";
+ zw = namenumber + "timestamp";
MQTTPublish(zw, resulttimestamp);
@@ -187,7 +201,6 @@ bool ClassFlowMQTT::doFlow(string zwtime)
MQTTPublish(topic, result);
}
-
OldValue = result;
return true;
diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.h b/code/components/jomjol_flowcontroll/ClassFlowMQTT.h
index 71ff8455..c79e9b13 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.h
+++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.h
@@ -9,7 +9,7 @@ class ClassFlowMQTT :
public ClassFlow
{
protected:
- std::string uri, topic, topicError, clientname, topicRate, topicTimeStamp;
+ std::string uri, topic, topicError, clientname, topicRate, topicTimeStamp, topicUptime, topicFreeMem;
std::string OldValue;
ClassFlowPostProcessing* flowpostprocessing;
std::string user, password;
diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp
index fdbd8644..07f7e7e0 100644
--- a/code/components/jomjol_helper/Helper.cpp
+++ b/code/components/jomjol_helper/Helper.cpp
@@ -78,8 +78,9 @@ void memCopyGen(uint8_t* _source, uint8_t* _target, int _size)
-FILE* OpenFileAndWait(const char* nm, char* _mode, int _waitsec)
+FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec)
{
+ printf("open config file %s in mode %s\n", nm, _mode);
FILE *pfile = fopen(nm, _mode);
if (pfile == NULL)
@@ -314,6 +315,14 @@ string toUpper(string in)
return in;
}
+string toLower(string in)
+{
+ for (int i = 0; i < in.length(); ++i)
+ in[i] = tolower(in[i]);
+
+ return in;
+}
+
// CPU Temp
extern "C" uint8_t temprature_sens_read();
float temperatureRead()
diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h
index ac6cccae..46fbf8d6 100644
--- a/code/components/jomjol_helper/Helper.h
+++ b/code/components/jomjol_helper/Helper.h
@@ -11,7 +11,7 @@ void FindReplace(std::string& line, std::string& oldString, std::string& newStri
void CopyFile(string input, string output);
-FILE* OpenFileAndWait(const char* nm, char* _mode, int _waitsec = 1);
+FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec = 1);
size_t findDelimiterPos(string input, string delimiter);
//string trim(string istring);
@@ -23,6 +23,7 @@ string getFileType(string filename);
int mkdir_r(const char *dir, const mode_t mode);
int removeFolder(const char* folderPath, const char* logTag);
+string toLower(string in);
string toUpper(string in);
float temperatureRead();
diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp
index 71825ca7..a026d985 100644
--- a/code/components/jomjol_logfile/ClassLogFile.cpp
+++ b/code/components/jomjol_logfile/ClassLogFile.cpp
@@ -12,7 +12,7 @@ ClassLogFile LogFile("/sdcard/log/message", "log_%Y-%m-%d.txt");
void ClassLogFile::WriteHeapInfo(std::string _id)
{
-std::string _zw = "\t" + _id;
+ std::string _zw = "\t" + _id;
if (loglevel > 0)
_zw = _zw + "\t" + getESPHeapInfo();
diff --git a/code/components/jomjol_mqtt/interface_mqtt.cpp b/code/components/jomjol_mqtt/interface_mqtt.cpp
index 7fde4733..3230cb8f 100644
--- a/code/components/jomjol_mqtt/interface_mqtt.cpp
+++ b/code/components/jomjol_mqtt/interface_mqtt.cpp
@@ -1,12 +1,14 @@
#include "interface_mqtt.h"
-
+//#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
#include "esp_log.h"
#include "mqtt_client.h"
#include "ClassLogFile.h"
-static const char *TAG = "interface_mqtt";
+static const char *TAG_INTERFACEMQTT = "interface_mqtt";
+std::map>* connectFunktionMap = NULL;
+std::map>* subscribeFunktionMap = NULL;
bool debugdetail = true;
// #define CONFIG_BROKER_URL "mqtt://192.168.178.43:1883"
@@ -23,44 +25,67 @@ void MQTTPublish(std::string _key, std::string _content, int retained_flag){
msg_id = esp_mqtt_client_publish(client, _key.c_str(), _content.c_str(), 0, 1, retained_flag);
zw = "sent publish successful in MQTTPublish, msg_id=" + std::to_string(msg_id) + ", " + _key + ", " + _content;
if (debugdetail) LogFile.WriteToFile(zw);
- ESP_LOGI(TAG, "sent publish successful in MQTTPublish, msg_id=%d, %s, %s", msg_id, _key.c_str(), _content.c_str());
+ ESP_LOGD(TAG_INTERFACEMQTT, "sent publish successful in MQTTPublish, msg_id=%d, %s, %s", msg_id, _key.c_str(), _content.c_str());
}
else {
- ESP_LOGI(TAG, "Problem with Publish, client=%d, mqtt_connected %d", (int) client, (int) mqtt_connected);
+ ESP_LOGW(TAG_INTERFACEMQTT, "Problem with Publish, client=%d, mqtt_connected %d", (int) client, (int) mqtt_connected);
}
}
static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event)
{
+ int msg_id;
+ std::string topic = "";
switch (event->event_id) {
+ case MQTT_EVENT_BEFORE_CONNECT:
+ ESP_LOGI(TAG_INTERFACEMQTT, "MQTT_EVENT_BEFORE_CONNECT");
+ break;
case MQTT_EVENT_CONNECTED:
- ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
+ ESP_LOGI(TAG_INTERFACEMQTT, "MQTT_EVENT_CONNECTED");
mqtt_connected = true;
+ MQTTconnected();
break;
case MQTT_EVENT_DISCONNECTED:
- ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED");
+ ESP_LOGI(TAG_INTERFACEMQTT, "MQTT_EVENT_DISCONNECTED");
+ break;
+ case MQTT_EVENT_SUBSCRIBED:
+ ESP_LOGI(TAG_INTERFACEMQTT, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
+ msg_id = esp_mqtt_client_publish(client, "/topic/qos0", "data", 0, 0, 0);
+ ESP_LOGI(TAG_INTERFACEMQTT, "sent publish successful, msg_id=%d", msg_id);
+ break;
+ case MQTT_EVENT_UNSUBSCRIBED:
+ ESP_LOGI(TAG_INTERFACEMQTT, "MQTT_EVENT_UNSUBSCRIBED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_PUBLISHED:
- ESP_LOGI(TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
+ ESP_LOGI(TAG_INTERFACEMQTT, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_DATA:
- ESP_LOGI(TAG, "MQTT_EVENT_DATA");
- printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
- printf("DATA=%.*s\r\n", event->data_len, event->data);
+ ESP_LOGI(TAG_INTERFACEMQTT, "MQTT_EVENT_DATA");
+ ESP_LOGI(TAG_INTERFACEMQTT, "TOPIC=%.*s\r\n", event->topic_len, event->topic);
+ ESP_LOGI(TAG_INTERFACEMQTT, "DATA=%.*s\r\n", event->data_len, event->data);
+ topic.assign(event->topic, event->topic_len);
+ if (subscribeFunktionMap != NULL) {
+ if (subscribeFunktionMap->find(topic) != subscribeFunktionMap->end()) {
+ ESP_LOGD(TAG_INTERFACEMQTT, "call handler function\r\n");
+ (*subscribeFunktionMap)[topic](topic, event->data, event->data_len);
+ }
+ } else {
+ ESP_LOGW(TAG_INTERFACEMQTT, "no handler available\r\n");
+ }
break;
case MQTT_EVENT_ERROR:
- ESP_LOGI(TAG, "MQTT_EVENT_ERROR");
+ ESP_LOGI(TAG_INTERFACEMQTT, "MQTT_EVENT_ERROR");
break;
default:
- ESP_LOGI(TAG, "Other event id:%d", event->event_id);
+ ESP_LOGI(TAG_INTERFACEMQTT, "Other event id:%d", event->event_id);
break;
}
return ESP_OK;
}
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) {
- ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id);
+ ESP_LOGD(TAG_INTERFACEMQTT, "Event dispatched from event loop base=%s, event_id=%d", base, event_id);
mqtt_event_handler_cb((esp_mqtt_event_handle_t) event_data);
}
@@ -82,7 +107,7 @@ void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user, st
if (_user.length() && _password.length()){
mqtt_cfg.username = _user.c_str();
mqtt_cfg.password = _password.c_str();
- printf("Connect to MQTT: %s, %s", mqtt_cfg.username, mqtt_cfg.password);
+ ESP_LOGI(TAG_INTERFACEMQTT, "Connect to MQTT: %s, %s", mqtt_cfg.username, mqtt_cfg.password);
};
client = esp_mqtt_client_init(&mqtt_cfg);
@@ -91,3 +116,91 @@ void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user, st
MQTTPublish(_LWTContext, "", 1);
}
+
+void MQTTdestroy() {
+ if (client != NULL) {
+ esp_mqtt_client_stop(client);
+ esp_mqtt_client_destroy(client);
+ }
+}
+
+bool MQTTisConnected() {
+ return mqtt_connected;
+}
+
+void MQTTregisterConnectFunction(std::string name, std::function func){
+ ESP_LOGD(TAG_INTERFACEMQTT, "MQTTregisteronnectFunction %s\r\n", name.c_str());
+ if (connectFunktionMap == NULL) {
+ connectFunktionMap = new std::map>();
+ }
+
+ if ((*connectFunktionMap)[name] != NULL) {
+ ESP_LOGW(TAG_INTERFACEMQTT, "connect function %s already registred", name.c_str());
+ return;
+ }
+
+ (*connectFunktionMap)[name] = func;
+
+ if (mqtt_connected) {
+ func();
+ }
+}
+
+void MQTTunregisterConnectFunction(std::string name){
+ ESP_LOGD(TAG_INTERFACEMQTT, "MQTTregisteronnectFunction %s\r\n", name.c_str());
+ if ((connectFunktionMap != NULL) && (connectFunktionMap->find(name) != connectFunktionMap->end())) {
+ connectFunktionMap->erase(name);
+ }
+}
+
+void MQTTregisterSubscribeFunction(std::string topic, std::function func){
+ ESP_LOGD(TAG_INTERFACEMQTT, "MQTTregisterSubscribeFunction %s\r\n", topic.c_str());
+ if (subscribeFunktionMap == NULL) {
+ subscribeFunktionMap = new std::map>();
+ }
+
+ if ((*subscribeFunktionMap)[topic] != NULL) {
+ ESP_LOGW(TAG_INTERFACEMQTT, "topic %s already registred for subscription", topic.c_str());
+ return;
+ }
+
+ (*subscribeFunktionMap)[topic] = func;
+
+ if (mqtt_connected) {
+ int msg_id = esp_mqtt_client_subscribe(client, topic.c_str(), 0);
+ ESP_LOGD(TAG_INTERFACEMQTT, "topic %s subscribe successful, msg_id=%d", topic.c_str(), msg_id);
+ }
+}
+
+void MQTTconnected(){
+ if (mqtt_connected) {
+ if (connectFunktionMap != NULL) {
+ for(std::map>::iterator it = connectFunktionMap->begin(); it != connectFunktionMap->end(); ++it) {
+ it->second();
+ ESP_LOGD(TAG_INTERFACEMQTT, "call connect function %s", it->first.c_str());
+ }
+ }
+
+ if (subscribeFunktionMap != NULL) {
+ for(std::map>::iterator it = subscribeFunktionMap->begin(); it != subscribeFunktionMap->end(); ++it) {
+ int msg_id = esp_mqtt_client_subscribe(client, it->first.c_str(), 0);
+ ESP_LOGD(TAG_INTERFACEMQTT, "topic %s subscribe successful, msg_id=%d", it->first.c_str(), msg_id);
+ }
+ }
+ }
+}
+
+void MQTTdestroySubscribeFunction(){
+ if (subscribeFunktionMap != NULL) {
+ if (mqtt_connected) {
+ for(std::map>::iterator it = subscribeFunktionMap->begin(); it != subscribeFunktionMap->end(); ++it) {
+ int msg_id = esp_mqtt_client_unsubscribe(client, it->first.c_str());
+ ESP_LOGI(TAG_INTERFACEMQTT, "topic %s unsubscribe successful, msg_id=%d", it->first.c_str(), msg_id);
+ }
+ }
+
+ subscribeFunktionMap->clear();
+ delete subscribeFunktionMap;
+ subscribeFunktionMap = NULL;
+ }
+}
\ No newline at end of file
diff --git a/code/components/jomjol_mqtt/interface_mqtt.h b/code/components/jomjol_mqtt/interface_mqtt.h
index f514ea2d..50990e6f 100644
--- a/code/components/jomjol_mqtt/interface_mqtt.h
+++ b/code/components/jomjol_mqtt/interface_mqtt.h
@@ -1,7 +1,23 @@
+#ifndef INTERFACE_MQTT_H
+#define INTERFACE_MQTT_H
+
#include
+#include |
@@ -83,7 +104,7 @@ textarea {
|
-
+ |
Time to keep the raw image (in days -"0" = forever)
|
@@ -97,7 +118,7 @@ textarea {
|
-
+ |
Wait time between illumination switch on and take the picture (in seconds)
|
@@ -110,7 +131,7 @@ textarea {
|
-
+ |
Quality index for picture (default = "5" - "0" high ... "63" low)
|
@@ -122,11 +143,11 @@ textarea {
|
-
+ |
Picture size camera (default = "VGA")
|
@@ -151,8 +172,8 @@ textarea {
|
@@ -230,9 +251,9 @@ textarea {
|
|
@@ -293,8 +314,8 @@ textarea {
ModelInputSize
|
- x:
- y:
+ x:
+ y:
|
Size of the input image for the CNN model
@@ -337,8 +358,8 @@ textarea {
|
|
@@ -353,8 +374,8 @@ textarea {
| |
ModelInputSize |
- x:
- y:
+ x:
+ y:
|
Size of the input image for the CNN model |
@@ -371,8 +392,8 @@ textarea {
|
@@ -402,8 +423,8 @@ textarea {
|
|
@@ -419,8 +440,8 @@ textarea {
|
|
@@ -436,8 +457,8 @@ textarea {
|
|
@@ -574,8 +595,8 @@ textarea {
|
|
@@ -596,6 +617,610 @@ textarea {
|
+
+
+
+ GPIO Settings
+ Enabling GPIO handler, disable by default integrated flash light. Please enable it with GPIO4 settings.
+
+ |
+
+
+
+ |
+
+ |
+
+ MainTopicMQTT
+ |
+
+
+ |
+
+ MQTT main topic for GPIO
+ |
+
+
+
+
+ |
+
+ |
+
+ GPIO 0 state
+ |
+
+ |
+
+ |
+
+
+ GPIO 0 Usable with restrictions.
+ Must be disabled when camera is used.
+ Pin is used to activate flash mode and must therefore be HIGH when booting.
+ |
+
+
+ |
+
+ GPIO 0 use interrupt
+ |
+
+ |
+
+ |
+
+
+ GPIO 0 enable interrupt trigger
+ |
+
+
+ |
+
+ GPIO 0 PWM duty resolution
+ |
+
+ | |
+
+
+ GPIO 0 LEDC PWM duty resolution in bit
+ |
+
+
+ |
+
+ GPIO 0 enable MQTT
+ |
+
+ | |
+
+
+ GPIO 0 enable MQTT publishing/subscribing
+ |
+
+
+ |
+
+ GPIO 0 enable HTTP
+ |
+
+ | |
+
+
+ GPIO 0 enable HTTP write/read
+ |
+
+
+ |
+
+ GPIO 0 name
+ |
+
+ | |
+
+
+ GPIO 0 MQTT topic name (empty = GPIO0). Allowed characters (a-z, A-Z, 0-9, _, -)
+ |
+
+
+
+
+
+ |
+
+ |
+
+ GPIO 1 state
+ |
+
+ |
+
+ |
+
+
+ GPIO 1 Used by default for serial communication as TX pin. Required for seriales monitor.
+ |
+
+
+ |
+
+ GPIO 1 use interrupt
+ |
+
+ |
+
+ |
+
+
+ GPIO 1 enable interrupt trigger
+ |
+
+
+ |
+
+ GPIO 1 PWM duty resolution
+ |
+
+ | |
+
+
+ GPIO 1 LEDC PWM duty resolution in bit
+ |
+
+
+ |
+
+ GPIO 1 enable MQTT
+ |
+
+ | |
+
+
+ GPIO 1 enable MQTT publishing/subscribing
+ |
+
+
+ |
+
+ GPIO 1 enable HTTP
+ |
+
+ | |
+
+
+ GPIO 1 enable HTTP write/read
+ |
+
+
+ |
+
+ GPIO 1 name
+ |
+
+ | |
+
+
+ GPIO 1 MQTT topic name (empty = GPIO1). Allowed characters (a-z, A-Z, 0-9, _, -)
+ |
+
+
+
+
+
+ |
+
+ |
+
+ GPIO 3 state
+ |
+
+ |
+
+ |
+
+
+ GPIO 3 Used by default for serial communication as RX pin.
+ |
+
+
+ |
+
+ GPIO 3 use interrupt
+ |
+
+ |
+
+ |
+
+
+ GPIO 3 Used by default for serial communication as RX pin.
+ |
+
+
+ |
+
+ GPIO 3 PWM duty resolution
+ |
+
+ | |
+
+
+ GPIO 3 LEDC PWM duty resolution in bit
+ |
+
+
+ |
+
+ GPIO 3 enable MQTT
+ |
+
+ | |
+
+
+ GPIO 3 enable MQTT publishing/subscribing
+ |
+
+
+ |
+
+ GPIO 3 enable HTTP
+ |
+
+ | |
+
+
+ GPIO 3 enable HTTP write/read
+ |
+
+
+ |
+
+ GPIO 3 name
+ |
+
+ | |
+
+
+ GPIO 3 MQTT topic name (empty = GPIO3). Allowed characters (a-z, A-Z, 0-9, _, -)
+ |
+
+
+
+
+
+ |
+
+ |
+
+ GPIO 4 state
+ |
+
+ |
+
+ |
+
+
+ GPIO 4 Usable with restrictions.
+ Pin is used for build-in flash light.
+ |
+
+
+ |
+
+ GPIO 4 use interrupt
+ |
+
+ |
+
+ |
+
+
+ GPIO 4 enable interrupt trigger
+ |
+
+
+ |
+
+ GPIO 4 PWM duty resolution
+ |
+
+ | |
+
+
+ GPIO 4 LEDC PWM duty resolution in bit
+ |
+
+
+ |
+
+ GPIO 4 enable MQTT
+ |
+
+ | |
+
+
+ GPIO 4 enable MQTT publishing/subscribing
+ |
+
+
+ |
+
+ GPIO 4 enable HTTP
+ |
+
+ | |
+
+
+ GPIO 4 enable HTTP write/read
+ |
+
+
+ |
+
+ GPIO 4 name
+ |
+
+ | |
+
+
+ GPIO 4 MQTT topic name (empty = GPIO4). Allowed characters (a-z, A-Z, 0-9, _, -)
+ |
+
+
+
+
+
+ |
+
+ |
+
+ GPIO 12 state
+ |
+
+ |
+
+ |
+
+
+ GPIO 12 is usable without restrictions
+ |
+
+
+ |
+
+ GPIO 12 use interrupt
+ |
+
+ |
+
+ |
+
+
+ GPIO 12 enable interrupt trigger
+ |
+
+
+ |
+
+ GPIO 12 PWM duty resolution
+ |
+
+ | |
+
+
+ GPIO 12 LEDC PWM duty resolution in bit
+ |
+
+
+ |
+
+ GPIO 12 enable MQTT
+ |
+
+ | |
+
+
+ GPIO 12 enable MQTT publishing/subscribing
+ |
+
+
+ |
+
+ GPIO 12 enable HTTP
+ |
+
+ | |
+
+
+ GPIO 12 enable HTTP write/read
+ |
+
+
+ |
+
+ GPIO 12 name
+ |
+
+ | |
+
+
+ GPIO 12 MQTT topic name (empty = GPIO12). Allowed characters (a-z, A-Z, 0-9, _, -)
+ |
+
+
+
+
+
+ |
+
+ |
+
+ GPIO 13 state
+ |
+
+ |
+
+ |
+
+
+ GPIO 13 is usable without restrictions
+ |
+
+
+ |
+
+ GPIO 13 use interrupt
+ |
+
+ |
+
+ |
+
+
+ GPIO 13 enable interrupt trigger
+ |
+
+
+ |
+
+ GPIO 13 PWM duty resolution
+ |
+
+ | |
+
+
+ GPIO 13 LEDC PWM duty resolution in bit
+ |
+
+
+ |
+
+ GPIO 13 enable MQTT
+ |
+
+ | |
+
+
+ GPIO 13 enable MQTT publishing/subscribing
+ |
+
+
+ |
+
+ GPIO 13 enable HTTP
+ |
+
+ | |
+
+
+ GPIO 13 enable HTTP write/read
+ |
+
+
+ |
+
+ GPIO 13 name
+ |
+
+ | |
+
+
+ GPIO 13 MQTT topic name (empty = GPIO13). Allowed characters (a-z, A-Z, 0-9, _, -)
+ |
+
+
+
Debug |
@@ -608,11 +1233,11 @@ textarea {
|
-
+ |
Turn on/off the extended logging
|
@@ -626,7 +1251,7 @@ textarea {
|
-
+ |
Time to keep the log files (in days - "0" = forever)
|
@@ -644,7 +1269,7 @@ textarea {
|
-
+ |
Time zone in POSIX syntax (Europe/Berlin = "CET-1CEST,M3.5.0,M10.5.0/3" - incl. daylight saving)
|
@@ -658,7 +1283,7 @@ textarea {
|
-
+ |
Time server to synchronize system time (default: "pool.ntp.org" - used if nothing is specified)
|
@@ -672,7 +1297,7 @@ textarea {
|
-
+ |
Hostname for server - will be transfered to wlan.ini at next startup)
|
@@ -709,7 +1334,6 @@ textarea {
function LoadConfigNeu() {
-
var isInitialSetup = getParameterByName('InitialSetup');
if (isInitialSetup === 'true')
{
@@ -731,7 +1355,7 @@ function LoadConfigNeu() {
UpdateInputIndividual();
UpdateExpertModus();
document.getElementById("divall").style.display = '';
- }
+}
function InitIndivParameter()
{
@@ -755,63 +1379,82 @@ function getParameterByName(name, url = window.location.href) {
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^]*)|&|#|$)'),
results = regex.exec(url);
- if (!results) return null;
+
+ if (!results) return null;
if (!results[2]) return '';
- return decodeURIComponent(results[2].replace(/\+/g, ' '));
+ return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
-function WriteParameter(_param, _category, _cat, _name, _optional, _select = false, _anzpara = 1, _number = -1){
- if (_number > -1)
- {
- {
- if (_optional) {
- document.getElementById(_cat+"_"+_name+"_enabled").checked = _param[_cat][_name]["enabled"];
- for (var j = 1; j <= _anzpara; ++j)
- document.getElementById(_cat+"_"+_name+"_value"+j).disabled = NUMBERS[_number][_cat][_name]["enabled"];
- }
- document.getElementById(_cat+"_"+_name+"_text").style="color:black;"
- if (_select) {
- var textToFind;
- textToFind = NUMBERS[_number][_cat][_name]["value1"];
- var dd = document.getElementById(_cat+"_"+_name+"_value1");
- for (var i = 0; i < dd.options.length; i++) {
- if (dd.options[i].text.toLowerCase() === textToFind.toLowerCase()) {
- dd.selectedIndex = i;
+function WriteParameter(_param, _category, _cat, _name, _optional, _number = -1){
+
+ let anzpara = _param[_cat][_name].anzParam;
+
+ if (_number > -1) {
+ if ((NUMBERS[_number] == undefined) || (NUMBERS[_number][_cat] == undefined) || (NUMBERS[_number][_cat][_name] == undefined))
+ return;
+
+ if (_optional) {
+ document.getElementById(_cat+"_"+_name+"_enabled").checked = NUMBERS[_number][_cat][_name]["enabled"];
+ for (var j = 1; j <= anzpara; ++j) {
+ document.getElementById(_cat+"_"+_name+"_value"+j).disabled = !NUMBERS[_number][_cat][_name]["enabled"];
+ }
+ }
+ document.getElementById(_cat+"_"+_name+"_text").style="color:black;"
+ setEnabled(_cat+"_"+_name, true);
+
+ for (var j = 1; j <= anzpara; ++j) {
+ let element = document.getElementById(_cat+"_"+_name+"_value"+j);
+ if (element.tagName.toLowerCase() == "select") {
+ var textToFind = NUMBERS[_number][_cat][_name]["value"+j];
+ if (textToFind == undefined)
+ continue;
+
+ for (var i = 0; i < element.options.length; i++) {
+ if (element.options[i].value.toLowerCase() === textToFind.toLowerCase()) {
+ element.selectedIndex = i;
break;
}
}
}
+ else if ((element.getAttribute("type") != null) && (element.getAttribute("type").toLowerCase() == "checkbox")) {
+ element.checked = NUMBERS[_number][_cat][_name]["value"+j] == "true";
+ }
else {
- for (var j = 1; j <= _anzpara; ++j)
- document.getElementById(_cat+"_"+_name+"_value"+j).value = NUMBERS[_number][_cat][_name]["value"+j];
+ element.value = NUMBERS[_number][_cat][_name]["value"+j];
}
}
}
- else
- {
- {
- if (_optional) {
- document.getElementById(_cat+"_"+_name+"_enabled").checked = _param[_cat][_name]["enabled"];
- for (var j = 1; j <= _anzpara; ++j)
- document.getElementById(_cat+"_"+_name+"_value"+j).disabled = !_param[_cat][_name]["enabled"];
- }
- document.getElementById(_cat+"_"+_name+"_text").style="color:black;"
- if (_select) {
- var textToFind;
- textToFind = _param[_cat][_name]["value1"];
- var dd = document.getElementById(_cat+"_"+_name+"_value1");
- for (var i = 0; i < dd.options.length; i++) {
- if (dd.options[i].text.toLowerCase() === textToFind.toLowerCase()) {
- dd.selectedIndex = i;
+ else {
+ if (_optional) {
+ document.getElementById(_cat+"_"+_name+"_enabled").checked = _param[_cat][_name]["enabled"];
+ for (var j = 1; j <= anzpara; ++j) {
+ document.getElementById(_cat+"_"+_name+"_value"+j).disabled = !_param[_cat][_name]["enabled"];
+ }
+ }
+ document.getElementById(_cat+"_"+_name+"_text").style="color:black;"
+ setEnabled(_cat+"_"+_name, true);
+
+ for (var j = 1; j <= anzpara; ++j) {
+ let element = document.getElementById(_cat+"_"+_name+"_value"+j);
+ if (element.tagName.toLowerCase() == "select") {
+ var textToFind = _param[_cat][_name]["value"+j];
+ if (textToFind == undefined)
+ continue;
+
+ for (var i = 0; i < element.options.length; i++) {
+ if (element.options[i].value.toLowerCase() === textToFind.toLowerCase()) {
+ element.selectedIndex = i;
break;
}
}
}
- else {
- for (var j = 1; j <= _anzpara; ++j)
- document.getElementById(_cat+"_"+_name+"_value"+j).value = _param[_cat][_name]["value"+j];
+ else if ((element.getAttribute("type") != null) && (element.getAttribute("type").toLowerCase() == "checkbox")) {
+ element.checked = _param[_cat][_name]["value"+j] == "true";
}
- }
+ else {
+ element.value = _param[_cat][_name]["value"+j];
+ }
+ }
}
///////////////// am Ende, falls Kategorie als gesamtes nicht ausgewählt --> deaktivieren
@@ -819,11 +1462,12 @@ function WriteParameter(_param, _category, _cat, _name, _optional, _select = fal
{
if (_optional) {
document.getElementById(_cat+"_"+_name+"_enabled").disabled = true;
- for (var j = 1; j <= _anzpara; ++j) {
+ for (var j = 1; j <= anzpara; ++j) {
document.getElementById(_cat+"_"+_name+"_value"+j).disabled = true;
}
}
document.getElementById(_cat+"_"+_name+"_text").style="color:lightgrey;"
+ setEnabled(_cat+"_"+_name, false);
}
EnDisableItem(_category[_cat]["enabled"], _param, _category, _cat, _name, _optional);
@@ -843,17 +1487,46 @@ function InvertEnableItem(_cat, _param)
document.getElementById(_zw).disabled = !_isOn;
document.getElementById(_zw).style = _color;
- if (param[_cat][_param]["anzParam"] == 2) {
- _color = "width: 30px;" + _color;
- }
+ setEnabled(_cat + "_" + _param, _isOn);
for (var j = 1; j <= param[_cat][_param]["anzParam"]; ++j) {
document.getElementById(_cat+"_"+_param+"_value"+j).disabled = !_isOn;
document.getElementById(_cat+"_"+_param+"_value"+j).style=_color;
}
+}
-
+function setEnabled(className, enabled) {
+ let elements = document.getElementsByClassName(className);
+ for (i = 0; i < elements.length; i++) {
+ if (enabled) {
+ elements[i].classList.remove("disabled");
+ } else {
+ elements[i].classList.add("disabled");
+ }
+ let inputs = elements[i].getElementsByTagName("input");
+ for (j = 0; j < inputs.length; j++) {
+ if (inputs[j].id.endsWith("_enabled"))
+ continue;
+
+ if (enabled) {
+ inputs[j].removeAttribute("disabled");
+ } else {
+ inputs[j].setAttribute("disabled", "disabled");
+ }
+ }
+ }
+}
+
+function setVisible(className, visible) {
+ let elements = document.getElementsByClassName(className);
+ for (i = 0; i < elements.length; i++) {
+ if (visible) {
+ elements[i].classList.remove("hidden");
+ } else {
+ elements[i].classList.add("hidden");
+ }
+ }
}
function EnDisableItem(_status, _param, _category, _cat, _name, _optional, _number = -1)
@@ -886,53 +1559,75 @@ function EnDisableItem(_status, _param, _category, _cat, _name, _optional, _numb
document.getElementById(_cat+"_"+_name+"_text").disabled = !_status;
document.getElementById(_cat+"_"+_name+"_text").style = _color;
- if (_param[_cat][_name]["anzParam"] == 2) {
- _color = "width: 30px;" + _color;
- }
+ setEnabled(_cat+"_"+_name, _status);
for (var j = 1; j <= _param[_cat][_name]["anzParam"]; ++j) {
document.getElementById(_cat+"_"+_name+"_value"+j).disabled = !_status;
document.getElementById(_cat+"_"+_name+"_value"+j).style=_color;
}
-
}
-function ReadParameter(_param, _cat, _name, _optional, _select = false, _number = -1){
- if (_number > -1)
- {
+function ReadParameter(_param, _cat, _name, _optional, _number = -1){
+ if (_number > -1) {
if (_cat == "Digits")
- _cat = "digit"
+ _cat = "digit";
if (_cat == "Analog")
- _cat = "analog"
+ _cat = "analog";
+
+ if ((NUMBERS[_number] == undefined) || (NUMBERS[_number][_cat] == undefined) || (NUMBERS[_number][_cat][_name] == undefined))
+ return;
+
if (_optional) {
- NUMBERS[_number][_cat][_name]["enabled"] = document.getElementById(_cat+"_"+_name+"_enabled").checked;
+ NUMBERS[_number][_cat][_name]["enabled"] = document.getElementById(_cat+"_"+_name+"_enabled").checked;
}
- if (_select) {
- var sel = document.getElementById(_cat+"_"+_name+"_value1");
- NUMBERS[_number][_cat][_name]["value1"] = sel.options[sel.selectedIndex].text;
- }
- else {
- for (var j = 1; j <= _param[_cat][_name]["anzParam"]; ++j) {
- NUMBERS[_number][_cat][_name]["value"+j] = document.getElementById(_cat+"_"+_name+"_value"+j).value;
+
+ for (var j = 1; j <= _param[_cat][_name]["anzParam"]; ++j) {
+ let element = document.getElementById(_cat+"_"+_name+"_value"+j);
+ if (element.tagName.toLowerCase() == "select") {
+ NUMBERS[_number][_cat][_name]["value"+j] = element.selectedIndex > -1 ? element.options[element.selectedIndex].value : "";
+ }
+ else if ((element.getAttribute("type") != null) && (element.getAttribute("type").toLowerCase() == "checkbox")) {
+ NUMBERS[_number][_cat][_name]["value"+j] = element.checked;
+ }
+ else {
+ if ((NUMBERS[_number][_cat][_name].checkRegExList != null) && (NUMBERS[_number][_cat][_name].checkRegExList[j-1] != null)) {
+ if (!element.value.match(NUMBERS[_cat][_name].checkRegExList[j-1])) {
+ element.classList.add("invalid-input");
+ } else {
+ element.classList.remove("invalid-input");
+ }
+ }
+ NUMBERS[_number][_cat][_name]["value"+j] = element.value;
}
}
}
else
{
if (_optional) {
- _param[_cat][_name]["enabled"] = document.getElementById(_cat+"_"+_name+"_enabled").checked;
+ _param[_cat][_name]["enabled"] = document.getElementById(_cat+"_"+_name+"_enabled").checked;
}
- if (_select) {
- var sel = document.getElementById(_cat+"_"+_name+"_value1");
- _param[_cat][_name]["value1"] = sel.options[sel.selectedIndex].text;
- }
- else {
- for (var j = 1; j <= _param[_cat][_name]["anzParam"]; ++j) {
- _param[_cat][_name]["value"+j] = document.getElementById(_cat+"_"+_name+"_value"+j).value;
+
+ for (var j = 1; j <= _param[_cat][_name]["anzParam"]; ++j) {
+ let element = document.getElementById(_cat+"_"+_name+"_value"+j);
+ if (element.tagName.toLowerCase() == "select") {
+ _param[_cat][_name]["value"+j] = element.selectedIndex > -1 ? element.options[element.selectedIndex].value : "";
}
- }
+ else if ((element.getAttribute("type") != null) && (element.getAttribute("type").toLowerCase() == "checkbox")) {
+ _param[_cat][_name]["value"+j] = element.checked;
+ }
+ else {
+ if ((_param[_cat][_name].checkRegExList != null) && (_param[_cat][_name].checkRegExList[j-1] != null)) {
+ if (!element.value.match(_param[_cat][_name].checkRegExList[j-1])) {
+ element.classList.add("invalid-input");
+ } else {
+ element.classList.remove("invalid-input");
+ }
+ }
+ _param[_cat][_name]["value"+j] = element.value;
+ }
+ }
}
}
@@ -940,20 +1635,22 @@ function UpdateInputIndividual()
{
if (NUNBERSAkt != -1)
{
- ReadParameter(param, "PostProcessing", "DecimalShift", true, false, NUNBERSAkt)
- ReadParameter(param, "PostProcessing", "MaxRateValue", true, false, NUNBERSAkt)
+ ReadParameter(param, "PostProcessing", "DecimalShift", true, NUNBERSAkt)
+ ReadParameter(param, "PostProcessing", "MaxRateValue", true, NUNBERSAkt)
}
var sel = document.getElementById("Numbers_value1");
NUNBERSAkt = sel.selectedIndex;
- WriteParameter(param, category, "PostProcessing", "DecimalShift", true, false, 1, NUNBERSAkt);
- WriteParameter(param, category, "PostProcessing", "MaxRateValue", true, false, 1, NUNBERSAkt);
+ WriteParameter(param, category, "PostProcessing", "DecimalShift", true, NUNBERSAkt);
+ WriteParameter(param, category, "PostProcessing", "MaxRateValue", true, NUNBERSAkt);
}
function UpdateInput() {
document.getElementById("Category_Analog_enabled").checked = category["Analog"]["enabled"];
document.getElementById("Category_Digits_enabled").checked = category["Digits"]["enabled"];
document.getElementById("Category_MQTT_enabled").checked = category["MQTT"]["enabled"];
+ document.getElementById("Category_GPIO_enabled").checked = category["GPIO"]["enabled"];
+ setVisible("GPIO_item", category["GPIO"]["enabled"]);
WriteParameter(param, category, "MakeImage", "LogImageLocation", true);
WriteParameter(param, category, "MakeImage", "LogfileRetentionInDays", true);
@@ -962,46 +1659,54 @@ function UpdateInput() {
WriteParameter(param, category, "MakeImage", "Brightness", false);
// WriteParameter(param, category, "MakeImage", "Contrast", false);
// WriteParameter(param, category, "MakeImage", "Saturation", false);
- WriteParameter(param, category, "MakeImage", "ImageSize", false, true, true);
- WriteParameter(param, category, "MakeImage", "FixedExposure", false, true, true);
+ WriteParameter(param, category, "MakeImage", "ImageSize", false, true);
+ WriteParameter(param, category, "MakeImage", "FixedExposure", false, true);
WriteParameter(param, category, "Alignment", "SearchFieldX", false);
WriteParameter(param, category, "Alignment", "SearchFieldY", false);
- WriteParameter(param, category, "Alignment", "AlignmentAlgo", true, true, true);
+ WriteParameter(param, category, "Alignment", "AlignmentAlgo", true, true);
WriteParameter(param, category, "Digits", "Model", false);
WriteParameter(param, category, "Digits", "LogImageLocation", true);
WriteParameter(param, category, "Digits", "LogfileRetentionInDays", true);
- WriteParameter(param, category, "Digits", "ModelInputSize", false, false, 2);
+ WriteParameter(param, category, "Digits", "ModelInputSize", false);
WriteParameter(param, category, "Analog", "Model", false);
WriteParameter(param, category, "Analog", "LogImageLocation", true);
WriteParameter(param, category, "Analog", "LogfileRetentionInDays", true);
- WriteParameter(param, category, "Analog", "ExtendedResolution", true, true);
- WriteParameter(param, category, "Analog", "ModelInputSize", false, false, 2);
+ WriteParameter(param, category, "Analog", "ExtendedResolution", true);
+ WriteParameter(param, category, "Analog", "ModelInputSize", false);
- WriteParameter(param, category, "PostProcessing", "PreValueUse", true, true);
+ WriteParameter(param, category, "PostProcessing", "PreValueUse", true);
WriteParameter(param, category, "PostProcessing", "PreValueAgeStartup", true);
- WriteParameter(param, category, "PostProcessing", "AllowNegativeRates", true, true);
+ WriteParameter(param, category, "PostProcessing", "AllowNegativeRates", true);
// WriteParameter(param, category, "PostProcessing", "MaxRateValue", true);
- WriteParameter(param, category, "PostProcessing", "ErrorMessage", true, true);
- WriteParameter(param, category, "PostProcessing", "CheckDigitIncreaseConsistency", true, true);
+ WriteParameter(param, category, "PostProcessing", "ErrorMessage", true);
+ WriteParameter(param, category, "PostProcessing", "CheckDigitIncreaseConsistency", true);
WriteParameter(param, category, "MQTT", "Uri", true);
WriteParameter(param, category, "MQTT", "MainTopic", true);
WriteParameter(param, category, "MQTT", "ClientID", true);
WriteParameter(param, category, "MQTT", "user", true);
- WriteParameter(param, category, "MQTT", "password", true);
+ WriteParameter(param, category, "MQTT", "password", true);
+
+ WriteParameter(param, category, "GPIO", "MainTopicMQTT", true);
+ WriteParameter(param, category, "GPIO", "IO0", true);
+ WriteParameter(param, category, "GPIO", "IO1", true);
+ WriteParameter(param, category, "GPIO", "IO3", true);
+ WriteParameter(param, category, "GPIO", "IO4", true);
+ WriteParameter(param, category, "GPIO", "IO12", true);
+ WriteParameter(param, category, "GPIO", "IO13", true);
- WriteParameter(param, category, "AutoTimer", "AutoStart", false, true);
+ WriteParameter(param, category, "AutoTimer", "AutoStart", false);
WriteParameter(param, category, "AutoTimer", "Intervall", false);
- WriteParameter(param, category, "Debug", "Logfile", true, true);
+ WriteParameter(param, category, "Debug", "Logfile", true);
WriteParameter(param, category, "Debug", "LogfileRetentionInDays", true);
WriteParameter(param, category, "System", "TimeZone", true);
WriteParameter(param, category, "System", "Hostname", true);
- WriteParameter(param, category, "System", "TimeServer", true);
+ WriteParameter(param, category, "System", "TimeServer", true);
}
function ReadParameterAll()
@@ -1009,7 +1714,8 @@ function ReadParameterAll()
category["Analog"]["enabled"] = document.getElementById("Category_Analog_enabled").checked;
category["Digits"]["enabled"] = document.getElementById("Category_Digits_enabled").checked;
category["MQTT"]["enabled"] = document.getElementById("Category_MQTT_enabled").checked;
-
+ category["GPIO"]["enabled"] = document.getElementById("Category_GPIO_enabled").checked;
+
ReadParameter(param, "MakeImage", "LogImageLocation", true);
ReadParameter(param, "MakeImage", "LogfileRetentionInDays", true);
ReadParameter(param, "MakeImage", "WaitBeforeTakingPicture", false);
@@ -1017,30 +1723,30 @@ function ReadParameterAll()
ReadParameter(param, "MakeImage", "Brightness", false);
// ReadParameter(param, "MakeImage", "Contrast", false);
// ReadParameter(param, "MakeImage", "Saturation", false);
- ReadParameter(param, "MakeImage", "ImageSize", false, true);
- ReadParameter(param, "MakeImage", "FixedExposure", false, true);
+ ReadParameter(param, "MakeImage", "ImageSize", false);
+ ReadParameter(param, "MakeImage", "FixedExposure", false);
ReadParameter(param, "Alignment", "SearchFieldX", false);
ReadParameter(param, "Alignment", "SearchFieldY", false);
- ReadParameter(param, "Alignment", "AlignmentAlgo", true, true);
+ ReadParameter(param, "Alignment", "AlignmentAlgo", true);
ReadParameter(param, "Digits", "Model", false);
ReadParameter(param, "Digits", "LogImageLocation", true);
ReadParameter(param, "Digits", "LogfileRetentionInDays", true);
- ReadParameter(param, "Digits", "ModelInputSize", false, false);
+ ReadParameter(param, "Digits", "ModelInputSize", false);
ReadParameter(param, "Analog", "Model", false);
ReadParameter(param, "Analog", "LogImageLocation", true);
ReadParameter(param, "Analog", "LogfileRetentionInDays", true);
- ReadParameter(param, "Analog", "ExtendedResolution", true, true);
- ReadParameter(param, "Analog", "ModelInputSize", false, false);
+ ReadParameter(param, "Analog", "ExtendedResolution", true);
+ ReadParameter(param, "Analog", "ModelInputSize", false);
- ReadParameter(param, "PostProcessing", "PreValueUse", true, true);
+ ReadParameter(param, "PostProcessing", "PreValueUse", true);
ReadParameter(param, "PostProcessing", "PreValueAgeStartup", true);
- ReadParameter(param, "PostProcessing", "AllowNegativeRates", true, true);
+ ReadParameter(param, "PostProcessing", "AllowNegativeRates", true);
ReadParameter(param, "PostProcessing", "MaxRateValue", true);
- ReadParameter(param, "PostProcessing", "ErrorMessage", true, true);
- ReadParameter(param, "PostProcessing", "CheckDigitIncreaseConsistency", true, true);
+ ReadParameter(param, "PostProcessing", "ErrorMessage", true);
+ ReadParameter(param, "PostProcessing", "CheckDigitIncreaseConsistency", true);
ReadParameter(param, "MQTT", "Uri", true);
ReadParameter(param, "MQTT", "MainTopic", true);
@@ -1048,10 +1754,18 @@ function ReadParameterAll()
ReadParameter(param, "MQTT", "user", true);
ReadParameter(param, "MQTT", "password", true);
- ReadParameter(param, "AutoTimer", "AutoStart", false, true);
+ ReadParameter(param, "GPIO", "MainTopicMQTT", true);
+ ReadParameter(param, "GPIO", "IO0", true);
+ ReadParameter(param, "GPIO", "IO1", true);
+ ReadParameter(param, "GPIO", "IO3", true);
+ ReadParameter(param, "GPIO", "IO4", true);
+ ReadParameter(param, "GPIO", "IO12", true);
+ ReadParameter(param, "GPIO", "IO13", true);
+
+ ReadParameter(param, "AutoTimer", "AutoStart", false);
ReadParameter(param, "AutoTimer", "Intervall", false);
- ReadParameter(param, "Debug", "Logfile", true, true);
+ ReadParameter(param, "Debug", "Logfile", true);
ReadParameter(param, "Debug", "LogfileRetentionInDays", true);
ReadParameter(param, "System", "TimeZone", true);
@@ -1101,11 +1815,16 @@ function UpdateExpertModus()
for (var i = 0; i < expert.length; i++) {
document.getElementById(expert[i].id).style = _style;
}
-
}
function saveTextAsFile()
{
+ ReadParameterAll();
+ if (document.getElementsByClassName("invalid-input").length > 0) {
+ alert("Settings cannot be saved. Please check your entries.");
+ return;
+ }
+
if (confirm("Are you sure you want to update \"config.ini\"?")) {
ReadParameterAll();
WriteConfigININew();
diff --git a/sd-card/html/gethost.js b/sd-card/html/gethost.js
index d7a4c082..3299486f 100644
--- a/sd-card/html/gethost.js
+++ b/sd-card/html/gethost.js
@@ -5,12 +5,12 @@ function gethost_Version(){
function getbasepath(){
var host = window.location.hostname;
- if ((host == "127.0.0.1") || (host == "localhost"))
+ if ((host == "127.0.0.1") || (host == "localhost") || (host == ""))
{
// host = "http://192.168.2.219"; // jomjol interner test
- host = "http://192.168.178.51"; // jomjol interner test
+// host = "http://192.168.178.46"; // jomjol interner test
// host = "http://192.168.178.22"; // jomjol interner Real
-
+ host = "http://192.168.43.191";
// host = "."; // jomjol interner localhost
}
diff --git a/sd-card/html/readconfigparam.js b/sd-card/html/readconfigparam.js
index 49b0f6ab..0c739e30 100644
--- a/sd-card/html/readconfigparam.js
+++ b/sd-card/html/readconfigparam.js
@@ -70,11 +70,11 @@ function ParseConfig() {
category[catname]["enabled"] = false;
category[catname]["found"] = false;
param[catname] = new Object();
- ParamAddValue(param, catname, "DecimalShift", 1, true);
+ ParamAddValue(param, catname, "DecimalShift", 1);
ParamAddValue(param, catname, "PreValueUse");
ParamAddValue(param, catname, "PreValueAgeStartup");
ParamAddValue(param, catname, "AllowNegativeRates");
- ParamAddValue(param, catname, "MaxRateValue", 1, true);
+ ParamAddValue(param, catname, "MaxRateValue", 1);
ParamAddValue(param, catname, "ErrorMessage");
ParamAddValue(param, catname, "CheckDigitIncreaseConsistency");
@@ -84,10 +84,23 @@ function ParseConfig() {
category[catname]["found"] = false;
param[catname] = new Object();
ParamAddValue(param, catname, "Uri");
- ParamAddValue(param, catname, "MainTopic");
+ ParamAddValue(param, catname, "MainTopic", 1, [/^([a-zA-Z0-9_-]+\/){0,10}[a-zA-Z0-9_-]+$/]);
ParamAddValue(param, catname, "ClientID");
ParamAddValue(param, catname, "user");
- ParamAddValue(param, catname, "password");
+ ParamAddValue(param, catname, "password");
+
+ var catname = "GPIO";
+ category[catname] = new Object();
+ category[catname]["enabled"] = false;
+ category[catname]["found"] = false;
+ param[catname] = new Object();
+ ParamAddValue(param, catname, "MainTopicMQTT", 1, [/^([a-zA-Z0-9_-]+\/){0,10}[a-zA-Z0-9_-]+$/]);
+ ParamAddValue(param, catname, "IO0", 6, [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]);
+ ParamAddValue(param, catname, "IO1", 6, [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]);
+ ParamAddValue(param, catname, "IO3", 6, [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]);
+ ParamAddValue(param, catname, "IO4", 6, [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]);
+ ParamAddValue(param, catname, "IO12", 6, [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]);
+ ParamAddValue(param, catname, "IO13", 6, [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]);
var catname = "AutoTimer";
category[catname] = new Object();
@@ -136,13 +149,13 @@ function ParseConfig() {
}
}
-function ParamAddValue(param, _cat, _param, _anzParam = 1, _isIndividual = false){
+function ParamAddValue(param, _cat, _param, _anzParam = 1, _checkRegExList = null){
param[_cat][_param] = new Object();
param[_cat][_param]["found"] = false;
param[_cat][_param]["enabled"] = false;
param[_cat][_param]["line"] = -1;
- param[_cat][_param]["anzParam"] = _anzParam;
- param[_cat][_param]["Numbers"] = _isIndividual;
+ param[_cat][_param]["anzParam"] = _anzParam;
+ param[_cat][_param].checkRegExList = _checkRegExList;
};
function ParseConfigParamAll(_aktline, _catname){
@@ -188,9 +201,12 @@ function ParamExtractValue(_param, _linesplit, _catname, _paramname, _aktline, _
function ParamExtractValueAll(_param, _linesplit, _catname, _aktline, _iscom){
for (var paramname in _param[_catname]) {
- _param_zw = _linesplit[0].substring(_linesplit[0].length - paramname.length, _linesplit[0].length);
- if ((_param_zw.toUpperCase() == paramname.toUpperCase()) && (_linesplit.length > _param[_catname][paramname]["anzParam"]))
+ if (_linesplit[0].toUpperCase() == paramname.toUpperCase())
{
+ while (_linesplit.length <= _param[_catname][paramname]["anzParam"]) {
+ _linesplit.push("");
+ }
+
_param[_catname][paramname]["found"] = true;
_param[_catname][paramname]["enabled"] = !_iscom;
_param[_catname][paramname]["line"] = _aktline;