mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-08 04:26:58 +03:00
Merge for next Bugfix Release (#1616)
* Fix for securing wlan.ini (#1509) * Fix for securing wlan.ini * Fixing error with ' instead of " * Changing to errorcode 403 * maybe strcmp instead of regular == Co-authored-by: Pär Hedberg <par.hedberg@nordicmedtest.se> * Update Web-Installer * solves #1530 (#1531) * Refactor JSON (#1518) * use correct log level * corrected logging * typo * refactored JSON generagion: removed unused parameters, consolidated into singel function, added "pre" * Wrapped 'rate' into double quotes, like all other JSON values Co-authored-by: CaCO3 <caco@ruinelli.ch> * Various corrections (#1519) * use correct log level * corrected logging * typo * add release to webinstaller * changed logs, added INFO log of raw, value, error * . Co-authored-by: CaCO3 <caco@ruinelli.ch> * Prevent auto restart on cam framebuffer init error (#1522) * use correct log level * revert autorestart on camera framebuffer init error * . Co-authored-by: CaCO3 <caco@ruinelli.ch> * #1524 - ensure the recognized digit is less than 10 (#1525) * fix kernel panic (vector out of range) in getReadoutRawString * fix key of caches * fix key of caches * fix key caches * fix cache keys * fix cache keys * move set variables to top * debug * fix key * testing * try fix changelog * test * Update Changelog.md for release * Revert "Update Changelog.md for release" This reverts commit4f51ec7962. * remove testing * fix release creation * testing * Update Changelog.md for release * test * Revert "Merge branch 'master' of https://github.com/haverland/AI-on-the-edge-device" This reverts commitf68695a4c0, reversing changes made toa096cf7182. * Revert "test" This reverts commita096cf7182. * revert testing * #1524 - ensure the result of ZeigerEvalHybridNeu is <10 * Fix late digit transition #1503 Co-authored-by: github-actions <github-actions@github.com> * fix frozen time in datafile on error (#1534) Co-authored-by: CaCO3 <caco@ruinelli.ch> * log NTP server name (#1497) * log NTP server name * . * . * replace calls to /wasserzaehler.html with calls to /value (#1469) Co-authored-by: CaCO3 <caco@ruinelli.ch> * Fix cookie usage, use correct http response codes, add 404 page (#1495) * replaced some HTTP response code with better matching codes * add custom 404 page, add log entry for debugging * fix cookie * replace non-necessary whitespace * . Co-authored-by: CaCO3 <caco@ruinelli.ch> * Don't autofail if NTP server can't be reached during initalization (#1498) This fixes an issue with a restricted network without internet access, where the hardcoded ntp server can't be reached and thus the esp resets, as it's not able to finish initalization. * Update Changelog.md * Update Changelog.md for release * Fix for securing wlan.ini (#1509) * Fix for securing wlan.ini * Fixing error with ' instead of " * Changing to errorcode 403 * maybe strcmp instead of regular == Co-authored-by: Pär Hedberg <par.hedberg@nordicmedtest.se> * Update Web-Installer * solves #1530 (#1531) * Refactor JSON (#1518) * use correct log level * corrected logging * typo * refactored JSON generagion: removed unused parameters, consolidated into singel function, added "pre" * Wrapped 'rate' into double quotes, like all other JSON values Co-authored-by: CaCO3 <caco@ruinelli.ch> * Various corrections (#1519) * use correct log level * corrected logging * typo * add release to webinstaller * changed logs, added INFO log of raw, value, error * . Co-authored-by: CaCO3 <caco@ruinelli.ch> * Prevent auto restart on cam framebuffer init error (#1522) * use correct log level * revert autorestart on camera framebuffer init error * . Co-authored-by: CaCO3 <caco@ruinelli.ch> * #1524 - ensure the recognized digit is less than 10 (#1525) * fix kernel panic (vector out of range) in getReadoutRawString * fix key of caches * fix key of caches * fix key caches * fix cache keys * fix cache keys * move set variables to top * debug * fix key * testing * try fix changelog * test * Update Changelog.md for release * Revert "Update Changelog.md for release" This reverts commit4f51ec7962. * remove testing * fix release creation * testing * Update Changelog.md for release * test * Revert "Merge branch 'master' of https://github.com/haverland/AI-on-the-edge-device" This reverts commitf68695a4c0, reversing changes made toa096cf7182. * Revert "test" This reverts commita096cf7182. * revert testing * #1524 - ensure the result of ZeigerEvalHybridNeu is <10 * Fix late digit transition #1503 Co-authored-by: github-actions <github-actions@github.com> * only use sntp_getservername() after init sntp * set default NTP server on dnew installations Co-authored-by: CaCO3 <caco@ruinelli.ch> Co-authored-by: Ralf Rachinger <git@ralfrachinger.de> Co-authored-by: jomjol <30766535+jomjol@users.noreply.github.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: parhedberg <par.hedberg@gmail.com> Co-authored-by: Pär Hedberg <par.hedberg@nordicmedtest.se> Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Co-authored-by: Frank Haverland <fspapaping@googlemail.com> * Renamed variables and added debug log (#1537) * add debug logs * renamed variables * renamed TAGs, added flow status logging * . * . Co-authored-by: CaCO3 <caco@ruinelli.ch> * replaced printf usage in LogFile.WriteToFile() * ENABLE_MQTT c++ macro definition (#1546) * macro * 2 * 2 * delete jomjol_mqtt from CMakeLists * mqtt macro * final * ENABLE_INFLUXDB c++ macro definition (#1547) * macro * 2 * 2 * delete jomjol_mqtt from CMakeLists * mqtt macro * final * ENABLE_INFLUXDB c++ macro definition * Update Changelog.md * Update Changelog.md * Rearange task to CPU (http, camera, mqtt) (#1557) * Streamlined MQTT interlock when not activated & interlock MQTT when WIFI is not connected (#1556) * streamlined mqtt interlock when disabled * Disconnect mqtt client before reboot * Interlock MQTT with WIFI * Update * loglevel to DEBUG * Update * mqtt msg id incremental * new ENABLE_MQTT includes * Loglevel to DEBUG * Loglevel * Update interface_mqtt.cpp * show uptime on overview page, moved labels from firmware to Web UI (#1543) * show uptime on overview page, moved labels from firmware to Web UI * show uptime on info page * also use formated time in log Co-authored-by: CaCO3 <caco@ruinelli.ch> * Continue boot on bad PSRAM (#1558) * add sensor status, show special index/setup page in case of a critical error * continue booting on PSRAM error * Update main.cpp added log messages * init PSRAM and add more log messages * cleanup of init checks * . * . * . Co-authored-by: CaCO3 <caco@ruinelli.ch> * add sensor status, show special index/setup page in case of a critical error (#1560) * add sensor status, show special index/setup page in case of a critical error * Added Reboot * . * added more buttons Co-authored-by: CaCO3 <caco@ruinelli.ch> Co-authored-by: jomjol <30766535+jomjol@users.noreply.github.com> * Update Webinstaller to v13.0.7 * remove html-from-11.3.1 in release (#1565) * fix kernel panic (vector out of range) in getReadoutRawString * fix key of caches * fix key of caches * fix key caches * fix cache keys * fix cache keys * move set variables to top * debug * fix key * testing * try fix changelog * test * Update Changelog.md for release * Revert "Update Changelog.md for release" This reverts commit4f51ec7962. * remove testing * fix release creation * testing * Update Changelog.md for release * test * Revert "Merge branch 'master' of https://github.com/haverland/AI-on-the-edge-device" This reverts commitf68695a4c0, reversing changes made toa096cf7182. * Revert "test" This reverts commita096cf7182. * revert testing * #1524 - ensure the result of ZeigerEvalHybridNeu is <10 * Fix late digit transition #1503 * only initial_esp32_setup and update.zip as artefacts * remove unneeded cache * rename step ota-v2 to ota * rename ota-v2 to ota Co-authored-by: github-actions <github-actions@github.com> * make the sidebar on the overviw page wider and show the round counter (#1570) Co-authored-by: CaCO3 <caco@ruinelli.ch> * Create reply-bot.yml * Update ClassFlowPostProcessing.cpp * Add bot (#1581) * Update reply-bot.yml * Create label-commenter-config.yml * added missing html change * extended instructions (#1583) Co-authored-by: CaCO3 <caco@ruinelli.ch> * Fix Rate Problem * removed redundant "Status:" * Bugfix Double Extract ZIP-Files * Update FeatureRequest.md (#1591) in case of position change between the measurments set this state to true, if there is no change set it back to false. In a defined time window this movement can lead into an alarm state / water leak.. haveing this state in the mqtt broker can trigger functions like closing the ater pipe walve and so on... * Update manifest.json * Delete .gitignore * Delete .gitmodules * Delete firmware.bin * Add files via upload * Block REST API calls till resource is ready (#1609) * Block REST API call till ressource is ready * Update * Update * Update * replace relative include of gethost.js with absolute one. This is needed as that file gets incuded on dynamically generated content which can be on different path levels (#1610) Co-authored-by: CaCO3 <caco@ruinelli.ch> * esp_spiram.h has been replaced by esp32/spiram.h (#1605) * esp_spiram.h has been replaced by esp32/spiram.h * Preparations for next Bugfix Release (#1615) * Merge branch 'rolling' (#1559) * Fix for securing wlan.ini (#1509) * Fix for securing wlan.ini * Fixing error with ' instead of " * Changing to errorcode 403 * maybe strcmp instead of regular == Co-authored-by: Pär Hedberg <par.hedberg@nordicmedtest.se> * Update Web-Installer * solves #1530 (#1531) * Refactor JSON (#1518) * use correct log level * corrected logging * typo * refactored JSON generagion: removed unused parameters, consolidated into singel function, added "pre" * Wrapped 'rate' into double quotes, like all other JSON values Co-authored-by: CaCO3 <caco@ruinelli.ch> * Various corrections (#1519) * use correct log level * corrected logging * typo * add release to webinstaller * changed logs, added INFO log of raw, value, error * . Co-authored-by: CaCO3 <caco@ruinelli.ch> * Prevent auto restart on cam framebuffer init error (#1522) * use correct log level * revert autorestart on camera framebuffer init error * . Co-authored-by: CaCO3 <caco@ruinelli.ch> * #1524 - ensure the recognized digit is less than 10 (#1525) * fix kernel panic (vector out of range) in getReadoutRawString * fix key of caches * fix key of caches * fix key caches * fix cache keys * fix cache keys * move set variables to top * debug * fix key * testing * try fix changelog * test * Update Changelog.md for release * Revert "Update Changelog.md for release" This reverts commit4f51ec7962. * remove testing * fix release creation * testing * Update Changelog.md for release * test * Revert "Merge branch 'master' of https://github.com/haverland/AI-on-the-edge-device" This reverts commitf68695a4c0, reversing changes made toa096cf7182. * Revert "test" This reverts commita096cf7182. * revert testing * #1524 - ensure the result of ZeigerEvalHybridNeu is <10 * Fix late digit transition #1503 Co-authored-by: github-actions <github-actions@github.com> * fix frozen time in datafile on error (#1534) Co-authored-by: CaCO3 <caco@ruinelli.ch> * log NTP server name (#1497) * log NTP server name * . * . * replace calls to /wasserzaehler.html with calls to /value (#1469) Co-authored-by: CaCO3 <caco@ruinelli.ch> * Fix cookie usage, use correct http response codes, add 404 page (#1495) * replaced some HTTP response code with better matching codes * add custom 404 page, add log entry for debugging * fix cookie * replace non-necessary whitespace * . Co-authored-by: CaCO3 <caco@ruinelli.ch> * Don't autofail if NTP server can't be reached during initalization (#1498) This fixes an issue with a restricted network without internet access, where the hardcoded ntp server can't be reached and thus the esp resets, as it's not able to finish initalization. * Update Changelog.md * Update Changelog.md for release * Fix for securing wlan.ini (#1509) * Fix for securing wlan.ini * Fixing error with ' instead of " * Changing to errorcode 403 * maybe strcmp instead of regular == Co-authored-by: Pär Hedberg <par.hedberg@nordicmedtest.se> * Update Web-Installer * solves #1530 (#1531) * Refactor JSON (#1518) * use correct log level * corrected logging * typo * refactored JSON generagion: removed unused parameters, consolidated into singel function, added "pre" * Wrapped 'rate' into double quotes, like all other JSON values Co-authored-by: CaCO3 <caco@ruinelli.ch> * Various corrections (#1519) * use correct log level * corrected logging * typo * add release to webinstaller * changed logs, added INFO log of raw, value, error * . Co-authored-by: CaCO3 <caco@ruinelli.ch> * Prevent auto restart on cam framebuffer init error (#1522) * use correct log level * revert autorestart on camera framebuffer init error * . Co-authored-by: CaCO3 <caco@ruinelli.ch> * #1524 - ensure the recognized digit is less than 10 (#1525) * fix kernel panic (vector out of range) in getReadoutRawString * fix key of caches * fix key of caches * fix key caches * fix cache keys * fix cache keys * move set variables to top * debug * fix key * testing * try fix changelog * test * Update Changelog.md for release * Revert "Update Changelog.md for release" This reverts commit4f51ec7962. * remove testing * fix release creation * testing * Update Changelog.md for release * test * Revert "Merge branch 'master' of https://github.com/haverland/AI-on-the-edge-device" This reverts commitf68695a4c0, reversing changes made toa096cf7182. * Revert "test" This reverts commita096cf7182. * revert testing * #1524 - ensure the result of ZeigerEvalHybridNeu is <10 * Fix late digit transition #1503 Co-authored-by: github-actions <github-actions@github.com> * only use sntp_getservername() after init sntp * set default NTP server on dnew installations Co-authored-by: CaCO3 <caco@ruinelli.ch> Co-authored-by: Ralf Rachinger <git@ralfrachinger.de> Co-authored-by: jomjol <30766535+jomjol@users.noreply.github.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: parhedberg <par.hedberg@gmail.com> Co-authored-by: Pär Hedberg <par.hedberg@nordicmedtest.se> Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Co-authored-by: Frank Haverland <fspapaping@googlemail.com> * Renamed variables and added debug log (#1537) * add debug logs * renamed variables * renamed TAGs, added flow status logging * . * . Co-authored-by: CaCO3 <caco@ruinelli.ch> * replaced printf usage in LogFile.WriteToFile() * ENABLE_MQTT c++ macro definition (#1546) * macro * 2 * 2 * delete jomjol_mqtt from CMakeLists * mqtt macro * final * ENABLE_INFLUXDB c++ macro definition (#1547) * macro * 2 * 2 * delete jomjol_mqtt from CMakeLists * mqtt macro * final * ENABLE_INFLUXDB c++ macro definition * Update Changelog.md Co-authored-by: parhedberg <par.hedberg@gmail.com> Co-authored-by: Pär Hedberg <par.hedberg@nordicmedtest.se> Co-authored-by: jomjol <30766535+jomjol@users.noreply.github.com> Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Co-authored-by: CaCO3 <caco@ruinelli.ch> Co-authored-by: Frank Haverland <fspapaping@googlemail.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Ralf Rachinger <git@ralfrachinger.de> Co-authored-by: Nicolas Liaudat <nliaudat@users.noreply.github.com> * Update Changelog.md for release Co-authored-by: parhedberg <par.hedberg@gmail.com> Co-authored-by: Pär Hedberg <par.hedberg@nordicmedtest.se> Co-authored-by: jomjol <30766535+jomjol@users.noreply.github.com> Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Co-authored-by: CaCO3 <caco@ruinelli.ch> Co-authored-by: Frank Haverland <fspapaping@googlemail.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Ralf Rachinger <git@ralfrachinger.de> Co-authored-by: Nicolas Liaudat <nliaudat@users.noreply.github.com> * new model version (#1619) * fix kernel panic (vector out of range) in getReadoutRawString * fix key of caches * fix key of caches * fix key caches * fix cache keys * fix cache keys * move set variables to top * debug * fix key * testing * try fix changelog * test * Update Changelog.md for release * Revert "Update Changelog.md for release" This reverts commit4f51ec7962. * remove testing * fix release creation * testing * Update Changelog.md for release * test * Revert "Merge branch 'master' of https://github.com/haverland/AI-on-the-edge-device" This reverts commitf68695a4c0, reversing changes made toa096cf7182. * Revert "test" This reverts commita096cf7182. * revert testing * #1524 - ensure the result of ZeigerEvalHybridNeu is <10 * Fix late digit transition #1503 * only initial_esp32_setup and update.zip as artefacts * remove unneeded cache * rename step ota-v2 to ota * rename ota-v2 to ota * new models - ana-class100 v1.5.4 - ana-cont-11.0.4 - dig-class100 v1.5.0 Co-authored-by: github-actions <github-actions@github.com> * Update Changelog.md (#1630) * Correct RenameNumber * Update Changelog.md * Fix reloading of data file (#1635) * Update data.html * fixed * show link to graph Co-authored-by: CaCO3 <caco@ruinelli.ch> Co-authored-by: parhedberg <par.hedberg@gmail.com> Co-authored-by: Pär Hedberg <par.hedberg@nordicmedtest.se> Co-authored-by: jomjol <30766535+jomjol@users.noreply.github.com> Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Co-authored-by: CaCO3 <caco@ruinelli.ch> Co-authored-by: Frank Haverland <fspapaping@googlemail.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Ralf Rachinger <git@ralfrachinger.de> Co-authored-by: Nicolas Liaudat <nliaudat@users.noreply.github.com> Co-authored-by: Slider0007 <115730895+Slider0007@users.noreply.github.com> Co-authored-by: smartboart <38385805+smartboart@users.noreply.github.com>
This commit is contained in:
@@ -164,6 +164,7 @@ static size_t jpg_encode_stream(void * arg, size_t index, const void* data, size
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
bool CCamera::SetBrightnessContrastSaturation(int _brightness, int _contrast, int _saturation)
|
||||
{
|
||||
bool result = false;
|
||||
@@ -281,7 +282,6 @@ void CCamera::EnableAutoExposure(int flashdauer)
|
||||
}
|
||||
|
||||
|
||||
|
||||
esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay)
|
||||
{
|
||||
string ftype;
|
||||
@@ -543,6 +543,7 @@ esp_err_t CCamera::CaptureToHTTP(httpd_req_t *req, int delay)
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void CCamera::LightOnOff(bool status)
|
||||
{
|
||||
GpioHandler* gpioHandler = gpio_handler_get();
|
||||
@@ -578,6 +579,7 @@ void CCamera::LightOnOff(bool status)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CCamera::LEDOnOff(bool status)
|
||||
{
|
||||
// Init the GPIO
|
||||
@@ -638,6 +640,7 @@ void CCamera::GetCameraParameter(httpd_req_t *req, int &qual, framesize_t &resol
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
framesize_t CCamera::TextToFramesize(const char * _size)
|
||||
{
|
||||
if (strcmp(_size, "QVGA") == 0)
|
||||
@@ -669,6 +672,7 @@ CCamera::CCamera()
|
||||
ledc_init();
|
||||
}
|
||||
|
||||
|
||||
esp_err_t CCamera::InitCam()
|
||||
{
|
||||
ESP_LOGD(TAG, "Init Camera");
|
||||
@@ -682,9 +686,11 @@ esp_err_t CCamera::InitCam()
|
||||
return err;
|
||||
}
|
||||
|
||||
CameraInitSuccessful = true;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
void CCamera::SetLEDIntensity(float _intrel)
|
||||
{
|
||||
_intrel = min(_intrel, (float) 100);
|
||||
@@ -694,3 +700,9 @@ void CCamera::SetLEDIntensity(float _intrel)
|
||||
ESP_LOGD(TAG, "Set led_intensity to %d of 8191", led_intensity);
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool CCamera::getCameraInitSuccessful()
|
||||
{
|
||||
return CameraInitSuccessful;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ class CCamera {
|
||||
int led_intensity = 4095;
|
||||
|
||||
void ledc_init(void);
|
||||
bool CameraInitSuccessful = false;
|
||||
|
||||
public:
|
||||
int image_height, image_width;
|
||||
@@ -42,6 +43,7 @@ class CCamera {
|
||||
void SetLEDIntensity(float _intrel);
|
||||
|
||||
void EnableAutoExposure(int flashdauer);
|
||||
bool getCameraInitSuccessful();
|
||||
|
||||
|
||||
framesize_t TextToFramesize(const char * text);
|
||||
|
||||
@@ -17,7 +17,8 @@ char scratch2[SCRATCH_BUFSIZE2];
|
||||
//#define DEBUG_DETAIL_ON
|
||||
|
||||
|
||||
void PowerResetCamera(){
|
||||
void PowerResetCamera()
|
||||
{
|
||||
ESP_LOGD(TAG, "Resetting camera by power down line");
|
||||
gpio_config_t conf;
|
||||
conf.intr_type = GPIO_INTR_DISABLE;
|
||||
@@ -37,182 +38,223 @@ void PowerResetCamera(){
|
||||
|
||||
esp_err_t handler_lightOn(httpd_req_t *req)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_lightOn - Start");
|
||||
ESP_LOGD(TAG, "handler_lightOn uri: %s", req->uri);
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_lightOn - Start");
|
||||
ESP_LOGD(TAG, "handler_lightOn uri: %s", req->uri);
|
||||
#endif
|
||||
|
||||
Camera.LightOnOff(true);
|
||||
const char* resp_str = (const char*) req->user_ctx;
|
||||
httpd_resp_send(req, resp_str, strlen(resp_str));
|
||||
if (Camera.getCameraInitSuccessful())
|
||||
{
|
||||
Camera.LightOnOff(true);
|
||||
const char* resp_str = (const char*) req->user_ctx;
|
||||
httpd_resp_send(req, resp_str, strlen(resp_str));
|
||||
}
|
||||
else
|
||||
{
|
||||
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera Light On API not yet initialized. Please retry later...");
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_lightOn - Done");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_lightOn - Done");
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
esp_err_t handler_lightOff(httpd_req_t *req)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_lightOff - Start");
|
||||
ESP_LOGD(TAG, "handler_lightOff uri: %s", req->uri);
|
||||
#endif
|
||||
Camera.LightOnOff(false);
|
||||
const char* resp_str = (const char*) req->user_ctx;
|
||||
httpd_resp_send(req, resp_str, strlen(resp_str));
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_lightOff - Start");
|
||||
ESP_LOGD(TAG, "handler_lightOff uri: %s", req->uri);
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_lightOff - Done");
|
||||
#endif
|
||||
if (Camera.getCameraInitSuccessful())
|
||||
{
|
||||
Camera.LightOnOff(false);
|
||||
const char* resp_str = (const char*) req->user_ctx;
|
||||
httpd_resp_send(req, resp_str, strlen(resp_str));
|
||||
}
|
||||
else
|
||||
{
|
||||
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera Light Off API not yet initialized. Please retry later...");
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_lightOff - Done");
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
esp_err_t handler_capture(httpd_req_t *req)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_capture - Start");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_capture - Start");
|
||||
#endif
|
||||
|
||||
int quality;
|
||||
framesize_t res;
|
||||
if (Camera.getCameraInitSuccessful())
|
||||
{
|
||||
int quality;
|
||||
framesize_t res;
|
||||
|
||||
Camera.GetCameraParameter(req, quality, res);
|
||||
Camera.GetCameraParameter(req, quality, res);
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Size: %d, Quality: %d", res, quality);
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Size: %d, Quality: %d", res, quality);
|
||||
#endif
|
||||
|
||||
Camera.SetQualitySize(quality, res);
|
||||
Camera.SetQualitySize(quality, res);
|
||||
|
||||
esp_err_t ressult;
|
||||
ressult = Camera.CaptureToHTTP(req);
|
||||
esp_err_t result;
|
||||
result = Camera.CaptureToHTTP(req);
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_capture - Done");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_capture - Done");
|
||||
#endif
|
||||
|
||||
return ressult;
|
||||
};
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera Capture API not yet initialized. Please retry later...");
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
esp_err_t handler_capture_with_ligth(httpd_req_t *req)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_capture_with_ligth - Start");
|
||||
#endif
|
||||
char _query[100];
|
||||
char _delay[10];
|
||||
|
||||
int quality;
|
||||
framesize_t res;
|
||||
int delay = 2500;
|
||||
|
||||
if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_capture_with_ligth - Start");
|
||||
#endif
|
||||
|
||||
if (Camera.getCameraInitSuccessful())
|
||||
{
|
||||
ESP_LOGD(TAG, "Query: %s", _query);
|
||||
if (httpd_query_key_value(_query, "delay", _delay, 10) == ESP_OK)
|
||||
char _query[100];
|
||||
char _delay[10];
|
||||
|
||||
int quality;
|
||||
framesize_t res;
|
||||
int delay = 2500;
|
||||
|
||||
if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Delay: %s", _delay);
|
||||
#endif
|
||||
delay = atoi(_delay);
|
||||
ESP_LOGD(TAG, "Query: %s", _query);
|
||||
if (httpd_query_key_value(_query, "delay", _delay, 10) == ESP_OK)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Delay: %s", _delay);
|
||||
#endif
|
||||
delay = atoi(_delay);
|
||||
|
||||
if (delay < 0)
|
||||
delay = 0;
|
||||
if (delay < 0)
|
||||
delay = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Camera.GetCameraParameter(req, quality, res);
|
||||
Camera.GetCameraParameter(req, quality, res);
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Size: %d, Quality: %d", res, quality);
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Size: %d, Quality: %d", res, quality);
|
||||
#endif
|
||||
|
||||
Camera.SetQualitySize(quality, res);
|
||||
Camera.LightOnOff(true);
|
||||
const TickType_t xDelay = delay / portTICK_PERIOD_MS;
|
||||
vTaskDelay( xDelay );
|
||||
Camera.SetQualitySize(quality, res);
|
||||
Camera.LightOnOff(true);
|
||||
const TickType_t xDelay = delay / portTICK_PERIOD_MS;
|
||||
vTaskDelay( xDelay );
|
||||
|
||||
esp_err_t ressult;
|
||||
ressult = Camera.CaptureToHTTP(req);
|
||||
esp_err_t result;
|
||||
result = Camera.CaptureToHTTP(req);
|
||||
|
||||
Camera.LightOnOff(false);
|
||||
Camera.LightOnOff(false);
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_capture_with_ligth - Done");
|
||||
#endif
|
||||
|
||||
return ressult;
|
||||
};
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_capture_with_ligth - Done");
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera Capture + flashlight API not yet initialized. Please retry later...");
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
esp_err_t handler_capture_save_to_file(httpd_req_t *req)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_capture_save_to_file - Start");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_capture_save_to_file - Start");
|
||||
#endif
|
||||
|
||||
char _query[100];
|
||||
char _delay[10];
|
||||
int delay = 0;
|
||||
char filename[100];
|
||||
std::string fn = "/sdcard/";
|
||||
|
||||
|
||||
int quality;
|
||||
framesize_t res;
|
||||
|
||||
if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
|
||||
if (Camera.getCameraInitSuccessful())
|
||||
{
|
||||
ESP_LOGD(TAG, "Query: %s", _query);
|
||||
if (httpd_query_key_value(_query, "filename", filename, 100) == ESP_OK)
|
||||
char _query[100];
|
||||
char _delay[10];
|
||||
int delay = 0;
|
||||
char filename[100];
|
||||
std::string fn = "/sdcard/";
|
||||
|
||||
|
||||
int quality;
|
||||
framesize_t res;
|
||||
|
||||
if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
|
||||
{
|
||||
fn.append(filename);
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Filename: %s", fn.c_str());
|
||||
#endif
|
||||
ESP_LOGD(TAG, "Query: %s", _query);
|
||||
if (httpd_query_key_value(_query, "filename", filename, 100) == ESP_OK)
|
||||
{
|
||||
fn.append(filename);
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Filename: %s", fn.c_str());
|
||||
#endif
|
||||
}
|
||||
else
|
||||
fn.append("noname.jpg");
|
||||
|
||||
if (httpd_query_key_value(_query, "delay", _delay, 10) == ESP_OK)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Delay: %s", _delay);
|
||||
#endif
|
||||
delay = atoi(_delay);
|
||||
|
||||
if (delay < 0)
|
||||
delay = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
fn.append("noname.jpg");
|
||||
|
||||
if (httpd_query_key_value(_query, "delay", _delay, 10) == ESP_OK)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Delay: %s", _delay);
|
||||
#endif
|
||||
delay = atoi(_delay);
|
||||
Camera.GetCameraParameter(req, quality, res);
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Size: %d, Quality: %d", res, quality);
|
||||
#endif
|
||||
Camera.SetQualitySize(quality, res);
|
||||
|
||||
if (delay < 0)
|
||||
delay = 0;
|
||||
}
|
||||
esp_err_t result;
|
||||
result = Camera.CaptureToFile(fn, delay);
|
||||
|
||||
const char* resp_str = (const char*) fn.c_str();
|
||||
httpd_resp_send(req, resp_str, strlen(resp_str));
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_capture_save_to_file - Done");
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
else
|
||||
fn.append("noname.jpg");
|
||||
|
||||
Camera.GetCameraParameter(req, quality, res);
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Size: %d, Quality: %d", res, quality);
|
||||
#endif
|
||||
Camera.SetQualitySize(quality, res);
|
||||
|
||||
esp_err_t ressult;
|
||||
ressult = Camera.CaptureToFile(fn, delay);
|
||||
|
||||
const char* resp_str = (const char*) fn.c_str();
|
||||
httpd_resp_send(req, resp_str, strlen(resp_str));
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_capture_save_to_file - Done");
|
||||
#endif
|
||||
|
||||
return ressult;
|
||||
};
|
||||
|
||||
else
|
||||
{
|
||||
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera Capture + save API not yet initialized. Please retry later...");
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void register_server_camera_uri(httpd_handle_t server)
|
||||
|
||||
@@ -935,7 +935,11 @@ std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::st
|
||||
|
||||
// Get and print information about each file in the archive.
|
||||
int numberoffiles = (int)mz_zip_reader_get_num_files(&zip_archive);
|
||||
for (sort_iter = 0; sort_iter < 2; sort_iter++)
|
||||
ESP_LOGI(TAG, "Numbers of files to be extrated: %d", numberoffiles);
|
||||
|
||||
|
||||
sort_iter = 0;
|
||||
// for (sort_iter = 0; sort_iter < 2; sort_iter++)
|
||||
{
|
||||
memset(&zip_archive, 0, sizeof(zip_archive));
|
||||
status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), sort_iter ? MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY : 0);
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
#include "server_tflite.h"
|
||||
#include "server_file.h"
|
||||
#include "server_GPIO.h"
|
||||
#ifdef ENABLE_MQTT
|
||||
#include "interface_mqtt.h"
|
||||
#endif //ENABLE_MQTT
|
||||
|
||||
|
||||
#include "ClassLogFile.h"
|
||||
@@ -55,6 +58,18 @@ esp_err_t handler_reboot(httpd_req_t *req);
|
||||
std::string _file_name_update;
|
||||
|
||||
|
||||
|
||||
static void infinite_loop(void)
|
||||
{
|
||||
int i = 0;
|
||||
ESP_LOGI(TAG, "When a new firmware is available on the server, press the reset button to download it");
|
||||
while(1) {
|
||||
ESP_LOGI(TAG, "Waiting for a new firmware... %d", ++i);
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void task_do_Update_ZIP(void *pvParameter)
|
||||
{
|
||||
std::string filetype = toUpper(getFileType(_file_name_update));
|
||||
@@ -107,26 +122,14 @@ void CheckUpdate()
|
||||
BaseType_t xReturned;
|
||||
int _i = configMINIMAL_STACK_SIZE;
|
||||
xReturned = xTaskCreate(&task_do_Update_ZIP, "task_do_Update_ZIP", configMINIMAL_STACK_SIZE * 35, NULL, tskIDLE_PRIORITY+1, NULL);
|
||||
TickType_t xDelay;
|
||||
xDelay = 2000000 / portTICK_PERIOD_MS;
|
||||
ESP_LOGD(TAG, "Wait for Update to be finished: sleep for: %ldms", (long) xDelay);
|
||||
vTaskDelay( xDelay );
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void infinite_loop(void)
|
||||
{
|
||||
int i = 0;
|
||||
ESP_LOGI(TAG, "When a new firmware is available on the server, press the reset button to download it");
|
||||
while(1) {
|
||||
ESP_LOGI(TAG, "Waiting for a new firmware... %d", ++i);
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
while(1) { // wait until reboot within task_do_Update_ZIP
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static bool ota_update_task(std::string fn)
|
||||
{
|
||||
esp_err_t err;
|
||||
@@ -601,6 +604,9 @@ void doReboot(){
|
||||
xTaskCreate(&task_reboot, "reboot", configMINIMAL_STACK_SIZE * 64, NULL, 10, NULL);
|
||||
// KillTFliteTasks(); // kills itself
|
||||
gpio_handler_destroy();
|
||||
#ifdef ENABLE_MQTT
|
||||
MQTTdestroy_client();
|
||||
#endif //ENABLE_MQTT
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
hard_restart();
|
||||
|
||||
@@ -93,7 +93,7 @@ void ClassFlowImage::RemoveOldLogs()
|
||||
if (!isLogImage)
|
||||
return;
|
||||
|
||||
ESP_LOGI(TAG, "remove old images");
|
||||
ESP_LOGD(TAG, "remove old images");
|
||||
if (logfileRetentionInDays == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -132,7 +132,7 @@ void ClassFlowImage::RemoveOldLogs()
|
||||
}
|
||||
}
|
||||
}
|
||||
ESP_LOGI(TAG, "Image folder deleted: %d | Image folder not deleted: %d", deleted, notDeleted);
|
||||
ESP_LOGD(TAG, "Image folder deleted: %d | Image folder not deleted: %d", deleted, notDeleted);
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
|
||||
@@ -189,36 +189,26 @@ string ClassFlowMQTT::GetMQTTMainTopic()
|
||||
}
|
||||
|
||||
|
||||
bool ClassFlowMQTT::Start(float AutoIntervall) {
|
||||
|
||||
// printf("URI: %s, MAINTOPIC: %s", uri.c_str(), maintopic.c_str());
|
||||
|
||||
if ((uri.length() == 0) || (maintopic.length() == 0))
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "MQTT not started because URI or Maintopic is not set. MQTT will be disabled.");
|
||||
MQTTdisable();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ClassFlowMQTT::Start(float AutoIntervall)
|
||||
{
|
||||
roundInterval = AutoIntervall; // Minutes
|
||||
keepAlive = roundInterval * 60 * 2.5; // Seconds, make sure it is greater thatn 2 rounds!
|
||||
|
||||
std::stringstream stream;
|
||||
stream << std::fixed << std::setprecision(1) << "Digitizer interval is " << roundInterval <<
|
||||
" minutes => setting MQTT LWT timeout to " << ((float)keepAlive/60) << " minutes.";
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, stream.str());
|
||||
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, stream.str());
|
||||
|
||||
mqttServer_setParameter(flowpostprocessing->GetNumbers(), keepAlive, roundInterval);
|
||||
|
||||
MQTT_Configure(uri, clientname, user, password, maintopic, LWT_TOPIC, LWT_CONNECTED, LWT_DISCONNECTED,
|
||||
keepAlive, SetRetainFlag, (void *)&GotConnected);
|
||||
bool MQTTConfigCheck = MQTT_Configure(uri, clientname, user, password, maintopic, LWT_TOPIC, LWT_CONNECTED,
|
||||
LWT_DISCONNECTED, keepAlive, SetRetainFlag, (void *)&GotConnected);
|
||||
|
||||
if (!MQTT_Init()) {
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Init at startup failed! Retry with next publish call");
|
||||
if (!MQTTConfigCheck) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return (MQTT_Init() == 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -237,7 +227,7 @@ bool ClassFlowMQTT::doFlow(string zwtime)
|
||||
|
||||
publishSystemData();
|
||||
|
||||
if (flowpostprocessing)
|
||||
if (flowpostprocessing && getMQTTisConnected())
|
||||
{
|
||||
std::vector<NumberPost*>* NUMBERS = flowpostprocessing->GetNumbers();
|
||||
|
||||
|
||||
@@ -707,6 +707,8 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
|
||||
NUMBERS[j]->ReturnValue = "";
|
||||
NUMBERS[j]->ErrorMessageText = "";
|
||||
NUMBERS[j]->Value = -1;
|
||||
/* TODO to be discussed, see https://github.com/jomjol/AI-on-the-edge-device/issues/1617 */
|
||||
// NUMBERS[j]->lastvalue = imagetime; // must only be set in case of good value !!! --> move to the end
|
||||
NUMBERS[j]->lastvalue = imagetime;
|
||||
|
||||
UpdateNachkommaDecimalShift();
|
||||
@@ -764,6 +766,9 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
|
||||
{
|
||||
string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw);
|
||||
/* TODO to be discussed, see https://github.com/jomjol/AI-on-the-edge-device/issues/1617 */
|
||||
NUMBERS[j]->lastvalue = imagetime;
|
||||
|
||||
WriteDataLog(j);
|
||||
continue; // es gibt keinen Zahl, da noch ein N vorhanden ist.
|
||||
}
|
||||
@@ -848,7 +853,9 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
|
||||
|
||||
if (abs(_ratedifference) > abs(NUMBERS[j]->MaxRateValue))
|
||||
{
|
||||
NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Rate too high - Read: " + RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
|
||||
WriteDataLog(j);
|
||||
|
||||
NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Rate too high - Read: " + RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " - Rate: " + RundeOutput(_ratedifference, NUMBERS[j]->Nachkomma);
|
||||
NUMBERS[j]->Value = NUMBERS[j]->PreValue;
|
||||
NUMBERS[j]->ReturnValue = "";
|
||||
NUMBERS[j]->ReturnRateValue = "";
|
||||
@@ -865,6 +872,8 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
|
||||
NUMBERS[j]->ReturnChangeAbsolute = RundeOutput(NUMBERS[j]->Value - NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
|
||||
NUMBERS[j]->PreValue = NUMBERS[j]->Value;
|
||||
NUMBERS[j]->PreValueOkay = true;
|
||||
NUMBERS[j]->lastvalue = imagetime;
|
||||
|
||||
|
||||
|
||||
NUMBERS[j]->ReturnValue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -35,6 +36,8 @@ static const char* TAG = "HELPER";
|
||||
|
||||
using namespace std;
|
||||
|
||||
unsigned int systemStatus = 0;
|
||||
|
||||
sdmmc_cid_t SDCardCid;
|
||||
sdmmc_csd_t SDCardCsd;
|
||||
|
||||
@@ -770,6 +773,38 @@ string getMac(void) {
|
||||
return macFormated;
|
||||
}
|
||||
|
||||
|
||||
void setSystemStatusFlag(SystemStatusFlag_t flag) {
|
||||
systemStatus = systemStatus | flag; // set bit
|
||||
|
||||
char buf[20];
|
||||
snprintf(buf, sizeof(buf), "0x%08X", getSystemStatus());
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "New System Status: " + std::string(buf));
|
||||
}
|
||||
|
||||
void clearSystemStatusFlag(SystemStatusFlag_t flag) {
|
||||
systemStatus = systemStatus | ~flag; // clear bit
|
||||
|
||||
char buf[20];
|
||||
snprintf(buf, sizeof(buf), "0x%08X", getSystemStatus());
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "New System Status: " + std::string(buf));
|
||||
}
|
||||
|
||||
int getSystemStatus(void) {
|
||||
return systemStatus;
|
||||
}
|
||||
|
||||
bool isSetSystemStatusFlag(SystemStatusFlag_t flag) {
|
||||
//ESP_LOGE(TAG, "Flag (0x%08X) is set (0x%08X): %d", flag, systemStatus , ((systemStatus & flag) == flag));
|
||||
|
||||
if ((systemStatus & flag) == flag) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
string getResetReason(void) {
|
||||
std::string reasonText;
|
||||
|
||||
@@ -792,6 +827,30 @@ string getResetReason(void) {
|
||||
return reasonText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current uptime formated ad xxf xxh xxm [xxs]
|
||||
*/
|
||||
std::string getFormatedUptime(bool compact) {
|
||||
char buf[20];
|
||||
#pragma GCC diagnostic ignored "-Wformat-truncation"
|
||||
|
||||
int uptime = (uint32_t)(esp_timer_get_time()/1000/1000); // in seconds
|
||||
|
||||
int days = int(floor(uptime / (3600*24)));
|
||||
int hours = int(floor((uptime - days * 3600*24) / (3600)));
|
||||
int minutes = int(floor((uptime - days * 3600*24 - hours * 3600) / (60)));
|
||||
int seconds = uptime - days * 3600*24 - hours * 3600 - minutes * 60;
|
||||
|
||||
if (compact) {
|
||||
snprintf(buf, sizeof(buf), "%dd%02dh%02dm%02ds", days, hours, minutes, seconds);
|
||||
}
|
||||
else {
|
||||
snprintf(buf, sizeof(buf), "%3dd %02dh %02dm %02ds", days, hours, minutes, seconds);
|
||||
}
|
||||
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
const char* get404(void) {
|
||||
return
|
||||
"<pre>\n\n\n\n"
|
||||
|
||||
@@ -63,6 +63,28 @@ string getSDCardCapacity();
|
||||
string getSDCardSectorSize();
|
||||
|
||||
string getMac(void);
|
||||
|
||||
|
||||
/* Error bit fields
|
||||
One bit per error
|
||||
Make sure it matches https://github.com/jomjol/AI-on-the-edge-device/wiki/Error-Codes */
|
||||
enum SystemStatusFlag_t { // One bit per error
|
||||
// First Byte
|
||||
SYSTEM_STATUS_PSRAM_BAD = 1 << 0, // 1, Critical Error
|
||||
SYSTEM_STATUS_HEAP_TOO_SMALL = 1 << 1, // 2, Critical Error
|
||||
SYSTEM_STATUS_CAM_BAD = 1 << 2, // 4, Critical Error
|
||||
|
||||
// Second Byte
|
||||
SYSTEM_STATUS_CAM_FB_BAD = 1 << (0+8), // 8, Flow still might work
|
||||
SYSTEM_STATUS_NTP_BAD = 1 << (1+8), // 9, Flow will work but time will be wrong
|
||||
};
|
||||
|
||||
void setSystemStatusFlag(SystemStatusFlag_t flag);
|
||||
void clearSystemStatusFlag(SystemStatusFlag_t flag);
|
||||
int getSystemStatus(void);
|
||||
bool isSetSystemStatusFlag(SystemStatusFlag_t flag);
|
||||
|
||||
string getResetReason(void);
|
||||
std::string getFormatedUptime(bool compact);
|
||||
|
||||
const char* get404(void);
|
||||
|
||||
@@ -115,7 +115,7 @@ void ClassLogFile::WriteToDedicatedFile(std::string _fn, esp_log_level_t level,
|
||||
{
|
||||
FILE* pFile;
|
||||
std::string zwtime;
|
||||
std::string logline = "";
|
||||
std::string ntpTime = "";
|
||||
|
||||
if (level > loglevel) {// Only write to file if loglevel is below threshold
|
||||
return;
|
||||
@@ -138,7 +138,7 @@ void ClassLogFile::WriteToDedicatedFile(std::string _fn, esp_log_level_t level,
|
||||
strftime(buffer, 80, "%Y-%m-%dT%H:%M:%S", timeinfo);
|
||||
|
||||
zwtime = std::string(buffer);
|
||||
logline = zwtime;
|
||||
ntpTime = zwtime;
|
||||
}
|
||||
|
||||
std::string loglevelString;
|
||||
@@ -163,11 +163,11 @@ void ClassLogFile::WriteToDedicatedFile(std::string _fn, esp_log_level_t level,
|
||||
loglevelString = "NONE";
|
||||
break;
|
||||
}
|
||||
|
||||
char uptime[20];
|
||||
snprintf(uptime, sizeof(uptime), "%8d", (uint32_t)(esp_timer_get_time()/1000/1000)); // in seconds
|
||||
logline = "[" + std::string(uptime) + "] " + logline + "\t<" + loglevelString + ">\t" + message + "\n";
|
||||
fputs(logline.c_str(), pFile);
|
||||
|
||||
std::string formatedUptime = getFormatedUptime(true);
|
||||
|
||||
ntpTime = "[" + formatedUptime + "] " + ntpTime + "\t<" + loglevelString + ">\t" + message + "\n";
|
||||
fputs(ntpTime.c_str(), pFile);
|
||||
fclose(pFile);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Can't open log file %s", _fn.c_str());
|
||||
@@ -298,7 +298,7 @@ void ClassLogFile::RemoveOldLogFile()
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Remove old log files");
|
||||
ESP_LOGD(TAG, "Remove old log files");
|
||||
|
||||
time_t rawtime;
|
||||
struct tm* timeinfo;
|
||||
@@ -350,7 +350,7 @@ void ClassLogFile::RemoveOldDataLog()
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Remove old data files");
|
||||
ESP_LOGD(TAG, "Remove old data files");
|
||||
|
||||
time_t rawtime;
|
||||
struct tm* timeinfo;
|
||||
|
||||
@@ -2,4 +2,4 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
|
||||
|
||||
idf_component_register(SRCS ${app_sources}
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES tflite-lib mqtt jomjol_tfliteclass jomjol_helper jomjol_mqtt jomjol_wlan)
|
||||
REQUIRES tflite-lib mqtt jomjol_tfliteclass jomjol_helper jomjol_mqtt jomjol_wlan)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifdef ENABLE_MQTT
|
||||
#include "interface_mqtt.h"
|
||||
|
||||
//#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
|
||||
#include "esp_log.h"
|
||||
#include "connect_wlan.h"
|
||||
#include "mqtt_client.h"
|
||||
#include "ClassLogFile.h"
|
||||
#include "server_tflite.h"
|
||||
@@ -18,86 +18,93 @@ std::map<std::string, std::function<bool(std::string, char*, int)>>* subscribeFu
|
||||
|
||||
|
||||
int failedOnRound = -1;
|
||||
|
||||
bool MQTT_Enabled = true;
|
||||
|
||||
esp_mqtt_event_id_t esp_mmqtt_ID = MQTT_EVENT_ANY;
|
||||
esp_mqtt_event_id_t esp_mqtt_ID = MQTT_EVENT_ANY;
|
||||
// ESP_EVENT_ANY_ID
|
||||
|
||||
bool mqtt_enabled = false;
|
||||
bool mqtt_configOK = false;
|
||||
bool mqtt_initialized = false;
|
||||
bool mqtt_connected = false;
|
||||
|
||||
esp_mqtt_client_handle_t client = NULL;
|
||||
std::string uri, client_id, lwt_topic, lwt_connected, lwt_disconnected, user, password, maintopic;
|
||||
int keepalive, SetRetainFlag;
|
||||
void (*callbackOnConnected)(std::string, int) = NULL;
|
||||
|
||||
|
||||
void MQTTdisable()
|
||||
bool MQTTPublish(std::string _key, std::string _content, int retained_flag)
|
||||
{
|
||||
MQTT_Enabled = false;
|
||||
}
|
||||
|
||||
bool MQTTPublish(std::string _key, std::string _content, int retained_flag) {
|
||||
int msg_id;
|
||||
std::string zw;
|
||||
|
||||
if (failedOnRound == getCountFlowRounds()) { // we already failed in this round, do not retry until the next round
|
||||
return true; // Fail quietly
|
||||
if (!mqtt_enabled) { // MQTT sevice not started / configured (MQTT_Init not called before)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (failedOnRound == getCountFlowRounds()) { // we already failed in this round, do not retry until the next round
|
||||
return true; // Fail quietly
|
||||
}
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("MQTT Publish");
|
||||
#endif
|
||||
|
||||
if (!mqtt_initialized) {
|
||||
if (!MQTT_Init()) {
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Init failed, skipping all MQTT publishings in this round!");
|
||||
failedOnRound = getCountFlowRounds();
|
||||
return false;
|
||||
MQTT_Init(); // Re-Init client if not initialized yet/anymore
|
||||
|
||||
if (mqtt_initialized && mqtt_connected) {
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
long long int starttime = esp_timer_get_time();
|
||||
#endif
|
||||
int msg_id = esp_mqtt_client_publish(client, _key.c_str(), _content.c_str(), 0, 1, retained_flag);
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Publish msg_id %d in %lld ms", msg_id, (esp_timer_get_time() - starttime)/1000);
|
||||
#endif
|
||||
if (msg_id == -1) {
|
||||
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Failed to publish topic '" + _key + "', re-trying...");
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
starttime = esp_timer_get_time();
|
||||
#endif
|
||||
msg_id = esp_mqtt_client_publish(client, _key.c_str(), _content.c_str(), 0, 1, retained_flag);
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Publish msg_id %d in %lld ms", msg_id, (esp_timer_get_time() - starttime)/1000);
|
||||
#endif
|
||||
if (msg_id == -1) {
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to publish topic '" + _key + "', skipping all MQTT publishings in this round!");
|
||||
failedOnRound = getCountFlowRounds();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg_id = esp_mqtt_client_publish(client, _key.c_str(), _content.c_str(), 0, 1, retained_flag);
|
||||
if (msg_id < 0) {
|
||||
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Failed to publish topic '" + _key + "', re-trying...");
|
||||
esp_mqtt_client_reconnect(client);
|
||||
|
||||
msg_id = esp_mqtt_client_publish(client, _key.c_str(), _content.c_str(), 0, 1, retained_flag);
|
||||
if (msg_id < 0) {
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to publish topic '" + _key + "', skipping all MQTT publishings in this round!");
|
||||
failedOnRound = getCountFlowRounds();
|
||||
return false;
|
||||
if (_content.length() > 80) { // Truncate message if too long
|
||||
_content.resize(80);
|
||||
_content.append("..");
|
||||
}
|
||||
|
||||
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Published topic: " + _key + ", content: " + _content + " (msg_id=" + std::to_string(msg_id) + ")");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_content.length() > 80) { // Truncate message if too long
|
||||
_content.resize(80);
|
||||
_content.append("..");
|
||||
else {
|
||||
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Publish skipped. Client not initalized or not connected. (topic: " + _key + ")");
|
||||
return false;
|
||||
}
|
||||
|
||||
zw = "Published topic: " + _key + ", content: " + _content + " (msg_id=" + std::to_string(msg_id) + ")";
|
||||
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, zw);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event)
|
||||
{
|
||||
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_LOGD(TAG, "MQTT_EVENT_BEFORE_CONNECT");
|
||||
mqtt_initialized = true;
|
||||
break;
|
||||
case MQTT_EVENT_CONNECTED:
|
||||
ESP_LOGD(TAG, "MQTT_EVENT_CONNECTED");
|
||||
mqtt_initialized = true;
|
||||
mqtt_connected = true;
|
||||
MQTTconnected();
|
||||
break;
|
||||
case MQTT_EVENT_DISCONNECTED:
|
||||
ESP_LOGD(TAG, "MQTT_EVENT_DISCONNECTED");
|
||||
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Disconnected from broker");
|
||||
mqtt_connected = false;
|
||||
break;
|
||||
case MQTT_EVENT_SUBSCRIBED:
|
||||
@@ -126,8 +133,15 @@ static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event)
|
||||
}
|
||||
break;
|
||||
case MQTT_EVENT_ERROR:
|
||||
ESP_LOGD(TAG, "MQTT_EVENT_ERROR");
|
||||
mqtt_initialized = false; // Force re-init on next publish call
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "MQTT_EVENT_ERROR - esp_mqtt_error_codes:");
|
||||
ESP_LOGD(TAG, "error_type:%d", event->error_handle->error_type);
|
||||
ESP_LOGD(TAG, "connect_return_code:%d", event->error_handle->connect_return_code);
|
||||
ESP_LOGD(TAG, "esp_transport_sock_errno:%d", event->error_handle->esp_transport_sock_errno);
|
||||
ESP_LOGD(TAG, "esp_tls_last_esp_err:%d", event->error_handle->esp_tls_last_esp_err);
|
||||
ESP_LOGD(TAG, "esp_tls_stack_err:%d", event->error_handle->esp_tls_stack_err);
|
||||
ESP_LOGD(TAG, "esp_tls_cert_verify_flags:%d", event->error_handle->esp_tls_cert_verify_flags);
|
||||
#endif
|
||||
mqtt_connected = false;
|
||||
break;
|
||||
default:
|
||||
@@ -143,16 +157,14 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
|
||||
}
|
||||
|
||||
|
||||
void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password,
|
||||
bool MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password,
|
||||
std::string _maintopic, std::string _lwt, std::string _lwt_connected, std::string _lwt_disconnected,
|
||||
int _keepalive, int _SetRetainFlag, void *_callbackOnConnected){
|
||||
#ifdef __HIDE_PASSWORD
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "URI: " + _mqttURI + ", clientname: " + _clientid +
|
||||
", user: " + _user + ", password: XXXXXXXX, maintopic: " + _maintopic + ", last-will-topic: " + _maintopic + "/" + _lwt + ", keepAlive: " + std::to_string(_keepalive));
|
||||
#else
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "URI: " + _mqttURI + ", clientname: " + _clientid +
|
||||
", user: " + _user + ", password: " + _password + ", maintopic: " + _maintopic + ", last-will-topic: " + _maintopic + "/" + _lwt + ", keepAlive: " + std::to_string(_keepalive));
|
||||
#endif
|
||||
int _keepalive, int _SetRetainFlag, void *_callbackOnConnected) {
|
||||
if ((_mqttURI.length() == 0) || (_maintopic.length() == 0) || (_clientid.length() == 0))
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Init aborted! Config error (URI, MainTopic or ClientID missing)");
|
||||
return false;
|
||||
}
|
||||
|
||||
uri = _mqttURI;
|
||||
client_id = _clientid;
|
||||
@@ -168,42 +180,60 @@ void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _us
|
||||
user = _user;
|
||||
password = _password;
|
||||
}
|
||||
|
||||
#ifdef __HIDE_PASSWORD
|
||||
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "URI: " + uri + ", clientname: " + client_id + ", user: " + user + ", password: XXXXXXXX, maintopic: "
|
||||
+ maintopic + ", last-will-topic: " + lwt_topic + ", keepAlive: " + std::to_string(keepalive) + ", RetainFlag: " + std::to_string(SetRetainFlag));
|
||||
#else
|
||||
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "URI: " + uri + ", clientname: " + client_id + ", user: " + user + ", password: " + password + ", maintopic: "
|
||||
+ maintopic + ", last-will-topic: " + lwt_topic + ", keepAlive: " + std::to_string(keepalive) + ", RetainFlag: " + std::to_string(SetRetainFlag));
|
||||
#endif
|
||||
|
||||
mqtt_configOK = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MQTT_Init() {
|
||||
|
||||
if (MQTT_Enabled == false)
|
||||
return false;
|
||||
|
||||
if ((client_id.length() == 0) || (lwt_topic.length() == 0))
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, std::string("Init with no Client_ID (" + client_id + ") or Last Will Topic (" + lwt_topic + "). Abort Init!"));
|
||||
return false;
|
||||
int MQTT_Init() {
|
||||
if (mqtt_initialized) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
esp_err_t ret;
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, std::string("Init"));
|
||||
|
||||
if (mqtt_configOK) {
|
||||
mqtt_enabled = true;
|
||||
} else {
|
||||
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Init called, but client is not yet configured.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!getWIFIisConnected()) {
|
||||
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Init called, but WIFI is not yet connected.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Init");
|
||||
MQTTdestroy_client();
|
||||
|
||||
std::string lw = lwt_disconnected;
|
||||
|
||||
esp_mqtt_client_config_t mqtt_cfg = {
|
||||
.uri = uri.c_str(),
|
||||
.client_id = client_id.c_str(),
|
||||
.lwt_topic = lwt_topic.c_str(),
|
||||
.lwt_msg = lw.c_str(),
|
||||
.lwt_msg = lwt_disconnected.c_str(),
|
||||
.lwt_retain = 1,
|
||||
.lwt_msg_len = (int)(lw.length()),
|
||||
.lwt_msg_len = (int)(lwt_disconnected.length()),
|
||||
.keepalive = keepalive,
|
||||
.disable_auto_reconnect = false, // Reconnection routine active
|
||||
.reconnect_timeout_ms = 10000 // Try to reconnect to broker every 10s
|
||||
.disable_auto_reconnect = false, // Reconnection routine active (Default: false)
|
||||
.buffer_size = 1536, // size of MQTT send/receive buffer (Default: 1024)
|
||||
.reconnect_timeout_ms = 15000, // Try to reconnect to broker (Default: 10000ms)
|
||||
.network_timeout_ms = 20000, // Network Timeout (Default: 10000ms)
|
||||
.message_retransmit_timeout = 3000 // Tiem after message resent when broker not acknowledged (QoS1, QoS2)
|
||||
|
||||
};
|
||||
|
||||
if (user.length() && password.length()){
|
||||
mqtt_cfg.username = user.c_str();
|
||||
mqtt_cfg.password = password.c_str();
|
||||
};
|
||||
}
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("MQTT Client Init");
|
||||
@@ -212,12 +242,12 @@ bool MQTT_Init() {
|
||||
client = esp_mqtt_client_init(&mqtt_cfg);
|
||||
if (client)
|
||||
{
|
||||
ret = esp_mqtt_client_register_event(client, esp_mmqtt_ID, mqtt_event_handler, client);
|
||||
esp_err_t ret = esp_mqtt_client_register_event(client, esp_mqtt_ID, mqtt_event_handler, client);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Could not register event (ret=" + std::to_string(ret) + ")!");
|
||||
mqtt_initialized = false;
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
@@ -226,40 +256,44 @@ bool MQTT_Init() {
|
||||
ret = esp_mqtt_client_start(client);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Could not start client (ret=" + std::to_string(ret) + "), retrying...");
|
||||
ret = esp_mqtt_client_start(client);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Could not start client (ret=" + std::to_string(ret) + ")!");
|
||||
mqtt_initialized = false;
|
||||
return false;
|
||||
}
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Client start failed (retval=" + std::to_string(ret) + ")!");
|
||||
mqtt_initialized = false;
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Client started, waiting for established connection...");
|
||||
mqtt_initialized = true;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Init failed, no handle created!");
|
||||
mqtt_initialized = false;
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Client started, waiting for established connection...");
|
||||
mqtt_initialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void MQTTdestroy_client() {
|
||||
if (client) {
|
||||
if (mqtt_connected) {
|
||||
esp_mqtt_client_disconnect(client);
|
||||
mqtt_connected = false;
|
||||
}
|
||||
esp_mqtt_client_stop(client);
|
||||
esp_mqtt_client_destroy(client);
|
||||
client = NULL;
|
||||
mqtt_initialized = false;
|
||||
mqtt_connected = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool MQTTisConnected() {
|
||||
bool getMQTTisEnabled() {
|
||||
return mqtt_enabled;
|
||||
}
|
||||
|
||||
bool getMQTTisConnected() {
|
||||
return mqtt_connected;
|
||||
}
|
||||
|
||||
@@ -347,4 +381,4 @@ void MQTTdestroySubscribeFunction(){
|
||||
subscribeFunktionMap = NULL;
|
||||
}
|
||||
}
|
||||
#endif //ENABLE_MQTT
|
||||
#endif //ENABLE_MQTT
|
||||
|
||||
@@ -6,15 +6,16 @@
|
||||
#include <map>
|
||||
#include <functional>
|
||||
|
||||
void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password,
|
||||
std::string _maintopic, std::string _lwt, std::string _lwt_connected, std::string _lwt_disconnected,
|
||||
int _keepalive, int SetRetainFlag, void *callbackOnConnected);
|
||||
bool MQTT_Init();
|
||||
bool MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password,
|
||||
std::string _maintopic, std::string _lwt, std::string _lwt_connected, std::string _lwt_disconnected,
|
||||
int _keepalive, int SetRetainFlag, void *callbackOnConnected);
|
||||
int MQTT_Init();
|
||||
void MQTTdestroy_client();
|
||||
|
||||
bool MQTTPublish(std::string _key, std::string _content, int retained_flag = 1); // retained Flag as Standart
|
||||
|
||||
bool MQTTisConnected();
|
||||
bool getMQTTisEnabled();
|
||||
bool getMQTTisConnected();
|
||||
|
||||
void MQTTregisterConnectFunction(std::string name, std::function<void()> func);
|
||||
void MQTTunregisterConnectFunction(std::string name);
|
||||
|
||||
@@ -128,7 +128,10 @@ void sendHomeAssistantDiscoveryTopic(std::string group, std::string field,
|
||||
MQTTPublish(topicFull, payload, true);
|
||||
}
|
||||
|
||||
void MQTThomeassistantDiscovery() {
|
||||
void MQTThomeassistantDiscovery() {
|
||||
if (!getMQTTisConnected())
|
||||
return;
|
||||
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "MQTT - Sending Homeassistant Discovery Topics (Meter Type: " + meterType + ", Value Unit: " + valueUnit + " , Rate Unit: " + rateUnit + ")...");
|
||||
|
||||
// Group | Field | User Friendly Name | Icon | Unit | Device Class | State Class | Entity Category
|
||||
@@ -161,6 +164,9 @@ void MQTThomeassistantDiscovery() {
|
||||
}
|
||||
|
||||
void publishSystemData() {
|
||||
if (!getMQTTisConnected())
|
||||
return;
|
||||
|
||||
char tmp_char[50];
|
||||
|
||||
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Publishing system MQTT topics...");
|
||||
@@ -180,6 +186,9 @@ void publishSystemData() {
|
||||
|
||||
|
||||
void publishStaticData() {
|
||||
if (!getMQTTisConnected())
|
||||
return;
|
||||
|
||||
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Publishing static MQTT topics...");
|
||||
MQTTPublish(maintopic + "/" + "MAC", getMac(), retainFlag);
|
||||
MQTTPublish(maintopic + "/" + "IP", *getIPAddress(), retainFlag);
|
||||
@@ -204,6 +213,7 @@ esp_err_t sendDiscovery_and_static_Topics(httpd_req_t *req) {
|
||||
}
|
||||
|
||||
void GotConnected(std::string maintopic, int retainFlag) {
|
||||
vTaskDelay(10000 / portTICK_PERIOD_MS); // Delay execution by 10s after connection got established
|
||||
if (HomeassistantDiscovery) {
|
||||
MQTThomeassistantDiscovery();
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ ClassFlowControll tfliteflow;
|
||||
TaskHandle_t xHandleblink_task_doFlow = NULL;
|
||||
TaskHandle_t xHandletask_autodoFlow = NULL;
|
||||
|
||||
bool FlowInitDone = false;
|
||||
bool flowisrunning = false;
|
||||
|
||||
long auto_intervall = 0;
|
||||
@@ -47,17 +48,18 @@ int getCountFlowRounds() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
esp_err_t GetJPG(std::string _filename, httpd_req_t *req)
|
||||
{
|
||||
return tfliteflow.GetJPGStream(_filename, req);
|
||||
}
|
||||
|
||||
|
||||
esp_err_t GetRawJPG(httpd_req_t *req)
|
||||
{
|
||||
return tfliteflow.SendRawJPG(req);
|
||||
}
|
||||
|
||||
|
||||
bool isSetupModusActive() {
|
||||
return tfliteflow.getStatusSetupModus();
|
||||
return false;
|
||||
@@ -66,70 +68,72 @@ bool isSetupModusActive() {
|
||||
|
||||
void KillTFliteTasks()
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Handle: xHandleblink_task_doFlow: %ld", (long) xHandleblink_task_doFlow);
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Handle: xHandleblink_task_doFlow: %ld", (long) xHandleblink_task_doFlow);
|
||||
#endif
|
||||
if (xHandleblink_task_doFlow != NULL)
|
||||
{
|
||||
TaskHandle_t xHandleblink_task_doFlowTmp = xHandleblink_task_doFlow;
|
||||
xHandleblink_task_doFlow = NULL;
|
||||
vTaskDelete(xHandleblink_task_doFlowTmp);
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Killed: xHandleblink_task_doFlow");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Killed: xHandleblink_task_doFlow");
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Handle: xHandletask_autodoFlow: %ld", (long) xHandletask_autodoFlow);
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Handle: xHandletask_autodoFlow: %ld", (long) xHandletask_autodoFlow);
|
||||
#endif
|
||||
if (xHandletask_autodoFlow != NULL)
|
||||
{
|
||||
TaskHandle_t xHandletask_autodoFlowTmp = xHandletask_autodoFlow;
|
||||
xHandletask_autodoFlow = NULL;
|
||||
vTaskDelete(xHandletask_autodoFlowTmp);
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Killed: xHandletask_autodoFlow");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Killed: xHandletask_autodoFlow");
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void doInit(void)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Start tfliteflow.InitFlow(config);");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Start tfliteflow.InitFlow(config);");
|
||||
#endif
|
||||
tfliteflow.InitFlow(CONFIG_FILE);
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Finished tfliteflow.InitFlow(config);");
|
||||
#endif
|
||||
FlowInitDone = true;
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Finished tfliteflow.InitFlow(config);");
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_MQTT
|
||||
tfliteflow.StartMQTTService();
|
||||
#endif //ENABLE_MQTT
|
||||
#ifdef ENABLE_MQTT
|
||||
tfliteflow.StartMQTTService();
|
||||
#endif //ENABLE_MQTT
|
||||
}
|
||||
|
||||
|
||||
bool doflow(void)
|
||||
{
|
||||
|
||||
{
|
||||
std::string zw_time = gettimestring(LOGFILE_TIME_FORMAT);
|
||||
ESP_LOGD(TAG, "doflow - start %s", zw_time.c_str());
|
||||
flowisrunning = true;
|
||||
tfliteflow.doFlow(zw_time);
|
||||
flowisrunning = false;
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "doflow - end %s", zw_time.c_str());
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "doflow - end %s", zw_time.c_str());
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void blink_task_doFlow(void *pvParameter)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "blink_task_doFlow");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "blink_task_doFlow");
|
||||
#endif
|
||||
if (!flowisrunning)
|
||||
{
|
||||
flowisrunning = true;
|
||||
@@ -143,10 +147,10 @@ void blink_task_doFlow(void *pvParameter)
|
||||
|
||||
esp_err_t handler_init(httpd_req_t *req)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_init - Start");
|
||||
ESP_LOGD(TAG, "handler_doinit uri: %s", req->uri);
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_init - Start");
|
||||
ESP_LOGD(TAG, "handler_doinit uri: %s", req->uri);
|
||||
#endif
|
||||
|
||||
const char* resp_str = "Init started<br>";
|
||||
httpd_resp_send(req, resp_str, strlen(resp_str));
|
||||
@@ -158,18 +162,19 @@ esp_err_t handler_init(httpd_req_t *req)
|
||||
/* Respond with an empty chunk to signal HTTP response completion */
|
||||
httpd_resp_send_chunk(req, NULL, 0);
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_init - Done");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_init - Done");
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
esp_err_t handler_doflow(httpd_req_t *req)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_doflow - Start");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_doflow - Start");
|
||||
#endif
|
||||
|
||||
ESP_LOGD(TAG, "handler_doFlow uri: %s", req->uri);
|
||||
|
||||
@@ -188,199 +193,208 @@ esp_err_t handler_doflow(httpd_req_t *req)
|
||||
/* Respond with an empty chunk to signal HTTP response completion */
|
||||
httpd_resp_send_chunk(req, NULL, 0);
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_doflow - Done");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_doflow - Done");
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
esp_err_t handler_json(httpd_req_t *req)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_json - Start");
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_json - Start");
|
||||
#endif
|
||||
|
||||
ESP_LOGD(TAG, "handler_JSON uri: %s", req->uri);
|
||||
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
httpd_resp_set_type(req, "application/json");
|
||||
|
||||
std::string zw = tfliteflow.getJSON();
|
||||
if (zw.length() > 0)
|
||||
|
||||
if (FlowInitDone)
|
||||
{
|
||||
httpd_resp_send(req, zw.c_str(), zw.length());
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
httpd_resp_set_type(req, "application/json");
|
||||
|
||||
std::string zw = tfliteflow.getJSON();
|
||||
if (zw.length() > 0)
|
||||
{
|
||||
httpd_resp_send(req, zw.c_str(), zw.length());
|
||||
}
|
||||
else
|
||||
{
|
||||
httpd_resp_send(req, NULL, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
httpd_resp_send(req, NULL, 0);
|
||||
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "JSON API not yet initialized. Please retry later...");
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_JSON - Done");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_JSON - Done");
|
||||
#endif
|
||||
return ESP_OK;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
esp_err_t handler_wasserzaehler(httpd_req_t *req)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_wasserzaehler - Start");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_wasserzaehler - Start");
|
||||
#endif
|
||||
|
||||
bool _rawValue = false;
|
||||
bool _noerror = false;
|
||||
bool _all = false;
|
||||
std::string _type = "value";
|
||||
string zw;
|
||||
|
||||
ESP_LOGD(TAG, "handler_wasserzaehler uri: %s", req->uri);
|
||||
|
||||
char _query[100];
|
||||
char _size[10];
|
||||
|
||||
if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
|
||||
if (FlowInitDone)
|
||||
{
|
||||
// ESP_LOGD(TAG, "Query: %s", _query);
|
||||
if (httpd_query_key_value(_query, "all", _size, 10) == ESP_OK)
|
||||
bool _rawValue = false;
|
||||
bool _noerror = false;
|
||||
bool _all = false;
|
||||
std::string _type = "value";
|
||||
string zw;
|
||||
|
||||
ESP_LOGD(TAG, "handler_wasserzaehler uri: %s", req->uri);
|
||||
|
||||
char _query[100];
|
||||
char _size[10];
|
||||
|
||||
if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "all is found%s", _size);
|
||||
#endif
|
||||
_all = true;
|
||||
// ESP_LOGD(TAG, "Query: %s", _query);
|
||||
if (httpd_query_key_value(_query, "all", _size, 10) == ESP_OK)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "all is found%s", _size);
|
||||
#endif
|
||||
_all = true;
|
||||
}
|
||||
|
||||
if (httpd_query_key_value(_query, "type", _size, 10) == ESP_OK)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "all is found: %s", _size);
|
||||
#endif
|
||||
_type = std::string(_size);
|
||||
}
|
||||
|
||||
if (httpd_query_key_value(_query, "rawvalue", _size, 10) == ESP_OK)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "rawvalue is found: %s", _size);
|
||||
#endif
|
||||
_rawValue = true;
|
||||
}
|
||||
if (httpd_query_key_value(_query, "noerror", _size, 10) == ESP_OK)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "noerror is found: %s", _size);
|
||||
#endif
|
||||
_noerror = true;
|
||||
}
|
||||
}
|
||||
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
|
||||
if (_all)
|
||||
{
|
||||
httpd_resp_set_type(req, "text/plain");
|
||||
ESP_LOGD(TAG, "TYPE: %s", _type.c_str());
|
||||
int _intype = READOUT_TYPE_VALUE;
|
||||
if (_type == "prevalue")
|
||||
_intype = READOUT_TYPE_PREVALUE;
|
||||
if (_type == "raw")
|
||||
_intype = READOUT_TYPE_RAWVALUE;
|
||||
if (_type == "error")
|
||||
_intype = READOUT_TYPE_ERROR;
|
||||
|
||||
|
||||
zw = tfliteflow.getReadoutAll(_intype);
|
||||
ESP_LOGD(TAG, "ZW: %s", zw.c_str());
|
||||
if (zw.length() > 0)
|
||||
httpd_resp_sendstr_chunk(req, zw.c_str());
|
||||
httpd_resp_sendstr_chunk(req, NULL);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
if (httpd_query_key_value(_query, "type", _size, 10) == ESP_OK)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "all is found: %s", _size);
|
||||
#endif
|
||||
_type = std::string(_size);
|
||||
}
|
||||
|
||||
if (httpd_query_key_value(_query, "rawvalue", _size, 10) == ESP_OK)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "rawvalue is found: %s", _size);
|
||||
#endif
|
||||
_rawValue = true;
|
||||
}
|
||||
if (httpd_query_key_value(_query, "noerror", _size, 10) == ESP_OK)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "noerror is found: %s", _size);
|
||||
#endif
|
||||
_noerror = true;
|
||||
}
|
||||
}
|
||||
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
|
||||
if (_all)
|
||||
{
|
||||
httpd_resp_set_type(req, "text/plain");
|
||||
ESP_LOGD(TAG, "TYPE: %s", _type.c_str());
|
||||
int _intype = READOUT_TYPE_VALUE;
|
||||
if (_type == "prevalue")
|
||||
_intype = READOUT_TYPE_PREVALUE;
|
||||
if (_type == "raw")
|
||||
_intype = READOUT_TYPE_RAWVALUE;
|
||||
if (_type == "error")
|
||||
_intype = READOUT_TYPE_ERROR;
|
||||
|
||||
|
||||
zw = tfliteflow.getReadoutAll(_intype);
|
||||
ESP_LOGD(TAG, "ZW: %s", zw.c_str());
|
||||
zw = tfliteflow.getReadout(_rawValue, _noerror);
|
||||
if (zw.length() > 0)
|
||||
httpd_resp_sendstr_chunk(req, zw.c_str());
|
||||
httpd_resp_sendstr_chunk(req, NULL);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
zw = tfliteflow.getReadout(_rawValue, _noerror);
|
||||
if (zw.length() > 0)
|
||||
httpd_resp_sendstr_chunk(req, zw.c_str());
|
||||
|
||||
string query = std::string(_query);
|
||||
// ESP_LOGD(TAG, "Query: %s, query.c_str());
|
||||
if (query.find("full") != std::string::npos)
|
||||
{
|
||||
string txt, zw;
|
||||
|
||||
txt = "<p>Aligned Image: <p><img src=\"/img_tmp/alg_roi.jpg\"> <p>\n";
|
||||
txt = txt + "Digital Counter: <p> ";
|
||||
httpd_resp_sendstr_chunk(req, txt.c_str());
|
||||
|
||||
std::vector<HTMLInfo*> htmlinfodig;
|
||||
htmlinfodig = tfliteflow.GetAllDigital();
|
||||
|
||||
for (int i = 0; i < htmlinfodig.size(); ++i)
|
||||
string query = std::string(_query);
|
||||
// ESP_LOGD(TAG, "Query: %s, query.c_str());
|
||||
if (query.find("full") != std::string::npos)
|
||||
{
|
||||
if (tfliteflow.GetTypeDigital() == Digital)
|
||||
{
|
||||
if (htmlinfodig[i]->val == 10)
|
||||
zw = "NaN";
|
||||
else
|
||||
zw = to_string((int) htmlinfodig[i]->val);
|
||||
string txt, zw;
|
||||
|
||||
txt = "<p>Aligned Image: <p><img src=\"/img_tmp/alg_roi.jpg\"> <p>\n";
|
||||
txt = txt + "Digital Counter: <p> ";
|
||||
httpd_resp_sendstr_chunk(req, txt.c_str());
|
||||
|
||||
std::vector<HTMLInfo*> htmlinfodig;
|
||||
htmlinfodig = tfliteflow.GetAllDigital();
|
||||
|
||||
txt = "<img src=\"/img_tmp/" + htmlinfodig[i]->filename + "\"> " + zw;
|
||||
for (int i = 0; i < htmlinfodig.size(); ++i)
|
||||
{
|
||||
if (tfliteflow.GetTypeDigital() == Digital)
|
||||
{
|
||||
if (htmlinfodig[i]->val == 10)
|
||||
zw = "NaN";
|
||||
else
|
||||
zw = to_string((int) htmlinfodig[i]->val);
|
||||
|
||||
txt = "<img src=\"/img_tmp/" + htmlinfodig[i]->filename + "\"> " + zw;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream stream;
|
||||
stream << std::fixed << std::setprecision(1) << htmlinfodig[i]->val;
|
||||
zw = stream.str();
|
||||
|
||||
txt = "<img src=\"/img_tmp/" + htmlinfodig[i]->filename + "\"> " + zw;
|
||||
}
|
||||
httpd_resp_sendstr_chunk(req, txt.c_str());
|
||||
delete htmlinfodig[i];
|
||||
}
|
||||
else
|
||||
htmlinfodig.clear();
|
||||
|
||||
txt = " <p> Analog Meter: <p> ";
|
||||
httpd_resp_sendstr_chunk(req, txt.c_str());
|
||||
|
||||
std::vector<HTMLInfo*> htmlinfoana;
|
||||
htmlinfoana = tfliteflow.GetAllAnalog();
|
||||
for (int i = 0; i < htmlinfoana.size(); ++i)
|
||||
{
|
||||
std::stringstream stream;
|
||||
stream << std::fixed << std::setprecision(1) << htmlinfodig[i]->val;
|
||||
stream << std::fixed << std::setprecision(1) << htmlinfoana[i]->val;
|
||||
zw = stream.str();
|
||||
|
||||
txt = "<img src=\"/img_tmp/" + htmlinfodig[i]->filename + "\"> " + zw;
|
||||
txt = "<img src=\"/img_tmp/" + htmlinfoana[i]->filename + "\"> " + zw;
|
||||
httpd_resp_sendstr_chunk(req, txt.c_str());
|
||||
delete htmlinfoana[i];
|
||||
}
|
||||
httpd_resp_sendstr_chunk(req, txt.c_str());
|
||||
delete htmlinfodig[i];
|
||||
}
|
||||
htmlinfodig.clear();
|
||||
|
||||
txt = " <p> Analog Meter: <p> ";
|
||||
httpd_resp_sendstr_chunk(req, txt.c_str());
|
||||
|
||||
std::vector<HTMLInfo*> htmlinfoana;
|
||||
htmlinfoana = tfliteflow.GetAllAnalog();
|
||||
for (int i = 0; i < htmlinfoana.size(); ++i)
|
||||
{
|
||||
std::stringstream stream;
|
||||
stream << std::fixed << std::setprecision(1) << htmlinfoana[i]->val;
|
||||
zw = stream.str();
|
||||
htmlinfoana.clear();
|
||||
|
||||
txt = "<img src=\"/img_tmp/" + htmlinfoana[i]->filename + "\"> " + zw;
|
||||
httpd_resp_sendstr_chunk(req, txt.c_str());
|
||||
delete htmlinfoana[i];
|
||||
}
|
||||
htmlinfoana.clear();
|
||||
}
|
||||
|
||||
}
|
||||
/* Respond with an empty chunk to signal HTTP response completion */
|
||||
httpd_resp_sendstr_chunk(req, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Value API not yet initialized. Please retry later...");
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Respond with an empty chunk to signal HTTP response completion */
|
||||
httpd_resp_sendstr_chunk(req, NULL);
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_wasserzaehler - Done");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_wasserzaehler - Done");
|
||||
#endif
|
||||
return ESP_OK;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
esp_err_t handler_editflow(httpd_req_t *req)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_editflow - Start");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_editflow - Start");
|
||||
#endif
|
||||
|
||||
ESP_LOGD(TAG, "handler_editflow uri: %s", req->uri);
|
||||
|
||||
@@ -392,9 +406,9 @@ esp_err_t handler_editflow(httpd_req_t *req)
|
||||
{
|
||||
if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "task is found: %s", _valuechar);
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "task is found: %s", _valuechar);
|
||||
#endif
|
||||
_task = string(_valuechar);
|
||||
}
|
||||
}
|
||||
@@ -427,10 +441,10 @@ esp_err_t handler_editflow(httpd_req_t *req)
|
||||
httpd_query_key_value(_query, "out", _valuechar, 30);
|
||||
out = string(_valuechar);
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "in: %s", in.c_str());
|
||||
ESP_LOGD(TAG, "out: %s", out.c_str());
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "in: %s", in.c_str());
|
||||
ESP_LOGD(TAG, "out: %s", out.c_str());
|
||||
#endif
|
||||
|
||||
in = "/sdcard" + in;
|
||||
out = "/sdcard" + out;
|
||||
@@ -469,14 +483,14 @@ esp_err_t handler_editflow(httpd_req_t *req)
|
||||
zw = string(_valuechar);
|
||||
dy = stoi(zw);
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "in: %s", in.c_str());
|
||||
ESP_LOGD(TAG, "out: %s", out.c_str());
|
||||
ESP_LOGD(TAG, "x: %s", zw.c_str());
|
||||
ESP_LOGD(TAG, "y: %s", zw.c_str());
|
||||
ESP_LOGD(TAG, "dx: %s", zw.c_str());
|
||||
ESP_LOGD(TAG, "dy: %s", zw.c_str());
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "in: %s", in.c_str());
|
||||
ESP_LOGD(TAG, "out: %s", out.c_str());
|
||||
ESP_LOGD(TAG, "x: %s", zw.c_str());
|
||||
ESP_LOGD(TAG, "y: %s", zw.c_str());
|
||||
ESP_LOGD(TAG, "dx: %s", zw.c_str());
|
||||
ESP_LOGD(TAG, "dy: %s", zw.c_str());
|
||||
#endif
|
||||
|
||||
if (httpd_query_key_value(_query, "enhance", _valuechar, 10) == ESP_OK)
|
||||
{
|
||||
@@ -570,103 +584,144 @@ esp_err_t handler_editflow(httpd_req_t *req)
|
||||
/* Respond with an empty chunk to signal HTTP response completion */
|
||||
httpd_resp_sendstr_chunk(req, NULL);
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_editflow - Done");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_editflow - Done");
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
esp_err_t handler_statusflow(httpd_req_t *req)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_prevalue - Start");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_prevalue - Start");
|
||||
#endif
|
||||
|
||||
const char* resp_str;
|
||||
if (FlowInitDone)
|
||||
{
|
||||
const char* resp_str;
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "handler_prevalue: %s", req->uri);
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "handler_prevalue: %s", req->uri);
|
||||
#endif
|
||||
|
||||
string* zw = tfliteflow.getActStatus();
|
||||
resp_str = zw->c_str();
|
||||
string* zw = tfliteflow.getActStatus();
|
||||
resp_str = zw->c_str();
|
||||
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
httpd_resp_send(req, resp_str, strlen(resp_str));
|
||||
/* Respond with an empty chunk to signal HTTP response completion */
|
||||
httpd_resp_send_chunk(req, NULL, 0);
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
httpd_resp_send(req, resp_str, strlen(resp_str));
|
||||
/* Respond with an empty chunk to signal HTTP response completion */
|
||||
httpd_resp_send_chunk(req, NULL, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flowstatus API not yet initialized. Please retry later...");
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_prevalue - Start");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_prevalue - Done");
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
esp_err_t handler_cputemp(httpd_req_t *req)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_cputemp - Start");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_cputemp - Start");
|
||||
#endif
|
||||
|
||||
const char* resp_str;
|
||||
char cputemp[20];
|
||||
|
||||
sprintf(cputemp, "CPU Temp: %4.1f°C", temperatureRead());
|
||||
sprintf(cputemp, "%4.1f°C", temperatureRead());
|
||||
|
||||
resp_str = cputemp;
|
||||
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
httpd_resp_send(req, resp_str, strlen(resp_str));
|
||||
/* Respond with an empty chunk to signal HTTP response completion */
|
||||
httpd_resp_send_chunk(req, NULL, 0);
|
||||
httpd_resp_send_chunk(req, NULL, 0);
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_cputemp - End");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_cputemp - End");
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
esp_err_t handler_rssi(httpd_req_t *req)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_rssi - Start");
|
||||
#endif
|
||||
|
||||
if (getWIFIisConnected())
|
||||
{
|
||||
const char* resp_str;
|
||||
char rssi[20];
|
||||
|
||||
sprintf(rssi, "%idBm", get_WIFI_RSSI());
|
||||
|
||||
resp_str = rssi;
|
||||
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
httpd_resp_send(req, resp_str, strlen(resp_str));
|
||||
/* Respond with an empty chunk to signal HTTP response completion */
|
||||
httpd_resp_send_chunk(req, NULL, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "RSSI API not yet initialized. Please retry later...");
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_rssi - End");
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
esp_err_t handler_uptime(httpd_req_t *req)
|
||||
{
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_rssi - Start");
|
||||
LogFile.WriteHeapInfo("handler_uptime - Start");
|
||||
#endif
|
||||
|
||||
const char* resp_str;
|
||||
char rssi[20];
|
||||
|
||||
sprintf(rssi, "RSSI: %idBm", get_WIFI_RSSI());
|
||||
|
||||
resp_str = rssi;
|
||||
|
||||
std::string formatedUptime = getFormatedUptime(false);
|
||||
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
httpd_resp_send(req, resp_str, strlen(resp_str));
|
||||
httpd_resp_send(req, formatedUptime.c_str(), strlen(formatedUptime.c_str()));
|
||||
/* Respond with an empty chunk to signal HTTP response completion */
|
||||
httpd_resp_send_chunk(req, NULL, 0);
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_rssi - End");
|
||||
LogFile.WriteHeapInfo("handler_uptime - End");
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
esp_err_t handler_prevalue(httpd_req_t *req)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_prevalue - Start");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_prevalue - Start");
|
||||
#endif
|
||||
|
||||
const char* resp_str;
|
||||
string zw;
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "handler_prevalue: %s", req->uri);
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "handler_prevalue: %s", req->uri);
|
||||
#endif
|
||||
|
||||
char _query[100];
|
||||
char _size[10] = "";
|
||||
@@ -674,15 +729,15 @@ esp_err_t handler_prevalue(httpd_req_t *req)
|
||||
|
||||
if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Query: %s", _query);
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Query: %s", _query);
|
||||
#endif
|
||||
|
||||
if (httpd_query_key_value(_query, "value", _size, 10) == ESP_OK)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Value: %s", _size);
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Value: %s", _size);
|
||||
#endif
|
||||
}
|
||||
|
||||
httpd_query_key_value(_query, "numbers", _numbers, 50);
|
||||
@@ -706,12 +761,13 @@ esp_err_t handler_prevalue(httpd_req_t *req)
|
||||
/* Respond with an empty chunk to signal HTTP response completion */
|
||||
httpd_resp_send_chunk(req, NULL, 0);
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_prevalue - End");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("handler_prevalue - End");
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
void task_autodoFlow(void *pvParameter)
|
||||
{
|
||||
@@ -721,6 +777,7 @@ void task_autodoFlow(void *pvParameter)
|
||||
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Restarted due to an Exception/panic! Postponing first round start by 5 minutes to allow for an OTA or to fetch the log!");
|
||||
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Setting logfile level to DEBUG until the next reboot!");
|
||||
LogFile.setLogLevel(ESP_LOG_DEBUG);
|
||||
//MQTTPublish(GetMQTTMainTopic() + "/" + "status", "Postponing first round", false);
|
||||
vTaskDelay(60*5000 / portTICK_RATE_MS); // Wait 5 minutes to give time to do an OTA or fetch the log
|
||||
}
|
||||
|
||||
@@ -744,20 +801,20 @@ void task_autodoFlow(void *pvParameter)
|
||||
|
||||
if (flowisrunning)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Autoflow: doFlow is already running!");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Autoflow: doFlow is already running!");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Autoflow: doFlow is started");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Autoflow: doFlow is started");
|
||||
#endif
|
||||
flowisrunning = true;
|
||||
doflow();
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Remove older log files");
|
||||
#endif
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Remove older log files");
|
||||
#endif
|
||||
LogFile.RemoveOldLogFile();
|
||||
LogFile.RemoveOldDataLog();
|
||||
}
|
||||
@@ -784,6 +841,7 @@ void task_autodoFlow(void *pvParameter)
|
||||
ESP_LOGD(TAG, "task_autodoFlow: end");
|
||||
}
|
||||
|
||||
|
||||
void TFliteDoAutoStart()
|
||||
{
|
||||
BaseType_t xReturned;
|
||||
@@ -801,10 +859,9 @@ void TFliteDoAutoStart()
|
||||
ESP_LOGD(TAG, "ERROR task_autodoFlow konnte nicht erzeugt werden!");
|
||||
}
|
||||
ESP_LOGD(TAG, "getESPHeapInfo: %s", getESPHeapInfo().c_str());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#ifdef ENABLE_MQTT
|
||||
std::string GetMQTTMainTopic()
|
||||
{
|
||||
@@ -873,6 +930,11 @@ void register_server_tflite_uri(httpd_handle_t server)
|
||||
camuri.user_ctx = (void*) "Light Off";
|
||||
httpd_register_uri_handler(server, &camuri);
|
||||
|
||||
camuri.uri = "/uptime";
|
||||
camuri.handler = handler_uptime;
|
||||
camuri.user_ctx = (void*) "Light Off";
|
||||
httpd_register_uri_handler(server, &camuri);
|
||||
|
||||
camuri.uri = "/editflow";
|
||||
camuri.handler = handler_editflow;
|
||||
camuri.user_ctx = (void*) "EditFlow";
|
||||
|
||||
@@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
|
||||
|
||||
idf_component_register(SRCS ${app_sources}
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES nvs_flash jomjol_helper)
|
||||
REQUIRES nvs_flash jomjol_helper jomjol_mqtt)
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sys.h"
|
||||
#ifdef ENABLE_MQTT
|
||||
#include "interface_mqtt.h"
|
||||
#endif //ENABLE_MQTT
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
@@ -38,6 +41,7 @@ static EventGroupHandle_t s_wifi_event_group;
|
||||
static const char *TAG = "WIFI";
|
||||
|
||||
static int s_retry_num = 0;
|
||||
bool WIFIConnected = false;
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
#define BLINK_GPIO GPIO_NUM_33
|
||||
@@ -113,9 +117,11 @@ static void event_handler(void* arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void* event_data)
|
||||
{
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
|
||||
WIFIConnected = false;
|
||||
LEDBlinkTask(200, 1, true);
|
||||
esp_wifi_connect();
|
||||
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||
WIFIConnected = false;
|
||||
// if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) {
|
||||
esp_wifi_connect();
|
||||
s_retry_num++;
|
||||
@@ -131,6 +137,14 @@ static void event_handler(void* arg, esp_event_base_t event_base,
|
||||
s_retry_num = 0;
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
|
||||
LEDBlinkTask(1000, 5, true);
|
||||
|
||||
WIFIConnected = true;
|
||||
#ifdef ENABLE_MQTT
|
||||
if (getMQTTisEnabled()) {
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
MQTT_Init(); // Init when WIFI is getting connected
|
||||
}
|
||||
#endif //ENABLE_MQTT
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,17 +263,17 @@ void wifi_init_sta(const char *_ssid, const char *_password, const char *_hostna
|
||||
/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
|
||||
* happened. */
|
||||
if (bits & WIFI_CONNECTED_BIT) {
|
||||
#ifdef __HIDE_PASSWORD
|
||||
ESP_LOGI(TAG, "connected to ap SSID: %s, password: XXXXXXX", _ssid);
|
||||
#else
|
||||
ESP_LOGI(TAG, "connected to ap SSID: %s, password: %s", _ssid, _password);
|
||||
#endif
|
||||
#ifdef __HIDE_PASSWORD
|
||||
ESP_LOGI(TAG, "connected to ap SSID: %s, password: XXXXXXX", _ssid);
|
||||
#else
|
||||
ESP_LOGI(TAG, "connected to ap SSID: %s, password: %s", _ssid, _password);
|
||||
#endif
|
||||
} else if (bits & WIFI_FAIL_BIT) {
|
||||
#ifdef __HIDE_PASSWORD
|
||||
ESP_LOGI(TAG, "Failed to connect to SSID: %s, password: XXXXXXXX", _ssid);
|
||||
#else
|
||||
ESP_LOGI(TAG, "Failed to connect to SSID: %s, password: %s", _ssid, _password);
|
||||
#endif
|
||||
#ifdef __HIDE_PASSWORD
|
||||
ESP_LOGI(TAG, "Failed to connect to SSID: %s, password: XXXXXXXX", _ssid);
|
||||
#else
|
||||
ESP_LOGI(TAG, "Failed to connect to SSID: %s, password: %s", _ssid, _password);
|
||||
#endif
|
||||
} else {
|
||||
ESP_LOGE(TAG, "UNEXPECTED EVENT");
|
||||
}
|
||||
@@ -289,3 +303,7 @@ void wifi_init_sta(const char *_ssid, const char *_password)
|
||||
wifi_init_sta(_ssid, _password, NULL, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
bool getWIFIisConnected() {
|
||||
return WIFIConnected;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ void wifi_init_sta(const char *_ssid, const char *_password);
|
||||
std::string* getIPAddress();
|
||||
std::string* getSSID();
|
||||
int get_WIFI_RSSI();
|
||||
bool getWIFIisConnected();
|
||||
|
||||
extern std::string hostname;
|
||||
extern std::string std_hostname;
|
||||
|
||||
@@ -65,5 +65,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/main/*.*)
|
||||
# idf_component_register(SRCS ${app_sources})
|
||||
|
||||
idf_component_register(SRCS ${app_sources}
|
||||
INCLUDE_DIRS ".")
|
||||
|
||||
INCLUDE_DIRS "."
|
||||
# REQUIRES esp_psram) # comming in IDF 5.0
|
||||
)
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "sdkconfig.h"
|
||||
//#include "esp_psram.h" // Comming in IDF 5.0, see https://docs.espressif.com/projects/esp-idf/en/v5.0-beta1/esp32/migration-guides/release-5.x/system.html?highlight=esp_psram_get_size
|
||||
#include "esp32/spiram.h"
|
||||
|
||||
// SD-Card ////////////////////
|
||||
#include "nvs_flash.h"
|
||||
@@ -122,7 +124,7 @@ bool Init_NVS_SDCard()
|
||||
return true;
|
||||
}
|
||||
|
||||
void task_NoSDBlink(void *pvParameter)
|
||||
void task_MainInitError_blink(void *pvParameter)
|
||||
{
|
||||
gpio_pad_select_gpio(BLINK_GPIO);
|
||||
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
|
||||
@@ -147,7 +149,6 @@ void task_NoSDBlink(void *pvParameter)
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
TickType_t xDelay;
|
||||
bool initSucessful = true;
|
||||
|
||||
ESP_LOGI(TAG, "\n\n\n\n\n"); // Add mark on log to see when it restarted
|
||||
|
||||
@@ -160,9 +161,9 @@ extern "C" void app_main(void)
|
||||
|
||||
if (!Init_NVS_SDCard())
|
||||
{
|
||||
xTaskCreate(&task_NoSDBlink, "task_NoSDBlink", configMINIMAL_STACK_SIZE * 64, NULL, tskIDLE_PRIORITY+1, NULL);
|
||||
return;
|
||||
};
|
||||
xTaskCreate(&task_MainInitError_blink, "task_MainInitError_blink", configMINIMAL_STACK_SIZE * 64, NULL, tskIDLE_PRIORITY+1, NULL);
|
||||
return; // No way to continue without SD-Card!
|
||||
}
|
||||
|
||||
string versionFormated = "Branch: '" + std::string(GIT_BRANCH) + \
|
||||
"', Revision: " + std::string(GIT_REV) +", Date/Time: " + std::string(BUILD_TIME) + \
|
||||
@@ -216,6 +217,7 @@ extern "C" void app_main(void)
|
||||
|
||||
if (!setup_time()) {
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "NTP Initialization failed!");
|
||||
setSystemStatusFlag(SYSTEM_STATUS_NTP_BAD);
|
||||
}
|
||||
|
||||
setBootTime();
|
||||
@@ -231,13 +233,32 @@ extern "C" void app_main(void)
|
||||
std::string zw = gettimestring("%Y%m%d-%H%M%S");
|
||||
ESP_LOGD(TAG, "time %s", zw.c_str());
|
||||
|
||||
/* Check if PSRAM can be initalized */
|
||||
esp_err_t ret;
|
||||
ret = esp_spiram_init();
|
||||
if (ret == ESP_FAIL) { // Failed to init PSRAM, most likely not available or broken
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to initialize PSRAM (" + std::to_string(ret) + ")!");
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Either your device misses the PSRAM chip or it is broken!");
|
||||
setSystemStatusFlag(SYSTEM_STATUS_PSRAM_BAD);
|
||||
}
|
||||
else { // PSRAM init ok
|
||||
/* Check if PSRAM provides at least 4 MB */
|
||||
size_t psram_size = esp_spiram_get_size();
|
||||
// size_t psram_size = esp_psram_get_size(); // comming in IDF 5.0
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "The device has " + std::to_string(psram_size/1024/1024) + " MBytes of PSRAM");
|
||||
if (psram_size < (4*1024*1024)) { // PSRAM is below 4 MBytes
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "At least 4 MBytes are required!");
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Does the device really have a 4 Mbytes PSRAM?");
|
||||
setSystemStatusFlag(SYSTEM_STATUS_PSRAM_BAD);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check available Heap memory */
|
||||
size_t _hsize = getESPHeapSize();
|
||||
if (_hsize < 4000000) // Check for a bit less than 4 MB (but clearly over 2 MB)
|
||||
{
|
||||
std::string _zws = "Not enough PSRAM available. Expected around 4 MBytes - available: " + std::to_string((float)_hsize/1024/1024) + " MBytes!";
|
||||
_zws = _zws + "\nEither not initialized, too small (2 MByte only) or not present at all. Firmware cannot start!!";
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zws);
|
||||
} else { // Bad Camera Status, retry init
|
||||
if (_hsize < 4000000) { // Check available Heap memory for a bit less than 4 MB (a test on a good device showed 4187558 bytes to be available)
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Not enough Heap memory available. Expected around 4 MBytes, but only " + std::to_string(_hsize) + " Bytes are available! That is not enough for this firmware!");
|
||||
setSystemStatusFlag(SYSTEM_STATUS_HEAP_TOO_SMALL);
|
||||
} else { // Heap memory is ok
|
||||
if (camStatus != ESP_OK) {
|
||||
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Failed to initialize camera module, retrying...");
|
||||
|
||||
@@ -251,7 +272,7 @@ extern "C" void app_main(void)
|
||||
if (camStatus != ESP_OK) {
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to initialize camera module!");
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Check that your camera module is working and connected properly!");
|
||||
initSucessful = false;
|
||||
setSystemStatusFlag(SYSTEM_STATUS_CAM_BAD);
|
||||
}
|
||||
} else { // Test Camera
|
||||
camera_fb_t * fb = esp_camera_fb_get();
|
||||
@@ -259,8 +280,8 @@ extern "C" void app_main(void)
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Camera Framebuffer cannot be initialized!");
|
||||
/* Easiest would be to simply restart here and try again,
|
||||
how ever there seem to be systems where it fails at startup but still work corectly later.
|
||||
Therefore we treat it still as successed!
|
||||
//initSucessful = false; */
|
||||
Therefore we treat it still as successed! */
|
||||
setSystemStatusFlag(SYSTEM_STATUS_CAM_FB_BAD);
|
||||
}
|
||||
else {
|
||||
esp_camera_fb_return(fb);
|
||||
@@ -269,8 +290,6 @@ extern "C" void app_main(void)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
xDelay = 2000 / portTICK_PERIOD_MS;
|
||||
ESP_LOGD(TAG, "main: sleep for: %ldms", (long) xDelay*10);
|
||||
vTaskDelay( xDelay );
|
||||
@@ -291,17 +310,24 @@ extern "C" void app_main(void)
|
||||
ESP_LOGD(TAG, "vor reg server main");
|
||||
register_server_main_uri(server, "/sdcard");
|
||||
|
||||
if (initSucessful) {
|
||||
|
||||
/* Testing */
|
||||
//setSystemStatusFlag(SYSTEM_STATUS_CAM_FB_BAD);
|
||||
//setSystemStatusFlag(SYSTEM_STATUS_PSRAM_BAD);
|
||||
|
||||
/* Main Init has successed or only an error which allows to continue operation */
|
||||
if (getSystemStatus() == 0) { // No error flag is set
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Initialization completed successfully!");
|
||||
ESP_LOGD(TAG, "vor do autostart");
|
||||
TFliteDoAutoStart();
|
||||
}
|
||||
else { // Initialization failed
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Initialization failed. Will restart in 5 minutes!");
|
||||
vTaskDelay(60*4000 / portTICK_RATE_MS); // Wait 4 minutes to give time to do an OTA or fetch the log
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Initialization failed. Will restart in 1 minute!");
|
||||
vTaskDelay(60*1000 / portTICK_RATE_MS); // Wait 1 minute to give time to do an OTA or fetch the log
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Initialization failed. Will restart now!");
|
||||
doReboot();
|
||||
else if (isSetSystemStatusFlag(SYSTEM_STATUS_CAM_FB_BAD) || // Non critical errors occured, we try to continue...
|
||||
isSetSystemStatusFlag(SYSTEM_STATUS_NTP_BAD)) {
|
||||
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Initialization completed with errors, but trying to continue...");
|
||||
ESP_LOGD(TAG, "vor do autostart");
|
||||
TFliteDoAutoStart();
|
||||
}
|
||||
else { // Any other error is critical and makes running the flow impossible.
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Initialization failed. Not starting flows!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +128,14 @@ esp_err_t info_get_handler(httpd_req_t *req)
|
||||
httpd_resp_sendstr_chunk(req, NULL);
|
||||
return ESP_OK;
|
||||
}
|
||||
else if (_task.compare("Round") == 0)
|
||||
{
|
||||
char formated[10] = "";
|
||||
snprintf(formated, sizeof(formated), "%d", getCountFlowRounds());
|
||||
httpd_resp_sendstr_chunk(req, formated);
|
||||
httpd_resp_sendstr_chunk(req, NULL);
|
||||
return ESP_OK;
|
||||
}
|
||||
else if (_task.compare("SDCardPartitionSize") == 0)
|
||||
{
|
||||
std::string zw;
|
||||
@@ -230,9 +238,33 @@ esp_err_t hello_main_handler(httpd_req_t *req)
|
||||
}
|
||||
}
|
||||
|
||||
if (filetosend == "/sdcard/html/index.html" && isSetupModusActive()) {
|
||||
ESP_LOGD(TAG, "System is in setup mode --> index.html --> setup.html");
|
||||
filetosend = "/sdcard/html/setup.html";
|
||||
if (filetosend == "/sdcard/html/index.html") {
|
||||
if (isSetSystemStatusFlag(SYSTEM_STATUS_PSRAM_BAD) || // Initialization failed with crritical errors!
|
||||
isSetSystemStatusFlag(SYSTEM_STATUS_CAM_BAD)) {
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "We have a critical error, not serving main page!");
|
||||
|
||||
char buf[20];
|
||||
std::string message = "<h1>AI on the Edge Device</h1><b>We have one or more critical errors:</b><br>";
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if (isSetSystemStatusFlag((SystemStatusFlag_t)(1<<i))) {
|
||||
snprintf(buf, sizeof(buf), "0x%08X", 1<<i);
|
||||
message += std::string(buf) + "<br>";
|
||||
}
|
||||
}
|
||||
|
||||
message += "<br>Please check <a href=\"https://github.com/jomjol/AI-on-the-edge-device/wiki/Error-Codes\" target=_blank>github.com/jomjol/AI-on-the-edge-device/wiki/Error-Codes</a> for more information!";
|
||||
message += "<br><br><button onclick=\"window.location.href='/reboot';\">Reboot</button>";
|
||||
message += " <button onclick=\"window.open('/ota_page.html');\">OTA Update</button>";
|
||||
message += " <button onclick=\"window.open('/log.html');\">Log Viewer</button>";
|
||||
message += " <button onclick=\"window.open('/info.html');\">Show System Info</button>";
|
||||
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, message.c_str());
|
||||
return ESP_FAIL;
|
||||
}
|
||||
else if (isSetupModusActive()) {
|
||||
ESP_LOGD(TAG, "System is in setup mode --> index.html --> setup.html");
|
||||
filetosend = "/sdcard/html/setup.html";
|
||||
}
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "Filename: %s", filename);
|
||||
@@ -427,9 +459,9 @@ httpd_handle_t start_webserver(void)
|
||||
httpd_handle_t server = NULL;
|
||||
httpd_config_t config = { };
|
||||
|
||||
config.task_priority = tskIDLE_PRIORITY+1; // 20210924 --> vorher +5
|
||||
config.task_priority = tskIDLE_PRIORITY+3; //20221211: before: tskIDLE_PRIORITY+1; // 20210924 --> vorher +5
|
||||
config.stack_size = 32768; //20210921 --> vorher 32768 // bei 32k stürzt das Programm beim Bilderaufnehmen ab
|
||||
config.core_id = tskNO_AFFINITY;
|
||||
config.core_id = 0; //20221211 --> force all not flow related tasks to CPU0, before: tskNO_AFFINITY;
|
||||
config.server_port = 80;
|
||||
config.ctrl_port = 32768;
|
||||
config.max_open_sockets = 5; //20210921 --> vorher 7
|
||||
@@ -437,8 +469,8 @@ httpd_handle_t start_webserver(void)
|
||||
config.max_resp_headers = 8;
|
||||
config.backlog_conn = 5;
|
||||
config.lru_purge_enable = true; // dadurch werden alte Verbindungen gekappt, falls neue benögt werden.
|
||||
config.recv_wait_timeout = 5; // default: 5 20210924 --> vorher 30
|
||||
config.send_wait_timeout = 5; // default: 5 20210924 --> vorher 30
|
||||
config.recv_wait_timeout = 5; // default: 5 20210924 --> vorher 30
|
||||
config.send_wait_timeout = 5; // default: 5 20210924 --> vorher 30
|
||||
config.global_user_ctx = NULL;
|
||||
config.global_user_ctx_free_fn = NULL;
|
||||
config.global_transport_ctx = NULL;
|
||||
|
||||
@@ -36,28 +36,31 @@ CONFIG_SPIRAM_MEMTEST=y
|
||||
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=16384
|
||||
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=40960
|
||||
CONFIG_SPIRAM_CACHE_WORKAROUND=y
|
||||
CONFIG_SPIRAM_IGNORE_NOTFOUND=y
|
||||
|
||||
CONFIG_ESP_INT_WDT_TIMEOUT_MS=300
|
||||
|
||||
CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024
|
||||
|
||||
CONFIG_HTTPD_PURGE_BUF_LEN=16
|
||||
|
||||
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=16
|
||||
|
||||
CONFIG_ESP32_WIFI_CACHE_TX_BUFFER_NUM=16
|
||||
|
||||
CONFIG_FATFS_LFN_HEAP=y
|
||||
|
||||
CONFIG_FATFS_MAX_LFN=255
|
||||
CONFIG_FATFS_API_ENCODING_ANSI_OEM=y
|
||||
|
||||
CONFIG_FMB_TIMER_PORT_ENABLED=y
|
||||
|
||||
CONFIG_MQTT_MSG_ID_INCREMENTAL=y
|
||||
CONFIG_MQTT_SKIP_PUBLISH_IF_DISCONNECTED=y
|
||||
CONFIG_MQTT_TASK_CORE_SELECTION_ENABLED=y
|
||||
CONFIG_MQTT_USE_CORE_0=y
|
||||
|
||||
CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER=n
|
||||
|
||||
CONFIG_CAMERA_CORE0=n
|
||||
CONFIG_CAMERA_CORE1=y
|
||||
CONFIG_OV7670_SUPPORT=n
|
||||
CONFIG_OV7725_SUPPORT=n
|
||||
CONFIG_NT99141_SUPPORT=n
|
||||
|
||||
Reference in New Issue
Block a user