Compare commits

...

1151 Commits

Author SHA1 Message Date
Frank Haverland
575d59dad2 fix release creation (#1422)
* 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 commit 4f51ec7962.

* 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 commit f68695a4c0, reversing
changes made to a096cf7182.

* Revert "test"

This reverts commit a096cf7182.

* revert testing

Co-authored-by: github-actions <github-actions@github.com>
2022-11-28 21:02:20 +01:00
CaCO3
524d800a0a Update info page (#1420)
* consolidate info page

* use new REST API

* .

* .

* .

* .

* .

* .

* .

* Make sure after the reboot we go to the overview page

* .

* Update server_main.cpp
2022-11-28 18:51:11 +01:00
jomjol
7b0e6200d6 Update Changelog.md 2022-11-27 19:21:37 +01:00
jomjol
65d011c9aa Merge branch 'rolling' 2022-11-27 18:43:31 +01:00
jomjol
dc3604f144 v13.0.0 2022-11-27 18:39:31 +01:00
CaCO3
1eb2dd4efa Update Changelog.md (#1418) 2022-11-27 17:07:23 +01:00
Frank Haverland
f4d345b902 fix problem with prepare release (#1417)
* fix kernel panic (vector out of range) in getReadoutRawString

* Update

* Revert "Update"

This reverts commit b50be7e825.

* fix key of caches

* fix key of caches

* fix key caches

* fix cache keys

* fix cache keys

* move set variables to top

* debug

Co-authored-by: jomjol <30766535+jomjol@users.noreply.github.com>
2022-11-27 17:07:12 +01:00
jomjol
a38837c61b Revert "Update"
This reverts commit b50be7e825.
2022-11-27 09:13:12 +01:00
jomjol
b50be7e825 Update 2022-11-27 09:12:24 +01:00
jomjol
74f45bee28 Update Changelog.md 2022-11-27 09:08:48 +01:00
jomjol
47b3b0c708 Update readconfigparam.js 2022-11-26 07:29:16 +01:00
CaCO3
9c390f3026 make button titles consistent (#1412)
Co-authored-by: CaCO3 <caco@ruinelli.ch>
2022-11-26 07:15:10 +01:00
jomjol
069aac5723 Downwards compatibility for DataLogging 2022-11-25 19:58:15 +01:00
CaCO3
9335cd73d5 Merge branch 'master' into rolling 2022-11-25 16:49:34 +01:00
CaCO3
e90beffb44 resolve release merge conflicts 2022-11-25 16:48:37 +01:00
CaCO3
55a06dbe1d resolve release merge conflicts 2022-11-25 16:47:59 +01:00
CaCO3
ae07159afe resolve release merge conflicts 2022-11-25 16:47:07 +01:00
CaCO3
1fff655ef1 resolve release merge conflicts 2022-11-25 16:46:26 +01:00
CaCO3
3815f9cf0a resolve release merge conflicts 2022-11-25 16:45:02 +01:00
CaCO3
e36490c89e resolve release merge conflicts 2022-11-25 16:37:54 +01:00
CaCO3
d4f02f971f solve release merge conflicts 2022-11-25 16:36:34 +01:00
CaCO3
ec326d9a11 resolve release merge conflicts 2022-11-25 08:32:28 +01:00
CaCO3
6e4df0ef87 Keep iframe page on reload (#1406)
* rename overview page

* reload same page in iframe again after reloading index page

Co-authored-by: CaCO3 <caco@ruinelli.ch>
2022-11-25 07:25:32 +01:00
CaCO3
3aa0411676 Use raw value as prevalue (#1405)
* remove loggng password

* use raw value of selected number as default value

* fix log message

Co-authored-by: CaCO3 <caco@ruinelli.ch>
2022-11-25 07:24:23 +01:00
CaCO3
9f20c126be Catch empty ref images (#1397)
* slow down constant reboots caused by the flow. With this, after a restart due to exception/panic the first round gets delayed by 5 minutes

* catch empty reference images

* .

Co-authored-by: CaCO3 <caco@ruinelli.ch>
2022-11-25 07:23:15 +01:00
jomjol
2707e8c9f4 Update tflite 2022-11-24 18:42:31 +01:00
CaCO3
0d467d8ad1 slow down reboot loops (#1396)
* slow down constant reboots caused by the flow. With this, after a restart due to exception/panic the first round gets delayed by 5 minutes

* retry InitCam() if it failed

* restart after 5 minutes if NTP init failed

* .

Co-authored-by: CaCO3 <caco@ruinelli.ch>
2022-11-23 21:52:51 +01:00
Slider0007
66be09c98e Add parameter to disable write data log (#1382) 2022-11-20 17:44:42 +01:00
CaCO3
60e9a427a5 Updated changelog (#1381) 2022-11-20 17:41:23 +01:00
rstephan
f72bdb7c45 Use none chunked transfer for "/json" endpoint (#1379) 2022-11-20 17:40:55 +01:00
jomjol
a53188e697 Update tflite, Readme.md 2022-11-18 21:46:22 +01:00
Slider0007
0dd63b9b7a Fix file retention, remove/correct logs (#1377) 2022-11-18 19:23:18 +01:00
CaCO3
513e300676 fix version check (#1374)
Co-authored-by: CaCO3 <caco@ruinelli.ch>
2022-11-18 06:54:51 +01:00
CaCO3
dd28859a9f Updated setup mode (#1370)
* update config

* delete unused file

* added notes about not-needed reboot, added links to wiki and discussions

Co-authored-by: CaCO3 <caco@ruinelli.ch>
2022-11-18 06:54:19 +01:00
CaCO3
ecc43edbba Improve NTP (#1364)
* checking NTP status on every round and restart NTP client if we still are in 1970

* .

* .

* .

Co-authored-by: CaCO3 <caco@ruinelli.ch>
2022-11-17 19:01:24 +01:00
CaCO3
bf8ab423e3 add link to file server (#1367) 2022-11-17 18:25:02 +01:00
CaCO3
8116a546b5 Update bug_report.yml 2022-11-17 18:07:40 +01:00
CaCO3
5c512367e2 Update bug_report.yml (#1365)
* Update bug_report.yml

* Update x_plain.yaml

* Update x_plain.yaml
2022-11-17 18:04:01 +01:00
CaCO3
e15ea561bc Enhance ROI editing (#1357)
* add labels to ROIs

* .

* fix naming check

* .

* .

Co-authored-by: CaCO3 <caco@ruinelli.ch>
2022-11-16 18:32:53 +01:00
CaCO3
9e4332314a Update training.yaml 2022-11-16 07:54:04 +01:00
CaCO3
880d9eae20 replace division by a multiplication (#1352)
Co-authored-by: CaCO3 <caco@ruinelli.ch>
2022-11-16 07:50:59 +01:00
SkylightXD
72fcd791db Update README.md (#1349)
Add gas meter case
2022-11-15 18:39:48 +01:00
CaCO3
39960b15ed Check web UI version and show alert on mismatch with Firmware version (#1329)
* SHhw Web UI version and compare it with the firmware. If it does not match, show a warning in the log

* compare version on Web UI loading and show alert on mismatch

* restructured info page
2022-11-14 19:58:22 +01:00
CaCO3
395b9a4c5b Lock sizes and keep X spaces equidistant (#1339)
* keep y, dx and dy identical

* added alert

* .

* add button to make X soaces equidistant

* .

* .

* add checkbox to synchronize dx and dy
2022-11-13 08:25:49 +01:00
George Ruinelli
5a2753a50b Updated issue templates 2022-11-12 16:58:02 +01:00
George Ruinelli
57c5c19cca Copy issue templated from master to rolling 2022-11-12 16:51:16 +01:00
CaCO3
c64ed36fa4 Support white space and equal in passwords (#1327)
* Updated the web Installer page, removed all redudnant files in the docs folder, updated the main README

* .

* consolidate the 2 identical ZerlegeZeile() function and move it to Helper.cpp and add workaround for whitespace and equal sign in password fields

* remove redundant code in HelperZerlegeZeile()

* Updated the web Installer page, removed all redudnant files in the docs folder, updated the main README

* .

* consolidate the 2 identical ZerlegeZeile() function and move it to Helper.cpp and add workaround for whitespace and equal sign in password fields

* remove redundant code in HelperZerlegeZeile()
2022-11-11 19:11:53 +01:00
CaCO3
754981c67f Update edit_config_param.html (#1323) 2022-11-11 19:09:59 +01:00
CaCO3
5c22986e2e fix log format 2022-11-10 23:49:10 +01:00
CaCO3
1746920f61 fix image url (#1322)
* Update index.html

* Update index.html
2022-11-10 20:59:52 +01:00
CaCO3
d33380d2a0 Update web installer (#1312)
* Updated the web Installer page, removed all redudnant files in the docs folder, updated the main README

* .
2022-11-10 18:53:06 +01:00
CaCO3
889ed9e6be Disable the Idle Task Watchdog resp. the Task Watchdog in general because we do not use it ATM. (#1303) 2022-11-09 18:25:42 +01:00
CaCO3
2b0e0f7d4e MQTT improvements (#1302)
* Update server_mqtt.cpp

* Update server_mqtt.cpp

* skipp all MQTT publishing until the next round if an error occures

* improve logging

* only use group for uid and topic if there is more than one number

* .

* .
2022-11-09 18:25:24 +01:00
CaCO3
2314d7ef18 Add missing file content (#1301)
* added file content
2022-11-07 21:53:03 +01:00
CaCO3
bec3a5ee3b Update miniz to 3.0.1 (#1300)
* minor update to 11.0.1 (resp. 3.0.1)

* Updated miniz from 3.0.0 to 3.0.1 and moved it to a separate component.
2022-11-07 21:16:47 +01:00
jomjol
c738a9a4da Improve SetPrevalue 2022-11-07 19:12:36 +01:00
jomjol
e7c8706b1b Update Internal libraries (esp32cam, tflite), Enhance debugging for OTA problems
Update Miniz
2022-11-06 17:41:32 +01:00
jomjol
f725adf5ba Merge branch 'rolling' of https://github.com/jomjol/AI-on-the-edge-device into rolling 2022-11-06 08:19:39 +01:00
jomjol
7bb1b08bdb Extend ROI, Number name check 2022-11-06 08:19:24 +01:00
CaCO3
d1e7ef1fce Add tag to logfile write (#1287)
* HTML: implement data viewer

* Correct CSV error

* Improve OTA

* Use consistent Log TAG syntax, name TAG variable the same in every file.

* .

* .

* .

* .

* .

* Update server_tflite.cpp

* Correct CSV error

* Improve OTA

* Use consistent Log TAG syntax, name TAG variable the same in every file.

* .

* .

* .

* .

* .

* Update server_tflite.cpp

* .

* .

* .

* .

* .

* .

* .

* .

Co-authored-by: jomjol <30766535+jomjol@users.noreply.github.com>
2022-11-06 08:13:53 +01:00
CaCO3
08f7e1275e Added more issue templates (#1291)
* Create training.yaml

* Update training.yaml

* Create plain.yaml

* Rename .github/plain.yaml to .github/ISSUE_TEMPLATE/plain.yaml

* Update plain.yaml

* Update plain.yaml

* Update plain.yaml

* Update bug_report.yml

* Update config.yml

* Create feature.yaml

* Update feature.yaml

* Update feature.yaml

* Update feature.yaml

* Update feature.yaml

* Update bug_report.yml

* Rename plain.yaml to _plain.yaml

* Rename _plain.yaml to x_plain.yaml

* Update bug_report.yml

* Update feature.yaml

* Update training.yaml

* Update config.yml

* Update training.yaml

* Update x_plain.yaml
2022-11-06 08:12:55 +01:00
jomjol
529690ec60 Update readconfigparam.js 2022-11-05 23:42:52 +01:00
jomjol
59431a7eaf OTA update, CSV log, data viewer
OTA update & HTML: implement data viewer

Correct CSV error

Improve OTA

Update data & OTA
2022-11-05 22:44:53 +01:00
jomjol
23b5ffbb92 Merge branch 'rolling' of https://github.com/jomjol/AI-on-the-edge-device into rolling 2022-11-05 19:56:15 +01:00
jomjol
9b8594c040 Change data to csv, harmonize REST API editflow 2022-11-05 19:56:09 +01:00
CaCO3
3e082ed06e Enhance homeassistant discovery (V5) (#1275)
* manual re-creation of #1246

* removed non-working approach to get interval

* postpone the MQTT service start until the ClassFlowControll::ReadParameter() gets called

* Increase the max_uri_handlers to 35 (was 30)

* removed newlines in logs

* added parameter to UI

* Register handler to re-start MQTT Discovery

* fix param
2022-11-05 19:32:58 +01:00
jomjol
22fe50f80a Ensure, that no ',' or '.' is in the ROIs name 2022-11-05 13:56:32 +01:00
jomjol
885cd71b80 Improved OTA (empty firmware directory) 2022-11-05 11:33:26 +01:00
jomjol
8c6805ec7c Update max_uri_handler, improve OTA debugging 2022-11-05 08:08:00 +01:00
CaCO3
1fc0b41fca Cleanup REST API 2 (#1273) 2022-11-04 22:38:18 +01:00
jomjol
7e26744e2e Revert "Revert "System instable""
This reverts commit 1d9ef7e634.
2022-11-04 21:59:22 +01:00
CaCO3
1d9ef7e634 Revert "System instable"
This reverts commit cb84074981339d44266a1a999a7567a722af11f4.

Cleanup REST API (#1255)

* Replaced URIs:
- value.html => value
- statusflow.html => statusflow
- cputemp.html => cputemp
- rssi.html => rssi
- statusflow.html => statusflow

Removed URLs:
 - wasserzaehler.html

* keep legacy API

* .

* .

* .

* .

* .

* .

* updated links

Remove ErrorMessage

Fix various warnings which become fatal with later gcc versons in esp-idf 5.x (#1268)

- we cannot use partial initialisation of structs in C++ files (copied from example C files initially it seems)
- IRAM_ATTR uses a COUNTER, do not use the attribute on the implementation
- provide missing copy implementations for Rgb and Hsv
- one no longer can |= on volatile variables; use = | instead
- fix project and header includes
- avoid redefining BLINK_GPIO
- Remove defined but unused variables
- Fix printf formats
- Add missing case statement (HTTP_EVENT_REDIRECT)
- RMT needs to be updated to new interface (CONFIG_RMT_SUPPRESS_DEPRECATE_WARN is on currently; see https://docs.espressif.com/projects/esp-idf/en/release-v5.0/esp32/api-reference/peripherals/rmt.html)
- Adjust tcpip_adpater_* to esp_netif_*
- Use buffered versions of *ntoa* functions for IPv4 addresses and not a static on the stack (also fixes warnings)
- Whatever I missed

Correct spelling of "Hostname" (#1270)

Correct sdkonfig

Increase max handler due to new handlers

Revert "Cleanup REST API (#1255)"

This reverts commit f3e73ec64a.

Revert "Increase max handler due to new handlers"

This reverts commit cbd63ad4bd.

System instable

Revert "Revert "Cleanup REST API (#1255)""

This reverts commit 2793c761413ffb987ab6a75da372e00e9f2f2cbd.

Co-Authored-By: Bjoern A. Zeeb <patch@zabbadoz.net>
2022-11-04 21:59:01 +01:00
Frank Haverland
1be49a75b1 fix kernel panic (vector out of range) in getReadoutRawString (#1250) 2022-10-31 22:04:34 +01:00
jomjol
b6b7587f0a Update README.md 2022-10-30 22:09:14 +01:00
jomjol
e3017c25a9 Test Installer 2022-10-30 22:02:16 +01:00
jomjol
d914e69e7a Update Webinstaller 2022-10-30 21:57:28 +01:00
jomjol
edf9f11048 Update Webinstaller 2022-10-30 21:54:02 +01:00
jomjol
44afd138c5 Create /docs + installer 2022-10-30 21:48:06 +01:00
CaCO3
d2b93a7110 Enhance UI (#1243)
* Temporarily disable data file writing as it can cause crashs, see https://github.com/jomjol/AI-on-the-edge-device/issues/1225

* removed edit function in graph as we don't need that in a release

* .

* improve log viewer

* replaced logfile enable/disable with enum to select log level. At least errors always will be logged (as before)

* .

* .

* colorize log

* scroll down

* improve log reload
2022-10-30 20:44:13 +01:00
CaCO3
ff726485ba Improve MQTT (#1232)
added shared variable for autointerval to use it as MQTT LWT timeout
2022-10-30 20:08:14 +01:00
jomjol
de46cd899e Merge pull request #1234 from jomjol/add-homeassistant-discovery2
Add homeassistant discovery
2022-10-30 10:58:54 +01:00
jomjol
37263bb239 Update ClassFlowPostProcessing.cpp 2022-10-29 20:20:59 +02:00
CaCO3
d21a38f42f Added parameter to enable/disable Homeassistant Discovery 2022-10-29 18:45:47 +02:00
CaCO3
9b9a7537f1 . 2022-10-29 12:06:20 +02:00
CaCO3
56d8c65008 add maintopic to entity name to get a better entity ID. For some undocumented reason, HA removes the maintopic again in the name, so it looks ok :) 2022-10-29 11:50:19 +02:00
CaCO3
fc24db7d59 truncate log MQTT contents when they are too long and remove all newline characters in logfile writes 2022-10-28 23:42:04 +02:00
CaCO3
0867dcc6da . 2022-10-28 22:58:39 +02:00
CaCO3
b9f57edb92 added separate binary sensor "problem" indicating an error state 2022-10-28 22:53:23 +02:00
CaCO3
7ebbba3cf2 refactoring 2022-10-28 17:50:27 +02:00
CaCO3
5188734c8b added device classes 2022-10-28 17:09:32 +02:00
CaCO3
4e476a75ca changed error topic to a binary sensor, removed meas unit if it has no unit 2022-10-28 16:53:55 +02:00
CaCO3
7a037a3254 adjusted icons 2022-10-28 16:27:00 +02:00
CaCO3
f6b44ac905 renaming 2022-10-28 16:11:09 +02:00
CaCO3
deecc128be added user friendly name, corrected Wifi icon 2022-10-28 16:00:13 +02:00
CaCO3
18f2b5824e Update build.yaml
replace dot as the OTA has issues with it
2022-10-28 00:27:28 +02:00
CaCO3
45084bab70 Merge branch 'rolling' into add-homeassistant-discovery2 2022-10-27 23:43:41 +02:00
CaCO3
6cdbe38717 . 2022-10-27 23:35:48 +02:00
CaCO3
fe0d0c2590 . 2022-10-27 23:16:15 +02:00
CaCO3
44f61c7c91 . 2022-10-27 23:10:39 +02:00
CaCO3
af8b7d6824 . 2022-10-27 22:26:56 +02:00
jomjol
170583f8fe Merge pull request #1233 from haverland/rolling
fix test cases running in stackoverlfow
2022-10-27 22:05:27 +02:00
CaCO3
648a35e4d7 Add HomeAssistant Discovery Topics 2022-10-27 22:02:21 +02:00
jomjol
99849063d9 Merge pull request #1231 from jomjol/improve-logfile-logging
Improve logging to logfile
2022-10-27 21:56:50 +02:00
Frank Haverland
5b22007a1e changelog update 2022-10-27 21:18:09 +02:00
Frank Haverland
80cf89c9d5 added new version of dig-class100 (new heliowatt images) 2022-10-27 21:02:55 +02:00
Frank Haverland
45d37ea957 fix testcase creation if analog has no pointers 2022-10-27 21:02:22 +02:00
Frank Haverland
f935c38571 fix test cases running in stackoverlfow 2022-10-27 20:14:26 +02:00
CaCO3
bfc7c2b8b7 . 2022-10-27 19:06:47 +02:00
CaCO3
08f90de683 . 2022-10-27 19:05:00 +02:00
CaCO3
32748e3182 . 2022-10-27 13:13:23 +02:00
CaCO3
7a280bc7c6 added callback on connected 2022-10-27 12:18:23 +02:00
CaCO3
f4ae688527 refactored check if logfile is enabled. error messages always get logged now 2022-10-27 10:44:28 +02:00
CaCO3
ca45d0a278 . 2022-10-27 10:03:05 +02:00
CaCO3
8f66fcf2a6 . 2022-10-27 01:12:53 +02:00
CaCO3
30549ac5af refactored MQTT 2022-10-27 01:09:09 +02:00
CaCO3
06ab14a6c9 Merge branch 'improve-mqtt' of https://github.com/jomjol/AI-on-the-edge-device into improve-mqtt 2022-10-26 22:46:08 +02:00
CaCO3
72e3570dc4 . 2022-10-26 22:46:01 +02:00
CaCO3
724169b059 . 2022-10-26 22:46:01 +02:00
CaCO3
6e58f5eebb updated log messages 2022-10-26 22:46:01 +02:00
CaCO3
96b3d7cc2f . 2022-10-26 22:46:01 +02:00
CaCO3
74c9eada47 . 2022-10-26 22:46:01 +02:00
CaCO3
9d65889824 removed \r\n in logs 2022-10-26 22:46:01 +02:00
CaCO3
98451c8fc7 renamed mainerrortopic with lwt, only send it once on connecting, minor fixes and cleanups 2022-10-26 22:46:01 +02:00
CaCO3
6b47eef4cd use unique MQTT client ID. Without this (and multiple running deevices with same ID), they disconnect each other! 2022-10-26 22:46:01 +02:00
CaCO3
158ec65e57 Merge branch 'rolling' of https://github.com/jomjol/AI-on-the-edge-device into rolling 2022-10-26 22:45:50 +02:00
CaCO3
c4bbd7c545 Temporarily disable data file writing as it can cause crashs, see https://github.com/jomjol/AI-on-the-edge-device/issues/1225 (#1228) 2022-10-26 22:44:19 +02:00
CaCO3
cb323eb715 Merge branch 'improve-mqtt' of https://github.com/jomjol/AI-on-the-edge-device into improve-mqtt 2022-10-26 22:40:21 +02:00
CaCO3
1aa23aa14a updated log messages 2022-10-26 22:40:08 +02:00
CaCO3
41abc19a97 . 2022-10-26 22:40:08 +02:00
CaCO3
99e03dde06 . 2022-10-26 22:40:08 +02:00
CaCO3
9d73c5475e removed \r\n in logs 2022-10-26 22:40:08 +02:00
CaCO3
25ae9a045f renamed mainerrortopic with lwt, only send it once on connecting, minor fixes and cleanups 2022-10-26 22:40:08 +02:00
CaCO3
dabe66819d use unique MQTT client ID. Without this (and multiple running deevices with same ID), they disconnect each other! 2022-10-26 22:40:08 +02:00
CaCO3
4ad7b97764 Merge branch 'rolling' of https://github.com/jomjol/AI-on-the-edge-device into rolling 2022-10-26 22:39:49 +02:00
CaCO3
083aeb42ec Update build.yaml (#1229) 2022-10-26 22:37:43 +02:00
CaCO3
a13d1d0692 Temporarily disable data file writing as it can cause crashs, see https://github.com/jomjol/AI-on-the-edge-device/issues/1225 2022-10-26 22:31:34 +02:00
jomjol
c12645ab4d Merge pull request #1227 from haverland/rolling
fix regression tests
2022-10-26 22:13:57 +02:00
Frank Haverland
116c99e55c fix regression tests 2022-10-26 20:10:19 +02:00
CaCO3
43b65d6b2e updated log messages 2022-10-26 11:12:56 +02:00
CaCO3
bc7a0e46b7 . 2022-10-26 10:54:28 +02:00
CaCO3
455962bd94 . 2022-10-26 10:53:24 +02:00
CaCO3
86c515bcb8 removed \r\n in logs 2022-10-26 10:52:06 +02:00
CaCO3
f09067a142 renamed mainerrortopic with lwt, only send it once on connecting, minor fixes and cleanups 2022-10-26 10:34:15 +02:00
CaCO3
8ce24df304 use unique MQTT client ID. Without this (and multiple running deevices with same ID), they disconnect each other! 2022-10-26 10:25:17 +02:00
jomjol
279a59d019 Merge pull request #1223 from jomjol/add-uri-to-get-last-80kB-of-logfile
Add URI to get last 80kBytes of the current logfile
2022-10-26 06:57:01 +02:00
CaCO3
d88e286696 changed to 80 kBytes 2022-10-26 01:14:00 +02:00
CaCO3
d07aa2a72d added a new URI /log to get last 16kBytes of the current logfile 2022-10-26 01:08:56 +02:00
CaCO3
bf30872439 skip multiple action runs on same content 2022-10-25 21:20:50 +02:00
jomjol
12dc4eb460 Updated graphical representation 2022-10-25 20:55:57 +02:00
jomjol
ab67d1ff35 Merge pull request #1220 from jomjol/various-improvements
Various improvements
2022-10-25 20:55:05 +02:00
CaCO3
86809d8bf8 fixed missing parameters 2022-10-25 20:44:15 +02:00
jomjol
85adf70394 Merge branch 'rolling' into various-improvements 2022-10-25 20:06:16 +02:00
jomjol
290e7f3835 Merge pull request #1206 from jomjol/add-log-level-to-logfile2
Add log level to logfile
2022-10-25 20:02:26 +02:00
George Ruinelli
e9e0eed871 . 2022-10-25 14:35:43 +02:00
George Ruinelli
4ab0f632b7 . 2022-10-25 14:29:34 +02:00
George Ruinelli
1a33834b3f . 2022-10-25 14:16:41 +02:00
CaCO3
1d367a58d5 Merge branch 'rolling' into add-log-level-to-logfile2 2022-10-25 14:14:23 +02:00
George Ruinelli
ec4ce66bcc . 2022-10-25 13:49:44 +02:00
George Ruinelli
4a0f5eadc2 . 2022-10-25 13:44:52 +02:00
George Ruinelli
f955f8786b show reset reason, add function to get MAC 2022-10-25 13:43:54 +02:00
George Ruinelli
38f6e49d00 Add USB port to readme 2022-10-25 13:19:26 +02:00
jomjol
4394d832b8 Merge pull request #1218 from jomjol/updated-explanation
Updated explanation for run interval
2022-10-25 06:58:10 +02:00
jomjol
9e68380814 Merge pull request #1219 from haverland/rolling
Fix Github-action on pull requests
2022-10-25 06:55:36 +02:00
Frank Haverland
c8bb95a852 Merge branch 'rolling' of https://github.com/haverland/AI-on-the-edge-device into rolling 2022-10-25 06:19:22 +02:00
Frank Haverland
9c2de84ee4 fix slashes in github.ref_name 2022-10-25 06:18:43 +02:00
Frank Haverland
d4b1c2c883 Merge branch 'jomjol:rolling' into rolling 2022-10-25 05:59:50 +02:00
CaCO3
550d9e1c87 typos 2022-10-24 22:45:36 +02:00
CaCO3
3f687a7233 Update edit_config_param.html 2022-10-24 22:42:44 +02:00
CaCO3
c1369ca0ff Update build.yaml (#1216) 2022-10-24 22:32:26 +02:00
George Ruinelli
76c8bce7b4 . 2022-10-24 21:41:40 +02:00
jomjol
e0ae9b8e4f Extend Graph.html 2022-10-24 21:20:46 +02:00
Frank Haverland
9de573c15e Merge branch 'rolling' of https://github.com/haverland/AI-on-the-edge-device into rolling 2022-10-24 19:37:55 +02:00
jomjol
716c23fed3 Update graph.html to data 2022-10-23 18:59:55 +02:00
jomjol
8e22bd06e9 Update ClassFlowCNNGeneral.cpp 2022-10-23 18:09:05 +02:00
jomjol
b78929745b Improve data logging 2022-10-23 16:12:34 +02:00
jomjol
6986f2186c Extented data logging 2022-10-23 13:50:02 +02:00
jomjol
3743ac18f5 Implement direct data logging 2022-10-23 12:36:09 +02:00
jomjol
13f1d40ca3 Merge branch 'rolling' of https://github.com/jomjol/AI-on-the-edge-device into rolling 2022-10-23 09:39:24 +02:00
jomjol
63f28097bd Update Changelog.md 2022-10-23 09:39:16 +02:00
jomjol
ff7fec1de4 Merge pull request #1208 from Slider0007/Add-sd-card-info+patch
Add SD card info to info.html (recommit incl. fix)
2022-10-23 08:42:02 +02:00
Slider0007
f65b2850a2 correct case sensitivity of include 2022-10-22 23:50:39 +02:00
Slider0007
3a999358b9 correct case sensitivity of include 2022-10-22 23:49:42 +02:00
Slider0007
d3e195df9f Name adjustment 2022-10-22 23:49:33 +02:00
Slider0007
dbf8e634d9 Name adjustment 2022-10-22 23:49:22 +02:00
Slider0007
2b810ca32d Name adjustment 2022-10-22 23:49:09 +02:00
Slider0007
0adfc45d36 Name adjustment 2022-10-22 23:48:55 +02:00
Slider0007
2a54d9b889 Name adjustment 2022-10-22 23:48:43 +02:00
Slider0007
4150c31b98 Add SD Card Info to info.html 2022-10-22 23:48:30 +02:00
Slider0007
803e8f2bff Add SD Card Info to info.html 2022-10-22 23:48:12 +02:00
George Ruinelli
b215345f11 remove unused variable 2022-10-22 21:45:35 +02:00
jomjol
98d35e0412 Revert "Merge pull request #1205 from Slider0007/Add-sdcard-info"
This reverts commit 437e8e4d25, reversing
changes made to 0a2b6b71ca.
2022-10-22 21:44:35 +02:00
jomjol
437e8e4d25 Merge pull request #1205 from Slider0007/Add-sdcard-info
Add sd card infos to info.html
2022-10-22 21:26:17 +02:00
Slider0007
e05085ddf0 Name adjustment 2022-10-22 20:31:17 +02:00
Slider0007
495b5de38c Name adjustment 2022-10-22 20:29:32 +02:00
Slider0007
c2b89dd199 Name adjustment 2022-10-22 20:27:21 +02:00
Slider0007
f15b1e5dfc Name adjustment 2022-10-22 19:35:51 +02:00
Slider0007
e308a1b5d9 Name adjustment 2022-10-22 19:30:37 +02:00
George Ruinelli
1e698440f9 added log level to logfile, adjusted some loglevels 2022-10-22 18:05:08 +02:00
Slider0007
98bf7e5387 Add SD Card Info to info.html 2022-10-22 13:17:02 +02:00
Slider0007
e1f8ac59cb Add SD Card Info to info.html 2022-10-22 13:11:11 +02:00
jomjol
0a2b6b71ca Merge pull request #1202 from jomjol/consolidate-uart-and-logfile-logging
Consolidate uart and logfile logging
2022-10-22 12:36:28 +02:00
jomjol
5daae7b47c Merge pull request #1201 from jomjol/replace-printf-with-esp_log
Replace printf with ESP_LOGD
2022-10-22 12:35:13 +02:00
George Ruinelli
4951fc9b80 removed redundant log entries (some now are DEBUG isntread of INFO or ERROR) 2022-10-21 23:19:36 +02:00
George Ruinelli
0bf8182728 . 2022-10-21 22:55:36 +02:00
George Ruinelli
a512d82793 . 2022-10-21 22:13:13 +02:00
George Ruinelli
4f305a8705 . 2022-10-21 21:33:05 +02:00
George Ruinelli
46daa4cb79 replaced printf with ESP_LOGD 2022-10-21 20:54:38 +02:00
jomjol
485363d7a2 Update FeatureRequest.md 2022-10-21 07:07:45 +02:00
jomjol
c8d2d9d4fd Implement direct data log 2022-10-19 22:27:26 +02:00
jomjol
0880213342 Merge branch 'rolling' of https://github.com/jomjol/AI-on-the-edge-device into rolling 2022-10-19 22:08:55 +02:00
jomjol
8d4fb74173 Implement data log 2022-10-19 22:08:02 +02:00
CaCO3
f10adb3383 Update build.yaml (#1193) 2022-10-19 22:01:56 +02:00
jomjol
3be33820d9 Merge branch 'rolling' of https://github.com/jomjol/AI-on-the-edge-device into rolling 2022-10-19 20:30:41 +02:00
jomjol
83f638c64f start implementing direct data log 2022-10-19 20:23:15 +02:00
jomjol
35d77a3925 Merge pull request #1188 from haverland/fix_analogtodigital
Fix analogtodigital with configuration transition start
2022-10-19 20:22:02 +02:00
jomjol
a33da0c750 Merge pull request #1189 from Slider0007/rolling
Fix for image logging + file deletion routines
2022-10-19 20:16:14 +02:00
Slider0007
cd2350140d Fix for image logging + file deletion routines 2022-10-19 09:32:52 +02:00
Frank Haverland
bd125b249b Merge branch 'jomjol:rolling' into rolling 2022-10-18 23:04:14 +02:00
Frank Haverland
33b9a15f73 enable debug on CNNGeneral 2022-10-18 23:02:11 +02:00
Frank Haverland
0e55fc7f7e add @Plawasan test cases. Works now with setable analogdigitTransistionstart 2022-10-18 23:01:09 +02:00
Frank Haverland
fc0bbc57cb update changelog 2022-10-17 22:27:39 +02:00
Frank Haverland
bc46149573 init the analogDigitalTransitionStart with 9.2 if nothing set in config 2022-10-17 22:22:47 +02:00
Frank Haverland
be8598bcaa read and save config for AnalogDigitalTransitionStart 2022-10-17 21:36:11 +02:00
Frank Haverland
ace1936a78 added AnalogDigitalTransitionStart to expert config 2022-10-17 20:47:12 +02:00
Frank Haverland
e5649d03b2 min and max of ANALOGDIGITALTRANSITIONSTART added 2022-10-17 20:40:20 +02:00
Frank Haverland
426d6bae3f fix name of ANALOGDIGITALTRANSITIONSTART 2022-10-17 20:37:15 +02:00
Frank Haverland
5d35df65f3 add testNegative 2022-10-17 20:29:50 +02:00
Frank Haverland
f91f5e3cba rewrite of ZeigerEvalAnalogToDigitNeu added explizit test-cases for it. 2022-10-17 20:29:35 +02:00
jomjol
1c66f8c6ca Merge pull request #1183 from haverland/minor_negative_accept
fix change for tollerance for extendedResolution.
2022-10-16 21:59:32 +02:00
Frank Haverland
a42902af0d Merge branch 'jomjol:rolling' into rolling 2022-10-16 21:19:04 +02:00
Frank Haverland
a871055d96 fix change for tollerance for extendedResolution. Added testcases for it 2022-10-16 21:12:52 +02:00
jomjol
64fcb9595c Implement Graph 2022-10-16 19:22:01 +02:00
jomjol
9d9cff977d Merge pull request #1181 from rdmueller/rolling
date for graph is now selectable
2022-10-16 19:13:39 +02:00
Ralf D. Müller
5724f37ea6 date for graph is now selectable 2022-10-16 14:22:38 +00:00
jomjol
3ca93b49ca Update FeatureRequest.md 2022-10-16 08:34:19 +02:00
jomjol
b2248818dd Remark for InfluxDB Version 2022-10-16 08:29:14 +02:00
jomjol
a702fbbe86 Create graph.html 2022-10-15 18:37:41 +02:00
jomjol
1002e502d5 Merge pull request #1179 from rdmueller/master
Graph of values directly on the web interface
2022-10-15 18:33:32 +02:00
Ralf D. Müller
17a8adae05 remove debug code 2022-10-15 16:11:15 +00:00
Ralf D. Müller
4fca050623 fix date 2022-10-15 16:04:49 +00:00
Ralf D. Müller
f371c176b6 set current date 2022-10-15 15:45:52 +00:00
Ralf D. Müller
1c6772f383 fix event 2022-10-15 15:22:49 +00:00
Ralf D. Müller
7d2f28084b made editor hidden as default 2022-10-15 15:20:22 +00:00
jomjol
923b8d7444 Merge pull request #1177 from haverland/minor_negative_accept
accept minor negative values if extended resolution is enabled
2022-10-15 16:53:29 +02:00
Frank Haverland
49e4eb3ef3 updated changelog 2022-10-15 16:02:01 +02:00
Frank Haverland
2c481c0d15 accept minor negative values if extendedResolution is enabled 2022-10-15 15:23:20 +02:00
jomjol
f2e854c935 Merge pull request #1174 from haverland/fix_analogtodigital
Fix analogtodigital
2022-10-15 08:33:05 +02:00
Frank Haverland
8045e0bfaf added testcases for #1143
cleanup the analogtodigit for better reading.
2022-10-14 23:20:05 +02:00
Frank Haverland
40e176ec28 digit will be roundet now from x.7..x.9 out of transition of the pointer 2022-10-14 20:03:18 +02:00
Frank Haverland
1ab135e989 fix hanging digits in transition 2022-10-14 19:53:04 +02:00
Frank Haverland
99c14ae9e0 Merge branch 'jomjol:rolling' into rolling 2022-10-14 19:21:17 +02:00
jomjol
00d859734d Merge pull request #1173 from jomjol/revert-1167-fix_analogtodigital
Revert "Fix analogtodigital"
2022-10-14 18:13:32 +02:00
jomjol
de4efff558 Revert "Fix analogtodigital" 2022-10-14 18:13:11 +02:00
jomjol
2ed3f4aa40 Revert "Merge pull request #1167 from haverland/fix_analogtodigital"
This reverts commit ba59c8ee66, reversing
changes made to 730006977c.
2022-10-14 18:12:11 +02:00
jomjol
ba59c8ee66 Merge pull request #1167 from haverland/fix_analogtodigital
Fix analogtodigital
2022-10-14 18:10:26 +02:00
CaCO3
fb97e22dee Update server_ota.cpp (#1169) 2022-10-13 23:26:05 +02:00
Frank Haverland
b0e7283d2b added lokal test case 2022-10-13 22:40:33 +02:00
Frank Haverland
e341564eee missing test cases from #1110 added 2022-10-13 22:15:08 +02:00
CaCO3
730006977c improved issues guiding (#1168) 2022-10-13 21:58:18 +02:00
Frank Haverland
ea26a5722a rewrite of analogtodigit, added new testcases 2022-10-13 21:41:40 +02:00
Frank Haverland
62742d92d2 set python verion because of warnings 2022-10-12 22:41:41 +02:00
Frank Haverland
50b9983534 fix warning set-output 2022-10-12 22:38:05 +02:00
Frank Haverland
34ea8302ef update action setup-python 2022-10-12 22:29:02 +02:00
Frank Haverland
a8fd0bbdef use newer actions checkout and cache 2022-10-12 22:09:38 +02:00
Frank Haverland
99e6243e25 test case description 2022-10-12 21:36:19 +02:00
Frank Haverland
0f6c767143 fix analogtodigital: remove rounding 2022-10-12 21:34:24 +02:00
jomjol
eb0b932c44 rolling 20221010 2022-10-10 07:09:00 +02:00
jomjol
1e4be0f3fe Merge pull request #1158 from Turbo87/pre-json
FlowPostProcessing::GetJSON: Add `pre` field to the `/json` response
2022-10-09 19:08:28 +02:00
Tobias Bieniek
47caa1b118 FlowPostProcessing::GetJSON: Add pre field to the /json response
This makes it easier for third-party software to fall back to the `pre` value, if the `value` itself is not available for some reason.
2022-10-09 18:45:59 +02:00
jomjol
641609e187 Update espressif32 to v5.2.0 2022-10-08 10:51:19 +02:00
jomjol
006fb6a611 Merge pull request #1147 from jomjol/refactor-config-page
Refactor config page
2022-10-08 10:45:35 +02:00
George Ruinelli
a0e4ee1d00 . 2022-10-07 21:56:29 +02:00
George Ruinelli
27d770c759 . 2022-10-07 21:54:38 +02:00
George Ruinelli
fe39b5120b . 2022-10-07 21:38:51 +02:00
George Ruinelli
74df27befd . 2022-10-07 21:30:21 +02:00
George Ruinelli
c92a1e430d . 2022-10-07 21:04:56 +02:00
George Ruinelli
642d22578f . 2022-10-07 20:41:51 +02:00
George Ruinelli
140ec1b380 . 2022-10-07 18:52:18 +02:00
George Ruinelli
17090c177e . 2022-10-07 18:40:26 +02:00
George Ruinelli
d2721cbd4b . 2022-10-07 18:18:21 +02:00
George Ruinelli
f80509c886 . 2022-10-07 16:59:23 +02:00
George Ruinelli
6c85796abe . 2022-10-07 16:56:35 +02:00
CaCO3
e82cbbf117 Rename bug_report.md to bug_report.yml 2022-10-04 23:24:32 +02:00
jomjol
bacdc97d90 Merge pull request #1131 from jomjol/fix-bug-template
Update bug_report.md
2022-10-04 21:54:59 +02:00
CaCO3
1e43c70adf Update bug_report.md 2022-10-04 21:24:45 +02:00
jomjol
16bb6e90a9 Update FeatureRequest.md 2022-10-03 09:07:03 +02:00
jomjol
cf6882c579 Merge branch 'rolling' of https://github.com/jomjol/AI-on-the-edge-device into rolling 2022-10-03 09:05:45 +02:00
jomjol
858d0b3361 Update FeatureRequest.md 2022-10-03 09:00:24 +02:00
jomjol
208a5433b7 Merge pull request #1121 from cristianmitran/patch-1
Support meter clock over
2022-10-02 17:33:35 +02:00
cristianmitran
9a7c9604fe Support meter clock over 2022-10-02 08:35:53 +02:00
jomjol
f44fa4df31 Update Changelog.md 2022-10-01 08:27:22 +02:00
jomjol
68a985a09f Merge pull request #1118 from jomjol/update-changelog
Update Changelog.md
2022-10-01 08:23:59 +02:00
jomjol
6b329aaa58 Rolling 20220930 2022-09-30 07:48:33 +02:00
jomjol
80798ae0e6 Merge branch 'master' into rolling 2022-09-30 07:26:36 +02:00
jomjol
cd61e2c92d Merge pull request #1117 from jomjol/updated-readme
update README.md
2022-09-30 07:26:01 +02:00
jomjol
c943510828 Rolling 20220930 2022-09-30 07:23:46 +02:00
CaCO3
9291d330dd Update Changelog.md 2022-09-29 23:45:38 +02:00
CaCO3
a856d9e2f2 Create README.md 2022-09-29 23:36:01 +02:00
jomjol
41f9436465 Merge pull request #1113 from jomjol/fix-missing-hash
Update build.yaml
2022-09-29 22:13:37 +02:00
jomjol
5233c14725 Update README.md 2022-09-29 19:54:40 +02:00
jomjol
3d42d949af Update README.md 2022-09-29 19:52:49 +02:00
github-actions
aec1dc770b Update Changelog.md for release 2022-09-29 17:21:56 +00:00
CaCO3
f335c17f0d Update build.yaml 2022-09-29 19:21:23 +02:00
jomjol
dfe2c466bc Merge branch 'rolling' 2022-09-29 19:08:24 +02:00
jomjol
bb924531ef v12.0.0 2022-09-29 19:07:18 +02:00
github-actions
6e24b6fa88 Update Changelog.md for release 2022-09-29 17:02:32 +00:00
jomjol
d9a7c197fc v12.0.0 2022-09-29 18:38:06 +02:00
jomjol
14d30bae9d Merge pull request #1111 from jomjol/rolling
v12.0.0
2022-09-29 18:36:32 +02:00
jomjol
97ef1904bb v12.0.0 2022-09-29 18:24:59 +02:00
George Ruinelli
0856aea069 moved issue template to right place 2022-09-28 13:07:43 +02:00
jomjol
73e9253cb7 Merge pull request #1104 from jomjol/delete-old-ota-page
Delete ota_page_old.html
2022-09-28 12:35:19 +02:00
jomjol
663e97db97 Merge pull request #1103 from jomjol/added-issue-templates
Added issue templates
2022-09-28 12:34:52 +02:00
CaCO3
8b64266602 Update bug_report.md 2022-09-28 12:09:20 +02:00
CaCO3
e697cc5ec8 Addjusted time notes in OTA page 2022-09-28 09:43:08 +02:00
CaCO3
2c4d5a42d8 Delete ota_page_old.html 2022-09-28 09:42:05 +02:00
CaCO3
2f2ec23a53 Create general_question.md 2022-09-28 08:40:52 +02:00
CaCO3
3ad72f39a6 Create bug_report.md 2022-09-28 08:39:55 +02:00
jomjol
88a074dfa9 Rolling 20220928 2022-09-28 07:16:56 +02:00
jomjol
8c5f956dfe Merge pull request #1100 from jomjol/formating
Update Changelog.md
2022-09-28 06:58:21 +02:00
jomjol
505eed8767 Merge pull request #1099 from caco3/improve-ota-page
updated OTA page
2022-09-28 06:57:25 +02:00
CaCO3
cc9a3d3551 Update Changelog.md 2022-09-27 23:48:24 +02:00
CaCO3
70b743e364 . 2022-09-27 23:10:31 +02:00
CaCO3
6307b7f278 added reload note 2022-09-27 23:06:45 +02:00
CaCO3
ed2ee7ad90 updated OTA page, added progress counter, made async, removed reboot button 2022-09-27 22:56:00 +02:00
jomjol
26789f4187 Merge pull request #1098 from jomjol/update
Update Changelog.md
2022-09-27 22:29:07 +02:00
jomjol
923fc20ca5 Merge branch 'rolling' into update 2022-09-27 22:29:02 +02:00
jomjol
6808a37b69 Merge pull request #1097 from haverland/rolling
Add description for update from rolling.
2022-09-27 22:25:27 +02:00
CaCO3
f996e65a4d Update Changelog.md 2022-09-27 20:53:51 +02:00
CaCO3
0168f6b9b7 Update Changelog.md 2022-09-27 20:52:10 +02:00
CaCO3
e6b8643124 Update Changelog.md 2022-09-27 20:48:05 +02:00
Frank Haverland
69a92712ef Merge branch 'jomjol:rolling' into rolling 2022-09-27 20:11:22 +02:00
Frank Haverland
93804cec3f fix numbering 2022-09-27 20:11:11 +02:00
Frank Haverland
8cd430efc7 add description to update rolling and a hint if anything bricks. 2022-09-27 20:06:54 +02:00
jomjol
8175c946f2 Rolling 20220927 2022-09-27 18:23:35 +02:00
jomjol
0eb70b6208 Merge pull request #1086 from haverland/rolling
Add file length check before upload ota
2022-09-27 18:13:03 +02:00
jomjol
5ac3378479 Merge pull request #1085 from caco3/cleanup-sdkconfig
Restructure sdkconfig
2022-09-27 18:10:36 +02:00
Frank Haverland
356b208f33 change max file characters to 100 2022-09-27 16:30:41 +02:00
Frank Haverland
924f03595b add number of max characters to the failure dialog in upload check 2022-09-27 16:23:11 +02:00
Frank Haverland
90595968b2 update release notes to update from 11.3.1 2022-09-26 23:19:09 +02:00
Frank Haverland
96a59ca429 add html.zip for update from 11.3.1 2022-09-26 23:04:25 +02:00
Frank Haverland
b76d6cd987 fix links 2022-09-26 22:42:56 +02:00
Frank Haverland
98b7224c65 Add suggestion on firefox 2022-09-26 22:39:29 +02:00
Frank Haverland
ece73f63c8 Merge branch 'jomjol:rolling' into rolling 2022-09-26 22:30:59 +02:00
Frank Haverland
b281ae9583 add check if filename longer than 30 characters,
fixed handling after error dialog
2022-09-26 22:29:48 +02:00
CaCO3
6af7e1edd2 Merge branch 'cleanup-sdkconfig' of https://github.com/caco3/AI-on-the-edge-device into cleanup-sdkconfig 2022-09-26 21:53:25 +02:00
CaCO3
f04ca2bdde We should not edit sdkconfig.esp32cam as it is an autogenerated file! Instead we can do our condfiguration in sdkconfig.defaults.
This commit moves all customization to sdkconfig.defaults. The generated sdkconfig.esp32cam is identical to what we had before.
2022-09-26 21:53:22 +02:00
CaCO3
9007d8c484 delet old files 2022-09-26 21:53:22 +02:00
CaCO3
d8a7e7a39d Merge branch 'rolling' of https://github.com/caco3/AI-on-the-edge-device into rolling
# Conflicts:
#	.github/workflows/build.yaml
2022-09-26 21:53:07 +02:00
CaCO3
ee13581475 We should not edit sdkconfig.esp32cam as it is an autogenerated file! Instead we can do our condfiguration in sdkconfig.defaults.
This commit moves all customization to sdkconfig.defaults. The generated sdkconfig.esp32cam is identical to what we had before.
2022-09-26 21:50:44 +02:00
CaCO3
8c86a3013a delet old files 2022-09-26 21:22:26 +02:00
jomjol
8aab81acc7 Merge pull request #1084 from haverland/rolling
Fix uploading on ota
2022-09-26 21:02:41 +02:00
Frank Haverland
8707190d16 Merge branch 'jomjol:rolling' into rolling 2022-09-26 20:08:48 +02:00
Frank Haverland
aa72cab84f reduce SCRATCH_BUFSIZE to fix upload errors 2022-09-26 19:57:59 +02:00
jomjol
29607a8617 Merge branch 'rolling' of https://github.com/jomjol/AI-on-the-edge-device into rolling 2022-09-26 18:19:20 +02:00
jomjol
2239ab9019 Update server_ota.cpp 2022-09-26 18:19:09 +02:00
jomjol
86ea8a8e26 Merge pull request #1077 from haverland/rolling
Cleanup build/release pipeline
2022-09-25 21:02:57 +02:00
CaCO3
bfa8d8e691 cleanup 2022-09-25 20:57:21 +02:00
Frank Haverland
dc788b14eb Merge branch 'jomjol:rolling' into rolling 2022-09-25 20:38:39 +02:00
Frank Haverland
228a87038e Link to the installtion guide in firmware-Readme. It will packed into the initial-setup.zip 2022-09-25 19:43:30 +02:00
jomjol
d11ee2a4cf Rolling 20220925 2022-09-25 19:39:10 +02:00
Frank Haverland
b38c940dd3 run release only on tagging 2022-09-25 19:33:58 +02:00
Frank Haverland
6a22d355eb Merge branch 'jomjol:rolling' into rolling 2022-09-25 19:26:38 +02:00
Frank Haverland
a3a46fb0bb remove release creation artefact from pack-for-fresh-install 2022-09-25 19:22:13 +02:00
Frank Haverland
452339a1f0 fix indent 2022-09-25 19:05:16 +02:00
Frank Haverland
5e93f1e8bd use caches from changer 2022-09-25 18:59:48 +02:00
Frank Haverland
2e4023cfd6 pack for fresh install now cleaner part of build 2022-09-25 18:46:35 +02:00
Frank Haverland
12c748534e cleanup initial-setup is now part of the release 2022-09-25 18:36:15 +02:00
jomjol
8275bdbc25 Merge pull request #1074 from haverland/rolling
Release creation like CaCo3's update-ota2
2022-09-25 18:27:28 +02:00
jomjol
0ffaf99e10 Merge pull request #1073 from caco3/improve-ota
Improve ota
2022-09-25 18:23:41 +02:00
Frank Haverland
b1b76feeb0 fix extracting directories 2022-09-25 17:56:04 +02:00
Frank Haverland
265616ff80 Merge branch 'master' into rolling 2022-09-25 17:22:41 +02:00
Frank Haverland
89c65f6226 add debug, changed upload size to 8MB 2022-09-25 17:22:24 +02:00
Frank Haverland
6634b36f4a new entries for the next release 2022-09-25 17:19:32 +02:00
github-actions
6c433d83fc Update Changelog.md for release 2022-09-25 15:06:17 +00:00
Frank Haverland
a9d77a0005 fix path 2022-09-25 16:40:53 +02:00
CaCO3
efb35b1aa7 corrected max upload size 2022-09-25 16:21:12 +02:00
Frank Haverland
6f9d21fc21 fix initial release.zip 2022-09-25 16:15:40 +02:00
Frank Haverland
f7df03f0c0 Merge branch 'master' of https://github.com/haverland/AI-on-the-edge-device 2022-09-25 16:14:22 +02:00
Frank Haverland
e92ff43e09 fix html.zip should part of inital setup.zip as part of sd-card 2022-09-25 16:14:12 +02:00
github-actions
592a52ef0b Update Changelog.md for release 2022-09-25 14:06:55 +00:00
CaCO3
4e19066e26 catch opening non-existing file for read on OTA 2022-09-25 15:59:29 +02:00
Frank Haverland
8e39e83c38 use new cache after pack-for-OTA-v2 2022-09-25 15:45:35 +02:00
CaCO3
78900defad fix printf missing \n 2022-09-25 15:31:43 +02:00
CaCO3
d0b78e7c73 fix javascript messages 2022-09-25 15:31:24 +02:00
Frank Haverland
d3675f269d fix removal 2022-09-25 15:27:41 +02:00
Frank Haverland
64d25f416a debug 2022-09-25 15:16:09 +02:00
Frank Haverland
3f8b38a1ce fix delete firmware folder 2022-09-25 14:49:53 +02:00
Frank Haverland
5979acc31e fix firmware folder 2022-09-25 14:35:24 +02:00
Frank Haverland
7397927b77 use cache 2022-09-25 14:30:53 +02:00
Frank Haverland
0d67282c00 use update.zip from branch-action 2022-09-25 14:05:41 +02:00
jomjol
f9939023c6 Rolling 20220925 2022-09-25 08:49:47 +02:00
jomjol
922d76dace Merge pull request #1067 from caco3/update-pipeline-split-jobs2
Split the jobs to speed it up. Renamed artifacts, updated instructions on OTA page
2022-09-25 08:49:17 +02:00
CaCO3
02bf674539 . 2022-09-25 00:02:36 +02:00
CaCO3
4ad315b3f7 . 2022-09-24 23:57:31 +02:00
CaCO3
342fa0465c . 2022-09-24 23:54:04 +02:00
CaCO3
2866badc04 . 2022-09-24 23:51:31 +02:00
CaCO3
60194d8db8 Split the jobs to speed it up. Renamed artifacts, updated instructions on OTA page 2022-09-24 23:38:19 +02:00
jomjol
165745bb7d Merge pull request #1065 from caco3/fix-submodule-rebase-conflict
fixed rebase conflicts
2022-09-24 22:38:21 +02:00
CaCO3
fc4f3eebb6 fixed rebase conflicts 2022-09-24 22:32:01 +02:00
jomjol
8a6bd97ec2 Merge pull request #1060 from caco3/replace-components-by-submodules
Replace components by submodules
2022-09-24 22:22:57 +02:00
CaCO3
c4ee48ad1e Merge branch 'replace-components-by-submodules' of https://github.com/caco3/AI-on-the-edge-device into replace-components-by-submodules
# Conflicts:
#	code/components/esp32-camera-master
#	code/components/esp32-camera-master/.github/workflows/build.yml
#	code/components/esp32-camera-master/.github/workflows/upload_component.yml
#	code/components/esp32-camera-master/CMakeLists.txt
#	code/components/esp32-camera-master/Kconfig
#	code/components/esp32-camera-master/README.md
#	code/components/esp32-camera-master/conversions/esp_jpg_decode.c
#	code/components/esp32-camera-master/conversions/jpge.cpp
#	code/components/esp32-camera-master/conversions/to_bmp.c
#	code/components/esp32-camera-master/conversions/to_jpg.cpp
#	code/components/esp32-camera-master/driver/cam_hal.c
#	code/components/esp32-camera-master/driver/esp_camera.c
#	code/components/esp32-camera-master/driver/include/esp_camera.h
#	code/components/esp32-camera-master/driver/include/sensor.h
#	code/components/esp32-camera-master/driver/private_include/sccb.h
#	code/components/esp32-camera-master/driver/sccb.c
#	code/components/esp32-camera-master/driver/sensor.c
#	code/components/esp32-camera-master/examples/main/take_picture.c
#	code/components/esp32-camera-master/idf_component.yml
#	code/components/esp32-camera-master/sensors/bf20a6.c
#	code/components/esp32-camera-master/sensors/gc0308.c
#	code/components/esp32-camera-master/sensors/private_include/bf20a6.h
#	code/components/esp32-camera-master/sensors/private_include/gc0308_settings.h
#	code/components/esp32-camera-master/sensors/private_include/ov5640_settings.h
#	code/components/esp32-camera-master/sensors/private_include/sc030iot.h
#	code/components/esp32-camera-master/sensors/private_include/sc101iot.h
#	code/components/esp32-camera-master/target/esp32/ll_cam.c
#	code/components/esp32-camera-master/target/esp32s2/ll_cam.c
#	code/components/esp32-camera-master/target/esp32s3/ll_cam.c
#	code/components/esp32-camera-master/target/private_include/ll_cam.h
#	code/components/esp32-camera-master/test/test_camera.c
#	code/components/tflite-lib/CMakeLists.txt
#	code/components/tflite-lib/tensorflow/lite/builtin_ops.h
#	code/components/tflite-lib/tensorflow/lite/c/common.cc
#	code/components/tflite-lib/tensorflow/lite/c/common.h
#	code/components/tflite-lib/tensorflow/lite/context_util.h
#	code/components/tflite-lib/tensorflow/lite/core/api/flatbuffer_conversions.cc
#	code/components/tflite-lib/tensorflow/lite/core/api/flatbuffer_conversions.h
#	code/components/tflite-lib/tensorflow/lite/experimental/microfrontend/lib/kiss_fft_int16.cc
#	code/components/tflite-lib/tensorflow/lite/kernels/internal/reference/hard_swish.h
#	code/components/tflite-lib/tensorflow/lite/kernels/internal/reference/mul.h
#	code/components/tflite-lib/tensorflow/lite/micro/all_ops_resolver.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/add.h
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/add_n.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/arg_min_max.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/batch_to_space_nd.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/circular_buffer.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/comparisons.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/concatenation.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/cumsum.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/depth_to_space.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/depthwise_conv.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/div.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/elementwise.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/elu.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/esp_nn/conv.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/esp_nn/depthwise_conv.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/esp_nn/softmax.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/exp.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/expand_dims.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/fill.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/floor_div.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/floor_mod.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/fully_connected.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/gather.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/gather_nd.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/kernel_runner.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/kernel_runner.h
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/kernel_util.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/kernel_util.h
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/l2_pool_2d.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/l2norm.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/log_softmax.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/lstm_eval.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/maximum_minimum.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/micro_ops.h
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/micro_tensor_utils.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/mul.h
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/neg.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/pack.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/pad.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/pooling.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/pooling.h
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/prelu.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/reduce_common.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/resize_bilinear.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/resize_nearest_neighbor.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/shape.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/slice.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/softmax.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/space_to_batch_nd.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/space_to_depth.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/split_v.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/squeeze.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/strided_slice.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/svdf.h
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/tanh.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/transpose.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/transpose_conv.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/unidirectional_sequence_lstm_test_config.h
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/unpack.cc
#	code/components/tflite-lib/tensorflow/lite/micro/kernels/zeros_like.cc
#	code/components/tflite-lib/tensorflow/lite/micro/micro_allocation_info.cc
#	code/components/tflite-lib/tensorflow/lite/micro/micro_allocator.cc
#	code/components/tflite-lib/tensorflow/lite/micro/micro_allocator.h
#	code/components/tflite-lib/tensorflow/lite/micro/micro_interpreter.cc
#	code/components/tflite-lib/tensorflow/lite/micro/micro_interpreter.h
#	code/components/tflite-lib/tensorflow/lite/micro/micro_mutable_op_resolver.h
#	code/components/tflite-lib/tensorflow/lite/micro/micro_profiler.cc
#	code/components/tflite-lib/tensorflow/lite/micro/micro_profiler.h
#	code/components/tflite-lib/tensorflow/lite/micro/recording_micro_allocator.cc
#	code/components/tflite-lib/tensorflow/lite/schema/schema_generated.h
#	code/components/tflite-lib/third_party/flatbuffers/include/flatbuffers/base.h
#	code/components/tflite-lib/third_party/flatbuffers/include/flatbuffers/flatbuffer_builder.h
#	code/components/tflite-lib/third_party/flatbuffers/include/flatbuffers/flatbuffers.h
#	code/components/tflite-lib/third_party/flatbuffers/include/flatbuffers/flexbuffers.h
#	code/components/tflite-lib/third_party/flatbuffers/include/flatbuffers/stl_emulation.h
#	code/components/tflite-lib/third_party/flatbuffers/include/flatbuffers/table.h
#	code/components/tflite-lib/third_party/flatbuffers/include/flatbuffers/util.h
#	code/components/tflite-lib/third_party/flatbuffers/include/flatbuffers/vector.h
#	code/components/tflite-lib/third_party/flatbuffers/include/flatbuffers/verifier.h
2022-09-24 22:17:07 +02:00
CaCO3
3e5aa77ff5 rebase 2022-09-24 22:14:02 +02:00
CaCO3
b45b0f6a2a . 2022-09-24 22:06:05 +02:00
CaCO3
fc77c0fdf1 fix actions 2022-09-24 22:06:05 +02:00
CaCO3
bf1e96a303 added readme 2022-09-24 22:06:05 +02:00
CaCO3
86ba3e9bf4 autogenerated file got update => maybe we also can remove it? 2022-09-24 22:06:05 +02:00
CaCO3
d0fb1fc0f1 removed zip files 2022-09-24 22:06:05 +02:00
CaCO3
8bf4939ac1 added tflite-lib (resp. tflite-micro-esp-examples) again as submodule (master) 2022-09-24 22:06:05 +02:00
CaCO3
75a653a5c7 removed tflite-lib 2022-09-24 22:05:58 +02:00
CaCO3
e713ffa52d autogenerated file got update => maybe we also can remove it? 2022-09-24 22:05:06 +02:00
CaCO3
abc3efc16e added esp-nn again as submodule (master) 2022-09-24 22:05:06 +02:00
CaCO3
25e20f9299 removed esp-nn 2022-09-24 22:04:52 +02:00
CaCO3
f2effc4253 autogenerated file got update => maybe we also can remove it? 2022-09-24 22:04:52 +02:00
CaCO3
fb03dba60c remove esp32-camera-master files 2022-09-24 22:04:32 +02:00
jomjol
68e57d5ec4 Rolling 20220924 2022-09-24 21:24:50 +02:00
jomjol
a1691a77cf Merge pull request #1059 from caco3/remove-autogenerated-version-files3
remove autogenerated version files
2022-09-24 06:38:10 +02:00
jomjol
aa5651a464 Merge pull request #1055 from caco3/improve-prev-value-page
Improve prev value page
2022-09-24 06:33:29 +02:00
jomjol
0a79fb6196 Merge pull request #1052 from caco3/re-aranged-menus3
moved the index-configure.html menus to the index.html page
2022-09-24 06:32:38 +02:00
CaCO3
7e108d707a . 2022-09-23 23:11:33 +02:00
CaCO3
fb850fb040 fix actions 2022-09-23 23:08:31 +02:00
CaCO3
95292b8213 added readme 2022-09-23 23:04:50 +02:00
CaCO3
e59dca4bec autogenerated file got update => maybe we also can remove it? 2022-09-23 21:55:51 +02:00
CaCO3
86e47c722d removed zip files 2022-09-23 21:55:39 +02:00
CaCO3
5a1127d2b9 added tflite-lib (resp. tflite-micro-esp-examples) again as submodule (master) 2022-09-23 21:52:24 +02:00
CaCO3
b1d4df4309 removed tflite-lib 2022-09-23 21:29:17 +02:00
CaCO3
f6f70776d9 autogenerated file got update => maybe we also can remove it? 2022-09-23 21:20:32 +02:00
CaCO3
570777db7e added esp-nn again as submodule (master) 2022-09-23 21:20:18 +02:00
CaCO3
b06b42f0e9 removed esp-nn 2022-09-23 21:17:44 +02:00
CaCO3
8a170a7e16 autogenerated file got update => maybe we also can remove it? 2022-09-23 21:17:01 +02:00
CaCO3
5e95634173 added esp32-camera-master again as submodule (version 2.0.2) 2022-09-23 21:14:41 +02:00
CaCO3
84cc3490a1 remove esp32-camera-master files 2022-09-23 21:11:03 +02:00
CaCO3
ee724d372d remove autogenerated version files 2022-09-23 21:02:56 +02:00
George Ruinelli
711578d0a2 fix closing of menu on mobile devices 2022-09-23 00:02:50 +02:00
George Ruinelli
1956416fb6 set current value als preValue input default 2022-09-22 23:12:46 +02:00
George Ruinelli
1ec1f4f75f remove default entries 2022-09-22 23:06:33 +02:00
George Ruinelli
0fb192d79e fixed width 2022-09-22 22:54:01 +02:00
George Ruinelli
19847652a9 close menu on click 2022-09-22 22:49:57 +02:00
jomjol
d807334141 Merge branch 'pr/1044' into rolling 2022-09-22 18:42:17 +02:00
George Ruinelli
a08a233484 . 2022-09-22 00:07:38 +02:00
George Ruinelli
7fc9676385 . 2022-09-22 00:00:54 +02:00
Cristian
7d8cdc79f2 Reversed the changes in the directory of the esp32-cam: /components/esp32-camera-master upon request from jomjol 2022-09-21 23:42:02 +02:00
Cristian
6938299b72 Few typing corrections and translations 2022-09-21 23:36:14 +02:00
Cristian
6794091919 Merge branch 'master' of https://github.com/jomjol/AI-on-the-edge-device into texts-typing-corrections 2022-09-21 23:34:50 +02:00
George Ruinelli
6631ebc12a . 2022-09-21 23:02:12 +02:00
jomjol
efc800c223 Rolling 20220921 2022-09-21 21:49:09 +02:00
jomjol
6756b6d741 Merge pull request #1042 from haverland/rolling
auto release creation and build artifact upload and release notes
2022-09-21 20:03:05 +02:00
jomjol
3138e36137 Merge pull request #1048 from jomjol/added-firmware-readme
re-added empty firmware folder with a readme pointing to the releases page
2022-09-21 19:51:50 +02:00
George Ruinelli
b3b1c18ff5 . 2022-09-21 17:51:53 +02:00
George Ruinelli
1c9cd46d88 . 2022-09-21 17:51:14 +02:00
George Ruinelli
f4074fb939 . 2022-09-21 17:48:29 +02:00
CaCO3
7d286337ce Update README.md 2022-09-21 16:55:43 +02:00
CaCO3
81f92b8b0f re-added empty firmware folder with a readme pointing to the releases page 2022-09-21 16:53:39 +02:00
Cristian
01337ddcbf Few typing corrections and translations 2022-09-21 09:37:15 +02:00
Frank Haverland
3fb545f869 remove notebook 2022-09-21 00:08:28 +02:00
Frank Haverland
04e59482b5 Merge branch 'master' into rolling 2022-09-21 00:00:06 +02:00
github-actions
50acd26804 Update Changelog.md for release 2022-09-20 21:56:39 +00:00
Frank Haverland
1bc8e698b4 Merge branch 'master' of https://github.com/haverland/AI-on-the-edge-device 2022-09-20 23:49:08 +02:00
Frank Haverland
46b8b67fed create full update.zip 2022-09-20 23:48:51 +02:00
Frank Haverland
84a653b5d5 example created 2022-09-20 23:43:47 +02:00
github-actions
dee7212531 Update Changelog.md for release 2022-09-20 21:38:40 +00:00
Frank Haverland
50b0593648 only zips from dist, Changelog like keepachangelog 2022-09-20 23:31:09 +02:00
Frank Haverland
4c786406c3 enable firmware creation 2022-09-20 23:12:29 +02:00
Frank Haverland
6fed12e9ad fix 2022-09-20 23:06:24 +02:00
Frank Haverland
11216350c4 Revert "Update Changelog.md for release"
This reverts commit 577dbdeb7c.
2022-09-20 22:57:09 +02:00
github-actions
577dbdeb7c Update Changelog.md for release 2022-09-20 20:54:52 +00:00
Frank Haverland
b75f77b31c Merge branch 'master' of https://github.com/haverland/AI-on-the-edge-device 2022-09-20 22:52:37 +02:00
Frank Haverland
2776e1b127 add release createion and changelog to releasenotes 2022-09-20 22:52:34 +02:00
jomjol
562cc4352b Rolling 20220919 2022-09-19 22:07:16 +02:00
jomjol
013d5a99a8 Merge pull request #1036 from caco3/update-readme
Update Landing Page on Github
2022-09-19 22:06:10 +02:00
jomjol
fbe7bb90c2 Merge pull request #1038 from jomjol/update-FeautreRequest.md
Update FeatureRequest.md
2022-09-19 22:02:51 +02:00
CaCO3
660326af42 Update FeatureRequest.md 2022-09-19 21:08:48 +02:00
CaCO3
80aa2dfc73 fix links 2022-09-19 20:37:31 +02:00
CaCO3
316d8f252a fix links 2022-09-19 20:36:19 +02:00
CaCO3
28a39d8dfc fix tools readme 2022-09-19 20:34:32 +02:00
CaCO3
3fc6c194e5 updated main landing page 2022-09-19 20:33:04 +02:00
jomjol
0e85b40eba Delete firmware directory 2022-09-19 20:30:49 +02:00
jomjol
d479c8d44e Rolling 20220919 2022-09-19 20:29:05 +02:00
jomjol
6b6e677f8b Delete firmware directory 2022-09-19 20:28:39 +02:00
jomjol
45c9914efa Merge pull request #1033 from caco3/auto-add-version
Auto add version
2022-09-19 20:03:56 +02:00
jomjol
a4299cab89 Merge pull request #1031 from haverland/rolling
Change link to Choosing the model in configuration page
2022-09-19 20:01:46 +02:00
Frank Haverland
67e4ee4aca Revert "Commit from GitHub Actions (Build and Pack)"
This reverts commit e1fc44d44a.
2022-09-19 19:50:42 +02:00
Frank Haverland
85750c9453 Revert "Commit from GitHub Actions (Build and Pack)"
This reverts commit 26949d8083.
2022-09-19 19:50:35 +02:00
Frank Haverland
d8b4b3f2cf Revert "commit build artifacts"
This reverts commit 5aa4714d05.
2022-09-19 19:49:24 +02:00
Frank Haverland
fedaef07eb Revert "fix indent"
This reverts commit b65d9e5a46.
2022-09-19 19:47:46 +02:00
Frank Haverland
9ae9a82cca Revert "fix path"
This reverts commit bf8589f9ec.
2022-09-19 19:47:43 +02:00
Frank Haverland
37fec1821f Revert "fix path"
This reverts commit 32e5c484ab.
2022-09-19 19:47:40 +02:00
Frank Haverland
c4e69bc036 Revert "discard version files"
This reverts commit 1c80c2108d.
2022-09-19 19:47:35 +02:00
Frank Haverland
7dd14282c6 Revert "fix double entry in html"
This reverts commit b6a571a90c.
2022-09-19 19:47:13 +02:00
Frank Haverland
7e72cc3d1b Revert change checkDigitConsistency (Issue #1028 and #1029) 2022-09-19 19:47:06 +02:00
Frank Haverland
8e2da52d82 Revert "Commit from GitHub Actions (Build and Pack)"
This reverts commit e38c861cb5.
2022-09-19 19:45:13 +02:00
github-actions
e38c861cb5 Commit from GitHub Actions (Build and Pack) 2022-09-19 17:43:35 +00:00
Frank Haverland
b6a571a90c fix double entry in html 2022-09-19 19:36:41 +02:00
github-actions
26949d8083 Commit from GitHub Actions (Build and Pack) 2022-09-19 17:21:23 +00:00
Frank Haverland
1c80c2108d discard version files 2022-09-19 19:13:51 +02:00
github-actions
e1fc44d44a Commit from GitHub Actions (Build and Pack) 2022-09-19 16:34:49 +00:00
Frank Haverland
32e5c484ab fix path 2022-09-19 18:28:03 +02:00
Frank Haverland
bf8589f9ec fix path 2022-09-19 18:27:31 +02:00
Frank Haverland
b65d9e5a46 fix indent 2022-09-19 18:05:41 +02:00
Frank Haverland
5aa4714d05 commit build artifacts 2022-09-19 18:03:55 +02:00
CaCO3
dd8500052e also set HTML version by cmake 2022-09-19 08:22:44 +02:00
CaCO3
2d68f44a40 show version in index pages 2022-09-18 23:25:57 +02:00
CaCO3
39ec90895e removed GIT_BASE_BRANCH and instead use the autogenerated values in info.html 2022-09-18 22:37:16 +02:00
CaCO3
3d1d41e36b remove PROJECT_VER. The compiler then automatically uses git to fetch the information, eg. "v11.3.0-12-g46dfc75-dirty" 2022-09-18 22:23:23 +02:00
CaCO3
46dfc75724 show version on startup in loag and on console 2022-09-18 22:16:49 +02:00
CaCO3
906915e058 add include guard 2022-09-18 22:14:21 +02:00
Frank Haverland
85418c678d Change link to Choosing the model in configuration page 2022-09-18 21:57:14 +02:00
jomjol
81e06c45d3 Rolling 20220918 2022-09-18 20:48:12 +02:00
jomjol
645fbf0231 Merge branch 'rolling' of https://github.com/jomjol/AI-on-the-edge-device into rolling 2022-09-18 18:20:46 +02:00
jomjol
5d10dba3c7 Merge pull request #1030 from haverland/rolling
Revert change in 11.3.1 on checkDigitConsistency  and add a fast forward transition range
2022-09-18 18:16:05 +02:00
Frank Haverland
78806c081b Create special handling for fast foreward, because it's not at the beginning of the Transition 2022-09-18 17:56:56 +02:00
Frank Haverland
3f659ccf7d Revert change in 11.3.1 on checkDigitConsistency (Issue #1028 and #1029) 2022-09-18 17:01:32 +02:00
jomjol
6cd52a3cdc v11.3.1 2022-09-17 21:19:24 +02:00
jomjol
a1f675419a v11.3.1 2022-09-17 21:04:55 +02:00
jomjol
9087c1b4e1 Create partitions.bin 2022-09-17 21:00:55 +02:00
jomjol
9418d55a2f Merge branch 'rolling' 2022-09-17 20:56:41 +02:00
jomjol
87076df23f v11.3.1 2022-09-17 20:56:14 +02:00
Frank Haverland
aba9603021 Merge branch 'master' of https://github.com/haverland/AI-on-the-edge-device 2022-09-17 16:26:58 +02:00
Frank Haverland
086aa3134b Merge branch 'master' of https://github.com/haverland/AI-on-the-edge-device 2022-09-17 16:24:26 +02:00
CaCO3
010691f3e5 Merge pull request #1027 from caco3/remove-11.3.0-binaries
Remove 11.3.0 binaries as there are some issues with them
2022-09-17 16:19:59 +02:00
CaCO3
12d9099543 Delete main.yml 2022-09-17 16:19:37 +02:00
Frank Haverland
c9b7f8d901 Merge branch 'jomjol:rolling' into rolling 2022-09-17 16:19:35 +02:00
CaCO3
0372f82f2e removed binaries as tehre are some issues with them 2022-09-17 16:13:24 +02:00
CaCO3
18be9afbe1 Merge branch 'jomjol:master' into master 2022-09-17 16:10:35 +02:00
jomjol
36f5618376 Rolling 20220917 2022-09-17 10:16:31 +02:00
jomjol
03542368d7 v11.3.0 2022-09-17 10:11:31 +02:00
jomjol
36a02d1658 Merge branch 'rolling' 2022-09-17 09:25:00 +02:00
jomjol
c65182b568 Prepare v11.3.0 2022-09-17 09:24:41 +02:00
Frank Haverland
e5bd824506 Merge branch 'rolling' of https://github.com/haverland/AI-on-the-edge-device into rolling 2022-09-16 18:46:45 +02:00
jomjol
10fbb610c3 Rolling 20220916 2022-09-16 17:56:51 +02:00
Frank Haverland
b8ab58a196 Testcases for #950 and #1020 2022-09-16 17:38:34 +02:00
jomjol
fa59b5ba6c Merge pull request #1019 from PLCHome/master
Communication error behind an HTTPS proxy
2022-09-16 16:46:29 +02:00
ChrisHanuta
67d47abde2 Communication error behind an HTTPS proxy
The device always requests via HTTP, not HTTPS
2022-09-16 10:18:40 +02:00
jomjol
042ff18e65 Merge pull request #1006 from haverland/rolling
fix handling in DigitalUebergangsbereichVorgaenger
2022-09-15 21:13:37 +02:00
Frank Haverland
3008952240 Merge branch 'jomjol:rolling' into rolling 2022-09-15 19:14:59 +02:00
jomjol
aef28c7128 Merge pull request #1014 from caco3/update-pipeline-artifacts-packaging
Update pipeline artifacts packaging
2022-09-14 20:34:25 +02:00
CaCO3
9c5dfe65c9 enable python prep again 2022-09-13 22:04:05 +02:00
CaCO3
b12cdd673b build several artifacts
See concept in https://github.com/jomjol/AI-on-the-edge-device/discussions/999#discussioncomment-3617232
2022-09-13 22:02:51 +02:00
Frank Haverland
8247580372 Merge branch 'jomjol:rolling' into rolling 2022-09-11 22:45:40 +02:00
Frank Haverland
d7c7537aa9 #921 #994 - fix handling in DigitalUebergangsbereichVorgaenger, reduced DigitalUebergangsbereichVorgaenger =0.7
added serial-debug in postprocessing (not enabled by default)
added test-case for #994
fixed checkDigitConsistency (pre value before analog lost)
added debug to proof need of double for NUMBERS.Value (see testcase 32289.4198)
2022-09-11 22:44:35 +02:00
CaCO3
ad05a1d4fa Create main.yml 2022-09-10 23:49:42 +02:00
jomjol
7bd819ad96 Merge branch 'rolling' of https://github.com/jomjol/AI-on-the-edge-device into rolling 2022-09-10 23:29:25 +02:00
jomjol
64b472d6bc Rolling 20220910 2022-09-10 23:29:19 +02:00
CaCO3
3d7a906cce set version of html in pipeline
Update build.yaml
2022-09-10 22:55:56 +02:00
CaCO3
8c4a5a957a Update build.yaml
set version of html in pipeline
2022-09-10 22:53:36 +02:00
CaCO3
21874473cc Merge pull request #1000 from caco3/fix-pipeline
Fix pipeline
2022-09-10 21:46:00 +02:00
CaCO3
8aa99b34d6 Update build.yaml 2022-09-10 21:44:48 +02:00
jomjol
6759164c82 Rolling 20220910 2022-09-10 21:38:32 +02:00
jomjol
2445377d0a Rolling 20220910 2022-09-10 21:38:02 +02:00
CaCO3
99b6393fbc Update build.yaml 2022-09-10 21:35:17 +02:00
CaCO3
7e049f3270 Update build.yaml 2022-09-10 21:25:55 +02:00
jomjol
79d1e6b932 Rollling 20220910 2022-09-10 20:19:31 +02:00
jomjol
3403e3ea5c Merge pull request #995 from haverland/rolling
testcase for #921 (2022-09-10)
2022-09-10 20:01:26 +02:00
jomjol
c3a3aa9c0d Merge pull request #996 from caco3/auto-build_and_pack
Auto build and pack
2022-09-10 20:00:56 +02:00
jomjol
89c9ff144c Merge pull request #989 from caco3/update-webUI
Update web UI
2022-09-10 19:57:03 +02:00
CaCO3
82e6334832 Update build.yaml 2022-09-10 17:28:23 +02:00
Frank Haverland
dd70aa8969 testcase for #921 (2022-09-10) 2022-09-10 17:06:23 +02:00
CaCO3
4cf190239e rename firmware file 2022-09-10 15:59:57 +02:00
CaCO3
cb4ba51eee initial action 2022-09-10 15:38:46 +02:00
CaCO3
4d03867550 updated html version 2022-09-07 22:29:07 +02:00
CaCO3
02294e3afc added link to releases page 2022-09-07 22:18:32 +02:00
CaCO3
f68aa1d931 moved jomjols name from the pages title to the info page, added links there to the Github page 2022-09-07 22:18:21 +02:00
CaCO3
fb390359e1 modified ota page to make separation between firmware/html and CNN better. renamed html/ to Web Interface, as the suer does not care how it is build 2022-09-07 21:59:59 +02:00
jomjol
764c64b615 Merge pull request #986 from haverland/rolling
Testcase für #950
2022-09-07 18:55:11 +02:00
Frank Haverland
a167770848 Merge branch 'jomjol:rolling' into rolling 2022-09-06 21:07:18 +02:00
Frank Haverland
551743abec add Testcase to #950 2022-09-06 21:02:58 +02:00
jomjol
68a596707b Rolling 20220409 2022-09-04 18:16:37 +02:00
jomjol
47da2d657e Merge pull request #980 from caco3/re-init-mqtt-on-publish-error
Try to publish. If it fails, run MQTT init and publish again.
2022-09-04 18:01:04 +02:00
jomjol
43372c94a8 Merge pull request #979 from nliaudat/master
Update FeatureRequest.md
2022-09-04 17:59:29 +02:00
jomjol
0643274c68 Merge pull request #976 from caco3/re-integrate-css
Older Firmware versions (11.2.0 and older) do not support css files, therefore we need to keep it integrated for now!
2022-09-04 17:59:04 +02:00
CaCO3
395b471700 added return codes. Try to publish. If it fails, run MQTT init and publish again. Increased Keep Alive timeout to make sure it is greater than the flow interval 2022-09-04 17:55:22 +02:00
Nicolas Liaudat
a040d56fdc Update FeatureRequest.md
deep sleep for a time period only
2022-09-04 16:56:24 +02:00
jomjol
3c8a65c540 Merge pull request #978 from caco3/show-backup-also-on-index_configure.html
Show the backup menu entry also on the index_configure.html page
2022-09-04 15:34:25 +02:00
jomjol
2f38643473 Merge pull request #977 from caco3/reload-index-page-after-reboot
reload index page instead only iframe. Also added a duration estimate.
2022-09-04 15:34:02 +02:00
George Ruinelli
906a2e05eb Show the backup menu entry also on the index_configure.html page 2022-09-03 21:55:01 +02:00
CaCO3
3390e24534 reload parent page instead only iframe. Also added a duration estimate. 2022-09-03 21:41:46 +02:00
George Ruinelli
dc28b892bc Older Firmware versions (11.2.0 and older) do not support css files, therefore we need to keep the css integrated for now! 2022-09-03 21:16:24 +02:00
jomjol
3023cd139d Merge pull request #972 from haverland/rolling
add test case for #921
2022-09-03 18:04:36 +02:00
Frank Haverland
127135e1cb new versions of dig-class100 and ana-class100
- new images and retraining
2022-09-03 16:54:08 +02:00
Frank Haverland
aa4e115f80 add test case for #921
https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1236119370
2022-09-03 16:23:01 +02:00
jomjol
90f204b833 Rolling 20220903 2022-09-03 10:52:48 +02:00
jomjol
77427a8ec4 Merge pull request #971 from caco3/add-mqtt-log-messages
Improve MQTT handling
2022-09-03 08:12:53 +02:00
CaCO3
eafcdb01c2 moved log entry 2022-09-03 00:26:16 +02:00
CaCO3
3f58086aa1 Re-init MQTT if it failed last time, added log messages 2022-09-03 00:09:50 +02:00
jomjol
d36a4dbdbe Merge pull request #967 from haverland/921-keinNulldurchgang
No transition if previous values calculate the eval_vorgaenger is 9 (no transition)
2022-09-02 20:26:21 +02:00
jomjol
6879aa96e2 Merge pull request #966 from haverland/rolling
Fix for html upload #959 and new test case for #921
2022-09-02 20:25:28 +02:00
jomjol
fc219cc7f3 Merge pull request #965 from f-fritz/configpage-information-text
Update config-page info-text about MQTT topic structure (explain VALUE_NAME key)
2022-09-02 20:24:34 +02:00
Frank Haverland
787f9362eb #921 No zero trasition 2022-09-01 21:42:12 +02:00
Frank Haverland
231ac5305f fix html-upload #959 2022-09-01 21:11:45 +02:00
f-fritz
4bd79e370f Update config-page info-text about MQTT topic structure (explain VALUE_NAME) 2022-09-01 11:22:19 +02:00
jomjol
5c0cd63da0 Rolling 20220831 2022-08-31 22:04:02 +02:00
jomjol
5a31543538 Merge branch 'pr/952' into rolling 2022-08-31 19:58:04 +02:00
jomjol
1b88bf8690 Rolling 20220831 2022-08-31 19:53:53 +02:00
jomjol
6db01e67c9 Merge branch 'rolling' of https://github.com/jomjol/AI-on-the-edge-device into rolling 2022-08-31 19:37:24 +02:00
jomjol
f7cb6576b3 Merge pull request #960 from caco3/improve-iframe-sizing
Various WebUI Improvements
2022-08-31 19:32:52 +02:00
Frank Haverland
4a71749d1c add test case for #921 (79.99996) 2022-08-31 18:23:11 +02:00
CaCO3
d13f457344 Merge branch 'rolling' into improve-iframe-sizing 2022-08-30 22:50:24 +02:00
George Ruinelli
ab41401643 add min iframe height (to fix view on android chrome browser) 2022-08-30 22:41:33 +02:00
George Ruinelli
592b93ce2b added reboot buttons to config pages 2022-08-30 22:07:25 +02:00
George Ruinelli
5dc7b90a1c reformating 2022-08-30 22:06:51 +02:00
George Ruinelli
b1e0203527 added system menu to configure_index.html, reformating 2022-08-30 22:06:37 +02:00
George Ruinelli
774dde5767 changed color of selected submenu entries to red 8like selected main menu entries) 2022-08-30 22:06:05 +02:00
George Ruinelli
c322cd8b48 changed iframe style to make sure it uses whole height (minus header) 2022-08-30 21:23:36 +02:00
George Ruinelli
3dcdd52eb7 added separate stylesheet and moved common js to a file. 2022-08-30 21:23:05 +02:00
George Ruinelli
fe17d97a05 added example log entry 2022-08-30 21:09:07 +02:00
George Ruinelli
b71a34b476 add support for css files 2022-08-30 21:08:30 +02:00
George Ruinelli
ea71c86f69 removed unused styles 2022-08-30 20:46:27 +02:00
jomjol
550fe605bd Rolling 20220830 2022-08-30 20:27:45 +02:00
jomjol
109dd97016 Merge pull request #957 from caco3/add-config-backup-functionality
Add config backup functionality
2022-08-30 20:14:04 +02:00
jomjol
715f0a10f3 Merge pull request #958 from caco3/improve-ota-page
Improve ota page
2022-08-30 20:11:12 +02:00
George Ruinelli
d01caea53e Reduce height of the OTA page to make sure point 4 is not hidden by default. 2022-08-30 18:07:48 +02:00
George Ruinelli
a9cab31a1f . 2022-08-30 17:57:39 +02:00
George Ruinelli
d0968e87d7 . 2022-08-30 17:54:21 +02:00
George Ruinelli
6417f780e6 added backup page 2022-08-30 00:29:50 +02:00
jomjol
fd4d76de93 Merge pull request #955 from haverland/rolling
fix https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuec…
2022-08-29 18:15:11 +02:00
Frank Haverland
cdf8663bd3 fix https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1229552041 2022-08-29 16:11:05 +02:00
George Ruinelli
bf9050757b reduce height of the OTA page to make sure point 4 is not hidden by default. 2022-08-28 23:59:52 +02:00
jomjol
bce99da6e5 v11.2.0 2022-08-28 20:04:36 +02:00
jomjol
234925c850 Merge branch 'rolling' 2022-08-28 19:54:15 +02:00
jomjol
c9b7a5f84c v11.2.0 2022-08-28 19:52:51 +02:00
Anthony
cfaeaa370a cleanup. 2022-08-28 02:11:08 -04:00
Anthony
8cd5a89d6a added CPU Temp and RSSI to staus box of webgui. 2022-08-28 01:17:57 -04:00
Anthony
090f8d5cc9 Added CPU temperature to MQTT. 2022-08-27 23:59:06 -04:00
Anthony
29ae8cfa7f updated config for CCW param, and roi to top aligm image when multiple number readings. 2022-08-27 18:50:11 -04:00
jomjol
338184712d Delete dig-cont_0570_s3_q.tflite 2022-08-27 20:41:14 +02:00
jomjol
b2c510d73e Rolling 20220827 2022-08-27 20:21:53 +02:00
Anthony
e8b649d315 latest update for CCW 2022-08-27 13:19:31 -04:00
jomjol
6a5d5511f1 Merge pull request #949 from caco3/beautify-restart
Beautify restart
2022-08-27 18:03:03 +02:00
jomjol
ec99ac3a3b Merge pull request #951 from haverland/rolling
Testcases for #942
2022-08-27 18:01:43 +02:00
Anthony
58cfd8bc42 fix for CCW parsing of config file into OTA zip. 2022-08-27 10:50:17 -04:00
Frank Haverland
f676f12e02 Testcases for https://github.com/jomjol/AI-on-the-edge-device/issues/942 2022-08-27 16:48:42 +02:00
Anthony
393fe43090 fixed parsing roi for CCW flag. 2022-08-26 23:12:23 -04:00
George Ruinelli
296a50a6d2 . 2022-08-26 23:51:24 +02:00
George Ruinelli
b1ee3d8793 Show progress on reboot and reload page automatically 2022-08-26 23:45:25 +02:00
Anthony
d930fdae78 fixes for CCW analog. 2022-08-26 17:05:00 -04:00
jomjol
993fbfe5a8 Rolling 2022-08-26 2022-08-26 21:20:26 +02:00
Anthony
af546ef0f1 Added Counter Clockwise option for analog dial. 2022-08-26 10:43:22 -04:00
jomjol
2b60e81a52 Rolling 2022-08-24 2022-08-24 17:52:21 +02:00
jomjol
11418459b8 Merge pull request #939 from caco3/rolling
Extend Config Page
2022-08-24 17:46:34 +02:00
George Ruinelli
3b8b8e47da Added link to wiki. Added filter for CNNs: on digital selection show all files except those which contain '/ana' in theri name and vice versa for the analog selection. 2022-08-22 23:48:48 +02:00
jomjol
ae302d49ef Rolling 2022-08-22 2022-08-22 22:17:32 +02:00
jomjol
0153229d3c Merge pull request #936 from haverland/rolling
add test case to reproduce
2022-08-22 21:07:02 +02:00
jomjol
eeb74dd6fd Merge pull request #931 from caco3/master
added favicon and adjusted window title to show hostname first
2022-08-22 21:01:46 +02:00
Frank Haverland
ecc62a3ba9 add test case to reproduce 2022-08-22 21:01:44 +02:00
jomjol
aca60465f0 v11.1.1 2022-08-22 18:20:00 +02:00
jomjol
57bdca37fc v11.1.1 2022-08-22 18:12:08 +02:00
jomjol
6409397770 Merge pull request #933 from haverland/rolling
Fix for #921, #919
2022-08-22 17:58:30 +02:00
Frank Haverland
974044adf0 last analog result_float as Readout parameter, testcases for #921, #919 2022-08-22 16:10:07 +02:00
Frank Haverland
59aeeda786 Merge branch 'rolling' into analogtodig_as_float 2022-08-22 10:33:10 +02:00
Frank Haverland
b6bf8d992f Test case for postprocessing 2022-08-22 10:31:25 +02:00
Frank Haverland
82cb966863 Merge branch 'jomjol:master' into master 2022-08-22 10:21:35 +02:00
jomjol
9d31edc67a Rolling 2022-08-21 2022-08-21 21:33:56 +02:00
George Ruinelli
1b4f4bdd6d added favicon and adjusted window title to show hostname first 2022-08-21 21:05:59 +02:00
jomjol
c9a879d329 v11.1.0 2022-08-21 17:56:46 +02:00
jomjol
ea69b1be00 v11.1.0 2022-08-21 17:44:34 +02:00
jomjol
2a8b3a87ea Merge pull request #922 from haverland/rolling
Rolling
2022-08-21 16:47:07 +02:00
jomjol
52783734ce Merge pull request #925 from jochenchrist/master
Remove .DS_Store
2022-08-21 16:44:12 +02:00
jomjol
0e1b390ec6 Merge pull request #918 from ppisljar/patch-1
Update FeatureRequest.md
2022-08-21 16:41:30 +02:00
jochen
ab49bdf82f .DS_Store removed 2022-08-20 19:25:52 +02:00
jochenchrist
25e7051271 Delete .DS_Store 2022-08-20 19:23:08 +02:00
Frank Haverland
85c0a72ae8 Merge branch 'jomjol:master' into master 2022-08-19 21:40:00 +02:00
Frank Haverland
7315f9adfc Merge branch 'jomjol:rolling' into rolling 2022-08-19 21:33:08 +02:00
Frank Haverland
af1aee4ac3 add testcase for #921 2022-08-19 21:30:11 +02:00
Frank Haverland
d6ff7eef88 fix problems with early transition of digits if analog pointers. #921 2022-08-19 21:05:23 +02:00
Frank Haverland
7706b4dbc3 fix for #919 the prev is int, so <9.0 instead of <9.5 2022-08-18 19:28:13 +02:00
Peter Pisljar
3561ecd2b7 Update FeatureRequest.md 2022-08-18 15:16:57 +02:00
jomjol
74c7ff7fdf v11.0.1 2022-08-15 22:48:42 +02:00
jomjol
a68ce353ad Merge pull request #910 from haverland/rolling
Fix naming of models and new version
2022-08-13 15:58:57 +02:00
Frank Haverland
0d168f3445 Merge branch 'jomjol:rolling' into rolling 2022-08-13 15:38:57 +02:00
Frank Haverland
073e04a3cc fix naming of models and new versions 2022-08-13 15:37:04 +02:00
jomjol
591dc048d4 v11.0.0 2022-08-13 14:26:04 +02:00
jomjol
bfe8d3b37a v11.0.0 2022-08-13 14:20:40 +02:00
jomjol
9695dba415 Merge branch 'master' into rolling 2022-08-07 21:20:28 +02:00
jomjol
6a48f0502e Merge pull request #885 from haverland/rolling
CNNThreshold removed vor Analog100 and Digital100
2022-08-07 21:19:37 +02:00
Frank Haverland
4a8d6592ab CNNThreshold removed for Analog100 and Digital100 2022-07-28 19:43:45 +02:00
jomjol
434aebd641 Merge pull request #881 from haverland/rolling
Ignore hidden files in configuration->model selection
2022-07-25 19:11:29 +02:00
Frank Haverland
c124c38e70 ignore hidden files in configuration->model selection 2022-07-25 16:30:11 +02:00
Frank Haverland
e6d60bb124 Merge branch 'jomjol:rolling' into rolling 2022-07-24 20:20:53 +02:00
Frank Haverland
99afb88957 Merge branch 'jomjol:master' into master 2022-07-24 20:20:28 +02:00
jomjol
085ea2028c v10.6.1 2022-07-24 19:07:43 +02:00
jomjol
0e7c600cf7 Rolling v10.6.1 2022-07-24 18:53:25 +02:00
Frank Haverland
3f3532defe Revert "Fix for #712 "Incorrect rollover digital numbers""
This reverts commit 11bfaf0e91.
2022-07-20 19:12:19 +02:00
Frank Haverland
a0ffc88e47 Merge branch 'rolling' of https://github.com/haverland/AI-on-the-edge-device into rolling 2022-07-20 18:37:05 +02:00
Frank Haverland
11bfaf0e91 Fix for #712 "Incorrect rollover digital numbers" 2022-07-20 18:35:42 +02:00
jomjol
189093d548 Merge pull request #862 from haverland/rolling
Version 1.0 of digital and analog categorical models
2022-07-18 20:33:02 +02:00
Frank Haverland
34eb89b1b6 fix extension finding for tlfite modellist 2022-07-18 19:18:09 +02:00
Frank Haverland
b725d242d3 Add Error to Logfile if output-dimenstion of model inconsistent. 2022-07-18 18:36:42 +02:00
Frank Haverland
568e88314b Merge branch 'jomjol:rolling' into rolling 2022-07-17 20:00:28 +02:00
Frank Haverland
70e94205d1 Merge branch 'jomjol:master' into master 2022-07-17 19:58:43 +02:00
jomjol
aaad952782 v10.6.0 2022-07-17 09:34:27 +02:00
jomjol
dc27911174 Preparation for v10.6.0 2022-07-17 09:00:10 +02:00
Frank Haverland
42678ae8e1 Merge branch 'jomjol:rolling' into rolling 2022-07-16 23:09:41 +02:00
Frank Haverland
b6341992f6 Version 1.0 of digital and analog categorical models 2022-07-16 21:29:56 +02:00
jomjol
17fd0f96df Rolling 20220716_2 2022-07-16 20:59:09 +02:00
jomjol
0b039e8d8c Merge pull request #861 from haverland/rolling
fix false value if analog + dighybrid on last digit if previous >=9.5
2022-07-16 20:07:02 +02:00
Frank Haverland
eab8a6d96b fix false value if analog + dighybrid on last digit if previous >=9.5 2022-07-16 19:37:30 +02:00
jomjol
9f72bf117e Rolling 20220716 2022-07-16 08:09:18 +02:00
jomjol
058e9436f0 Merge pull request #858 from haverland/rolling
Rolling: Add analog classification model
2022-07-16 07:50:00 +02:00
Frank Haverland
ebd8fe0e4f Merge branch 'rolling' of https://github.com/haverland/AI-on-the-edge-device into rolling 2022-07-03 21:02:00 +02:00
Frank Haverland
7970f5f691 Add analog classification (100) as modeltype analog100 2022-07-03 21:01:42 +02:00
jomjol
0689ca86c5 Merge branch 'rolling' of https://github.com/jomjol/AI-on-the-edge-device into rolling 2022-07-01 07:27:28 +02:00
jomjol
5783e0f182 Rolling 20220107 2022-07-01 07:27:26 +02:00
jomjol
e190aa8d03 Merge pull request #839 from haverland/rolling
Rolling: Add testing for CNNFlowcontroll
2022-06-28 07:09:35 +02:00
Frank Haverland
15bac02cbf Merge branch 'jomjol:rolling' into rolling 2022-06-26 23:23:16 +02:00
Frank Haverland
7fdacce9a2 Merge branch 'rolling' of https://github.com/haverland/AI-on-the-edge-device into rolling 2022-06-26 23:21:39 +02:00
Frank Haverland
78ea179e9a added testing to cnnflowcontroll::ZeigerEval/ZeigerEvalHybrid 2022-06-26 23:21:01 +02:00
jomjol
2cfc3fadb2 Rolling 20220626 2022-06-26 21:57:20 +02:00
jomjol
60cdee2ea6 Merge pull request #834 from haverland/rolling
Rolling: Fix -1 issue on watermeter (digital100 + analog)
2022-06-26 21:12:43 +02:00
Frank Haverland
a17ac6860d Merge branch 'jomjol:rolling' into rolling 2022-06-26 13:47:06 +02:00
Frank Haverland
ef24466702 revert comment out in ZeigerEval
use ZeigerEvalHybrid instead of ZeigerEval in DoubleHyprid10/Digital100 branch
2022-06-26 13:44:55 +02:00
jomjol
de78027b0e Merge pull request #837 from toolsfactory/master
Added Homie Mqtt request
2022-06-26 12:11:35 +02:00
jomjol
28c40a0ad2 Merge branch 'rolling' into master 2022-06-26 12:11:02 +02:00
Michael Geissler
230bbb2239 Added Homie Mqtt request 2022-06-26 08:14:41 +02:00
Frank Haverland
bda2913a32 cleanup, disable debugging 2022-06-24 14:59:51 +02:00
Frank Haverland
78daaf6e5b fix -1 on the last digital digit if using digital100 model 2022-06-24 14:58:00 +02:00
jomjol
8939167a39 Rolling 20220618_v3 2022-06-18 16:01:25 +02:00
jomjol
b48c6111d9 Merge pull request #827 from haverland/rolling
Rolling: Add hostname to title of configuration
2022-06-18 16:00:24 +02:00
Frank Haverland
de1e919b96 add hostname to configure 2022-06-18 15:39:54 +02:00
jomjol
35a96027f1 Rolling 20220618_v2 2022-06-18 14:42:30 +02:00
Frank Haverland
8e12d71580 Merge branch 'jomjol:master' into master 2022-06-18 13:40:43 +02:00
jomjol
7a36bfa2ff Rolling 20220618 2022-06-18 11:10:31 +02:00
jomjol
dfeac0cb7f Rolling 20220609 2022-06-09 21:16:05 +02:00
jomjol
dfec780157 Merge pull request #817 from haverland/rolling
Digital100 model processing added
2022-06-01 20:34:43 +02:00
Frank Haverland
4cc93324f8 Digital100 model 2022-05-31 22:33:12 +02:00
Frank Haverland
bf8833eae6 add Digital100 model processing with output 0.0-9.9 as categorical network 2022-05-30 23:22:17 +02:00
jomjol
00028010ee Rolling 20220526 2022-05-26 20:31:26 +02:00
Frank Haverland
a681a76c4b Kaggle Notebook | pmd-effnet-zca | Version 1 2022-05-24 21:41:45 +02:00
jomjol
cce812ff11 Rolling 20220417 2022-04-17 21:51:26 +02:00
jomjol
ccb4bd595c Rolling 20220415 2022-04-15 14:49:58 +02:00
jomjol
dc7eedcd8f Merge pull request #774 from wetneb/534-influxdb
InfluxDB integration
2022-04-15 14:39:53 +02:00
jomjol
40faa78929 Merge branch 'rolling' into 534-influxdb 2022-04-15 14:39:09 +02:00
Antonin Delpeuch
eb53db00d0 First draft of InfluxDB integration, for #534 2022-04-15 10:19:14 +02:00
jomjol
658ef39736 Rolling 20220322 2022-03-22 20:51:55 +01:00
jomjol
0e90bcb2ef Rolling 20220320 2022-03-20 21:36:44 +01:00
jomjol
a020fce2d7 Merge pull request #725 from mkelley88/master
Update README.md
2022-03-15 20:27:34 +01:00
Matthew T. Kelley
525ccf7aba Update README.md
Made changes to increase clarity of documentation.
2022-03-15 04:50:37 -04:00
jomjol
ebcfc16f63 Create dig-s0-q-20220224.tflite 2022-02-24 21:17:54 +01:00
jomjol
4b825efffb v10.5.2 2022-02-22 19:17:20 +01:00
jomjol
71871016d2 v10.5.1 2022-02-20 16:24:05 +01:00
jomjol
c07ef23d5b v10.5.1 2022-02-20 16:05:36 +01:00
jomjol
cbe884ad63 v10.5.0 2022-02-18 21:22:00 +01:00
jomjol
1dd703b337 v10.5.0 2022-02-18 21:14:04 +01:00
jomjol
bcb1d98191 Rolling 20220215 2022-02-15 21:29:09 +01:00
jomjol
1f5486e8cc Rolling 20220215 2022-02-15 21:26:38 +01:00
jomjol
1371be6f2c v10.4.0 2022-02-12 09:11:43 +01:00
jomjol
b0d8ed6248 v10.4.0 2022-02-12 09:02:00 +01:00
jomjol
379f4585e3 Rolling 20220211 2022-02-11 21:38:40 +01:00
jomjol
45a71981c8 Rolling 20220208 2022-02-08 19:36:25 +01:00
jomjol
ac3409f644 Update FeatureRequest.md 2022-02-06 20:24:59 +01:00
jomjol
11c33f81dd Rolling 20220206 2022-02-06 19:50:47 +01:00
jomjol
641cc860d8 v10.3.0 2022-01-29 15:59:13 +01:00
jomjol
2029bd6e8a Rolling 20220122 2022-01-29 15:41:56 +01:00
jomjol
1ca5e1218d Rolling 20220128 2022-01-28 19:17:05 +01:00
jomjol
887c704f63 Rolling 20220127 2022-01-27 21:43:54 +01:00
jomjol
567dc74cd7 Rolling 20220123 2022-01-23 19:47:34 +01:00
jomjol
53606d5055 Rolling 20220121 2022-01-21 20:50:54 +01:00
jomjol
19a6c21c44 Rolling 20220118 2022-01-18 07:16:38 +01:00
jomjol
3a4b11e4b3 v10.2.0 2022-01-14 21:03:38 +01:00
jomjol
d981574ab2 Update FeatureRequest.md 2022-01-14 20:42:24 +01:00
jomjol
eb817739b9 v10.2.0 2022-01-14 20:34:59 +01:00
jomjol
8972f17638 Merge branch 'wifi-mod' 2022-01-14 20:28:42 +01:00
jomjol
4d997d9473 v10.2.0 2022-01-14 20:28:01 +01:00
jomjol
e79c86c7b6 v10.2.0 2022-01-14 20:18:24 +01:00
jomjol
96bb86536f v10.1.1 2022-01-12 21:02:05 +01:00
jomjol
2daf6c8b3f v10.1.0 2022-01-09 09:47:16 +01:00
jomjol
24b46158de v10.1.0 2022-01-09 09:43:22 +01:00
jomjol
63d336ba28 Rolling 20220104 2022-01-04 21:17:20 +01:00
jomjol
8dd3a92671 Rolling 20220103 2022-01-03 17:32:01 +01:00
jomjol
8e8897c70d v10.0.2 2022-01-01 08:57:07 +01:00
jomjol
eac513411e v10.0.2 2022-01-01 08:53:55 +01:00
jomjol
98f9274085 V10.0.1 2021-12-31 09:02:59 +01:00
jomjol
884dd9fc3b V10.0.0 2021-12-30 18:38:15 +01:00
jomjol
04c564936a Master 10.0.0 2021-12-30 18:29:01 +01:00
jomjol
957138960a Rolling 20211230 2021-12-30 11:02:20 +01:00
jomjol
58a0297915 Rolling 20211223 2021-12-23 08:03:46 +01:00
jomjol
61bf536207 Rolling 20211212 2021-12-12 19:30:07 +01:00
jomjol
4136a7b372 Merge pull request #456 from mad2xlc/master
tabindex to html
2021-12-12 17:45:25 +01:00
Stefan
b3afc9961d Merge branch 'jomjol:master' into master 2021-12-12 10:36:53 +01:00
jomjol
27e2e042da Rolling 2021-21-03 2021-12-03 18:12:45 +01:00
Frederik Kemner
cc659bad30 Time based flow rate limiting
Take time since last valid value into account for flow rate limiting
2021-12-03 11:27:20 +01:00
jomjol
776931c0ad v9.2.0 2021-12-02 21:56:05 +01:00
jomjol
e22b4b6fe1 v9.2.0 2021-12-02 21:52:45 +01:00
jomjol
cad534bffe update wiki 2021-12-02 21:47:37 +01:00
jomjol
3b44adb6fa Rolling 20211128 2021-11-28 09:09:24 +01:00
jomjol
cc0bd1473f Rolling 20211124 2021-11-24 07:32:03 +01:00
jomjol
58124d27bf Rolling 2021-11-23 2021-11-23 17:57:07 +01:00
Sven Rojek
9ad118814a add basic exception handling for the camera module 2021-11-21 19:05:17 +01:00
jomjol
270f8dd093 v9.1.1 2021-11-16 07:15:55 +01:00
jomjol
fde0ae4781 v9.1.0 2021-11-14 08:57:19 +01:00
jomjol
b87ce8c75d Merge branch 'master' into rolling 2021-11-14 08:52:40 +01:00
jomjol
e372c87836 v9.1.0 2021-11-14 08:52:28 +01:00
jomjol
f8478d7742 Merge branch 'master' into rolling 2021-11-14 08:48:42 +01:00
jomjol
a3d6923fec v9.1.0 2021-11-14 08:47:55 +01:00
jomjol
7bfa22187d Merge branch 'pr/398' into rolling 2021-11-14 08:19:13 +01:00
pixel::doc
7a8affae32 Update Helper.cpp
Change "open config file" to "open file"
2021-11-14 01:05:40 +01:00
jomjol
e48dd7c4c4 rolling 20211106 2021-11-06 22:46:16 +01:00
mad2xlc
6d298c1746 added tabindex for coordinate fields 2021-11-04 17:17:22 +01:00
jomjol
4fe9ab92e0 image update 2021-10-27 18:57:07 +02:00
jomjol
f2ac4cdc64 v9.0.0 2021-10-23 16:35:40 +02:00
jomjol
be902401d1 Merge branch 'rolling' 2021-10-23 16:32:44 +02:00
jomjol
020e93bca2 v9.0.0 2021-10-23 16:31:55 +02:00
jomjol
61dfdc2258 Add files via upload 2021-10-23 15:44:46 +02:00
jomjol
a98e3c8eab Add files via upload 2021-10-22 21:31:21 +02:00
jomjol
58a90ff706 v8.5.0 2021-10-07 07:45:40 +02:00
jomjol
d0bf12f3d4 v8.5.0 2021-10-07 07:16:46 +02:00
jomjol
af16785bbf Rolling 20211002 2021-10-02 14:59:09 +02:00
jomjol
18f6e83a2c v8.4.0 2021-09-25 18:57:40 +02:00
jomjol
147d97421b Merge branch 'rolling' 2021-09-25 18:53:47 +02:00
jomjol
dcf2feb7aa v8.4.0 2021-09-25 18:53:14 +02:00
jomjol
e63e940b96 v8.4.0 2021-09-25 08:08:21 +02:00
jomjol
68b0fb83ee v8.4.0 2021-09-24 19:57:48 +02:00
jomjol
f15e5f060a v8.4.0 2021-09-23 18:43:53 +02:00
jomjol
e2a403441f Rolling 20210922 2021-09-22 22:13:08 +02:00
jomjol
9b3665b9c6 Rolling 20210921 v2 2021-09-21 19:41:20 +02:00
jomjol
f4c8bf9206 Rolling 20210921 2021-09-21 18:49:32 +02:00
jomjol
c033db9c31 Rolling 20210921 2021-09-21 07:27:46 +02:00
jomjol
9300526f49 Rolling 2021-09-20 2021-09-20 21:18:34 +02:00
jomjol
b6dd1f7f2d Update 2021-09-14 20:00:45 +02:00
jomjol
1e6eddca04 Rolling 20210913 2021-09-13 20:05:54 +02:00
jomjol
19ca0d7dd7 Update Versioninfo 2021-09-12 07:33:30 +02:00
jomjol
7fcb5d1c0c v8.3.0 2021-09-12 07:29:30 +02:00
jomjol
dd995ec28a Rolling 20210910 2021-09-10 09:26:52 +02:00
jomjol
af99de3535 IgnoreLeadingNaN 2021-09-02 11:04:01 +02:00
jomjol
3567cc2fb0 Merge pull request #330 from pixeldoc2000/pixeldoc2000-patch-1
Pixeldoc2000 patch 1
2021-09-02 11:00:49 +02:00
pixel::doc
5e9d9bd264 Update edit_config_param.html
Fixed some more Text.
2021-09-02 10:09:36 +02:00
pixel::doc
62447c1bb9 Update edit_config_param.html
Fixed some Text
2021-09-02 00:23:59 +02:00
jomjol
a86434c9a2 Rolling 20210831 2021-08-31 11:40:29 +02:00
jomjol
b7b70299f7 Rolling 20210830 2021-08-30 21:21:18 +02:00
jomjol
eb02e0aec1 new images 2021-08-29 20:57:21 +02:00
jomjol
7816e53db7 v8.2.0 2021-08-24 08:37:18 +02:00
jomjol
7ae08e572a Merge branch 'rolling' 2021-08-24 08:34:32 +02:00
jomjol
47d15d8adb v8.2.0 2021-08-24 08:33:56 +02:00
jomjol
0dac0e87e4 rolling 20210823 2021-08-23 18:57:48 +02:00
jomjol
b290099d5b v12.0.0 2021-08-12 07:25:12 +02:00
jomjol
f6b1a41a0b v12.0.0 2021-08-12 07:20:58 +02:00
jomjol
e529af04cf Update FeatureRequest.md 2021-08-10 20:19:05 +02:00
jomjol
6c365dd949 rolling v20210809 2021-08-09 21:53:07 +02:00
jomjol
32f15fc557 rolling 20210708 2021-08-07 15:25:27 +02:00
jomjol
6f06af1d5f Update README.md 2021-08-01 21:52:00 +02:00
jomjol
a91f99faab update 2021-08-01 21:49:29 +02:00
jomjol
17a87b23a1 v8.0.5 2021-08-01 21:46:17 +02:00
jomjol
d4b5ec2ae2 v8.0.4 2021-07-29 20:18:53 +02:00
jomjol
1bcaf09855 v8.0.4 2021-07-29 20:14:36 +02:00
jomjol
fa3842b2b4 v8.0.3 2021-07-25 18:15:35 +02:00
jomjol
ea72256e56 Merge branch 'rolling' 2021-07-25 18:08:43 +02:00
jomjol
be5828cb3e v8.0.3 2021-07-25 18:07:50 +02:00
jomjol
104b72505c Rolling - 20210725 2021-07-25 13:44:22 +02:00
jomjol
23728a0686 Update README.md 2021-07-23 21:02:19 +02:00
jomjol
eaaa856b13 Update README.md 2021-07-23 21:01:50 +02:00
jomjol
01e81d02b5 v8.0.2 2021-07-23 20:57:42 +02:00
jomjol
9ae8d0a512 Merge branch 'rolling' 2021-07-23 20:48:28 +02:00
jomjol
da16322fb8 v8.0.2 2021-07-23 20:47:23 +02:00
jomjol
a6d39afc26 rolling 20210723 2021-07-23 07:44:59 +02:00
jomjol
1b6a124f54 Update FeatureRequest.md 2021-07-21 07:00:12 +02:00
jomjol
8aff6bf8f3 Rolling 20210719 2021-07-19 21:54:14 +02:00
jomjol
21115752aa Merge pull request #280 from jomjol/rolling
v8.0.1
2021-07-18 16:58:23 +02:00
jomjol
025c2b88b9 v8.0.1 2021-07-18 16:57:35 +02:00
jomjol
655f9d7c97 Update version 2021-07-14 20:00:06 +02:00
jomjol
03b5e36114 Merge branch 'rolling' 2021-07-14 19:52:11 +02:00
jomjol
9c78c1e9ca v8.0.0 2021-07-14 19:48:49 +02:00
jomjol
136186a526 rolling 20210713 BETA v8.0.0 2021-07-13 21:41:17 +02:00
jomjol
1f6b02a671 Rolling 20210712 2021-07-12 22:06:32 +02:00
jomjol
76a0518d52 Rolling 20210721 BugFix 2021-07-11 23:47:24 +02:00
jomjol
a688a69af6 Merge branch 'rolling' of https://github.com/jomjol/AI-on-the-edge-device into rolling 2021-07-11 18:28:00 +02:00
jomjol
b890ffc5f3 Rolling 20210711 2021-07-11 18:27:25 +02:00
jomjol
b98558107e Merge pull request #263 from Zwer2k/rolling
Rolling
2021-07-11 17:51:09 +02:00
Zwer2k
3e360ad0fb add log in gpio handler
add nullpint check in tfliteCass
2021-07-11 16:19:45 +02:00
Zwer2k
a7ced407f8 Update README.md
improve case if gpio is disabled
remove /test html route
2021-07-11 13:56:37 +02:00
Zwer2k
45a1e137d1 Merge branch 'rolling' of https://github.com/jomjol/AI-on-the-edge-device into rolling 2021-07-11 11:24:26 +02:00
Zwer2k
a44e0d81cc gpio handler work 2021-07-10 12:36:13 +02:00
Zwer2k
749fc6699c Merge remote-tracking branch 'origin/gpio-handler' into rolling 2021-07-08 21:54:44 +02:00
jomjol
d7bb147a23 Rolling 20210708 2021-07-08 21:45:33 +02:00
jomjol
08b0b254f2 rolling 20210707 2021-07-07 21:57:59 +02:00
Zwer2k
5414a4c3f1 Merge remote-tracking branch 'upstream/rolling' into rolling 2021-07-06 23:33:01 +02:00
Zwer2k
7944ab329d litle improvements on html and config.ini 2021-07-06 21:32:49 +02:00
Zwer2k
8ca14a434c gpio handler works again
remove memory leak in FlowDigit
2021-07-06 01:25:20 +02:00
jomjol
e24ba68fec rolling 20210705 2021-07-05 07:30:04 +02:00
Zwer2k
b205326782 gpio handler is working 2021-07-04 23:59:59 +02:00
jomjol
daa1960dff rolling 20210704 bug fix 2021-07-04 10:20:07 +02:00
jomjol
894c7f6972 Revert "Revert "rolling 20210704 bugfix""
This reverts commit 737dcc76b8.
2021-07-04 08:12:50 +02:00
jomjol
737dcc76b8 Revert "rolling 20210704 bugfix"
This reverts commit b42f17916b.
2021-07-04 08:12:36 +02:00
jomjol
b42f17916b rolling 20210704 bugfix 2021-07-04 08:06:04 +02:00
jomjol
2c6ce6fd07 rolling 20210705 2021-07-04 07:54:17 +02:00
jomjol
f243f4b8ea Rolling 20210701 2021-07-01 19:47:44 +02:00
jomjol
02e881ebc0 Add files via upload 2021-07-01 19:15:36 +02:00
Zwer2k
7b8f10a14e work on GPIO handler
bigfix: memory leak in GetJPGStream
2021-06-25 01:19:23 +02:00
Zwer2k
d995c31b7b work on GPIO handler
bigfix: memory leak in GetJPGStream
2021-06-18 01:29:59 +02:00
jomjol
45154cb55c 20210617 2021-06-17 20:28:24 +02:00
jomjol
48067b10cd v7.1.2 2021-06-17 20:10:30 +02:00
Zwer2k
f24c40d780 work on GPIO handling 2021-06-13 01:24:02 +02:00
jomjol
f4edd36744 Update README.md 2021-06-11 07:41:06 +02:00
jomjol
a202a6abdc Rolling 20210611 2021-06-11 07:31:06 +02:00
Zwer2k
c25adfe28a add interrupt to gpio config
bugfix in gpio config
2021-06-09 00:16:31 +02:00
Zwer2k
822c6cc45c complete extended config.ini handling for GPIO settings
added TopicUptime and MainTopicGPIO
2021-06-08 22:24:53 +02:00
Zwer2k
c48b44d06a extend config.ini handler for GPIO settings
add BootTime incode
2021-06-08 00:59:28 +02:00
jomjol
21a59fbd35 Update README.md 2021-05-30 21:52:52 +02:00
jomjol
cdcf940d12 v7.1.1 2021-05-30 21:49:50 +02:00
jomjol
6cefc44fb6 Update README.md 2021-05-28 20:56:24 +02:00
jomjol
8308f159ad Merge pull request #237 from jomjol/master
Sync Rolling
2021-05-28 19:57:20 +02:00
jomjol
e5ff8f2164 Update Firmware 2021-05-28 19:56:10 +02:00
jomjol
a000252c8a Merge pull request #236 from jomjol/rolling
Update to v7.1.0
2021-05-28 19:53:08 +02:00
jomjol
9a42c580cf v7.1.0 2021-05-28 19:52:26 +02:00
jomjol
6e0a7a742e Rolling 210527 2021-05-27 19:22:27 +02:00
jomjol
026bac121f Rolling 20210522-v2 2021-05-22 11:37:46 +02:00
jomjol
8a26b817f7 Rolling 20210522 2021-05-22 07:39:10 +02:00
jomjol
528a4435a9 Rolling 20210520 2021-05-20 21:58:37 +02:00
jomjol
9b791bb7a7 rolling 20210520 2021-05-20 07:00:09 +02:00
jomjol
58eb0b1292 rolling 20210517 2021-05-17 19:35:38 +02:00
jomjol
39eda4a4be Merge pull request #224 from jomjol/master
sync rolling
2021-05-13 08:23:03 +02:00
jomjol
87a6445ff6 Update version in firmware 2021-05-13 08:22:20 +02:00
jomjol
b7e6d33d48 Merge pull request #223 from jomjol/rolling
Update v7.0.1
2021-05-13 08:17:03 +02:00
jomjol
52e9cd20ee Update v7.0.1 2021-05-13 08:16:01 +02:00
jomjol
b34bd5d988 Merge pull request #217 from jomjol/master
Synch rolling
2021-05-08 18:23:54 +02:00
jomjol
58d5e7bc58 v7.0.0 2021-05-08 18:23:10 +02:00
jomjol
1e09bfbb80 Merge pull request #216 from jomjol/rolling
Update to v7.0.0
2021-05-08 18:20:11 +02:00
jomjol
91fa1c066c Vorbereitung v7.0.0 2021-05-08 18:16:58 +02:00
jomjol
10d49b55d1 Rolling 20210507 2021-05-07 21:33:16 +02:00
jomjol
67d0bf6a27 Update config.ini 2021-05-06 21:54:38 +02:00
jomjol
d36cbde7aa Rolling 20210506v2 2021-05-06 21:50:14 +02:00
jomjol
016f4088d4 Rolling 20210506 2021-05-06 20:28:27 +02:00
jomjol
c2d1bbb4be Merge pull request #205 from jomjol/rolling
v6.7.2
2021-05-01 19:53:26 +02:00
jomjol
bc6a01444a v6.7.2 2021-05-01 19:52:10 +02:00
jomjol
24f0902194 Merge pull request #204 from jomjol/master
Sync Rolling
2021-05-01 17:47:08 +02:00
jomjol
19fd6a10dd v6.7.1 2021-05-01 17:44:56 +02:00
jomjol
a45a5296e4 Merge branch 'rolling' into master 2021-05-01 17:40:31 +02:00
jomjol
1459bb15c1 Prepare v6.7.1 2021-05-01 17:32:22 +02:00
jomjol
ce5f3c463b Rolling 2021-05-01 08:15:11 +02:00
jomjol
04ebbf35e7 Update README.md 2021-04-23 07:22:07 +02:00
jomjol
ba1d6e30e2 Update README.md 2021-04-23 07:15:16 +02:00
jomjol
e9ac8933f9 Update Version 2021-04-23 07:14:11 +02:00
jomjol
ec96b7f878 Merge pull request #194 from jomjol/rolling
Update to v6.7.0
2021-04-23 07:10:11 +02:00
jomjol
ba7d429178 v6.7.0 2021-04-23 07:08:18 +02:00
jomjol
79be2089be Prepare to v6.7.0 2021-04-23 07:04:05 +02:00
jomjol
ea2305de47 Rolling 20210420 2021-04-20 19:44:16 +02:00
jomjol
635b2c35a8 Update README.md 2021-04-08 10:42:42 +02:00
jomjol
afdc4bb3f1 Merge pull request #179 from queeek/patch-1
Update README.md
2021-04-08 10:38:53 +02:00
Ina
3d49ec72ba Update README.md
3D Housing link is linked to the housing only project
2021-04-08 10:07:21 +02:00
jomjol
520f818adc Merge pull request #176 from jomjol/master
Sync Rolling
2021-04-05 10:18:36 +02:00
jomjol
20b054472e Update 2021-04-05 10:17:54 +02:00
jomjol
21a70c5655 Merge pull request #175 from jomjol/rolling
Update to v6.6.1
2021-04-05 10:12:59 +02:00
jomjol
08270f5d6d Update to v6.6.1 2021-04-05 10:12:21 +02:00
jomjol
9923be2f1d Merge pull request #171 from jomjol/master
Sync Rolling
2021-03-28 20:12:17 +02:00
jomjol
5df57c95d4 Update to v6.6.0 2021-03-28 20:11:22 +02:00
jomjol
d8c91466d0 Merge pull request #170 from jomjol/rolling
Update to v6.6.0
2021-03-28 20:08:46 +02:00
jomjol
37b2e370fe Prepare v6.6.0 2021-03-28 20:08:02 +02:00
jomjol
98dfba0640 Rolling 20210327 2021-03-27 17:16:54 +01:00
jomjol
574c9084c2 Merge pull request #166 from jomjol/master
Sync Rolling
2021-03-25 21:01:25 +01:00
jomjol
9862ae8e7a Update to v6.5.0 2021-03-25 20:58:44 +01:00
jomjol
7bc4e63209 Merge pull request #165 from jomjol/rolling
Update to v6.5.0
2021-03-25 20:51:30 +01:00
jomjol
ad40150cfa Update 2021-03-25 20:50:10 +01:00
jomjol
970530d99f Update Rolling to v6.5.0 2021-03-25 20:48:19 +01:00
jomjol
c6ae989b82 Update Restart Hostname 2021-03-21 20:56:30 +01:00
jomjol
a0ebf354b1 Create focus_adjustment.jpg 2021-03-21 19:52:23 +01:00
jomjol
97ecbc792e Create focus_adjustment.jpg 2021-03-21 19:50:01 +01:00
jomjol
5934a59489 Update 2021-03-21 19:41:34 +01:00
jomjol
ee18046581 Rolling 20210321 2021-03-21 19:24:20 +01:00
jomjol
1e4e38c02f Merge pull request #158 from jomjol/master
Update rolling to v6.4.0
2021-03-21 12:56:08 +01:00
jomjol
7a3038eceb Update FeatureRequest.md 2021-03-21 12:49:23 +01:00
jomjol
7d2f86b72e Update README.md 2021-03-21 12:45:52 +01:00
jomjol
3aaa319505 Update README.md 2021-03-21 12:45:03 +01:00
jomjol
f4075f0a51 Create FeatureRequest.md 2021-03-21 12:39:28 +01:00
jomjol
59643a8d52 Update README.md 2021-03-21 11:44:46 +01:00
jomjol
baf2a880e4 Merge pull request #157 from jomjol/master
Align Rolling to v6.4.0
2021-03-20 09:49:22 +01:00
jomjol
d71e8320c7 Update to v6.4.0 2021-03-20 09:47:50 +01:00
jomjol
3b3d924f40 final update 2021-03-16 21:14:09 +01:00
jomjol
60701bc007 Merge branch 'rolling' into master 2021-03-16 21:10:07 +01:00
jomjol
5ca3e184e0 Prepare v6.3.1 2021-03-16 21:02:27 +01:00
jomjol
2903d1a0a6 Update 2021-03-14 12:59:14 +01:00
jomjol
5f0f1802a4 Merge pull request #150 from jomjol/rolling
Rolling
2021-03-14 12:55:44 +01:00
jomjol
5be56d9b00 Prepare for 6.3.0 2021-03-14 12:52:23 +01:00
jomjol
d3fd1b5045 Rollling 20210313 2021-03-13 17:48:12 +01:00
jomjol
4615e87483 Merge pull request #147 from jomjol/rolling
Rolling
2021-03-10 21:16:41 +01:00
jomjol
fb9b72deea v6.2.2 2021-03-10 21:15:47 +01:00
jomjol
5cc873a6bb Merge pull request #141 from jomjol/master
Synch Master to Rolling
2021-03-09 21:11:05 +01:00
jomjol
26745496a5 Update to 6.2.1 2021-03-09 21:09:59 +01:00
jomjol
4537725852 Update Firmware 2021-03-08 20:32:58 +01:00
jomjol
676bda22ae Merge pull request #138 from jomjol/rolling
Update to v6.2.0
2021-03-08 20:28:46 +01:00
jomjol
87028e5f35 Merge branch 'master' into rolling 2021-03-08 20:28:16 +01:00
jomjol
912083d20f Prepare for Update to v6.2.0 2021-03-08 20:26:52 +01:00
jomjol
4b6044dade Rolling 2021-03-06 2021-03-06 21:20:02 +01:00
jomjol
871d3b537d rolling 2021-03-06 2021-03-06 20:10:31 +01:00
jomjol
01f8a514a1 Revert 2021-03-01 07:24:17 +01:00
jomjol
7dbd77d2a4 Revert "Update rolling"
This reverts commit 94dde53c21.
2021-03-01 07:16:15 +01:00
jomjol
94dde53c21 Update rolling 2021-02-28 18:40:55 +01:00
jomjol
e47eaa3ac3 Merge pull request #128 from jomjol/rolling-camera-speedup
Rolling camera speedup
2021-02-27 13:16:38 +01:00
jomjol
4060299204 update 2021-02-27 13:15:49 +01:00
jomjol
70a99927cd update 2021-02-27 13:15:03 +01:00
jomjol
688cee9463 Update 2021-02-27 12:51:50 +01:00
jomjol
fa3e300c37 Update platformio.ini 2021-02-06 12:04:00 +01:00
jomjol
9dbad050fd Rolling 2021-02-03 21:26:00 +01:00
jomjol
87202115d0 Update Rolling 2021-01-23 22:30:19 +01:00
jomjol
abc4cb444a Merge pull request #96 from jomjol/master
Rolling to v6.1.0
2021-01-20 19:53:35 +01:00
jomjol
78744840eb Update 2021-01-20 19:52:26 +01:00
jomjol
46cfe45cf6 Merge branch 'rolling' into master 2021-01-20 19:43:33 +01:00
jomjol
91ff41a9d9 Prepare for v6.1.0 2021-01-20 19:39:10 +01:00
jomjol
3869da9d06 Rolling 20210119 2021-01-19 20:14:37 +01:00
jomjol
2530691347 Update Rolling 20210118 2021-01-18 21:15:23 +01:00
jomjol
c65de27e9d Update Rolling 2021-01-17 12:44:20 +01:00
jomjol
9bb715fcb2 Update Versioninfo 2021-01-05 20:46:14 +01:00
jomjol
8c4f39ab49 Update version info 2021-01-05 18:16:46 +01:00
jomjol
e5206091dd Update version file 2021-01-05 08:32:07 +01:00
jomjol
e53c6fe64c Merge branch 'rolling-speed-up-alignment' into rolling 2021-01-05 08:17:21 +01:00
jomjol
b893b24d88 Update README.md 2021-01-05 08:11:22 +01:00
jomjol
c7caa55223 Prepare update rolling 2021-01-05 07:49:58 +01:00
jomjol
c675019ef3 Almost done 2021-01-04 22:49:36 +01:00
jomjol
f2fea0a402 Merge pull request #82 from jomjol/master
Update Rolling from Master Release v6.0.0
2021-01-02 09:00:50 +01:00
jomjol
aeafd631d5 Update 2021-01-02 08:59:02 +01:00
jomjol
aa442632ea Merge pull request #81 from jomjol/rolling
Update to v6.0.0
2021-01-02 08:54:05 +01:00
jomjol
2a4b5f88a7 Preparation for v6.0.0 2021-01-02 08:50:20 +01:00
jomjol
0e36010937 Bug-fixing 2021-01-01 14:59:07 +01:00
jomjol
8a06825871 Rolling 20210101 2021-01-01 10:58:20 +01:00
jomjol
ce2f1bcde6 Merge pull request #77 from jomjol/rolling-update-cimage
Improvment of CBasisImage handling
2021-01-01 10:14:04 +01:00
jomjol
c59826471c Update 2021-01-01 10:13:00 +01:00
jomjol
9c8f64f602 Bug-Fixing 2020-12-31 12:13:03 +01:00
jomjol
d4342a77c8 Update README.md 2020-12-31 11:57:48 +01:00
jomjol
054d2296c4 Update README.md 2020-12-31 11:54:52 +01:00
jomjol
ae116981ef MQTT: LWT 2020-12-30 10:35:50 +01:00
jomjol
becb886ab7 Update digital CNN, bug fixing 2020-12-29 22:27:48 +01:00
jomjol
3502ac9263 Bug fixing 2020-12-29 10:42:42 +01:00
jomjol
c64cb94b7d Merge pull request #75 from jomjol/rolling-reduce-sd-use
Update with reduced SD card usage
2020-12-28 16:27:29 +01:00
jomjol
dffb28816d Update for rolling 2020-12-28 16:26:05 +01:00
jomjol
6e521f07c4 Modify ClassControllCamera_MakeImage 2020-12-27 17:36:08 +01:00
jomjol
c05313aefc Limit Image to VGA-Size 2020-12-26 20:11:22 +01:00
jomjol
db0ca1cb9b Improved Logfile, extended Logging 2020-12-26 09:18:16 +01:00
jomjol
584a73255a TimeServer 2020-12-24 16:08:58 +01:00
jomjol
3a66385059 Update README.md 2020-12-23 22:06:48 +01:00
jomjol
7e4f83c2f5 Waitmissing for missing memory 2020-12-23 11:09:27 +01:00
jomjol
9971c82e99 Restructure Image Processing 2020-12-23 08:00:11 +01:00
jomjol
b418525b3b Inital 2020-12-22 08:08:07 +01:00
jomjol
f5c28107d4 rolling 2020-12-07 21:38:43 +01:00
jomjol
793f928e6e Rolling - fixed IP 2020-12-06 21:13:27 +01:00
jomjol
a8fb2e37d5 Merge pull request #71 from jomjol/master
Update Rolling
2020-12-06 19:36:03 +01:00
jomjol
11fed9394a Update 2020-12-06 19:34:52 +01:00
jomjol
bcdd0c66c0 Merge pull request #70 from jomjol/rolling
Update to v5.0.0
2020-12-06 19:31:04 +01:00
jomjol
e988215d8a Prepare for v5.0.0 2020-12-06 19:28:17 +01:00
jomjol
f616643335 Rolling 2020-06-12 2020-12-06 08:24:32 +01:00
jomjol
816f93222b Rolling 20201204 2020-12-04 22:09:20 +01:00
jomjol
9e85b1240a Rolling - 202-12-03 2020-12-03 20:38:28 +01:00
jomjol
c5059b4568 Merge pull request #69 from jomjol/master
Sync rolling master to v4.1.1
2020-12-02 21:58:42 +01:00
jomjol
2ae304dcf5 Update 2020-12-02 21:57:55 +01:00
jomjol
ffc15aa57a Merge pull request #68 from jomjol/rolling
Update to v4.1.1
2020-12-02 21:54:53 +01:00
jomjol
c9c02daff7 Prepare v4.1.1 2020-12-02 21:53:44 +01:00
jomjol
f6f3e2377e Rolling 2020-12-02 2020-12-02 07:50:51 +01:00
jomjol
ed3226e3a0 Merge pull request #66 from jomjol/master
Rolling to v4.1.0
2020-11-30 22:15:24 +01:00
jomjol
8f5200e79d update 2020-11-30 22:13:49 +01:00
jomjol
2753552997 Merge pull request #65 from jomjol/rolling
Update to v4.1.0
2020-11-30 21:47:35 +01:00
jomjol
a061ea7125 Preparation for v4.1.0 2020-11-30 21:46:37 +01:00
jomjol
068d57f382 Rolling 30.11.20 2020-11-30 21:36:50 +01:00
jomjol
c76a635414 Update 2020-11-30 2020-11-30 12:35:55 +01:00
jomjol
1b5f6b4683 Update configuration management 2020-11-29 15:41:26 +01:00
jomjol
891adf3397 Update 2020-11-27 17:00:13 +01:00
jomjol
190e7e76d3 Update Rolling 2020-11-26 21:17:13 +01:00
jomjol
eb47d5139f Rolling Update 2020-11-21 2020-11-21 22:47:43 +01:00
jomjol
288910e67e Update README.md 2020-11-20 19:37:13 +01:00
jomjol
1a0feb4f19 compatibitly mit esp-idf pure 2020-11-20 19:34:55 +01:00
jomjol
1cba7d3e1d Update README.md 2020-11-19 19:19:50 +01:00
jomjol
0ff99b716c Update 2020-11-19 19:16:11 +01:00
jomjol
a537e785fb Update 20201119 2020-11-19 19:15:13 +01:00
jomjol
dbbc5ea127 Merge pull request #49 from jomjol/master
Correct Version Info
2020-11-15 18:41:47 +01:00
jomjol
3e6713d16c Correct Version Info 2020-11-15 18:36:31 +01:00
jomjol
a86aa8034d Merge pull request #47 from jomjol/master
Start Rolling v4.0.0
2020-11-15 12:57:48 +01:00
jomjol
c292ecd54b Update to v4.0.0 2020-11-15 12:56:02 +01:00
jomjol
7bfdfd3c38 Merge branch 'master' of https://github.com/jomjol/AI-on-the-edge-device 2020-11-15 12:51:20 +01:00
jomjol
3f154e3a53 Update v4.0.0 2020-11-15 12:49:36 +01:00
jomjol
06ba8372d0 Merge pull request #46 from jomjol/rolling
Prepare v4.0.0
2020-11-15 12:36:11 +01:00
jomjol
eae9b66eed Prepare v4.0.0 2020-11-15 12:34:32 +01:00
jomjol
4caca9b06a Merge pull request #44 from jomjol/rolling
Update to v4.0.0
2020-11-15 12:04:12 +01:00
jomjol
de772d7ddd Prepare for 4.0 2020-11-15 12:02:03 +01:00
jomjol
707472ba27 Rolling 2020-11-13 2020-11-13 19:03:06 +01:00
jomjol
46265debc3 Merge pull request #42 from Zwer2k/master
Logfile rotation implemented
2020-11-13 07:09:49 +01:00
jomjol
14d221bf9c Merge branch 'rolling' into master 2020-11-13 07:05:37 +01:00
Jurij Retzlaff
f4f871002b rotation of image log files implemented
improved rotation of message log files
implement deletion of temp images before start new flow
a little bit code cleaning
2020-11-12 23:27:00 +01:00
jomjol
bb92d4aa54 Merge pull request #41 from jomjol/update_tflite
Update tflite
2020-11-08 12:40:25 +01:00
Jurij Retzlaff
acc7253ca1 logfile rotating implemented 2020-11-08 11:23:22 +01:00
jomjol
f1002b5f9d Update tflite 2020-11-08 03:28:31 +01:00
jomjol
84cea8e3d6 Update tflite 2020-11-08 03:27:52 +01:00
jomjol
05a0f6fa62 Bug-Fix 2020-11-03 22:17:57 +01:00
jomjol
2ab2f070b4 v3.1.0 2020-10-26 18:34:35 +01:00
jomjol
103de2011b v3.1.0 2020-10-26 18:34:09 +01:00
jomjol
3cec93e2f1 Merge branch 'master' of https://github.com/jomjol/AI-on-the-edge-device 2020-10-26 18:30:45 +01:00
jomjol
a23d7ee6e2 v3.1.0 2020-10-26 18:29:52 +01:00
jomjol
42afbcf655 Merge pull request #38 from jomjol/rolling
Rolling
2020-10-26 18:24:54 +01:00
jomjol
c61167bdfa Update README.md 2020-10-26 18:22:23 +01:00
jomjol
642cefb84f Update 2020-10-25 2020-10-25 19:56:22 +01:00
jomjol
1223aa7c70 Bug-Fix 2020-10-24 11:56:36 +02:00
jomjol
0d90977917 Nightly 20201019 2020-10-19 07:04:26 +02:00
jomjol
7e57e85e75 Merge pull request #36 from jomjol/master
Update to v3.0.0
2020-10-14 18:47:45 +02:00
jomjol
8f518954aa Update to v3.0.0 2020-10-14 18:46:46 +02:00
jomjol
26144815d2 Merge pull request #35 from jomjol/rolling
Rolling
2020-10-14 18:27:49 +02:00
jomjol
21d07be7df Update 20201013 2020-10-13 20:13:28 +02:00
jomjol
04f69f0853 Update README.md 2020-10-04 08:23:26 +02:00
jomjol
0678c81959 Update config.ini 2020-10-04 08:22:23 +02:00
jomjol
70a88088f2 Rolling 2020-10-04
Initial MQTT
2020-10-04 08:09:59 +02:00
jomjol
f8e8c756ab nightly 20200929 2020-09-29 19:13:16 +02:00
jomjol
6e26fa6e3c Merge pull request #33 from phlupp/rolling
Add HTML Version / modify Sysinfo / move Sysinfo to server_main
2020-09-29 18:36:22 +02:00
Philipp Harsch
b54d6e785d modify Sysinfo 2020-09-29 02:54:18 +02:00
Philipp Harsch
5d2e22cd86 Add HTML Version 2020-09-29 02:25:49 +02:00
Philipp Harsch
ccd1d3f460 Add HTML Version 2020-09-29 02:08:59 +02:00
Philipp Harsch
964486a819 add html version 2020-09-29 00:15:12 +02:00
phlupp
9080f1d2f0 Merge pull request #3 from jomjol/rolling
Pull Rolling
2020-09-28 22:21:07 +02:00
jomjol
aab8dfcde5 Merge pull request #32 from jomjol/master
Update Rolling
2020-09-28 20:04:23 +02:00
jomjol
1633b74ab2 Update to v21.1 2020-09-28 20:03:38 +02:00
jomjol
bafd67be36 Merge pull request #31 from jomjol/rolling
Update README.md
2020-09-28 19:55:46 +02:00
jomjol
8f1d7d081d Update README.md 2020-09-28 19:55:17 +02:00
jomjol
66bfcd1d45 Merge branch 'rolling' into master 2020-09-28 19:53:49 +02:00
jomjol
d89438a15f Update to v2.1.1 2020-09-28 19:37:20 +02:00
jomjol
d77fa5245d Update 2020-09-27 08:28:19 +02:00
jomjol
67115dd8d8 Merge pull request #29 from jomjol/rolling
Update to v2.2.0
2020-09-27 08:21:59 +02:00
jomjol
cefe125304 Update to v2.2.0 2020-09-27 08:19:23 +02:00
jomjol
5a98b3d0bb Version 2020-09-26 19:29:39 +02:00
jomjol
480da7c38b Merge pull request #28 from jomjol/rolling
Rolling
2020-09-25 19:16:52 +02:00
jomjol
d428abc12f Update to v2.1.0 2020-09-25 19:15:59 +02:00
jomjol
a08144cc9f Update 20200925 2020-09-25 08:42:45 +02:00
jomjol
0868c22ac6 Merge pull request #27 from michaeljoos72/rolling
HTML Update
2020-09-24 20:37:16 +02:00
michaeljoos72
8ff17650dd HTML Update
- Direkt Dropdown-Link "System --> Log Viewer"
- Small text corrections
- Avoid Scrollbars in Overview in case picture was not loaded
2020-09-24 18:39:18 +02:00
michaeljoos72
5e037d7ab9 Merge pull request #1 from jomjol/rolling
Update Rolling
2020-09-23 23:06:16 +02:00
jomjol
8d2ddc2f22 Update README.md 2020-09-23 21:12:10 +02:00
jomjol
7963474bf0 Update 20200923 2020-09-23 21:01:40 +02:00
jomjol
a8aa6d6329 Update 2020-09-21 22:36:57 +02:00
jomjol
5b52b806ae Error Correction 2020-09-21 22:36:47 +02:00
jomjol
b059713df5 Update 2020-09-21 22:15:11 +02:00
jomjol
48ec76ab38 Update 2020-09-21 2020-09-21 22:12:51 +02:00
jomjol
fe446d60d7 Merge pull request #25 from phlupp/rolling
Update Rolling CPU Temp - Sysinfo - Duplikate
2020-09-21 20:42:22 +02:00
Philipp Harsch
9e2e0d4591 update 2020-09-20 22:33:33 +02:00
phlupp
87935a23d4 Add CPU Temp to log - add sysinfo handler 2020-09-20 20:53:53 +02:00
phlupp
2b178dcbd7 add CPU Temp 2020-09-20 20:47:52 +02:00
phlupp
05cdc99079 add CPU Temp 2020-09-20 20:47:18 +02:00
phlupp
51bca222c0 Delete Helper.h
Duplikat
2020-09-20 20:44:17 +02:00
phlupp
61bbe57018 Delete Helper.cpp
Duplikat
2020-09-20 20:43:52 +02:00
phlupp
9997539736 Merge pull request #2 from jomjol/rolling
Update Rolling
2020-09-20 20:40:08 +02:00
jomjol
d142917afc Update HTML 2020-09-20 17:04:50 +02:00
jomjol
41c1316575 Merge pull request #24 from michaeljoos72/rolling
Update HTML / Autorefresh (JQuery)
2020-09-20 17:02:49 +02:00
michaeljoos72
d4be57f59e Update reboot_page.html 2020-09-20 08:47:53 +02:00
phlupp
6a047d14a0 Merge pull request #1 from jomjol/rolling
Rolling
2020-09-20 01:21:03 +02:00
michaeljoos72
0d1b58542b Update HTML / Autorefresh
- Update HTML-Content (SD-Card)
- Implementation of Auto-Refresh (Picture & Values)  on Overview-Page (300s)
- Implementation of "jquery-3.5.1.min.js"
2020-09-19 19:07:26 +02:00
jomjol
bb05957d33 update rolling 2020-09-16 07:04:12 +02:00
jomjol
157b071a78 Merge pull request #19 from phlupp/patch-4
update Hostname
2020-09-16 06:58:21 +02:00
jomjol
927b5e6e38 Merge pull request #20 from phlupp/patch-3
update hostname, aufgeräumt und std wert auf "watermeter" gesetzt
2020-09-16 06:57:49 +02:00
phlupp
fb0fb551ff update Hostname, aufgeräumt und optimiert, Standar auf "watermeter" gesetzt 2020-09-15 22:26:59 +02:00
phlupp
db02a306e9 Hostname aus ini an console 2020-09-15 22:18:30 +02:00
phlupp
7d84891813 HostName Änderungen aufgeräumt und standard Hostname auf "watermeter" gesetzt 2020-09-15 22:12:35 +02:00
jomjol
e1a33003f0 Update firmware.bin 2020-09-15 06:57:26 +02:00
jomjol
64c7a171ae Merge pull request #18 from phlupp/patch-2
update hostname
2020-09-15 06:55:07 +02:00
phlupp
6a3cb6d9d9 update hostname 2020-09-15 00:10:06 +02:00
jomjol
efed040e9e Update firmware.bin 2020-09-14 21:10:14 +02:00
jomjol
2148f1031f Merge pull request #17 from phlupp/patch-1
Hostname
2020-09-14 21:07:52 +02:00
phlupp
6659456cb3 Hostname 2020-09-14 21:02:57 +02:00
jomjol
207cc585d9 Bug fix, Hostname 2020-09-14 19:43:32 +02:00
jomjol
df80124c57 Bug fix DecimalShift 2020-09-13 21:23:11 +02:00
jomjol
dd1155dc89 Bug fixing 2020-09-13 20:27:21 +02:00
jomjol
4bbed42fb8 Update README.md 2020-09-13 14:01:34 +02:00
jomjol
d70beb57fc Implementation of DecimalShift 2020-09-13 13:53:00 +02:00
489 changed files with 29343 additions and 72021 deletions

67
.github/ISSUE_TEMPLATE/bug_report.yml vendored Normal file
View File

@@ -0,0 +1,67 @@
name: 🐞 Bug Report
description: Use this form if you think you found a bug / Verwende dieses Formular, wenn Du denkst, dass Du einen Fehler gefunden hast.
labels: bug
body:
- type: markdown
attributes:
value: |
Thank you for taking your time to report a bug.
Before you proceed, please check:
- [ ] Do you use the [latest version](https://github.com/jomjol/AI-on-the-edge-device/releases)?
- [ ] Is there already another similar issue? Check for open and closed [Issue](https://github.com/jomjol/AI-on-the-edge-device/issues) and [Discussions](https://github.com/jomjol/AI-on-the-edge-device/discussions).
- [ ] Are instructions in the [README](https://github.com/jomjol/AI-on-the-edge-device/tree/master#readme) solving your issue?
- [ ] Are instructions in the [Wiki](https://github.com/jomjol/AI-on-the-edge-device/wiki) solving your issue?
Du darfst gerne auch in Deutsch schreiben!
- type: textarea
validations:
required: true
attributes:
label: The Problem
description: A clear and concise description of what the bug is.
- type: input
validations:
required: true
attributes:
label: Version
description: Which version are you using? (See menu `System > Info`).
- type: textarea
validations:
required: true
attributes:
label: Logfile
description: Add the logfile (See menu `System > Log Viewer`) to help explain your problem. This will be automatically formatted into code, so no need to format it on your side.
render: shell
- type: textarea
attributes:
label: Expected Behavior
description: A clear and concise description of what you expected to happen.
- type: textarea
attributes:
label: Screenshots
description: If applicable, add screenshots to help explain your problem.
- type: textarea
attributes:
label: Additional Context
description: Add any other context about the problem here.

5
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: 💬 Open a new Discussion
url: https://github.com/jomjol/AI-on-the-edge-device/discussions/categories/q-a
about: Use this form if you have a question or need help setting your AI-on-the-edge-device it up

23
.github/ISSUE_TEMPLATE/feature.yaml vendored Normal file
View File

@@ -0,0 +1,23 @@
name: 💡 Feature Request
description: Use this form if you have an idea or wish for a new feature
labels: feature
body:
- type: markdown
attributes:
value: |
Thank you for taking your time to document your idea.
Before you proceed, please check:
- [ ] Is there already another similar issue open or closed? Check for open and closed [Issue](https://github.com/jomjol/AI-on-the-edge-device/issues) and [Discussions](https://github.com/jomjol/AI-on-the-edge-device/discussions).
- [ ] Is there already another similar [discussion](https://github.com/jomjol/AI-on-the-edge-device/discussions) ongoing?
Please be aware that we might decline your request if we have a reason for it!
- type: textarea
validations:
required: true
attributes:
label: The Feature
description: A clear and concise description of what the new feature should do. If possible, refer to other projects or add a mockup.

19
.github/ISSUE_TEMPLATE/training.yaml vendored Normal file
View File

@@ -0,0 +1,19 @@
name: 📖 New Training Data
description: Use this form if you collected images and want to provide them for training the model
title: New Training Data
labels: new training data
assignees: jomjol
body:
- type: markdown
attributes:
value: |
Before you proceed, please check:
- [ ] Did you make sure we don't have similar data yet in the training data? (see [Digital Counters](https://jomjol.github.io/neural-network-digital-counter-readout/) resp. [Analog Needles](https://jomjol.github.io/neural-network-analog-needle-readout))
- [ ] Did you follow the guideline as documented in the [Wiki](https://github.com/jomjol/AI-on-the-edge-device/wiki/ROI-Configuration)? We will only be able to accept the files if they fulfill the rules!
- type: textarea
validations:
required: true
attributes:
label: Files
description: You can drag & drop your **zipped** images here

8
.github/ISSUE_TEMPLATE/x_plain.yaml vendored Normal file
View File

@@ -0,0 +1,8 @@
name: 🗒️ Blank Form
description: Use this form if none of the others fit. Please only use none of the others fit!
body:
- type: textarea
attributes:
label: Issue

333
.github/workflows/build.yaml vendored Normal file
View File

@@ -0,0 +1,333 @@
name: Build and Pack
on: [push, pull_request]
jobs:
#########################################################################################
## Build Firmware
#########################################################################################
build:
runs-on: ubuntu-latest
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@v5
with:
concurrent_skipping: same_content_newer
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Set Variables
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Cache PlatformIO
uses: actions/cache@v3
with:
path: ~/.platformio
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install --upgrade platformio
- name: Build Firmware
#run: echo "Testing... ${{ github.ref_name }}, ${{ steps.vars.outputs.sha_short }}" > ./sd-card/html/version.txt; mkdir -p ./code/.pio/build/esp32cam/; cd ./code/.pio/build/esp32cam/; echo "${{ steps.vars.outputs.sha_short }}" > firmware.bin; cp firmware.bin partitions.bin; cp firmware.bin bootloader.bin # Testing
run: cd code; platformio run --environment esp32cam
- name: Store generated files in cache
uses: actions/cache@v3
with:
path: |
./code/.pio/build/esp32cam/firmware.bin
./code/.pio/build/esp32cam/partitions.bin
./code/.pio/build/esp32cam/bootloader.bin
./sd-card/html/version.txt
key: ${{ github.run_number }}
#########################################################################################
## Pack for old OTA (v1)
#########################################################################################
pack-for-OTA-v1:
# Old OTA concept
# firmware__*.zip needs to be unpacked before attaching to the release!
# The bin filename can contain versioning.
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- name: Get generated files from cache
uses: actions/cache@v3
with:
path: |
./code/.pio/build/esp32cam/firmware.bin
./code/.pio/build/esp32cam/partitions.bin
./code/.pio/build/esp32cam/bootloader.bin
./sd-card/html/version.txt
key: ${{ github.run_number }}
- name: Set Variables
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "branch=$(echo ${{ github.ref_name }} | tr / __)" >> $GITHUB_OUTPUT
- name: Rename firmware file to contain versioning (old ota)
run: |
mkdir -p ./dist_old_ota
cp "./code/.pio/build/esp32cam/firmware.bin" "./dist_old_ota/firmware__${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }}).bin"
- name: Upload Firmware artifact (old OTA concept)
uses: actions/upload-artifact@v3
with:
# name: "firmware__${{ github.ref_name }}__(${{ steps.vars.outputs.sha_short }})__(extract_before_upload__only_needed_for_migration_from_11.3.1)"
name: "firmware__(extract_before_upload)__${{ steps.vars.outputs.branch }}__(${{ steps.vars.outputs.sha_short }})"
path: ./dist_old_ota/*
- name: Upload Web interface artifact (old OTA concept)
uses: actions/upload-artifact@v3
with:
name: "html__${{ steps.vars.outputs.branch }}__(${{ steps.vars.outputs.sha_short }})"
path: ./sd-card/html/*
#########################################################################################
## Pack for new OTA (v2)
#########################################################################################
pack-for-OTA-v2:
# New OTA concept
# update__version.zip file with following content:
# - /firmware.bin
# - (optional) /html/*
# - (optional) /config/*.tfl
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- name: Get generated files from cache
uses: actions/cache@v3
with:
path: |
./code/.pio/build/esp32cam/firmware.bin
./code/.pio/build/esp32cam/partitions.bin
./code/.pio/build/esp32cam/bootloader.bin
./sd-card/html/version.txt
key: ${{ github.run_number }}
- name: Set Variables
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "branch=$(echo ${{ github.ref_name }} | tr / __)" >> $GITHUB_OUTPUT
- name: Prepare update.zip artifact
run: |
mkdir -p ./dist
cp "./code/.pio/build/esp32cam/firmware.bin" "dist/firmware.bin"
# - name: Upload update.zip Artifact (Firmware only)
# uses: actions/upload-artifact@v3
# with:
# name: "update_firmware_only__${{ github.ref_name }}_(${{ steps.vars.outputs.sha_short }})"
# path: ./dist/*
- name: Add Web UI to dist
run: cp -r ./sd-card/html ./dist/
# - name: Upload update.zip artifact (Firmware + Web UI)
# uses: actions/upload-artifact@v3
# with:
# name: "update_firmware+webinterface__${{ github.ref_name }}_(${{ steps.vars.outputs.sha_short }})"
# path: ./dist/*
- name: Add CNN to dist
run: |
mkdir ./dist/config/
cp ./sd-card/config/*.tfl ./dist/config/ 2>/dev/null || true
cp ./sd-card/config/*.tflite ./dist/config/ 2>/dev/null || true
- name: Upload dist as update.zip artifact (Firmware + Web UI + CNN)
uses: actions/upload-artifact@v3
with:
name: "update__${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
path: ./dist/*
- name: Store generated files in cache
uses: actions/cache@v3
with:
path: dist
key: ${{ github.run_number }}-pack-for-OTA-v2
#########################################################################################
## Pack for a fresh install (USB flashing) (initial_esp32_setup)
#########################################################################################
pack-for-fresh-install:
# creates old style binaries for fresh installation (backward compatible to wiki)
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- name: Get generated files from cache
uses: actions/cache@v3
with:
path: |
./code/.pio/build/esp32cam/firmware.bin
./code/.pio/build/esp32cam/partitions.bin
./code/.pio/build/esp32cam/bootloader.bin
./sd-card/html/version.txt
key: ${{ github.run_number }}
- name: Set Variables
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "branch=$(echo ${{ github.ref_name }} | tr / __)" >> $GITHUB_OUTPUT
- name: Prepare artifacts for release
run: |
mkdir -p firmware
rm -rf firmware/*.zip
mkdir -p release
# copy builds to firmware folder
cp -f "./code/.pio/build/esp32cam/firmware.bin" "firmware/firmware.bin"
cp -f "./code/.pio/build/esp32cam/bootloader.bin" "firmware/bootloader.bin"
cp -f "./code/.pio/build/esp32cam/partitions.bin" "firmware/partitions.bin"
zip -r ./firmware/sd-card.zip sd-card
cd ./firmware
- name: Upload initial_esp32_setup.zip artifact (Firmware + Bootloader + Partitions + Web UI)
uses: actions/upload-artifact@v3
with:
name: "initial_esp32_setup__${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
path: ./firmware
- name: Store generated files in cache
uses: actions/cache@v3
with:
path: firmware
key: ${{ github.run_number }}-pack-for-fresh-install
#########################################################################################
## Prepare and create release
#########################################################################################
release:
runs-on: ubuntu-latest
needs: [pack-for-OTA-v2, pack-for-fresh-install]
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3
- name: Set Variables
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Get generated files from cache
uses: actions/cache@v3
with:
path: |
./code/.pio/build/esp32cam/firmware.bin
./code/.pio/build/esp32cam/partitions.bin
./code/.pio/build/esp32cam/bootloader.bin
./sd-card/html/version.txt
key: ${{ github.run_number }}
# import the changes from
- name: Get generated files from cache
uses: actions/cache@v3
with:
path: dist
key: ${{ github.run_number }}-pack-for-OTA-v2
# import cached artifacts from pack-for-fresh-install
- name: Get generated files from cache
uses: actions/cache@v3
with:
path: firmware
key: ${{ github.run_number }}-pack-for-fresh-install
- name: Prepare artifacts for release
run: |
mkdir -p release
mkdir -p dist
# create a update.zip like "update__rolling"
pwd
ls ./dist
cd ./dist
zip -r ../release/update.zip .
cd ../firmware
zip -r ../release/initial_esp32_setup.zip .
cd ../sd-card/html
zip -r ../../firmware/html-from-11.3.1.zip .
# extract the version used in next step
- id: get_version
if: startsWith(github.ref, 'refs/tags/')
uses: battila7/get-version-action@v2
# the changelog [unreleased] will now be changed to the release version
- name: Update changelog
uses: thomaseizinger/keep-a-changelog-new-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
changelogPath: Changelog.md
version: ${{ steps.get_version.outputs.version-without-v }}
# the release notes will be extracted from changelog
- name: Extract release notes
id: extract-release-notes
if: startsWith(github.ref, 'refs/tags/')
uses: ffurrer2/extract-release-notes@v1
with:
changelog_file: Changelog.md
# Releases should only be created on master by tagging the last commit.
# all artifacts in firmware folder pushed to the release
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
name: ${{ steps.get_version.outputs.version-without-v }}
body: ${{ steps.extract-release-notes.outputs.release_notes }}
files: |
release/*
firmware/firmware.bin
firmware/html-from-11.3.1.zip
# Commit&Push Changelog to master branch. Must be manually merged back to rolling
- name: Commit changes and push changes
if: startsWith(github.ref, 'refs/tags/')
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git add Changelog.md
git commit Changelog.md -m "Update Changelog.md for ${{github.event.inputs.versionIncrement}} release"
git push origin HEAD:master

13
.gitignore vendored
View File

@@ -2,17 +2,24 @@
.pio/
.vscode/
.code-workspace
.helper/
/sd-card/htm./.vscode/
/code/build
/code/.helper
/sd-card/html/debug/
/firmware/
version.txt
/dist/
/dist_release/
/dist_old_ota
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
code/edgeAI.code-workspace
.DS_Store

9
.gitmodules vendored Normal file
View File

@@ -0,0 +1,9 @@
[submodule "code/components/esp32-camera"]
path = code/components/esp32-camera
url = https://github.com/espressif/esp32-camera.git
[submodule "code/components/esp-nn"]
path = code/components/esp-nn
url = https://github.com/espressif/esp-nn.git
[submodule "code/components/tflite-micro-esp-examples"]
path = code/components/tflite-micro-esp-examples
url = https://github.com/espressif/tflite-micro-esp-examples.git

View File

@@ -1,6 +1,752 @@
# Versions
# Changelog
##### 0.1.0 (2020-08-07)
## [Unreleased]
* Initial Version
**Home Assistant MQTT Discovery Support**
### Update Procedure
:bangbang: **Make sure to read the instructions below carfully!**.
1. Backup your configuration (use the `System -> Backup/Restore` page)!
1. You should update to `12.0.1` before you update to this release. All other migrations are untested.
1. Upload and update the `update-*.zip` file from this release.
1. Let it restart and check on the `System -> Info` page that the Firmware as well as the Web UI got updated. If only one got updated, redo the update. If it fails several times, you also can update the Firmware and the Web UI separately.
1. Safe way:
1. Update first the `firmware.bin` (extract from zip file) and do the Reboot
1. Update with the full zip file (`update-*.zip`, ignore the version warning after the reboot)
1. Please go to `Settings -> Configuration` and address the changed parameters:
* DataLogging (storing the values for data graph)
* Debug (extended by different debug reporting levels)
If anything breaks you can try to enforce manual update as following:
**OTA:**
1. Make sure the last run of the update completed the **Uploading** step.
1. Call `http://<IP>/ota?task=update&file=<UPLOAD_FILENAME>` to enforce the extraction/flashing.
**Initial Setup:**
1. Use the initial_esp32_setup.zip ( <https://github.com/jomjol/AI-on-the-edge-device/wiki/Installation> ) as alternative to have a clean install.
### Added
- Implementation of [Home Assistant MQTT Discovery](https://www.home-assistant.io/integrations/mqtt/#mqtt-discovery)
- Improved ROIs configuration: locked ROI geometry, equidistant delta x
- Improved OTA Update mechanism (only working after installation for next update)
- Added data logging in `/log/data` - One day per file and each measurement is on one line
- Format: csv - comma separated
- Content: `time`, `name-of-number`, `raw-value`, `return-value`, `pre-value`, `change-rate`, `change-absolute`, `error-text`, `cnn-digital`, `cnn-analog`
- Show graph of values direct in the user interface (thanks to [@rdmueller](https://github.com/rdmueller))
- Using new data logging (see above)
- Possibility to choose different values and switch between different numbers (if present)
Note: You need to activate data logging for this feature to work, see above!
- PreValue is now contained in `/json` ([#1154](https://github.com/jomjol/AI-on-the-edge-device/issues/1154))
- SD card info into the `System>Info` menu (thanks to [@Slider007]( https://github.com/Slider0007))
- Version check (Firmware vs. Web UI)
- Various minor new features
### Changed
- Updated tflite (`dig-cont_0600_s3.tflite`)
- Updated OTA functionality (more robust, but not fully bullet prove yet)
- Updated Espressif library to `espressif32@v5.2.0`
- [#1176](https://github.com/jomjol/AI-on-the-edge-device/discussions/1176) accept minor negative values (-0.2) if extended resolution is enabled
- [#1143](https://github.com/jomjol/AI-on-the-edge-device/issues/1143) added config parameter `AnalogDigitalTransitionStart`. It can setup very early and very late digit transition starts.
- New version of `dig-class100` (v1.4.0): added images of heliowatt powermeter
### Fixed
- [#1116](https://github.com/jomjol/AI-on-the-edge-device/issues/1116) precision problem at setting prevalue
- [#1119](https://github.com/jomjol/AI-on-the-edge-device/issues/1119) renamed `firmware.bin` not working in OTA
- [#1143](https://github.com/jomjol/AI-on-the-edge-device/issues/1143) changed postprocess for `analog->digit` (lowest digit processing)
- [#1280](https://github.com/jomjol/AI-on-the-edge-device/issues/1280) check ROIs name for unsupported characters
- [#983](https://github.com/jomjol/AI-on-the-edge-device/issues/983) old log files did not get deleted
- Failed NTP time sync during startup gets now retried every round if needed
- Whitespaces and `=` in MQTT and InfluxDB passwords
- Various minor fixes and improvements
### Removed
- n.a.
## [12.0.1] 2022-09-29
Improve **u**ser e**x**perience
:bangbang: The release breaks a few things in ota update :bangbang:
**Make sure to read the instructions below carfully!**.
1. Backup your configuration (use the `System > Backup/Restore` page)!
2. You should update to `11.3.1` before you update to this release. All other migrations are not tested.
Rolling newer than `11.3.1` can also be used, but no guaranty.
3. Upload and update the `firmware.bin` file from this release. **but do not reboot**
4. Upload the `html-from-11.3.1.zip` in html upload and update the web interface.
5. Now you can reboot.
If anything breaks you can try to
1. Call `http://<IP>/ota?task=update&file=firmware.bin` resp. `http://<IP>/ota?task=update&file=html.zip` if the upload successed but the extraction failed.
1. Use the initial_esp32_setup.zip ( <https://github.com/jomjol/AI-on-the-edge-device/wiki/Installation> ) as alternative.
### Added
- Automatic release creation
- Newest firmware of rolling branch now automatically build and provided in [Github Actions Output](https://github.com/jomjol/AI-on-the-edge-device/actions) (developers only)
- [#1068](https://github.com/jomjol/AI-on-the-edge-device/issues/1068) New update mechanism:
- Handling of all files (`zip`, `tfl`, `tflite`, `bin`) within in one common update interface
- Using the `update.zip` from the [Release page](https://github.com/jomjol/AI-on-the-edge-device/releases)
- Status (`upload`, `processing`, ...) displayed on Web Interface
- Automatical detection and suggestion for reboot where needed (Web Interface uupdates only need a page refresh)
- :bangbang: Best for OTA use Firefox. Chrome works with warnings. Safari stuck in upload.
### Changed
- Integrated version info better shown on the Info page and in the log
- Updated menu
- Update used libraries (`tflite`, `esp32-cam`, `esp-nn`, as of 20220924)
### Fixed
- [#1092](https://github.com/jomjol/AI-on-the-edge-device/issues/1092) censor passwords in log outputs
- [#1029](https://github.com/jomjol/AI-on-the-edge-device/issues/1029) wrong change of `checkDigitConsistency` now working like releases before `11.3.1`
- Spelling corrections (**[cristianmitran](https://github.com/cristianmitran)**)
### Removed
- Remove the folder `/firmware` from GitHub repository.
If you want to get the latest `firmware.bin` and `html.zip` files, please download from the automated [build action](https://github.com/jomjol/AI-on-the-edge-device/actions) or [release page](https://github.com/jomjol/AI-on-the-edge-device/releases)
## [11.3.1](https://github.com/jomjol/AI-on-the-edge-device/releases/tag/v11.3.1), 2022-09-17
Intermediate Digits
- **ATTENTION**:
- first update the `firmware.bin` and ensure that the new version is running
- Only afterwards update the `html.zip`
- Otherwise the downwards compatibility of the new counter clockwise feature is not given and you end in a reboot loop, that needs manual flashing!
- **NEW v11.3.1**: corrected corrupted asset `firmware.bin`
- Increased precision (more than 6-7 digits)
- Implements Counter Clockwise Analog Pointers
- Improved post processing algorithm
- Debugging: intensive use of testcases
- MQTT: improved handling, extended logging, automated reconnect
- HTML: Backup Option for Configuration
- HTML: Improved Reboot
- HTML: Update WebUI (Reboot, Infos, CPU Temp, RSSI)
- This version is largely also based on the work of **[caco3](https://github.com/caco3)**, **[adellafave](https://github.com/adellafave)**, **[haverland](https://github.com/haverland)**, **[stefanbode](https://github.com/stefanbode)**, **[PLCHome](https://github.com/PLCHome)**
## [11.2.0](https://github.com/jomjol/AI-on-the-edge-device/releases/tag/v11.2.0), 2022-08-28
Intermediate Digits
- Updated Tensorflow / TFlite to newest tflite (version as of 2022-07-27)
- Updated analog neural network file (`ana-cont_11.3.0_s2.tflite` - default, `ana-class100_0120_s1_q.tflite`)
- Updated digital neural network file (`dig-cont_0570_s3.tflite` - default, `dig-class100_0120_s2_q.tflite`)
- Added automated filtering of tflite-file in the graphical configuration (thanks to @**[caco3](https://github.com/caco3)**)
- Updated consistency algorithm & test cases
- HTML: added favicon and system name, Improved reboot dialog (thanks to @**[caco3](https://github.com/caco3)**)
## [11.1.1](https://github.com/jomjol/AI-on-the-edge-device/releases/tag/v11.1.1), 2022-08-22
Intermediate Digits
- New and improved consistency check (especially with analog and digital counters mixed)
- Bug Fix: digital counter algorithm
## [11.0.1](https://github.com/jomjol/AI-on-the-edge-device/releases/tag/v11.0.1), 2022-08-18
Intermediate Digits
- **NEW v11.0.1**: Bug Fix InfluxDB configuration (only update of html.zip necessary)
- Implementation of new CNN types to detect intermediate values of digits with rolling numbers
- By default the old algo (0, 1, ..., 9, "N") is active (due to the limited types of digits trained so far)
- Activation can be done by selection a tflite file with the new trained model in the 'config.ini'
- **Details can be found in the [wiki](https://github.com/jomjol/AI-on-the-edge-device/wiki/Neural-Network-Types)** (different types, trained image types, naming convention)
- Updated neural network files (and adaption to new naming convention)
- Published a tool to download and combine log files - **Thanks to **
- Files see ['/tools/logfile-tool'](tbd), How-to see [wiki](https://github.com/jomjol/AI-on-the-edge-device/wiki/Gasmeter-Log-Downloader)
- Bug Fix: InfluxDB enabling in grahic configuration
## [10.6.2](https://github.com/jomjol/AI-on-the-edge-device/releases/tag/v10.6.2), 2022-07-24
Stability Increase
### Added
- **NEW 10.6.2**: ignore hidden files in model selection (configuration page)
- **NEW 10.6.1**: Revoke esp32cam & tflite update
- **NEW 10.6.1**: Bug Fix: tflite-filename with ".", HTML spelling error
- IndluxDB: direct injection into InfluxDB - thanks to **[wetneb](https://github.com/wetneb)**
- MQTT: implemented "Retain Flag" and extend with absolute Change (in addition to rate)
- `config.ini`: removal of modelsize (readout from tflite)
- Updated analog neural network file (`ana1000s2.tflite`) & digital neural network file (`dig1400s2q.tflite`)
- TFMicro/Lite: Update (espressif Version 20220716)
- Updated esp32cam (v20220716)
- ESP-IDF: Update to 4.4
- Internal update (CNN algorithm optimizations, reparation for new neural network type)
- Bug Fix: no time with fixed IP, Postprocessing, MQTT
## [10.5.2](https://github.com/jomjol/AI-on-the-edge-device/releases/tag/v10.5.2), 2022-02-22
Stability Increase
### Changed
- NEW 10.5.2: Bug Fix: wrong `firmware.bin` (no rate update)
- NEW 10.5.1: Bug Fix: wrong return value, rate value & PreValue status, HTML: SSID & IP were not displayed
- MQTT: changed wifi naming to "wifiRSSI"
- HTML: check selectable values for consistency
- Refactoring of check postprocessing consistency (e.g. max rate, negative rate, ...)
- Bug Fix: corrected error in "Check Consistency Increase"
## [10.4.0](https://github.com/jomjol/AI-on-the-edge-device/releases/tag/v10.4.0), 2022-02-12
Stability Increase
### Changed
- Graphical configuration: select available neural network files (_.tfl,_.tflite) from drop down menu
- OTA-update: add option to upload tfl / tflite files to the correct location (`/config/`)
- In the future the new files will also be copied to the `firmware` directory of the repository
- Added Wifi RSSI to MQTT information
- Updated analog neural network file (`ana-s3-q-20220105.tflite`)
- Updated digital neural network file (`dig-s1-q-20220102.tflite`)
- Updated build environment to `Espressif 3.5.0`
## [10.3.0] - (2022-01-29)
Stability Increase
### Changed
- Implemented LED flash dimming (`LEDIntensity`).
Remark: as auto illumination in the camera is used, this is rather for energy saving. It will not help reducing reflections
- Additional camera parameters: saturation, contrast (although not too much impact yet)
- Some readings will have removable "N"s that can not be removed automatically and are handled with an "error" --> no return value in the field "value" anymore (still reported back via field "raw value")
- Updated esp32 camera hardware driver
- Bug fix: MQTT, HTML improvements
**ATTENTION: The new ESP32 camera hardware driver is much more stable on newer OV2640 versions (no or much less reboots) but seems to be not fully compatible with older versions.**
If you have problem with stalled systems you can try the following
- Update the parameter `ImageQuality` to `12` instead of current value `5` (manually in the `config.ini`)
- If this is not helping, you might need to update your hardware or stay with version 9.2
## [10.2.0] - (2022-01-14)
Stability Increase
### Changed
- Due to the updated camera driver, the image looks different and a new setup might be needed
- Update reference image
- Update Alignment marks
- Reduce reboot due to camera problems
- Update esp32-camera to new version (master as of 2022-01-09)
## [10.1.1] - (2022-01-12)
Stability Increase
### Changed
- Bug Fix MQTT problem
- Issue:
- Changing from v9.x to 10.x the MQTT-parameter "Topic" was renamed into "MainTopic" to address multiple number meters. This renaming should have been done automatically in the background within the graphical configuration, but was not working. Instead the parameter "Topic" was deleted and "MainTopic" was set to disabled and "undefined".
- ToDo
- Update the `html.zip`
- If old `config.ini` available: copy it to `/config`, open the graphical configuration and save it again.
- If old `config.ini` not available: reset the parameter "MainTopic" within the `config.ini` manually
- Reboot
## [10.1.0] - (2022-01-09)
Stability Increase
### Changed
- Reduce ESP32 frequency to 160MHz
- Update tflite (new source: <https://github.com/espressif/tflite-micro-esp-examples>)
- Update analog neural network (ana-s3-q-20220105.tflite)
- Update digital neural network (dig-s1-q-20220102.tflite)
- Increased web-server buffers
- bug fix: compiler compatibility
## [10.0.2] - (2022-01-01)
Stability Increase
### Changed
- NEW v10.0.2: Corrected JSON error
- Updated compiler toolchain to ESP-IDF 4.3
- Removal of memory leak
- Improved error handling during startup (check PSRAM and camera with remark in logfile)
- MQTT: implemented raw value additionally, removal of regex contrain
- Normalized Parameter `MaxRateValue` to "change per minute"
- HTML: improved input handling
- Corrected error handling: in case of error the old value, rate, timestamp are not transmitted any more
## [9.2.0] - (2021-12-02)
External Illumination
### Changed
- Direct JSON access: `http://IP-ADRESS/json`
- Error message in log file in case camera error during startup
- Upgrade analog CNN to v9.1.0
- Upgrade digital CNN to v13.3.0 (added new images)
- html: support of different ports
## [9.1.1] - External Illumination (2021-11-16)
### Changed
- NEW 9.1.1 bug fix: LED implemenetation
- External LEDs: change control mode (resolve bug with more than 2 LEDs)
- Additional info into log file
- Bug fix: decimal shift, html, log file
## [9.0.0] - External Illumination (2021-10-23)
### Changed
- Implementation of external illumination to adjust positioning, brightness and color of the illumination now set individually
- Technical details can be found in the wiki: <https://github.com/jomjol/AI-on-the-edge-device/wiki/External-LED>
<img src="https://raw.githubusercontent.com/jomjol/ai-on-the-edge-device/master/images/intern_vs_external.jpg" width="500">
- New housing published for external LEDs and small clearing: <https://www.thingiverse.com/thing:5028229>
## [8.5.0] - Multi Meter Support (2021-10-07)
### Changed
- Upgrade digital CNN to v13.1.0 (added new images)
- bug fix: wlan password with space, double digit output
## [8.4.0] - Multi Meter Support (2021-09-25)
### Changed
- License change (remove MIT license, remark see below)
- html: show hostname in title and main page
- configuration:
- moved setting `ExtendedResolution` to individual number settings
- New parameter `IgnoreLeadingNaN` (delete leading NaN's specifically)
- **ATTENTION**: update of the `config.ini` needed (open, adjust `ExtendedResolution`, save)
- Bug fixing (html, images of recognized numbers)
**ATTENTION: LICENSE CHANGE - removal of MIT License.**
- Currently no licence published - copyright belongs to author
- If you are interested in a commercial usage or dedicated versions please contact the developer
- no limits to private usage
## [8.3.0] - Multi Meter Support (2021-09-12)
### Changed
- Upgrade digital CNN to v12.1.0 (added new images)
- Dedicated NaN handling, internal refactoring (CNN-Handling)
- HTML: confirmation after config.ini update
- Bug fixing
## [8.2.0] - Multi Meter Support (2021-08-24)
### Changed
- Improve server responsiveness
- Flow status and prevalue status in overview
- Improved prevalue handling
## [8.1.0] - Multi Meter Support (2021-08-12)
### Changed
- GPIO: using the general mqtt main topic for GPIO
- Upgrade digital CNN to v12.0.0 (added new images)
- Update tfmicro to new master (2021-08-07)
- Bug fix: remove text in mqtt value, remove connect limit in wlan reconnet
## [8.0.5] - Multi Meter Support (2021-08-01)
### Changed
- NEW 8.0.5: bug fix: saving prevalue
- NEW 8.0.4: bug fix: load config.ini after upgrade
- NEW 8.0.3: bug fix: reboot during `config.ini` handling, html error
- NEW 8.0.2: saving roundes prevalue, bug fix html server
- NEW 8.0.1: bug fix: html handling of parameter `FixedExposure` and `ImageSize`
- Dual / multi meter support (more than 1 number to be recognized)
This is implemented with the feature "number" on the ROI definition as well as selected options
- MQTT: standardization of the naming - including new topics (`json`, `freeMem`, `uptime`)c
- Preparation for extended GPIO support (thanks to Zwerk2k) - not tested and fully functional yet
- Bug fixing: html server, memory leak, MQTT connect, hostname, turn of flash LED
<span style="color: red;">**ATTENTION: the configuration and prevalue files are modified automatically and will not be backward compatible!**</span>
## [7.1.2] MQTT-Update - (2021-06-17)
### Changed
- NEW: 7.1.2: bug fix setting hostname, Flash-LED not off during reboot
- NEW: 7.1.1: bug fix wlan password with "=" (again)
- MQTT error message: changes "no error", send retain flag
- Update wlan handling to esp-idf 4.1
- Upgrade digital CNN to v8.7.0 (added new images)
- Bug fix: MQTT, WLAN, LED-Controll, GPIO usage, fixed IP, calculation flow rate
## [7.0.1] MQTT-Update - (2021-05-13)
### Changed
- NEW: 7.0.1: bug fix wlan password with "="
- Upgrade digital CNN to v8.5.0 (added new images)
- New MQTT topics: flow rate (units/minute), time stamp (last correct read readout)
- Update MQTT/Error topic to " " in case no error (instead of empty string)
- Portrait or landscape image orientation in rotated image (avoid cropping)
## [6.7.2] Image Processing in Memory - (2021-05-01)
### Changed
- NEW 6.7.2: Updated html for setup modus - remove reboot on edit configuration)
- NEW 6.7.1: Improved stability of camera (back to v6.6.1) - remove black strips and areas
- Upgrade digital CNN to v8.3.0 (added new type of digits)
- Internal update: TFlite (v2.5), esp32cam, startup sequence
- Rollback to espressif v2.1.0, as v3.2.0 shows unstable reboot
- Bugfix: WLan-passwords, reset of hostname
## [6.6.1] Image Processing in Memory - (2021-04-05)
### Changed
- NEW 6.6.1: failed SD card initialization indicated by fast blinking LED at startup
- Improved SD-card handling (increase compatibility with more type of cards)
## [6.5.0] Image Processing in Memory - (2021-03-25)
### Changed
- Upgrade digital CNN to v8.2.0 (added new type of digits)
- Supporting alignment structures in ROI definition
- Bug fixing: definition of hostname in `config.ini`
## [6.4.0] Image Processing in Memory - (2021-03-20)
### Changed
- Additional alignment marks for settings the ROIs (analog and digit)
- Upgrade analog CNN to v7.0.0 (added new type of pointer)
## [6.3.1] Image Processing in Memory - (2021-03-16)
### Changed
- NEW: 6.3.1: bug fixing in initial edit reference image and `config.ini` (Spelling error in `InitialRotate`)
- Initial setup mode: bug fixing, error correction
- Bug-fixing
## [6.2.2] Image Processing in Memory - (2021-03-10)
### Changed
- NEW 6.2.2: bug fixing
- NEW 6.2.1: Changed brightness and contrast to default if not enabled (resolves to bright images)
- Determination of fixed illumination settings during startup - speed up of 5s in each run
- Update digital CNN to v8.1.1 (additional digital images trained)
- Extended error message in MQTT error message
- Image brightness is now adjustable
- Bug fixing: minor topics
## [6.1.0] Image Processing in Memory - (2021-01-20)
### Changed
- Disabling of analog / digital counters in configuration
- Improved Alignment Algorithm (`AlignmentAlgo` = `Default`, `Accurate` , `Fast`)
- Analog counters: `ExtendedResolution` (last digit is extended by sub comma value of CNN)
- `config.ini`: additional parameter `hostname` (additional to wlan.ini)
- Switching of GPIO12/13 via http-interface: `/GPIO?GPIO=12&Status=high/low`
- Bug fixing: html configuration page, wlan password ("=" now possible)
## [6.0.0] Image Processing in Memory - (2021-01-02)
### Changed
- **Major change**: image processing fully in memory - no need of SD card buffer anymore
- Need to limit camera resolution to VGA (due to memory limits)
- MQTT: Last Will Testament (LWT) implemented: "connection lost" in case of connection lost to `TopicError`
- Disabled `CheckDigitIncreaseConsistency` in default configuration - must now be explicit enabled if needed
- Update digital CNN to v7.2.1 (additional digital images trained)
- Setting of arbitrary time server in `config.ini`
- Option for fixed IP-, DNS-Settings in `wlan.ini`
- Increased stability (internal image and camera handling)
- Bug fixing: edit digits, handling PreValue, html-bugs
## [5.0.0] Setup Modus - (2020-12-06)
### Changed
- Implementation of initial setup modus for fresh installation
- Code restructuring (full compatibility between pure ESP-IDF and Platformio w/ espressif)
## [4.1.1] Configuration editor - (2020-12-02)
### Changed
- Bug fixing: internal improvement of file handling (reduce not responding)
## [4.1.0] Configuration editor - (2020-11-30)
### Changed
- Implementation of configuration editor (including basic and expert mode)
- Adjustable time zone to adjust to local time setting (incl. daylight saving time)
- MQTT: additional topic for error reporting
- standardized access to current logfile via `http://IP-ADRESS/logfileact`
- Update digital CNN to v7.2.0, analog CNN to 6.3.0
- Bug fixing: truncation error, CheckDigitConsistency & PreValue implementation
## [4.0.0] Tflite Core - (2020-11-15)
### Changed
- Implementation of rolling log-files
- Update Tflite-Core to master@20201108 (v2.4)
- Bug-fixing for reducing reboots
## [3.1.0] MQTT-Client - (2020-10-26)
### Changed
- Update digital CNN to v6.5.0 and HTML (Info to hostname, IP, ssid)
- New implementation of "checkDigitConsistency" also for digits
- MQTT-Adapter: user and password for sign in MQTT-Broker
## [3.0.0] MQTT-Client (2020-10-14)
### Changed
- Implementation of MQTT Client
- Improved Version Control
- bug-fixing
## [2.2.1] Version Control (2020-09-27)
### Changed
- Bug-Fixing (hostname in wlan.ini and error handling inside flow)
## \[2.2.0| Version Control (2020-09-27)
### Changed
- Integrated automated versioning system (menu: SYSTEM --> INFO)
- Update Build-System to PlatformIO - Espressif 32 v2.0.0 (ESP-IDF 4.1)
## [2.1.0] Decimal Shift, Chrome & Edge (2020-09-25)
### Changed
- Implementation of Decimal Shift
- Update default CNN for digits to v6.4.0
- Improvement HTML
- Support for Chrome and Edge
- Reduce logging to minimum - extended logging on demand
- Implementation of hostname in wlan.ini (`hostname = "HOSTNAME")`
- Bug fixing, code corrections
## [2.0.0] Layout update (2020-09-12)
### Changed
- Update to **new and modern layout**
- Support for Chrome improved
- Improved robustness: improved error handling in auto flow reduces spontaneous reboots
- File server: Option for "DELETE ALL"
- WLan: support of spaces in SSID and password
- Reference Image: Option for mirror image, option for image update on the fly
- additional parameter in `wasserzaehler.html?noerror=true` to suppress an potential error message
- bug fixing
## [1.1.3](2020-09-09)
### Changed
- **Bug in configuration of analog ROIs corrected** - correction in v.1.0.2 did not work properly
- Improved update page for the web server (`/html` can be updated via a zip-file, which is provided in `/firmware/html.zip`)
- Improved Chrome support
## [1.1.0](2020-09-06)
### Changed
- Implementation of "delete complete directory"
**Attention: beside the `firmware.bin`, also the content of `/html` needs to be updated!**
## [1.0.2](2020-09-06)
### Changed
- Bug in configuration of analog ROIs corrected
- minor bug correction
## [1.0.1](2020-09-05)
### Changed
- preValue.ini Bug corrected
- minor bug correction
## [1.0.0](2020-09-04)
### Changed
- **First usable version** - compatible to previous project (<https://github.com/jomjol/water-meter-system-complete>)
- NEW:
- no docker container for CNN calculation necessary
- web based configuration editor on board
## [0.1.0](2020-08-07)
### Changed
- Initial Version
[Unreleased]: https://github.com/jomjol/AI-on-the-edge-device/compare/12.0.1...HEAD
[12.0.1]: https://github.com/jomjol/AI-on-the-edge-device/compare/11.3.1...12.0.1
[11.4.3]: https://github.com/haverland/AI-on-the-edge-device/compare/10.6.2...11.4.3
[11.4.2]: https://github.com/haverland/AI-on-the-edge-device/compare/10.6.2...11.4.2
[11.3.9]: https://github.com/haverland/AI-on-the-edge-device/compare/10.6.2...11.3.9

272
FeatureRequest.md Normal file
View File

@@ -0,0 +1,272 @@
## Feature Requests
**There are a lot of ideas for further improvements, but only limited capacity on side of the developer.** Therefore I have created this page as a collection of ideas.
1. Who ever has a new idea can put it here, so it that it is not forgotten.
2. Who ever has time, capacity and passion to support, can take any of the ideas and implement them.
I will support and help where ever I can!
____
#### #33 Implement MATTER protocoll
* see [#1404](https://github.com/jomjol/AI-on-the-edge-device/issues/1404)
#### #32 Add feature to correct misinterpreted value
* If a value is misinterpreted, the user can manually correct the value.
* The misinterpreted ROIs would be saved in a "training data" -folder on the SD-card
* Stretch goal: make sending of saved training data as easy as pushing a button =)
#### #31 Implement InfluxDB v2.x interface
* Currently only InfluxDB v1.x is supportet, extend to v2.x
* Remark: interface has changed
* see [#1160](https://github.com/jomjol/AI-on-the-edge-device/issues/1160)
#### #30 Support meter clock over
* In case of meter clocking over, that is, reaching its max. value and starting over from 0,
accept the new value and calculate correctly the difference.
(see line 739 onwards in ClassFlowPostProcessing.cpp)
#### ~~#29 Add favicon and use the hostname for the website~~- implemented v11.3.1
~~* https://github.com/jomjol/AI-on-the-edge-device/issues/927~~
#### #28 Improved error handling for ROIs
* In case a ROI is out of the image, there is no error message, but a non sense image is used
* Implement a error message for wrong configuratioin of ROI
#### #27 Use Homie Spec for Mqtt binding
* Use the standardized Home Protocol for the Mqtt binding
* https://homieiot.github.io/
#### #26 Changes behaviour for "N" replacement
* in case the higher digits has already increased by minium 1 - don't set the "N" to the last value, but to "0"
* https://github.com/jomjol/AI-on-the-edge-device/issues/792
#### #25 Trigger Measurement via MQTT
* https://github.com/jomjol/AI-on-the-edge-device/issues/727
#### #24 Show Mqtt state directly in Webserver
* Show MQTT log in Web page. E.g. connection established or failed to connect...
#### #23 CPU Temp and Mqtt values
* Show the CPU Temp directly in Webpage. Also add the value to MQTT sending
#### ~~#22 Direct hint to the different neural network files in the other repositories~~- implemented >v11.3.1
~~* https://github.com/jomjol/AI-on-the-edge-device/issues/644~~
#### #21 Extended "CheckDigitalConsistency" Logik
* https://github.com/jomjol/AI-on-the-edge-device/issues/590
#### #20 Deep sleep and push mode
* Let the device be normally in deep sleep state, and wake it up periodically to collect data and push it via MQTT or HTTP post.
* Support ESP-NOW to reduce the overhead of connecting to wifi and mqtt
* the above should enable battery powered applications
* An other way to set deep sleep would be to enable it in a specific period (at night).
#### #19 Extended log informations
* https://github.com/jomjol/AI-on-the-edge-device/issues/580
#### ~~#18 Document WLAN-strength in web page~~
* ~~https://github.com/jomjol/AI-on-the-edge-device/issues/563~~
#### ~~#17 Direct InfluxDB connection~~
* ~~Done in v10.6.0~~
#### #16 Serial Communication
* https://github.com/jomjol/AI-on-the-edge-device/issues/512
* Send the readout value via RX/TX interface with a dedicated TAG
* Make dedicated communication FlowModule
* Modification of RX/TX communication
* Configuration interfache
#### #15 Calibration for FishEye image
* https://github.com/jomjol/AI-on-the-edge-device/issues/507
1. The development of such a correction algorithm with the libraries, that are available for the ESP32 environment.
2. New module for integration of the flow into the image processing flow.
3. Extension of the configuration (config.ini) and html-pages
4. Parameter adjustment and testing for every different fish-eye module
5. Maintenance for further updates / modules, ...
#### ~~#14 Backup and restore option for configuration~~- implemented v11.3.1
* ~~https://github.com/jomjol/AI-on-the-edge-device/issues/459~~
* ~~Implement a zip file compression for store and restore~~
* ~~Update the html to handle it~~
#### #13 Manage non linear gauge without CNN re-training
* https://github.com/jomjol/AI-on-the-edge-device/issues/443
* Implement a look up table for non linear analog meters
#### ~~#12 Less reboots due to memory leakage~~
* ~~Issue: #414 & #425 #430~~
#### #11 MQTT - configurable payload
* https://github.com/jomjol/AI-on-the-edge-device/issues/344
#### #10 Improve and bug fix logging of images
* https://github.com/jomjol/AI-on-the-edge-device/issues/307
#### #9 Basic auth for the UI
* https://github.com/jomjol/AI-on-the-edge-device/issues/283
* Implementation of an authentication mechanism.
#### #8 MQTT configurable readout intervall
Make the readout intervall configurable via MQTT.
* Change the mqtt part to receive and process input and not only sending
#### #7 Extended Error Handling
Check different types of error (e.g. tflite not availabe) and generate an error on the html page.
To do:
* Make a list of "important" errors
* Implement a checking algo
* Extend the firmware and html page for the error handling
#### ~~#6 Check for double ROI names~~ - implemented v8.0.0
~~Check during configuration, that ROI names are unique.~~
~~To do:~~
* ~~Implementation of ROI name checking in html code before saving analog or digital ROIs~~
#### #5 Configurable decimal separator (point or comma)
Decimal separator configurable for different systems
To do:
* Implementation of decimal point into postprocessing module
* Extension of configuration
* Adaption of the html configuration to implement shifting
#### ~~#4 Initial Shifting and Rotation~~ - implemented v7.0.0
* ~~https://github.com/jomjol/AI-on-the-edge-device/issues/123~~
~~Implementation of a shifting additional to the initial rotation of the raw camera input~~
~~To do:~~
* ~~Implementation of shifting~~
* ~~Extension of configuration~~
* ~~Adaption of the html configuration to implement shifting~~
#### ~~#3 Allow grouping of digits to multiple reading values~~ - implemented v8.0.0
* ~~https://github.com/jomjol/AI-on-the-edge-device/issues/123~~
~~Implementation of two different independent readouts in one setup~~
~~To do:~~
* ~~Extend the configuration, setting and processing flow for two independend readouts~~
____
#### #2 MQTT-controll with callback
* https://github.com/jomjol/AI-on-the-edge-device/issues/105
Extend the MQTT client to also enable callbacks for configuration setting
To do:
* implement callback for receiving information and override `config.ini` settings
* change configuration management to handle online updates (currently changes need a restart)
* think about the startup, as there the default config is loaded
____
#### ~~#1 Optional GPIO for external flash/lighting~~ - implemented (v8.0.0)
* ~~https://github.com/jomjol/AI-on-the-edge-device/issues/133~~
~~Implementation of an an extrnal flash / lightning through GPIOs.~~
* ~~available GPIOs: 12 & 13 (currently in use for html switching)~~
~~To do:~~
* ~~Implementation of a software module for external light source (e.g. WS8132 LED controller, ...)~~
* ~~Update of the camera module to use the external light instead of the internal flash light~~
* ~~Adopt the configuration algorithm with a configurable light source~~

162
README.md
View File

@@ -1,92 +1,96 @@
# AI-on-the-edge-device
# Welcome to the AI-on-the-edge-device
<img src="images/icon/watermeter.svg" width="100px">
This is an example of Artificial Intelligence (AI) calculations on a very cheap hardware.
Artificial intelligence based systems have been established in our every days live. Just think of speech or image recognition. Most of the systems relay on either powerful processors or a direct connection to the cloud for doing the calculations up there. With the increasing power of modern processors the AI systems are coming closer to the end user - which is usually called **edge computing**.
Here this edge computing is brought into a practical oriented example, where a AI network is implemented on a ESP32 device so: **AI on the edge**.
### Details on **function**, **installation** and **configuration** can be found on the **[Wiki Page](https://github.com/jomjol/AI-on-the-edge-device/wiki)**
This projects allows you to digitalize your **analoge** water, gas, power and other meters using cheap and easily available hardware.
A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571627
All you need is an [ESP32 board with a supported camera](https://github.com/jomjol/AI-on-the-edge-device/wiki/Hardware-Compatibility) and a bit of a practical hand.
<img src="images/esp32-cam.png" width="200px">
## Key features
- **Small** and **cheap** device (3x4.5x2 cm³, < 10 EUR)
- camera and illumination integrated
- Web surface for administration and control
- OTA-Interface to update directly through the web interface
- API for easy integration
- Inline Image processing (feature detection, alignment, ROI extraction)
- Tensorflow Lite (TFlite) integration - including easy to use wrapper
## Workflow
The device takes a photo of your meter at a defined interval. It then extracts the Regions of Interest (ROI's) out of it and runs them through an artificial inteligence. As a result, you get the digitalized value of your meter.
There are several options what to do with that value. Either send it to a MQTT broker, write it to an InfluxDb or simply provide it throug a REST API.
<img src="https://raw.githubusercontent.com/jomjol/AI-on-the-edge-device/master/images/idea.jpg" width="600">
## Impressions
### AI-on-the-edge-device on a Water Meter
<img src="https://raw.githubusercontent.com/jomjol/AI-on-the-edge-device/master/images/watermeter_all.jpg" width="200"><img src="https://raw.githubusercontent.com/jomjol/AI-on-the-edge-device/master/images/main.jpg" width="200"><img src="https://raw.githubusercontent.com/jomjol/AI-on-the-edge-device/master/images/size.png" width="200">
### Web Interface (Water Meter)
<img src="https://raw.githubusercontent.com/jomjol/AI-on-the-edge-device/master/images/watermeter.jpg" width="600">
<img src="https://raw.githubusercontent.com/jomjol/AI-on-the-edge-device/master/images/edit_reference.jpg" width="600">
### AI-on-the-edge-device on a Electrical Power Meter
<img src="https://raw.githubusercontent.com/jomjol/AI-on-the-edge-device/master/images/powermeter.jpg" width="600">
## Setup
There is a growing [wiki](https://github.com/jomjol/AI-on-the-edge-device/wiki) which provides you with a lot of information.
Head there to get a start, set it up and configure it.
## Change log
There are also a articles in the German Heise magazine "make:" about the setup and the technical background (behind a paywall) : [DIY - Setup](https://www.heise.de/select/make/2021/2/2103513300897420296)
For further background information, head to [Neural Networks](https://www.heise.de/select/make/2021/6/2126410443385102621), [Training Neural Networks](https://www.heise.de/select/make/2022/1/2134114065999161585) and [Programming on the ESP32](https://www.heise.de/select/make/2022/2/2204010051597422030)
### Download
The latest available version is available on the [Releases page](https://github.com/jomjol/AI-on-the-edge-device/releases).
### Flashing of the ESP32
Initially you will have to flash the ESP32 through an USB connection. Later an update is possible directly over the Air (OTA).
There are different ways to flash your ESP32:
- [Web Installer and Console](https://jomjol.github.io/AI-on-the-edge-device/index.html) (Webbrowser based tool to flash the ESP32 and extract the Log over USB)
- Flash Tool from Espressif
- ESPtool (Command Line Tool)
See the [Wiki](https://github.com/jomjol/AI-on-the-edge-device/wiki/Installation) for more information.
## Casing
A 3d-printable housing can be found here:
- https://www.thingiverse.com/thing:4573481 (Water Meter)
- https://www.thingiverse.com/thing:5028229 (Power Meter)
- https://www.thingiverse.com/thing:5224101 (Gas Meter)
- https://www.thingiverse.com/thing:4571627 (ESP32-Cam housing only)
## Build it yourself
See [Build Instructions](code/README.md).
## Donate
If you would like to support the developer with a cup of coffee you can do that via [Paypal](https://www.paypal.com/donate?hosted_button_id=8TRSVYNYKDSWL).
<form action="https://www.paypal.com/donate" method="post" target="_top">
<input type="hidden" name="hosted_button_id" value="8TRSVYNYKDSWL" />
<input type="image" src="https://www.paypalobjects.com/en_US/DK/i/btn/btn_donateCC_LG.gif" border="0" name="submit" title="PayPal - The safer, easier way to pay online!" alt="Donate with PayPal button" />
<img alt="" border="0" src="https://www.paypal.com/en_DE/i/scr/pixel.gif" width="1" height="1" />
</form>
If you have any technical topics, you can create an [Issue](https://github.com/jomjol/AI-on-the-edge-device/issues).
In other cases you can contact the developer via email: <img src="https://raw.githubusercontent.com/jomjol/AI-on-the-edge-device/master/images/mail.jpg" height="25">
## Changes and History
See [Changelog](Changelog.md)
## Tools
* Logfile downloader and combiner (Thx to [reserve85](https://github.com/reserve85))
* Files see ['/tools/logfile-tool'](tbd), How-to see [wiki](https://github.com/jomjol/AI-on-the-edge-device/wiki/Gasmeter-Log-Downloader)
## Additional Ideas
There are some ideas and feature requests which are not followed currently - mainly due to capacity reasons on side of the developer. They are collected here: [FeatureRequest.md](FeatureRequest.md)
------
### Known Issues
* Parts of the web page only works correctly in **Firefox** and Chrome!
With **Edge** not all parts (especially the configuration) are **not full functional**.
* spontaneous reboot, especially in case of intensive web server access (improved since v2.0.0)
------
**General remark:** Beside the `firmware.bin`, typically also the content of `/html` needs to be updated!
##### Rolling - (2020-09-12)
* based on v2.0.0 (2020-09-12)
##### 2.0.0 Layout update (2020-09-12)
* Update to **new and modern layout**
* Support for Chrome improved
* Improved robustness: improved error handling in auto flow reduces spontaneous reboots
* File server: Option for "DELETE ALL"
* WLan: support of spaces in SSID and password
* Reference Image: Option for mirror image, option for image update on the fly
* additional parameter in `wasserzaehler.html?noerror=true` to suppress an potential error message
* bug fixing
##### 1.1.3 (2020-09-09)
* **Bug in configuration of analog ROIs corrected** - correction in v.1.0.2 did not work properly
* Improved update page for the web server (`/html` can be updated via a zip-file, which is provided in `/firmware/html.zip`)
* Improved Chrome support
##### 1.1.0 (2020-09-06)
* Implementation of "delete complete directory"
**Attention: beside the `firmware.bin`, also the content of `/html` needs to be updated!**
##### 1.0.2 (2020-09-06)
* Bug in configuration of analog ROIs corrected
* minor bug correction
##### 1.0.1 (2020-09-05)
* preValue.ini Bug corrected
* minor bug correction
##### 1.0.0 (2020-09-04)
* **First usable version** - compatible to previous project (https://github.com/jomjol/water-meter-system-complete)
* NEW:
* no docker container for CNN calculation necessary
* web based configuration editor on board
##### 0.1.0 (2020-08-07)
* Initial Version
#### [Full Changelog](Changelog.md)
## Solved topics
* n.a.

3
code/.gitignore vendored
View File

@@ -3,4 +3,5 @@
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
.helper
version.cpp
sdkconfig.esp32cam

View File

@@ -1,3 +1,3 @@
copy "C:\Users\Muell\Documents\Programmieren\GitHub\AI-on-the-edge-device\code\.pio\build\esp32cam\firmware.bin" "C:\Users\Muell\Documents\Programmieren\GitHub\AI-on-the-edge-device\firmware\firmware.bin"
copy "C:\Users\Muell\Documents\Programmieren\GitHub\AI-on-the-edge-device\code\.pio\build\esp32cam\bootloader.bin" "C:\Users\Muell\Documents\Programmieren\GitHub\AI-on-the-edge-device\firmware\bootloader.bin"
copy "C:\Users\Muell\Documents\Programmieren\GitHub\AI-on-the-edge-device\code\.pio\build\esp32cam\partitions.bin" "C:\Users\Muell\Documents\Programmieren\GitHub\AI-on-the-edge-device\firmware\partitions.bin"
copy "..\..\code\.pio\build\esp32cam\firmware.bin" "..\..\firmware\firmware.bin"
copy "..\..\code\.pio\build\esp32cam\bootloader.bin" "..\..\firmware\bootloader.bin"
copy "..\..\code\.pio\build\esp32cam\partitions.bin" "..\..\firmware\partitions.bin"

1
code/.helper/makezip.bat Normal file
View File

@@ -0,0 +1 @@
powershell Compress-Archive -Path "..\..\sd-card\html\*.*" -DestinationPath "..\..\firmware\html.zip"

View File

@@ -1,8 +1,13 @@
cmake_minimum_required(VERSION 3.16.0)
cmake_minimum_required(VERSION 3.13.4)
list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common components/tflite-micro-esp-examples/components/tflite-lib)
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.cpp
${CMAKE_CURRENT_BINARY_DIR}/_version.cpp
COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_SOURCE_DIR}/version.cmake)
set(PROJECT_VER "0.0.9.3")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(esp32cam-server-only)

62
code/README.md Normal file
View File

@@ -0,0 +1,62 @@
# Build
## Preparations
```
git clone https://github.com/jomjol/AI-on-the-edge-device.git
cd AI-on-the-edge-device
git checkout rolling
git submodule update --init
```
## Build and Flash within terminal
See further down to build it within an IDE.
### Compile
```
cd code
platformio run --environment esp32cam
```
### Upload
```
pio run --target upload --upload-port /dev/ttyUSB0
```
Alternatively you also can set the UART device in `platformio.ini`, eg. `upload_port = /dev/ttyUSB0`
### Monitor UART Log
```
pio device monitor -p /dev/ttyUSB0
```
## Build and Flash with Visual Code IDE
- Download and install VS Code
- https://code.visualstudio.com/Download
- Install the VS Code platform io plugin
- <img src="https://raw.githubusercontent.com/jomjol/ai-on-the-edge-device/master/images/platformio_plugin.jpg" width="200" align="middle">
- Check for error messages, maybe you need to manually add some python libraries
- e.g. in my Ubuntu a python3-env was missing: `sudo apt-get install python3-venv`
- git clone this project
- in Linux:
```
git clone https://github.com/jomjol/AI-on-the-edge-device.git
cd AI-on-the-edge-device
git checkout rolling
git submodule update --init
```
- in VS code, open the `AI-on-the-edge-device/code`
- from terminal: `cd AI-on-the-edge-device/code && code .`
- open a pio terminal (click on the terminal sign in the bottom menu bar)
- make sure you are in the `code` directory
- To build, type `platformio run --environment esp32cam`
- or use the graphical interface:
<img src="https://raw.githubusercontent.com/jomjol/ai-on-the-edge-device/master/images/platformio_build.jpg" width="200" align="middle">
- the build artifacts are stored in `code/.pio/build/esp32cam/`
- Connect the device and type `pio device monitor`. There you will see your device and can copy the name to the next instruction
- Add `upload_port = you_device_port` to the `platformio.ini` file
- make sure an sd card with the contents of the `sd_card` folder is inserted and you have changed the wifi details
- `pio run --target erase` to erase the flash
- `pio run --target upload` this will upload the `bootloader.bin, partitions.bin,firmware.bin` from the `code/.pio/build/esp32cam/` folder.
- `pio device monitor` to observe the logs via uart

View File

@@ -0,0 +1,7 @@
FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
idf_component_register(SRCS ${app_sources}
INCLUDE_DIRS "."
REQUIRES jomjol_logfile)

View File

@@ -0,0 +1,84 @@
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "Helper.h"
#include "configFile.h"
#include <esp_log.h>
static const char *TAG = "CONFIG";
ConfigFile::ConfigFile(std::string filePath)
{
std::string config = FormatFileName(filePath);
pFile = OpenFileAndWait(config.c_str(), "r");
}
ConfigFile::~ConfigFile()
{
fclose(pFile);
}
bool ConfigFile::isNewParagraph(std::string input)
{
if ((input[0] == '[') || ((input[0] == ';') && (input[1] == '[')))
{
return true;
}
return false;
}
bool ConfigFile::GetNextParagraph(std::string& aktparamgraph, bool &disabled, bool &eof)
{
while (getNextLine(&aktparamgraph, disabled, eof) && !isNewParagraph(aktparamgraph));
if (isNewParagraph(aktparamgraph))
return true;
return false;
}
bool ConfigFile::getNextLine(std::string *rt, bool &disabled, bool &eof)
{
eof = false;
char zw[1024] = "";
if (pFile == NULL)
{
*rt = "";
return false;
}
if (fgets(zw, 1024, pFile))
{
ESP_LOGD(TAG, "%s", zw);
if ((strlen(zw) == 0) && feof(pFile))
{
*rt = "";
eof = true;
return false;
}
}
else
{
*rt = "";
eof = true;
return false;
}
*rt = zw;
*rt = trim(*rt);
while ((zw[0] == ';' || zw[0] == '#' || (rt->size() == 0)) && !(zw[1] == '[')) // Kommentarzeilen (; oder #) und Leerzeilen überspringen, es sei denn es ist ein neuer auskommentierter Paragraph
{
fgets(zw, 1024, pFile);
ESP_LOGD(TAG, "%s", zw);
if (feof(pFile))
{
*rt = "";
eof = true;
return false;
}
*rt = zw;
*rt = trim(*rt);
}
disabled = ((*rt)[0] == ';');
return true;
}

View File

@@ -0,0 +1,15 @@
#include <string>
#include <vector>
class ConfigFile {
public:
ConfigFile(std::string filePath);
~ConfigFile();
bool isNewParagraph(std::string input);
bool GetNextParagraph(std::string& aktparamgraph, bool &disabled, bool &eof);
bool getNextLine(std::string* rt, bool &disabled, bool &eof);
private:
FILE* pFile;
};

View File

@@ -0,0 +1,9 @@
FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
idf_component_register(SRCS ${app_sources}
INCLUDE_DIRS "." "../../include"
REQUIRES esp_http_server jomjol_logfile jomjol_configfile jomjol_mqtt jomjol_flowcontroll)

View File

@@ -0,0 +1,132 @@
#include "Color.h"
#include <algorithm>
#include <cmath>
#include <cassert>
namespace {
// Int -> fixed point
int up( int x ) { return x * 255; }
} // namespace
int iRgbSqrt( int num ) {
// https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Binary_numeral_system_.28base_2.29
assert( "sqrt input should be non-negative" && num >= 0 );
assert( "sqrt input should no exceed 16 bits" && num <= 0xFFFF );
int res = 0;
int bit = 1 << 16;
while ( bit > num )
bit >>= 2;
while ( bit != 0 ) {
if ( num >= res + bit ) {
num -= res + bit;
res = ( res >> 1 ) + bit;
} else
res >>= 1;
bit >>= 2;
}
return res;
}
Rgb::Rgb( Hsv y ) {
// https://stackoverflow.com/questions/24152553/hsv-to-rgb-and-back-without-floating-point-math-in-python
// greyscale
if( y.s == 0 ) {
r = g = b = y.v;
return;
}
const int region = y.h / 43;
const int remainder = ( y.h - ( region * 43 ) ) * 6;
const int p = ( y.v * ( 255 - y.s ) ) >> 8;
const int q = ( y.v * ( 255 - ( ( y.s * remainder ) >> 8 ) ) ) >> 8;
const int t = ( y.v * ( 255 - ( ( y.s * (255 -remainder ) ) >> 8 ) ) ) >> 8;
switch( region ) {
case 0: r = y.v; g = t; b = p; break;
case 1: r = q; g = y.v; b = p; break;
case 2: r = p; g = y.v; b = t; break;
case 3: r = p; g = q; b = y.v; break;
case 4: r = t; g = p; b = y.v; break;
case 5: r = y.v; g = p; b = q; break;
default: __builtin_trap();
}
a = y.a;
}
Rgb& Rgb::operator=( Hsv hsv ) {
Rgb r{ hsv };
swap( r );
return *this;
}
Rgb Rgb::operator+( Rgb in ) const {
auto copy = *this;
copy += in;
return copy;
}
Rgb& Rgb::operator+=( Rgb in ) {
unsigned int red = r + in.r;
r = ( red < 255 ) ? red : 255;
unsigned int green = g + in.g;
g = ( green < 255 ) ? green : 255;
unsigned int blue = b + in.b;
b = ( blue < 255 ) ? blue : 255;
return *this;
}
Rgb& Rgb::blend( Rgb in ) {
unsigned int inAlpha = in.a * ( 255 - a );
unsigned int alpha = a + inAlpha;
r = iRgbSqrt( ( ( r * r * a ) + ( in.r * in.r * inAlpha ) ) / alpha );
g = iRgbSqrt( ( ( g * g * a ) + ( in.g * in.g * inAlpha ) ) / alpha );
b = iRgbSqrt( ( ( b * b * a ) + ( in.b * in.b * inAlpha ) ) / alpha );
a = alpha;
return *this;
}
uint8_t IRAM_ATTR Rgb::getGrb( int idx ) {
switch ( idx ) {
case 0: return g;
case 1: return r;
case 2: return b;
}
__builtin_unreachable();
}
Hsv::Hsv( Rgb r ) {
int min = std::min( r.r, std::min( r.g, r.b ) );
int max = std::max( r.r, std::max( r.g, r.b ) );
int chroma = max - min;
v = max;
if ( chroma == 0 ) {
h = s = 0;
return;
}
s = up( chroma ) / max;
int hh;
if ( max == r.r )
hh = ( up( int( r.g ) - int( r.b ) ) ) / chroma / 6;
else if ( max == r.g )
hh = 255 / 3 + ( up( int( r.b ) - int( r.r ) ) ) / chroma / 6;
else
hh = 2 * 255 / 3 + ( up( int( r.r ) - int( r.g ) ) ) / chroma / 6;
if ( hh < 0 )
hh += 255;
h = hh;
a = r.a;
}
Hsv& Hsv::operator=( Rgb rgb ) {
Hsv h{ rgb };
swap( h );
return *this;
}

View File

@@ -0,0 +1,69 @@
#pragma once
#include <cstdint>
#include "esp_attr.h"
union Hsv;
union Rgb {
struct __attribute__ ((packed)) {
uint8_t r, g, b, a;
};
uint32_t value;
Rgb( uint8_t r = 0, uint8_t g = 0, uint8_t b = 0, uint8_t a = 255 ) : r( r ), g( g ), b( b ), a( a ) {}
Rgb( Hsv c );
Rgb& operator=( Rgb rgb ) { swap( rgb ); return *this; }
Rgb& operator=( Hsv hsv );
Rgb operator+( Rgb in ) const;
Rgb& operator+=( Rgb in );
bool operator==( Rgb in ) const { return in.value == value; }
Rgb& blend( Rgb in );
void swap( Rgb& o ) { value = o.value; }
void linearize() {
r = channelGamma(r);
g = channelGamma(g);
b = channelGamma(b);
}
uint8_t IRAM_ATTR getGrb( int idx );
void stretchChannels( uint8_t maxR, uint8_t maxG, uint8_t maxB ) {
r = stretch( r, maxR );
g = stretch( g, maxG );
b = stretch( b, maxB );
}
void stretchChannelsEvenly( uint8_t max ) {
stretchChannels( max, max, max );
}
private:
uint8_t stretch( int value, uint8_t max ) {
return ( value * max ) >> 8;
}
uint8_t channelGamma( int channel ) {
/* The optimal gamma correction is x^2.8. However, this is expensive to
* compute. Therefore, we use x^3 for gamma correction. Also, we add a
* bias as the WS2812 LEDs do not turn on for values less than 4. */
if (channel == 0)
return channel;
channel = channel * channel * channel * 251;
channel >>= 24;
return static_cast< uint8_t >( 4 + channel );
}
};
union Hsv {
struct __attribute__ ((packed)) {
uint8_t h, s, v, a;
};
uint32_t value;
Hsv( uint8_t h, uint8_t s = 0, uint8_t v = 0, uint8_t a = 255 ) : h( h ), s( s ), v( v ), a( a ) {}
Hsv( Rgb r );
Hsv& operator=( Hsv h ) { swap( h ); return *this; }
Hsv& operator=( Rgb rgb );
bool operator==( Hsv in ) const { return in.value == value; }
void swap( Hsv& o ) { value = o.value; }
};

View File

@@ -0,0 +1,63 @@
#include "SmartLeds.h"
IsrCore SmartLed::_interruptCore = CoreCurrent;
intr_handle_t SmartLed::_interruptHandle = NULL;
SmartLed*& IRAM_ATTR SmartLed::ledForChannel( int channel ) {
static SmartLed* table[8] = { nullptr };
assert( channel < 8 );
return table[ channel ];
}
void IRAM_ATTR SmartLed::interruptHandler(void*) {
for (int channel = 0; channel != 8; channel++) {
auto self = ledForChannel( channel );
if ( RMT.int_st.val & (1 << (24 + channel ) ) ) { // tx_thr_event
if ( self )
self->copyRmtHalfBlock();
RMT.int_clr.val |= 1 << ( 24 + channel );
} else if ( RMT.int_st.val & ( 1 << (3 * channel ) ) ) { // tx_end
if ( self )
xSemaphoreGiveFromISR( self->_finishedFlag, nullptr );
RMT.int_clr.val |= 1 << ( 3 * channel );
}
}
}
void IRAM_ATTR SmartLed::copyRmtHalfBlock() {
int offset = detail::MAX_PULSES * _halfIdx;
_halfIdx = !_halfIdx;
int len = 3 - _componentPosition + 3 * ( _count - 1 );
len = std::min( len, detail::MAX_PULSES / 8 );
if ( !len ) {
for ( int i = 0; i < detail::MAX_PULSES; i++) {
RMTMEM.chan[ _channel].data32[i + offset ].val = 0;
}
}
int i;
for ( i = 0; i != len && _pixelPosition != _count; i++ ) {
uint8_t val = _buffer[ _pixelPosition ].getGrb( _componentPosition );
for ( int j = 0; j != 8; j++, val <<= 1 ) {
int bit = val >> 7;
int idx = i * 8 + offset + j;
RMTMEM.chan[ _channel ].data32[ idx ].val = _bitToRmt[ bit & 0x01 ].value;
}
if ( _pixelPosition == _count - 1 && _componentPosition == 2 ) {
RMTMEM.chan[ _channel ].data32[ i * 8 + offset + 7 ].duration1 =
_timing.TRS / ( detail::RMT_DURATION_NS * detail::DIVIDER );
}
_componentPosition++;
if ( _componentPosition == 3 ) {
_componentPosition = 0;
_pixelPosition++;
}
}
for ( i *= 8; i != detail::MAX_PULSES; i++ ) {
RMTMEM.chan[ _channel ].data32[ i + offset ].val = 0;
}
}

View File

@@ -0,0 +1,530 @@
#pragma once
/*
* A C++ driver for the WS2812 LEDs using the RMT peripheral on the ESP32.
*
* Jan "yaqwsx" Mrázek <email@honzamrazek.cz>
*
* Based on the work by Martin F. Falatic - https://github.com/FozzTexx/ws2812-demo
*/
/*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <memory>
#include <cassert>
#include <cstring>
#if defined ( ARDUINO )
extern "C" { // ...someone forgot to put in the includes...
#include "esp32-hal.h"
#include "esp_intr_alloc.h"
#include "esp_ipc.h"
#include "driver/gpio.h"
#include "driver/periph_ctrl.h"
#include "freertos/semphr.h"
#include "soc/rmt_struct.h"
#include <driver/spi_master.h>
#include "esp_idf_version.h"
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL( 4, 0, 0 )
#include "soc/dport_reg.h"
#endif
}
#elif defined ( ESP_PLATFORM )
extern "C" { // ...someone forgot to put in the includes...
#include <esp_intr_alloc.h>
#include <esp_ipc.h>
#include <driver/gpio.h>
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
#include <soc/dport_reg.h>
#include <soc/gpio_sig_map.h>
#include <soc/rmt_struct.h>
#include <driver/spi_master.h>
}
#include <stdio.h>
#endif
#include "Color.h"
namespace detail {
struct TimingParams {
uint32_t T0H;
uint32_t T1H;
uint32_t T0L;
uint32_t T1L;
uint32_t TRS;
};
union RmtPulsePair {
struct {
int duration0:15;
int level0:1;
int duration1:15;
int level1:1;
};
uint32_t value;
};
static const int DIVIDER = 4; // 8 still seems to work, but timings become marginal
static const int MAX_PULSES = 32; // A channel has a 64 "pulse" buffer - we use half per pass
static const double RMT_DURATION_NS = 12.5; // minimum time of a single RMT duration based on clock ns
} // namespace detail
using LedType = detail::TimingParams;
static const LedType LED_WS2812 = { 350, 700, 800, 600, 50000 };
static const LedType LED_WS2812B = { 400, 850, 850, 400, 50100 };
static const LedType LED_SK6812 = { 300, 600, 900, 600, 80000 };
static const LedType LED_WS2813 = { 350, 800, 350, 350, 300000 };
enum BufferType { SingleBuffer = 0, DoubleBuffer };
enum IsrCore { CoreFirst = 0, CoreSecond = 1, CoreCurrent = 2};
class SmartLed {
public:
// The RMT interrupt must not run on the same core as WiFi interrupts, otherwise SmartLeds
// can't fill the RMT buffer fast enough, resulting in rendering artifacts.
// Usually, that means you have to set isrCore == CoreSecond.
//
// If you use anything other than CoreCurrent, the FreeRTOS scheduler MUST be already running,
// so you can't use it if you define SmartLed as global variable.
SmartLed( const LedType& type, int count, int pin, int channel = 0, BufferType doubleBuffer = SingleBuffer, IsrCore isrCore = CoreCurrent)
: _timing( type ),
_channel( channel ),
_count( count ),
_firstBuffer( new Rgb[ count ] ),
_secondBuffer( doubleBuffer ? new Rgb[ count ] : nullptr ),
_finishedFlag( xSemaphoreCreateBinary() )
{
assert( channel >= 0 && channel < 8 );
assert( ledForChannel( channel ) == nullptr );
xSemaphoreGive( _finishedFlag );
DPORT_SET_PERI_REG_MASK( DPORT_PERIP_CLK_EN_REG, DPORT_RMT_CLK_EN );
DPORT_CLEAR_PERI_REG_MASK( DPORT_PERIP_RST_EN_REG, DPORT_RMT_RST );
PIN_FUNC_SELECT( GPIO_PIN_MUX_REG[ pin ], 2 );
gpio_set_direction( static_cast< gpio_num_t >( pin ), GPIO_MODE_OUTPUT );
gpio_matrix_out( static_cast< gpio_num_t >( pin ), RMT_SIG_OUT0_IDX + _channel, 0, 0 );
initChannel( _channel );
RMT.tx_lim_ch[ _channel ].limit = detail::MAX_PULSES;
RMT.int_ena.val |= 1 << ( 24 + _channel );
RMT.int_ena.val |= 1 << ( 3 * _channel );
_bitToRmt[ 0 ].level0 = 1;
_bitToRmt[ 0 ].level1 = 0;
_bitToRmt[ 0 ].duration0 = _timing.T0H / ( detail::RMT_DURATION_NS * detail::DIVIDER );
_bitToRmt[ 0 ].duration1 = _timing.T0L / ( detail::RMT_DURATION_NS * detail::DIVIDER );
_bitToRmt[ 1 ].level0 = 1;
_bitToRmt[ 1 ].level1 = 0;
_bitToRmt[ 1 ].duration0 = _timing.T1H / ( detail::RMT_DURATION_NS * detail::DIVIDER );
_bitToRmt[ 1 ].duration1 = _timing.T1L / ( detail::RMT_DURATION_NS * detail::DIVIDER );
if ( !anyAlive() ) {
_interruptCore = isrCore;
if(isrCore != CoreCurrent) {
ESP_ERROR_CHECK(esp_ipc_call_blocking(isrCore, registerInterrupt, NULL));
} else {
registerInterrupt(NULL);
}
}
ledForChannel( channel ) = this;
}
~SmartLed() {
ledForChannel( _channel ) = nullptr;
if ( !anyAlive() ) {
if(_interruptCore != CoreCurrent) {
ESP_ERROR_CHECK(esp_ipc_call_blocking(_interruptCore, unregisterInterrupt, NULL));
} else {
unregisterInterrupt(NULL);
}
}
vSemaphoreDelete( _finishedFlag );
}
Rgb& operator[]( int idx ) {
return _firstBuffer[ idx ];
}
const Rgb& operator[]( int idx ) const {
return _firstBuffer[ idx ];
}
void show() {
_buffer = _firstBuffer.get();
startTransmission();
swapBuffers();
}
bool wait( TickType_t timeout = portMAX_DELAY ) {
if( xSemaphoreTake( _finishedFlag, timeout ) == pdTRUE ) {
xSemaphoreGive( _finishedFlag );
return true;
}
return false;
}
int size() const {
return _count;
}
Rgb *begin() { return _firstBuffer.get(); }
const Rgb *begin() const { return _firstBuffer.get(); }
const Rgb *cbegin() const { return _firstBuffer.get(); }
Rgb *end() { return _firstBuffer.get() + _count; }
const Rgb *end() const { return _firstBuffer.get() + _count; }
const Rgb *cend() const { return _firstBuffer.get() + _count; }
private:
static intr_handle_t _interruptHandle;
static IsrCore _interruptCore;
static void initChannel( int channel ) {
RMT.apb_conf.fifo_mask = 1; //enable memory access, instead of FIFO mode.
RMT.apb_conf.mem_tx_wrap_en = 1; //wrap around when hitting end of buffer
RMT.conf_ch[ channel ].conf0.div_cnt = detail::DIVIDER;
RMT.conf_ch[ channel ].conf0.mem_size = 1;
RMT.conf_ch[ channel ].conf0.carrier_en = 0;
RMT.conf_ch[ channel ].conf0.carrier_out_lv = 1;
RMT.conf_ch[ channel ].conf0.mem_pd = 0;
RMT.conf_ch[ channel ].conf1.rx_en = 0;
RMT.conf_ch[ channel ].conf1.mem_owner = 0;
RMT.conf_ch[ channel ].conf1.tx_conti_mode = 0; //loop back mode.
RMT.conf_ch[ channel ].conf1.ref_always_on = 1; // use apb clock: 80M
RMT.conf_ch[ channel ].conf1.idle_out_en = 1;
RMT.conf_ch[ channel ].conf1.idle_out_lv = 0;
}
static void registerInterrupt(void *) {
ESP_ERROR_CHECK(esp_intr_alloc( ETS_RMT_INTR_SOURCE, 0, interruptHandler, nullptr, &_interruptHandle));
}
static void unregisterInterrupt(void*) {
esp_intr_free( _interruptHandle );
}
static SmartLed*& IRAM_ATTR ledForChannel( int channel );
static void IRAM_ATTR interruptHandler( void* );
void IRAM_ATTR copyRmtHalfBlock();
void swapBuffers() {
if ( _secondBuffer )
_firstBuffer.swap( _secondBuffer );
}
void startTransmission() {
// Invalid use of the library
if( xSemaphoreTake( _finishedFlag, 0 ) != pdTRUE )
abort();
_pixelPosition = _componentPosition = _halfIdx = 0;
copyRmtHalfBlock();
if ( _pixelPosition < _count )
copyRmtHalfBlock();
RMT.conf_ch[ _channel ].conf1.mem_rd_rst = 1;
RMT.conf_ch[ _channel ].conf1.tx_start = 1;
}
static bool anyAlive() {
for ( int i = 0; i != 8; i++ )
if ( ledForChannel( i ) != nullptr ) return true;
return false;
}
const LedType& _timing;
int _channel;
detail::RmtPulsePair _bitToRmt[ 2 ];
int _count;
std::unique_ptr< Rgb[] > _firstBuffer;
std::unique_ptr< Rgb[] > _secondBuffer;
Rgb *_buffer;
xSemaphoreHandle _finishedFlag;
int _pixelPosition;
int _componentPosition;
int _halfIdx;
};
class Apa102 {
public:
struct ApaRgb {
ApaRgb( uint8_t r = 0, uint8_t g = 0, uint32_t b = 0, uint32_t v = 0xFF )
: v( 0xE0 | v ), b( b ), g( g ), r( r )
{}
ApaRgb& operator=( const Rgb& o ) {
r = o.r;
g = o.g;
b = o.b;
return *this;
}
ApaRgb& operator=( const Hsv& o ) {
*this = Rgb{ o };
return *this;
}
uint8_t v, b, g, r;
};
static const int FINAL_FRAME_SIZE = 4;
static const int TRANS_COUNT = 2 + 8;
Apa102( int count, int clkpin, int datapin, BufferType doubleBuffer = SingleBuffer )
: _count( count ),
_firstBuffer( new ApaRgb[ count ] ),
_secondBuffer( doubleBuffer ? new ApaRgb[ count ] : nullptr ),
_initFrame( 0 )
{
spi_bus_config_t buscfg;
memset( &buscfg, 0, sizeof( buscfg ) );
buscfg.mosi_io_num = datapin;
buscfg.miso_io_num = -1;
buscfg.sclk_io_num = clkpin;
buscfg.quadwp_io_num = -1;
buscfg.quadhd_io_num = -1;
buscfg.max_transfer_sz = 65535;
spi_device_interface_config_t devcfg;
memset( &devcfg, 0, sizeof( devcfg ) );
devcfg.clock_speed_hz = 1000000;
devcfg.mode = 0;
devcfg.spics_io_num = -1;
devcfg.queue_size = TRANS_COUNT;
devcfg.pre_cb = nullptr;
auto ret = spi_bus_initialize( HSPI_HOST, &buscfg, 1 );
assert( ret == ESP_OK );
ret = spi_bus_add_device( HSPI_HOST, &devcfg, &_spi );
assert( ret == ESP_OK );
std::fill_n( _finalFrame, FINAL_FRAME_SIZE, 0xFFFFFFFF );
}
~Apa102() {
// ToDo
}
ApaRgb& operator[]( int idx ) {
return _firstBuffer[ idx ];
}
const ApaRgb& operator[]( int idx ) const {
return _firstBuffer[ idx ];
}
void show() {
_buffer = _firstBuffer.get();
startTransmission();
swapBuffers();
}
void wait() {
for ( int i = 0; i != _transCount; i++ ) {
spi_transaction_t *t;
spi_device_get_trans_result( _spi, &t, portMAX_DELAY );
}
}
private:
void swapBuffers() {
if ( _secondBuffer )
_firstBuffer.swap( _secondBuffer );
}
void startTransmission() {
for ( int i = 0; i != TRANS_COUNT; i++ ) {
_transactions[ i ].cmd = 0;
_transactions[ i ].addr = 0;
_transactions[ i ].flags = 0;
_transactions[ i ].rxlength = 0;
_transactions[ i ].rx_buffer = nullptr;
}
// Init frame
_transactions[ 0 ].length = 32;
_transactions[ 0 ].tx_buffer = &_initFrame;
spi_device_queue_trans( _spi, _transactions + 0, portMAX_DELAY );
// Data
_transactions[ 1 ].length = 32 * _count;
_transactions[ 1 ].tx_buffer = _buffer;
spi_device_queue_trans( _spi, _transactions + 1, portMAX_DELAY );
_transCount = 2;
// End frame
for ( int i = 0; i != 1 + _count / 32 / FINAL_FRAME_SIZE; i++ ) {
_transactions[ 2 + i ].length = 32 * FINAL_FRAME_SIZE;
_transactions[ 2 + i ].tx_buffer = _finalFrame;
spi_device_queue_trans( _spi, _transactions + 2 + i, portMAX_DELAY );
_transCount++;
}
}
spi_device_handle_t _spi;
int _count;
std::unique_ptr< ApaRgb[] > _firstBuffer, _secondBuffer;
ApaRgb *_buffer;
spi_transaction_t _transactions[ TRANS_COUNT ];
int _transCount;
uint32_t _initFrame;
uint32_t _finalFrame[ FINAL_FRAME_SIZE ];
};
class LDP8806 {
public:
struct LDP8806_GRB {
LDP8806_GRB( uint8_t g_7bit = 0, uint8_t r_7bit = 0, uint32_t b_7bit = 0 )
: g( g_7bit ), r( r_7bit ), b( b_7bit )
{
}
LDP8806_GRB& operator=( const Rgb& o ) {
//Convert 8->7bit colour
r = ( o.r * 127 / 256 ) | 0x80;
g = ( o.g * 127 / 256 ) | 0x80;
b = ( o.b * 127 / 256 ) | 0x80;
return *this;
}
LDP8806_GRB& operator=( const Hsv& o ) {
*this = Rgb{ o };
return *this;
}
uint8_t g, r, b;
};
static const int LED_FRAME_SIZE_BYTES = sizeof( LDP8806_GRB );
static const int LATCH_FRAME_SIZE_BYTES = 3;
static const int TRANS_COUNT_MAX = 20;//Arbitrary, supports up to 600 LED
LDP8806( int count, int clkpin, int datapin, BufferType doubleBuffer = SingleBuffer, uint32_t clock_speed_hz = 2000000 )
: _count( count ),
_firstBuffer( new LDP8806_GRB[ count ] ),
_secondBuffer( doubleBuffer ? new LDP8806_GRB[ count ] : nullptr ),
// one 'latch'/start-of-data mark frame for every 32 leds
_latchFrames( ( count + 31 ) / 32 )
{
spi_bus_config_t buscfg;
memset( &buscfg, 0, sizeof( buscfg ) );
buscfg.mosi_io_num = datapin;
buscfg.miso_io_num = -1;
buscfg.sclk_io_num = clkpin;
buscfg.quadwp_io_num = -1;
buscfg.quadhd_io_num = -1;
buscfg.max_transfer_sz = 65535;
spi_device_interface_config_t devcfg;
memset( &devcfg, 0, sizeof( devcfg ) );
devcfg.clock_speed_hz = clock_speed_hz;
devcfg.mode = 0;
devcfg.spics_io_num = -1;
devcfg.queue_size = TRANS_COUNT_MAX;
devcfg.pre_cb = nullptr;
auto ret = spi_bus_initialize( HSPI_HOST, &buscfg, 1 );
assert( ret == ESP_OK );
ret = spi_bus_add_device( HSPI_HOST, &devcfg, &_spi );
assert( ret == ESP_OK );
std::fill_n( _latchBuffer, LATCH_FRAME_SIZE_BYTES, 0x0 );
}
~LDP8806() {
// noop
}
LDP8806_GRB& operator[]( int idx ) {
return _firstBuffer[ idx ];
}
const LDP8806_GRB& operator[]( int idx ) const {
return _firstBuffer[ idx ];
}
void show() {
_buffer = _firstBuffer.get();
startTransmission();
swapBuffers();
}
void wait() {
while ( _transCount-- ) {
spi_transaction_t *t;
spi_device_get_trans_result( _spi, &t, portMAX_DELAY );
}
}
private:
void swapBuffers() {
if ( _secondBuffer )
_firstBuffer.swap( _secondBuffer );
}
void startTransmission() {
_transCount = 0;
for ( int i = 0; i != TRANS_COUNT_MAX; i++ ) {
_transactions[ i ].cmd = 0;
_transactions[ i ].addr = 0;
_transactions[ i ].flags = 0;
_transactions[ i ].rxlength = 0;
_transactions[ i ].rx_buffer = nullptr;
}
// LED Data
_transactions[ 0 ].length = ( LED_FRAME_SIZE_BYTES * 8 ) * _count;
_transactions[ 0 ].tx_buffer = _buffer;
spi_device_queue_trans( _spi, _transactions + _transCount, portMAX_DELAY );
_transCount++;
// 'latch'/start-of-data marker frames
for ( int i = 0; i < _latchFrames; i++ ) {
_transactions[ _transCount ].length = ( LATCH_FRAME_SIZE_BYTES * 8 );
_transactions[ _transCount ].tx_buffer = _latchBuffer;
spi_device_queue_trans( _spi, _transactions + _transCount, portMAX_DELAY );
_transCount++;
}
}
spi_device_handle_t _spi;
int _count;
std::unique_ptr< LDP8806_GRB[] > _firstBuffer, _secondBuffer;
LDP8806_GRB *_buffer;
spi_transaction_t _transactions[ TRANS_COUNT_MAX ];
int _transCount;
int _latchFrames;
uint8_t _latchBuffer[ LATCH_FRAME_SIZE_BYTES ];
};

View File

@@ -0,0 +1,684 @@
#include <string>
#include <functional>
#include "string.h"
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_event.h"
#include "server_tflite.h"
//#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
#include "esp_log.h"
//#include "errno.h"
#include <sys/stat.h>
#include <vector>
//#include <regex>
#include "defines.h"
#include "server_GPIO.h"
#include "ClassLogFile.h"
#include "configFile.h"
#include "Helper.h"
#include "interface_mqtt.h"
static const char *TAG = "GPIO";
QueueHandle_t gpio_queue_handle = NULL;
#define DEBUG_DETAIL_ON
GpioPin::GpioPin(gpio_num_t gpio, const char* name, gpio_pin_mode_t mode, gpio_int_type_t interruptType, uint8_t dutyResolution, std::string mqttTopic, bool httpEnable)
{
_gpio = gpio;
_name = name;
_mode = mode;
_interruptType = interruptType;
_mqttTopic = mqttTopic;
}
GpioPin::~GpioPin()
{
ESP_LOGD(TAG,"reset GPIO pin %d", _gpio);
if (_interruptType != GPIO_INTR_DISABLE) {
//hook isr handler for specific gpio pin
gpio_isr_handler_remove(_gpio);
}
gpio_reset_pin(_gpio);
}
static void IRAM_ATTR gpio_isr_handler(void* arg)
{
GpioResult gpioResult;
gpioResult.gpio = *(gpio_num_t*) arg;
gpioResult.value = gpio_get_level(gpioResult.gpio);
BaseType_t ContextSwitchRequest = pdFALSE;
xQueueSendToBackFromISR(gpio_queue_handle,(void*)&gpioResult,&ContextSwitchRequest);
if(ContextSwitchRequest){
taskYIELD();
}
}
static void gpioHandlerTask(void *arg) {
ESP_LOGD(TAG,"start interrupt task");
while(1){
if(uxQueueMessagesWaiting(gpio_queue_handle)){
while(uxQueueMessagesWaiting(gpio_queue_handle)){
GpioResult gpioResult;
xQueueReceive(gpio_queue_handle,(void*)&gpioResult,10);
ESP_LOGD(TAG,"gpio: %d state: %d", gpioResult.gpio, gpioResult.value);
((GpioHandler*)arg)->gpioInterrupt(&gpioResult);
}
}
((GpioHandler*)arg)->taskHandler();
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
void GpioPin::gpioInterrupt(int value) {
if (_mqttTopic != "") {
ESP_LOGD(TAG, "gpioInterrupt %s %d", _mqttTopic.c_str(), value);
MQTTPublish(_mqttTopic, value ? "true" : "false");
currentState = value;
}
}
void GpioPin::init()
{
gpio_config_t io_conf;
//set interrupt
io_conf.intr_type = _interruptType;
//set as output mode
io_conf.mode = (_mode == GPIO_PIN_MODE_OUTPUT) || (_mode == GPIO_PIN_MODE_BUILT_IN_FLASH_LED) ? gpio_mode_t::GPIO_MODE_OUTPUT : gpio_mode_t::GPIO_MODE_INPUT;
//bit mask of the pins that you want to set,e.g.GPIO18/19
io_conf.pin_bit_mask = (1ULL << _gpio);
//set pull-down mode
io_conf.pull_down_en = _mode == GPIO_PIN_MODE_INPUT_PULLDOWN ? gpio_pulldown_t::GPIO_PULLDOWN_ENABLE : gpio_pulldown_t::GPIO_PULLDOWN_DISABLE;
//set pull-up mode
io_conf.pull_up_en = _mode == GPIO_PIN_MODE_INPUT_PULLDOWN ? gpio_pullup_t::GPIO_PULLUP_ENABLE : gpio_pullup_t::GPIO_PULLUP_DISABLE;
//configure GPIO with the given settings
gpio_config(&io_conf);
// if (_interruptType != GPIO_INTR_DISABLE) { // ohne GPIO_PIN_MODE_EXTERNAL_FLASH_WS281X, wenn das genutzt wird, dann soll auch der Handler hier nicht initialisiert werden, da das dann über SmartLED erfolgt.
if ((_interruptType != GPIO_INTR_DISABLE) && (_interruptType != GPIO_PIN_MODE_EXTERNAL_FLASH_WS281X)) {
//hook isr handler for specific gpio pin
ESP_LOGD(TAG, "GpioPin::init add isr handler for GPIO %d", _gpio);
gpio_isr_handler_add(_gpio, gpio_isr_handler, (void*)&_gpio);
}
if ((_mqttTopic != "") && ((_mode == GPIO_PIN_MODE_OUTPUT) || (_mode == GPIO_PIN_MODE_OUTPUT_PWM) || (_mode == GPIO_PIN_MODE_BUILT_IN_FLASH_LED))) {
std::function<bool(std::string, char*, int)> f = std::bind(&GpioPin::handleMQTT, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
MQTTregisterSubscribeFunction(_mqttTopic, f);
}
}
bool GpioPin::getValue(std::string* errorText)
{
if ((_mode != GPIO_PIN_MODE_INPUT) && (_mode != GPIO_PIN_MODE_INPUT_PULLUP) && (_mode != GPIO_PIN_MODE_INPUT_PULLDOWN)) {
(*errorText) = "GPIO is not in input mode";
}
return gpio_get_level(_gpio) == 1;
}
void GpioPin::setValue(bool value, gpio_set_source setSource, std::string* errorText)
{
ESP_LOGD(TAG, "GpioPin::setValue %d", value);
if ((_mode != GPIO_PIN_MODE_OUTPUT) && (_mode != GPIO_PIN_MODE_OUTPUT_PWM) && (_mode != GPIO_PIN_MODE_BUILT_IN_FLASH_LED)) {
(*errorText) = "GPIO is not in output mode";
} else {
gpio_set_level(_gpio, value);
if ((_mqttTopic != "") && (setSource != GPIO_SET_SOURCE_MQTT)) {
MQTTPublish(_mqttTopic, value ? "true" : "false");
}
}
}
void GpioPin::publishState() {
int newState = gpio_get_level(_gpio);
if (newState != currentState) {
ESP_LOGD(TAG,"publish state of GPIO %d new state %d", _gpio, newState);
MQTTPublish(_mqttTopic, newState ? "true" : "false");
currentState = newState;
}
}
bool GpioPin::handleMQTT(std::string, char* data, int data_len) {
ESP_LOGD(TAG, "GpioPin::handleMQTT data %.*s", data_len, data);
std::string dataStr(data, data_len);
dataStr = toLower(dataStr);
std::string errorText = "";
if ((dataStr == "true") || (dataStr == "1")) {
setValue(true, GPIO_SET_SOURCE_MQTT, &errorText);
} else if ((dataStr == "false") || (dataStr == "0")) {
setValue(false, GPIO_SET_SOURCE_MQTT, &errorText);
} else {
errorText = "wrong value ";
errorText.append(data, data_len);
}
if (errorText != "") {
ESP_LOGE(TAG, "%s", errorText.c_str());
}
return (errorText == "");
}
esp_err_t callHandleHttpRequest(httpd_req_t *req)
{
ESP_LOGD(TAG,"callHandleHttpRequest");
GpioHandler *gpioHandler = (GpioHandler*)req->user_ctx;
return gpioHandler->handleHttpRequest(req);
}
void taskGpioHandler(void *pvParameter)
{
ESP_LOGD(TAG,"taskGpioHandler");
((GpioHandler*)pvParameter)->init();
}
GpioHandler::GpioHandler(std::string configFile, httpd_handle_t httpServer)
{
ESP_LOGI(TAG,"start GpioHandler");
_configFile = configFile;
_httpServer = httpServer;
ESP_LOGI(TAG, "register GPIO Uri");
registerGpioUri();
}
GpioHandler::~GpioHandler() {
if (gpioMap != NULL) {
clear();
delete gpioMap;
}
}
void GpioHandler::init()
{
// TickType_t xDelay = 60000 / portTICK_PERIOD_MS;
// ESP_LOGD(TAG, "wait before start %ldms", (long) xDelay);
// vTaskDelay( xDelay );
ESP_LOGD(TAG, "*************** Start GPIOHandler_Init *****************");
if (gpioMap == NULL) {
gpioMap = new std::map<gpio_num_t, GpioPin*>();
} else {
clear();
}
ESP_LOGI(TAG, "read GPIO config and init GPIO");
if (!readConfig()) {
clear();
delete gpioMap;
gpioMap = NULL;
ESP_LOGI(TAG, "GPIO init completed, handler is disabled");
return;
}
for(std::map<gpio_num_t, GpioPin*>::iterator it = gpioMap->begin(); it != gpioMap->end(); ++it) {
it->second->init();
}
std::function<void()> f = std::bind(&GpioHandler::handleMQTTconnect, this);
MQTTregisterConnectFunction("gpio-handler", f);
if (xHandleTaskGpio == NULL) {
gpio_queue_handle = xQueueCreate(10,sizeof(GpioResult));
BaseType_t xReturned = xTaskCreate(&gpioHandlerTask, "gpio_int", configMINIMAL_STACK_SIZE * 8, (void *)this, tskIDLE_PRIORITY + 2, &xHandleTaskGpio);
if(xReturned == pdPASS ) {
ESP_LOGD(TAG, "xHandletaskGpioHandler started");
} else {
ESP_LOGD(TAG, "xHandletaskGpioHandler not started %d ", (int)xHandleTaskGpio);
}
}
ESP_LOGI(TAG, "GPIO init completed, is enabled");
}
void GpioHandler::taskHandler() {
if (gpioMap != NULL) {
for(std::map<gpio_num_t, GpioPin*>::iterator it = gpioMap->begin(); it != gpioMap->end(); ++it) {
if ((it->second->getInterruptType() == GPIO_INTR_DISABLE))
it->second->publishState();
}
}
}
void GpioHandler::handleMQTTconnect()
{
if (gpioMap != NULL) {
for(std::map<gpio_num_t, GpioPin*>::iterator it = gpioMap->begin(); it != gpioMap->end(); ++it) {
if ((it->second->getMode() == GPIO_PIN_MODE_INPUT) || (it->second->getMode() == GPIO_PIN_MODE_INPUT_PULLDOWN) || (it->second->getMode() == GPIO_PIN_MODE_INPUT_PULLUP))
it->second->publishState();
}
}
}
void GpioHandler::deinit() {
MQTTunregisterConnectFunction("gpio-handler");
clear();
if (xHandleTaskGpio != NULL) {
vTaskDelete(xHandleTaskGpio);
xHandleTaskGpio = NULL;
}
}
void GpioHandler::gpioInterrupt(GpioResult* gpioResult) {
if ((gpioMap != NULL) && (gpioMap->find(gpioResult->gpio) != gpioMap->end())) {
(*gpioMap)[gpioResult->gpio]->gpioInterrupt(gpioResult->value);
}
}
bool GpioHandler::readConfig()
{
if (!gpioMap->empty())
clear();
ConfigFile configFile = ConfigFile(_configFile);
std::vector<std::string> zerlegt;
std::string line = "";
bool disabledLine = false;
bool eof = false;
gpio_num_t gpioExtLED = (gpio_num_t) 0;
// ESP_LOGD(TAG, "readConfig - Start 1");
while ((!configFile.GetNextParagraph(line, disabledLine, eof) || (line.compare("[GPIO]") != 0)) && !eof) {}
if (eof)
return false;
// ESP_LOGD(TAG, "readConfig - Start 2 line: %s, disabbledLine: %d", line.c_str(), (int) disabledLine);
_isEnabled = !disabledLine;
if (!_isEnabled)
return false;
// ESP_LOGD(TAG, "readConfig - Start 3");
// std::string mainTopicMQTT = "";
std::string mainTopicMQTT = GetMQTTMainTopic();
if (mainTopicMQTT.length() > 0)
{
mainTopicMQTT = mainTopicMQTT + "/GPIO";
ESP_LOGD(TAG, "MAINTOPICMQTT found");
}
bool registerISR = false;
while (configFile.getNextLine(&line, disabledLine, eof) && !configFile.isNewParagraph(line))
{
zerlegt = ZerlegeZeile(line);
// const std::regex pieces_regex("IO([0-9]{1,2})");
// std::smatch pieces_match;
// if (std::regex_match(zerlegt[0], pieces_match, pieces_regex) && (pieces_match.size() == 2))
// {
// std::string gpioStr = pieces_match[1];
ESP_LOGD(TAG, "conf param %s", toUpper(zerlegt[0]).c_str());
if (toUpper(zerlegt[0]) == "MAINTOPICMQTT") {
// ESP_LOGD(TAG, "MAINTOPICMQTT found");
// mainTopicMQTT = zerlegt[1];
} else if ((zerlegt[0].rfind("IO", 0) == 0) && (zerlegt.size() >= 6))
{
ESP_LOGI(TAG,"Enable GP%s in %s mode", zerlegt[0].c_str(), zerlegt[1].c_str());
std::string gpioStr = zerlegt[0].substr(2, 2);
gpio_num_t gpioNr = (gpio_num_t)atoi(gpioStr.c_str());
gpio_pin_mode_t pinMode = resolvePinMode(toLower(zerlegt[1]));
gpio_int_type_t intType = resolveIntType(toLower(zerlegt[2]));
uint16_t dutyResolution = (uint8_t)atoi(zerlegt[3].c_str());
bool mqttEnabled = toLower(zerlegt[4]) == "true";
bool httpEnabled = toLower(zerlegt[5]) == "true";
char gpioName[100];
if (zerlegt.size() >= 7) {
strcpy(gpioName, trim(zerlegt[6]).c_str());
} else {
sprintf(gpioName, "GPIO%d", gpioNr);
}
std::string mqttTopic = mqttEnabled ? (mainTopicMQTT + "/" + gpioName) : "";
GpioPin* gpioPin = new GpioPin(gpioNr, gpioName, pinMode, intType,dutyResolution, mqttTopic, httpEnabled);
(*gpioMap)[gpioNr] = gpioPin;
if (pinMode == GPIO_PIN_MODE_EXTERNAL_FLASH_WS281X)
{
ESP_LOGD(TAG, "Set WS2812 to GPIO %d", gpioNr);
gpioExtLED = gpioNr;
}
if (intType != GPIO_INTR_DISABLE) {
registerISR = true;
}
}
if (toUpper(zerlegt[0]) == "LEDNUMBERS")
{
LEDNumbers = stoi(zerlegt[1]);
}
if (toUpper(zerlegt[0]) == "LEDCOLOR")
{
uint8_t _r, _g, _b;
_r = stoi(zerlegt[1]);
_g = stoi(zerlegt[2]);
_b = stoi(zerlegt[3]);
LEDColor = Rgb{_r, _g, _b};
}
if (toUpper(zerlegt[0]) == "LEDTYPE")
{
if (zerlegt[1] == "WS2812")
LEDType = LED_WS2812;
if (zerlegt[1] == "WS2812B")
LEDType = LED_WS2812B;
if (zerlegt[1] == "SK6812")
LEDType = LED_SK6812;
if (zerlegt[1] == "WS2813")
LEDType = LED_WS2813;
}
}
if (registerISR) {
//install gpio isr service
gpio_install_isr_service(ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_IRAM);
}
if (gpioExtLED > 0)
{
// LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Startsequence 06"); // Nremove
// vTaskDelay( xDelay );
// xDelay = 5000 / portTICK_PERIOD_MS;
// ESP_LOGD(TAG, "main: sleep for: %ldms", (long) xDelay);
// SmartLed leds( LED_WS2812, 2, GPIO_NUM_12, 0, DoubleBuffer );
// leds[ 0 ] = Rgb{ 255, 0, 0 };
// leds[ 1 ] = Rgb{ 255, 255, 255 };
// leds.show();
// SmartLed leds = new SmartLed(LEDType, LEDNumbers, gpioExtLED, 0, DoubleBuffer);
// _SmartLED = new SmartLed( LED_WS2812, 2, GPIO_NUM_12, 0, DoubleBuffer );
}
return true;
}
void GpioHandler::clear()
{
ESP_LOGD(TAG, "GpioHandler::clear");
if (gpioMap != NULL) {
for(std::map<gpio_num_t, GpioPin*>::iterator it = gpioMap->begin(); it != gpioMap->end(); ++it) {
delete it->second;
}
gpioMap->clear();
}
// gpio_uninstall_isr_service(); can't uninstall, isr service is used by camera
}
void GpioHandler::registerGpioUri()
{
ESP_LOGI(TAG, "server_GPIO - Registering URI handlers");
httpd_uri_t camuri = { };
camuri.method = HTTP_GET;
camuri.uri = "/GPIO";
camuri.handler = callHandleHttpRequest;
camuri.user_ctx = (void*)this;
httpd_register_uri_handler(_httpServer, &camuri);
}
esp_err_t GpioHandler::handleHttpRequest(httpd_req_t *req)
{
ESP_LOGD(TAG, "handleHttpRequest");
if (gpioMap == NULL) {
std::string resp_str = "GPIO handler not initialized";
httpd_resp_send(req, resp_str.c_str(), resp_str.length());
return ESP_OK;
}
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_switch_GPIO - Start");
#endif
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handler_switch_GPIO");
char _query[200];
char _valueGPIO[30];
char _valueStatus[30];
std::string gpio, status;
if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK) {
ESP_LOGD(TAG, "Query: %s", _query);
if (httpd_query_key_value(_query, "GPIO", _valueGPIO, 30) == ESP_OK)
{
ESP_LOGD(TAG, "GPIO is found %s", _valueGPIO);
gpio = std::string(_valueGPIO);
} else {
std::string resp_str = "GPIO No is not defined";
httpd_resp_send(req, resp_str.c_str(), resp_str.length());
return ESP_OK;
}
if (httpd_query_key_value(_query, "Status", _valueStatus, 30) == ESP_OK)
{
ESP_LOGD(TAG, "Status is found %s", _valueStatus);
status = std::string(_valueStatus);
}
} else {
const char* resp_str = "Error in call. Use /GPIO?GPIO=12&Status=high";
httpd_resp_send(req, resp_str, strlen(resp_str));
return ESP_OK;
}
status = toUpper(status);
if ((status != "HIGH") && (status != "LOW") && (status != "TRUE") && (status != "FALSE") && (status != "0") && (status != "1") && (status != ""))
{
std::string zw = "Status not valid: " + status;
httpd_resp_sendstr_chunk(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;
}
int gpionum = stoi(gpio);
// frei: 16; 12-15; 2; 4 // nur 12 und 13 funktionieren 2: reboot, 4: BlitzLED, 15: PSRAM, 14/15: DMA für SDKarte ???
gpio_num_t gpio_num = resolvePinNr(gpionum);
if (gpio_num == GPIO_NUM_NC)
{
std::string zw = "GPIO" + std::to_string(gpionum) + " unsupported - only 12 & 13 free";
httpd_resp_sendstr_chunk(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;
}
if (gpioMap->count(gpio_num) == 0) {
char resp_str [30];
sprintf(resp_str, "GPIO%d is not registred", gpio_num);
httpd_resp_send(req, resp_str, strlen(resp_str));
return ESP_OK;
}
if (status == "")
{
std::string resp_str = "";
status = (*gpioMap)[gpio_num]->getValue(&resp_str) ? "HIGH" : "LOW";
if (resp_str == "") {
resp_str = status;
}
httpd_resp_sendstr_chunk(req, resp_str.c_str());
httpd_resp_sendstr_chunk(req, NULL);
}
else
{
std::string resp_str = "";
(*gpioMap)[gpio_num]->setValue((status == "HIGH") || (status == "TRUE") || (status == "1"), GPIO_SET_SOURCE_HTTP, &resp_str);
if (resp_str == "") {
resp_str = "GPIO" + std::to_string(gpionum) + " switched to " + status;
}
httpd_resp_sendstr_chunk(req, resp_str.c_str());
httpd_resp_sendstr_chunk(req, NULL);
}
return ESP_OK;
};
void GpioHandler::flashLightEnable(bool value)
{
ESP_LOGD(TAG, "GpioHandler::flashLightEnable %s", value ? "true" : "false");
if (gpioMap != NULL) {
for(std::map<gpio_num_t, GpioPin*>::iterator it = gpioMap->begin(); it != gpioMap->end(); ++it)
{
if (it->second->getMode() == GPIO_PIN_MODE_BUILT_IN_FLASH_LED) //|| (it->second->getMode() == GPIO_PIN_MODE_EXTERNAL_FLASH_PWM) || (it->second->getMode() == GPIO_PIN_MODE_EXTERNAL_FLASH_WS281X))
{
std::string resp_str = "";
it->second->setValue(value, GPIO_SET_SOURCE_INTERNAL, &resp_str);
if (resp_str == "") {
ESP_LOGD(TAG, "Flash light pin GPIO %d switched to %s", (int)it->first, (value ? "on" : "off"));
} else {
ESP_LOGE(TAG, "Can't set flash light pin GPIO %d. Error: %s", (int)it->first, resp_str.c_str());
}
} else
{
if (it->second->getMode() == GPIO_PIN_MODE_EXTERNAL_FLASH_WS281X)
{
#ifdef __LEDGLOBAL
if (leds_global == NULL) {
ESP_LOGI(TAG, "init SmartLed: LEDNumber=%d, GPIO=%d", LEDNumbers, (int)it->second->getGPIO());
leds_global = new SmartLed( LEDType, LEDNumbers, it->second->getGPIO(), 0, DoubleBuffer );
} else {
// wait until we can update: https://github.com/RoboticsBrno/SmartLeds/issues/10#issuecomment-386921623
leds_global->wait();
}
#else
SmartLed leds( LEDType, LEDNumbers, it->second->getGPIO(), 0, DoubleBuffer );
#endif
if (value)
{
for (int i = 0; i < LEDNumbers; ++i)
#ifdef __LEDGLOBAL
(*leds_global)[i] = LEDColor;
#else
leds[i] = LEDColor;
#endif
}
else
{
for (int i = 0; i < LEDNumbers; ++i)
#ifdef __LEDGLOBAL
(*leds_global)[i] = Rgb{0, 0, 0};
#else
leds[i] = Rgb{0, 0, 0};
#endif
}
#ifdef __LEDGLOBAL
leds_global->show();
#else
leds.show();
#endif
}
}
}
}
}
gpio_num_t GpioHandler::resolvePinNr(uint8_t pinNr)
{
switch(pinNr) {
case 0:
return GPIO_NUM_0;
case 1:
return GPIO_NUM_1;
case 3:
return GPIO_NUM_3;
case 4:
return GPIO_NUM_4;
case 12:
return GPIO_NUM_12;
case 13:
return GPIO_NUM_13;
default:
return GPIO_NUM_NC;
}
}
gpio_pin_mode_t GpioHandler::resolvePinMode(std::string input)
{
if( input == "disabled" ) return GPIO_PIN_MODE_DISABLED;
if( input == "input" ) return GPIO_PIN_MODE_INPUT;
if( input == "input-pullup" ) return GPIO_PIN_MODE_INPUT_PULLUP;
if( input == "input-pulldown" ) return GPIO_PIN_MODE_INPUT_PULLDOWN;
if( input == "output" ) return GPIO_PIN_MODE_OUTPUT;
if( input == "built-in-led" ) return GPIO_PIN_MODE_BUILT_IN_FLASH_LED;
if( input == "output-pwm" ) return GPIO_PIN_MODE_OUTPUT_PWM;
if( input == "external-flash-pwm" ) return GPIO_PIN_MODE_EXTERNAL_FLASH_PWM;
if( input == "external-flash-ws281x" ) return GPIO_PIN_MODE_EXTERNAL_FLASH_WS281X;
return GPIO_PIN_MODE_DISABLED;
}
gpio_int_type_t GpioHandler::resolveIntType(std::string input)
{
if( input == "disabled" ) return GPIO_INTR_DISABLE;
if( input == "rising-edge" ) return GPIO_INTR_POSEDGE;
if( input == "falling-edge" ) return GPIO_INTR_NEGEDGE;
if( input == "rising-and-falling" ) return GPIO_INTR_ANYEDGE ;
if( input == "low-level-trigger" ) return GPIO_INTR_LOW_LEVEL;
if( input == "high-level-trigger" ) return GPIO_INTR_HIGH_LEVEL;
return GPIO_INTR_DISABLE;
}
static GpioHandler *gpioHandler = NULL;
void gpio_handler_create(httpd_handle_t server)
{
if (gpioHandler == NULL)
gpioHandler = new GpioHandler(CONFIG_FILE, server);
}
void gpio_handler_init()
{
if (gpioHandler != NULL) {
gpioHandler->init();
}
}
void gpio_handler_deinit() {
if (gpioHandler != NULL) {
gpioHandler->deinit();
}
}
void gpio_handler_destroy()
{
if (gpioHandler != NULL) {
delete gpioHandler;
gpioHandler = NULL;
}
}
GpioHandler* gpio_handler_get()
{
return gpioHandler;
}

View File

@@ -0,0 +1,112 @@
#ifndef SERVER_GPIO_H
#define SERVER_GPIO_H
#include <esp_log.h>
#include <esp_http_server.h>
#include <map>
#include "driver/gpio.h"
#include "SmartLeds.h"
//#include "ClassControllCamera.h"
// wenn __LEDGLOBAL definiert ist, wird eine globale Variable für die LED-Ansteuerung verwendet, ansonsten lokal und jedesmal neu
#define __LEDGLOBAL
typedef enum {
GPIO_PIN_MODE_DISABLED = 0x0,
GPIO_PIN_MODE_INPUT = 0x1,
GPIO_PIN_MODE_INPUT_PULLUP = 0x2,
GPIO_PIN_MODE_INPUT_PULLDOWN = 0x3,
GPIO_PIN_MODE_OUTPUT = 0x4,
GPIO_PIN_MODE_BUILT_IN_FLASH_LED = 0x5,
GPIO_PIN_MODE_OUTPUT_PWM = 0x6,
GPIO_PIN_MODE_EXTERNAL_FLASH_PWM = 0x7,
GPIO_PIN_MODE_EXTERNAL_FLASH_WS281X = 0x8,
} gpio_pin_mode_t;
struct GpioResult {
gpio_num_t gpio;
int value;
};
typedef enum {
GPIO_SET_SOURCE_INTERNAL = 0,
GPIO_SET_SOURCE_MQTT = 1,
GPIO_SET_SOURCE_HTTP = 2,
} gpio_set_source;
class GpioPin {
public:
GpioPin(gpio_num_t gpio, const char* name, gpio_pin_mode_t mode, gpio_int_type_t interruptType, uint8_t dutyResolution, std::string mqttTopic, bool httpEnable);
~GpioPin();
void init();
bool getValue(std::string* errorText);
void setValue(bool value, gpio_set_source setSource, std::string* errorText);
bool handleMQTT(std::string, char* data, int data_len);
void publishState();
void gpioInterrupt(int value);
gpio_int_type_t getInterruptType() { return _interruptType; }
gpio_pin_mode_t getMode() { return _mode; }
gpio_num_t getGPIO(){return _gpio;};
private:
gpio_num_t _gpio;
const char* _name;
gpio_pin_mode_t _mode;
gpio_int_type_t _interruptType;
std::string _mqttTopic;
int currentState = -1;
};
esp_err_t callHandleHttpRequest(httpd_req_t *req);
void taskGpioHandler(void *pvParameter);
class GpioHandler {
public:
GpioHandler(std::string configFile, httpd_handle_t httpServer);
~GpioHandler();
void init();
void deinit();
void registerGpioUri();
esp_err_t handleHttpRequest(httpd_req_t *req);
void taskHandler();
void gpioInterrupt(GpioResult* gpioResult);
void flashLightEnable(bool value);
bool isEnabled() { return _isEnabled; }
void handleMQTTconnect();
private:
std::string _configFile;
httpd_handle_t _httpServer;
std::map<gpio_num_t, GpioPin*> *gpioMap = NULL;
TaskHandle_t xHandleTaskGpio = NULL;
bool _isEnabled = false;
int LEDNumbers = 2;
Rgb LEDColor = Rgb{ 255, 255, 255 };
LedType LEDType = LED_WS2812;
#ifdef __LEDGLOBAL
SmartLed *leds_global = NULL;
#endif
bool readConfig();
void clear();
gpio_num_t resolvePinNr(uint8_t pinNr);
gpio_pin_mode_t resolvePinMode(std::string input);
gpio_int_type_t resolveIntType(std::string input);
};
void gpio_handler_create(httpd_handle_t server);
void gpio_handler_init();
void gpio_handler_deinit();
void gpio_handler_destroy();
GpioHandler* gpio_handler_get();
#endif //SERVER_GPIO_H

View File

@@ -0,0 +1,9 @@
FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
idf_component_register(SRCS ${app_sources}
INCLUDE_DIRS "."
REQUIRES esp32-camera esp_http_server jomjol_logfile jomjol_image_proc nvs_flash jomjol_fileserver_ota jomjol_controlGPIO)

View File

@@ -0,0 +1,695 @@
#include "ClassControllCamera.h"
#include "ClassLogFile.h"
#include <stdio.h>
#include "driver/gpio.h"
#include "esp_timer.h"
#include "esp_log.h"
#include "Helper.h"
#include "CImageBasis.h"
#include "server_ota.h"
#include "server_GPIO.h"
#define BOARD_ESP32CAM_AITHINKER
#include <esp_event.h>
#include <esp_log.h>
#include <esp_system.h>
#include <nvs_flash.h>
#include <sys/param.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_camera.h"
// #define DEBUG_DETAIL_ON
#define USE_PWM_LEDFLASH
#ifdef USE_PWM_LEDFLASH
//// PWM für Flash-LED
#define LEDC_TIMER LEDC_TIMER_1 // LEDC_TIMER_0
#define LEDC_MODE LEDC_LOW_SPEED_MODE
#define LEDC_OUTPUT_IO (4) // Define the output GPIO
#define LEDC_CHANNEL LEDC_CHANNEL_1
#define LEDC_DUTY_RES LEDC_TIMER_13_BIT // Set duty resolution to 13 bits
//#define LEDC_DUTY (195) // Set duty to 50%. ((2 ** 13) - 1) * 50% = 4095
#define LEDC_FREQUENCY (5000) // Frequency in Hertz. Set frequency at 5 kHz
#endif
// ESP32Cam (AiThinker) PIN Map
#define CAM_PIN_PWDN 32
#define CAM_PIN_RESET -1 //software reset will be performed
#define CAM_PIN_XCLK 0
#define CAM_PIN_SIOD 26
#define CAM_PIN_SIOC 27
#define CAM_PIN_D7 35
#define CAM_PIN_D6 34
#define CAM_PIN_D5 39
#define CAM_PIN_D4 36
#define CAM_PIN_D3 21
#define CAM_PIN_D2 19
#define CAM_PIN_D1 18
#define CAM_PIN_D0 5
#define CAM_PIN_VSYNC 25
#define CAM_PIN_HREF 23
#define CAM_PIN_PCLK 22
static const char *TAG = "CAM";
static camera_config_t camera_config = {
.pin_pwdn = CAM_PIN_PWDN,
.pin_reset = CAM_PIN_RESET,
.pin_xclk = CAM_PIN_XCLK,
.pin_sscb_sda = CAM_PIN_SIOD,
.pin_sscb_scl = CAM_PIN_SIOC,
.pin_d7 = CAM_PIN_D7,
.pin_d6 = CAM_PIN_D6,
.pin_d5 = CAM_PIN_D5,
.pin_d4 = CAM_PIN_D4,
.pin_d3 = CAM_PIN_D3,
.pin_d2 = CAM_PIN_D2,
.pin_d1 = CAM_PIN_D1,
.pin_d0 = CAM_PIN_D0,
.pin_vsync = CAM_PIN_VSYNC,
.pin_href = CAM_PIN_HREF,
.pin_pclk = CAM_PIN_PCLK,
//XCLK 20MHz or 10MHz for OV2640 double FPS (Experimental)
.xclk_freq_hz = 20000000, // Orginalwert
// .xclk_freq_hz = 5000000, // Test, um die Bildfehler los zu werden !!!! Hängt in Version 9.2 !!!!
.ledc_timer = LEDC_TIMER_0,
.ledc_channel = LEDC_CHANNEL_0,
.pixel_format = PIXFORMAT_JPEG, //YUV422,GRAYSCALE,RGB565,JPEG
.frame_size = FRAMESIZE_VGA, //QQVGA-UXGA Do not use sizes above QVGA when not JPEG
// .frame_size = FRAMESIZE_UXGA, //QQVGA-UXGA Do not use sizes above QVGA when not JPEG
.jpeg_quality = 12, //0-63 lower number means higher quality
.fb_count = 1, //if more than one, i2s runs in continuous mode. Use only with JPEG
.fb_location = CAMERA_FB_IN_PSRAM, /*!< The location where the frame buffer will be allocated */
// .grab_mode = CAMERA_GRAB_WHEN_EMPTY,
.grab_mode = CAMERA_GRAB_LATEST, // erst ab neuer esp32cam-version
};
#include "driver/ledc.h"
CCamera Camera;
#define FLASH_GPIO GPIO_NUM_4
#define BLINK_GPIO GPIO_NUM_33
typedef struct {
httpd_req_t *req;
size_t len;
} jpg_chunking_t;
void CCamera::ledc_init(void)
{
#ifdef USE_PWM_LEDFLASH
// Prepare and then apply the LEDC PWM timer configuration
ledc_timer_config_t ledc_timer = { };
ledc_timer.speed_mode = LEDC_MODE;
ledc_timer.timer_num = LEDC_TIMER;
ledc_timer.duty_resolution = LEDC_DUTY_RES;
ledc_timer.freq_hz = LEDC_FREQUENCY; // Set output frequency at 5 kHz
ledc_timer.clk_cfg = LEDC_AUTO_CLK;
ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
// Prepare and then apply the LEDC PWM channel configuration
ledc_channel_config_t ledc_channel = { };
ledc_channel.speed_mode = LEDC_MODE;
ledc_channel.channel = LEDC_CHANNEL;
ledc_channel.timer_sel = LEDC_TIMER;
ledc_channel.intr_type = LEDC_INTR_DISABLE;
ledc_channel.gpio_num = LEDC_OUTPUT_IO;
ledc_channel.duty = 0; // Set duty to 0%
ledc_channel.hpoint = 0;
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
#endif
}
static size_t jpg_encode_stream(void * arg, size_t index, const void* data, size_t len){
jpg_chunking_t *j = (jpg_chunking_t *)arg;
if(!index){
j->len = 0;
}
if(httpd_resp_send_chunk(j->req, (const char *)data, len) != ESP_OK){
return 0;
}
j->len += len;
return len;
}
bool CCamera::SetBrightnessContrastSaturation(int _brightness, int _contrast, int _saturation)
{
bool result = false;
sensor_t * s = esp_camera_sensor_get();
if (_brightness > -100)
_brightness = min(2, max(-2, _brightness));
if (_contrast > -100)
_contrast = min(2, max(-2, _contrast));
if (_saturation > -100)
_saturation = min(2, max(-2, _saturation));
if (_saturation > -100)
s->set_saturation(s, _saturation);
if (_contrast > -100)
s->set_contrast(s, _contrast);
if (_brightness > -100)
s->set_brightness(s, _brightness);
if ((_brightness != brightness) && (_brightness > -100))
result = true;
if ((_contrast != contrast) && (_contrast > -100))
result = true;
if ((_saturation != saturation) && (_saturation > -100))
result = true;
if (_brightness > -100)
brightness = _brightness;
if (_contrast > -100)
contrast = _contrast;
if (_saturation > -100)
saturation = _saturation;
if (result && isFixedExposure)
EnableAutoExposure(waitbeforepicture_org);
return result;
}
void CCamera::SetQualitySize(int qual, framesize_t resol)
{
sensor_t * s = esp_camera_sensor_get();
s->set_quality(s, qual);
s->set_framesize(s, resol);
ActualResolution = resol;
ActualQuality = qual;
if (resol == FRAMESIZE_QVGA)
{
image_height = 240;
image_width = 320;
}
if (resol == FRAMESIZE_VGA)
{
image_height = 480;
image_width = 640;
}
// No higher Mode than VGA, damit der Kameraspeicher ausreicht.
/*
if (resol == FRAMESIZE_SVGA)
{
image_height = 600;
image_width = 800;
}
if (resol == FRAMESIZE_XGA)
{
image_height = 768;
image_width = 1024;
}
if (resol == FRAMESIZE_SXGA)
{
image_height = 1024;
image_width = 1280;
}
if (resol == FRAMESIZE_UXGA)
{
image_height = 1200;
image_width = 1600;
}
*/
}
void CCamera::EnableAutoExposure(int flashdauer)
{
ESP_LOGD(TAG, "EnableAutoExposure");
LEDOnOff(true);
if (flashdauer > 0)
LightOnOff(true);
const TickType_t xDelay = flashdauer / portTICK_PERIOD_MS;
vTaskDelay( xDelay );
camera_fb_t * fb = esp_camera_fb_get();
esp_camera_fb_return(fb);
fb = esp_camera_fb_get();
if (!fb) {
ESP_LOGE(TAG, "Camera Capture Failed");
LEDOnOff(false);
LightOnOff(false);
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Capture Failed (Procedure 'EnableAutoExposure') --> Reboot! "
"Check that your camera module is working and connected properly.");
//doReboot();
}
esp_camera_fb_return(fb);
sensor_t * s = esp_camera_sensor_get();
s->set_gain_ctrl(s, 0);
s->set_exposure_ctrl(s, 0);
LEDOnOff(false);
LightOnOff(false);
isFixedExposure = true;
waitbeforepicture_org = flashdauer;
}
esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay)
{
string ftype;
uint8_t *zwischenspeicher = NULL;
LEDOnOff(true);
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - Start");
#endif
if (delay > 0)
{
LightOnOff(true);
const TickType_t xDelay = delay / portTICK_PERIOD_MS;
vTaskDelay( xDelay );
}
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - After LightOn");
#endif
camera_fb_t * fb = esp_camera_fb_get();
esp_camera_fb_return(fb);
fb = esp_camera_fb_get();
if (!fb) {
ESP_LOGE(TAG, "CaptureToBasisImage: Capture Failed");
LEDOnOff(false);
LightOnOff(false);
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "is not working anymore (CCamera::CaptureToBasisImage) - most probably caused by a hardware problem (instablility, ...). "
"System will reboot.");
doReboot();
return ESP_FAIL;
}
int _size = fb->len;
zwischenspeicher = (uint8_t*) malloc(_size);
if (!zwischenspeicher)
{
ESP_LOGE(TAG, "Insufficient memory space for image in function CaptureToBasisImage()");
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Insufficient memory space for image in function CaptureToBasisImage()");
}
for (int i = 0; i < _size; ++i)
*(zwischenspeicher + i) = *(fb->buf + i);
esp_camera_fb_return(fb);
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - After fb_get");
#endif
LEDOnOff(false);
if (delay > 0)
LightOnOff(false);
// TickType_t xDelay = 1000 / portTICK_PERIOD_MS;
// vTaskDelay( xDelay ); // wait for power to recover
uint8_t * buf = NULL;
CImageBasis _zwImage;
_zwImage.LoadFromMemory(zwischenspeicher, _size);
free(zwischenspeicher);
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - After LoadFromMemory");
#endif
stbi_uc* p_target;
stbi_uc* p_source;
int channels = 3;
int width = image_width;
int height = image_height;
#ifdef DEBUG_DETAIL_ON
std::string _zw = "Targetimage: " + std::to_string((int) _Image->rgb_image) + " Size: " + std::to_string(_Image->width) + ", " + std::to_string(_Image->height);
_zw = _zw + " _zwImage: " + std::to_string((int) _zwImage.rgb_image) + " Size: " + std::to_string(_zwImage.width) + ", " + std::to_string(_zwImage.height);
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, _zw);
#endif
for (int x = 0; x < width; ++x)
for (int y = 0; y < height; ++y)
{
p_target = _Image->rgb_image + (channels * (y * width + x));
p_source = _zwImage.rgb_image + (channels * (y * width + x));
p_target[0] = p_source[0];
p_target[1] = p_source[1];
p_target[2] = p_source[2];
}
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - After Copy To Target");
#endif
free(buf);
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - Done");
#endif
return ESP_OK;
}
esp_err_t CCamera::CaptureToFile(std::string nm, int delay)
{
string ftype;
LEDOnOff(true); // Abgeschaltet, um Strom zu sparen !!!!!!
if (delay > 0)
{
LightOnOff(true);
const TickType_t xDelay = delay / portTICK_PERIOD_MS;
vTaskDelay( xDelay );
}
camera_fb_t * fb = esp_camera_fb_get();
esp_camera_fb_return(fb);
fb = esp_camera_fb_get();
if (!fb) {
ESP_LOGE(TAG, "CaptureToFile: Camera Capture Failed");
LEDOnOff(false);
LightOnOff(false);
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Capture Failed (CCamera::CaptureToFile) --> Reboot! "
"Check that your camera module is working and connected properly.");
//doReboot();
return ESP_FAIL;
}
LEDOnOff(false);
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "w %d, h %d, size %d", fb->width, fb->height, fb->len);
#endif
nm = FormatFileName(nm);
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "Save Camera to : %s", nm.c_str());
#endif
ftype = toUpper(getFileType(nm));
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "Filetype: %s", ftype.c_str());
#endif
uint8_t * buf = NULL;
size_t buf_len = 0;
bool converted = false;
if (ftype.compare("BMP") == 0)
{
frame2bmp(fb, &buf, &buf_len);
converted = true;
}
if (ftype.compare("JPG") == 0)
{
if(fb->format != PIXFORMAT_JPEG){
bool jpeg_converted = frame2jpg(fb, ActualQuality, &buf, &buf_len);
converted = true;
if(!jpeg_converted){
ESP_LOGE(TAG, "JPEG compression failed");
}
} else {
buf_len = fb->len;
buf = fb->buf;
}
}
FILE * fp = OpenFileAndWait(nm.c_str(), "wb");
if (fp == NULL) /* If an error occurs during the file creation */
{
fprintf(stderr, "fopen() failed for '%s'\n", nm.c_str());
}
else
{
fwrite(buf, sizeof(uint8_t), buf_len, fp);
fclose(fp);
}
if (converted)
free(buf);
esp_camera_fb_return(fb);
if (delay > 0)
{
LightOnOff(false);
}
return ESP_OK;
}
esp_err_t CCamera::CaptureToHTTP(httpd_req_t *req, int delay)
{
camera_fb_t * fb = NULL;
esp_err_t res = ESP_OK;
size_t fb_len = 0;
int64_t fr_start = esp_timer_get_time();
LEDOnOff(true);
if (delay > 0)
{
LightOnOff(true);
const TickType_t xDelay = delay / portTICK_PERIOD_MS;
vTaskDelay( xDelay );
}
fb = esp_camera_fb_get();
esp_camera_fb_return(fb);
fb = esp_camera_fb_get();
if (!fb) {
ESP_LOGE(TAG, "Camera capture failed");
LEDOnOff(false);
LightOnOff(false);
httpd_resp_send_500(req);
// doReboot();
return ESP_FAIL;
}
LEDOnOff(false);
res = httpd_resp_set_type(req, "image/jpeg");
if(res == ESP_OK){
res = httpd_resp_set_hdr(req, "Content-Disposition", "inline; filename=raw.jpg");
}
if(res == ESP_OK){
if(fb->format == PIXFORMAT_JPEG){
fb_len = fb->len;
res = httpd_resp_send(req, (const char *)fb->buf, fb->len);
} else {
jpg_chunking_t jchunk = {req, 0};
res = frame2jpg_cb(fb, 80, jpg_encode_stream, &jchunk)?ESP_OK:ESP_FAIL;
httpd_resp_send_chunk(req, NULL, 0);
fb_len = jchunk.len;
}
}
esp_camera_fb_return(fb);
int64_t fr_end = esp_timer_get_time();
ESP_LOGI(TAG, "JPG: %uKB %ums", (uint32_t)(fb_len/1024), (uint32_t)((fr_end - fr_start)/1000));
if (delay > 0)
{
LightOnOff(false);
}
return res;
}
void CCamera::LightOnOff(bool status)
{
GpioHandler* gpioHandler = gpio_handler_get();
if ((gpioHandler != NULL) && (gpioHandler->isEnabled())) {
ESP_LOGD(TAG, "Use gpioHandler flashLigh");
gpioHandler->flashLightEnable(status);
} else {
#ifdef USE_PWM_LEDFLASH
if (status)
{
ESP_LOGD(TAG, "Internal Flash-LED turn on with PWM %d", led_intensity);
ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, led_intensity));
// Update duty to apply the new value
ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
}
else
{
ESP_LOGD(TAG, "Internal Flash-LED turn off PWM");
ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, 0));
ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
}
#else
// Init the GPIO
gpio_pad_select_gpio(FLASH_GPIO);
// Set the GPIO as a push/pull output
gpio_set_direction(FLASH_GPIO, GPIO_MODE_OUTPUT);
if (status)
gpio_set_level(FLASH_GPIO, 1);
else
gpio_set_level(FLASH_GPIO, 0);
#endif
}
}
void CCamera::LEDOnOff(bool status)
{
// Init the GPIO
gpio_pad_select_gpio(BLINK_GPIO);
/* Set the GPIO as a push/pull output */
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
if (!status)
gpio_set_level(BLINK_GPIO, 1);
else
gpio_set_level(BLINK_GPIO, 0);
}
void CCamera::GetCameraParameter(httpd_req_t *req, int &qual, framesize_t &resol)
{
char _query[100];
char _qual[10];
char _size[10];
resol = ActualResolution;
qual = ActualQuality;
if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
{
ESP_LOGD(TAG, "Query: %s", _query);
if (httpd_query_key_value(_query, "size", _size, 10) == ESP_OK)
{
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "Size: %s", _size);
#endif
if (strcmp(_size, "QVGA") == 0)
resol = FRAMESIZE_QVGA; // 320x240
if (strcmp(_size, "VGA") == 0)
resol = FRAMESIZE_VGA; // 640x480
if (strcmp(_size, "SVGA") == 0)
resol = FRAMESIZE_SVGA; // 800x600
if (strcmp(_size, "XGA") == 0)
resol = FRAMESIZE_XGA; // 1024x768
if (strcmp(_size, "SXGA") == 0)
resol = FRAMESIZE_SXGA; // 1280x1024
if (strcmp(_size, "UXGA") == 0)
resol = FRAMESIZE_UXGA; // 1600x1200
}
if (httpd_query_key_value(_query, "quality", _qual, 10) == ESP_OK)
{
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "Quality: %s", _qual);
#endif
qual = atoi(_qual);
if (qual > 63)
qual = 63;
if (qual < 0)
qual = 0;
}
};
}
framesize_t CCamera::TextToFramesize(const char * _size)
{
if (strcmp(_size, "QVGA") == 0)
return FRAMESIZE_QVGA; // 320x240
if (strcmp(_size, "VGA") == 0)
return FRAMESIZE_VGA; // 640x480
if (strcmp(_size, "SVGA") == 0)
return FRAMESIZE_SVGA; // 800x600
if (strcmp(_size, "XGA") == 0)
return FRAMESIZE_XGA; // 1024x768
if (strcmp(_size, "SXGA") == 0)
return FRAMESIZE_SXGA; // 1280x1024
if (strcmp(_size, "UXGA") == 0)
return FRAMESIZE_UXGA; // 1600x1200
return ActualResolution;
}
CCamera::CCamera()
{
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "CreateClassCamera");
#endif
brightness = -5;
contrast = -5;
saturation = -5;
isFixedExposure = false;
ledc_init();
}
esp_err_t CCamera::InitCam()
{
ESP_LOGD(TAG, "Init Camera");
ActualQuality = camera_config.jpeg_quality;
ActualResolution = camera_config.frame_size;
//initialize the camera
esp_err_t err = esp_camera_init(&camera_config);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Camera Init Failed");
return err;
}
return ESP_OK;
}
void CCamera::SetLEDIntensity(float _intrel)
{
_intrel = min(_intrel, (float) 100);
_intrel = max(_intrel, (float) 0);
_intrel = _intrel / 100;
led_intensity = (int) (_intrel * 8191);
ESP_LOGD(TAG, "Set led_intensity to %d of 8191", led_intensity);
}

View File

@@ -9,38 +9,48 @@
#include "esp_camera.h"
#include <string>
#include "esp_http_server.h"
#include <esp_http_server.h>
#include "CImageBasis.h"
#define CAMERA_MODEL_AI_THINKER
static const char *TAGCAMERACLASS = "server_part_camera";
class CCamera {
protected:
int ActualQuality;
framesize_t ActualResolution;
int brightness, contrast, saturation;
bool isFixedExposure;
int waitbeforepicture_org;
int led_intensity = 4095;
void ledc_init(void);
public:
int image_height, image_width;
CCamera();
esp_err_t InitCam();
void LightOnOff(bool status);
void LEDOnOff(bool status);
esp_err_t CaptureToHTTP(httpd_req_t *req, int delay = 0);
void SetQualitySize(int qual, framesize_t resol);
bool SetBrightnessContrastSaturation(int _brightness, int _contrast, int _saturation);
void GetCameraParameter(httpd_req_t *req, int &qual, framesize_t &resol);
void SetLEDIntensity(float _intrel);
void EnableAutoExposure(int flashdauer);
framesize_t TextToFramesize(const char * text);
esp_err_t CaptureToFile(std::string nm, int delay = 0);
esp_err_t CaptureToBasisImage(CImageBasis *_Image, int delay = 0);
};
extern CCamera Camera;
#endif

View File

@@ -11,11 +11,48 @@
#include <stdint.h>
#include <stdbool.h>
#define OV9650_PID (0x96)
#define OV7725_PID (0x77)
#define OV2640_PID (0x26)
#define OV3660_PID (0x36)
#define OV5640_PID (0x56)
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
OV9650_PID = 0x96,
OV7725_PID = 0x77,
OV2640_PID = 0x26,
OV3660_PID = 0x3660,
OV5640_PID = 0x5640,
OV7670_PID = 0x76,
NT99141_PID = 0x1410,
GC2145_PID = 0x2145,
GC032A_PID = 0x232a,
GC0308_PID = 0x9b,
} camera_pid_t;
typedef enum {
CAMERA_OV7725,
CAMERA_OV2640,
CAMERA_OV3660,
CAMERA_OV5640,
CAMERA_OV7670,
CAMERA_NT99141,
CAMERA_GC2145,
CAMERA_GC032A,
CAMERA_GC0308,
CAMERA_MODEL_MAX,
CAMERA_NONE,
} camera_model_t;
typedef enum {
OV2640_SCCB_ADDR = 0x30,// 0x60 >> 1
OV5640_SCCB_ADDR = 0x3C,// 0x78 >> 1
OV3660_SCCB_ADDR = 0x3C,// 0x78 >> 1
OV7725_SCCB_ADDR = 0x21,// 0x42 >> 1
OV7670_SCCB_ADDR = 0x21,// 0x42 >> 1
NT99141_SCCB_ADDR = 0x2A,// 0x54 >> 1
GC2145_SCCB_ADDR = 0x3C,// 0x78 >> 1
GC032A_SCCB_ADDR = 0x21,// 0x42 >> 1
GC0308_SCCB_ADDR = 0x21,// 0x42 >> 1
} camera_sccb_addr_t;
typedef enum {
PIXFORMAT_RGB565, // 2BPP/RGB565
@@ -56,6 +93,15 @@ typedef enum {
FRAMESIZE_INVALID
} framesize_t;
typedef struct {
const camera_model_t model;
const char *name;
const camera_sccb_addr_t sccb_addr;
const camera_pid_t pid;
const framesize_t max_size;
const bool support_jpeg;
} camera_sensor_info_t;
typedef enum {
ASPECT_RATIO_4X3,
ASPECT_RATIO_3X2,
@@ -99,11 +145,13 @@ typedef struct {
// Resolution table (in sensor.c)
extern const resolution_info_t resolution[];
// camera sensor table (in sensor.c)
extern const camera_sensor_info_t camera_sensor[];
typedef struct {
uint8_t MIDH;
uint8_t MIDL;
uint8_t PID;
uint16_t PID;
uint8_t VER;
} sensor_id_t;
@@ -188,4 +236,10 @@ typedef struct _sensor {
int (*set_xclk) (sensor_t *sensor, int timer, int xclk);
} sensor_t;
camera_sensor_info_t *esp_camera_sensor_get_info(sensor_id_t *id);
#ifdef __cplusplus
}
#endif
#endif /* __SENSOR_H__ */

View File

@@ -7,16 +7,24 @@
#include "ClassControllCamera.h"
#include "ClassLogFile.h"
#include "esp_log.h"
static const char *TAG = "server_cam";
#define SCRATCH_BUFSIZE2 8192
char scratch2[SCRATCH_BUFSIZE2];
//#define DEBUG_DETAIL_ON
void PowerResetCamera(){
ESP_LOGD(TAGPARTCAMERA, "Resetting camera by power down line");
gpio_config_t conf = { 0 };
ESP_LOGD(TAG, "Resetting camera by power down line");
gpio_config_t conf;
conf.intr_type = GPIO_INTR_DISABLE;
conf.pin_bit_mask = 1LL << GPIO_NUM_32;
conf.mode = GPIO_MODE_OUTPUT;
conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
conf.pull_up_en = GPIO_PULLUP_DISABLE;
gpio_config(&conf);
// carefull, logic is inverted compared to reset pin
@@ -29,43 +37,72 @@ void PowerResetCamera(){
esp_err_t handler_lightOn(httpd_req_t *req)
{
LogFile.WriteToFile("handler_lightOn");
printf("handler_lightOn uri:\n"); printf(req->uri); printf("\n");
#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));
httpd_resp_send(req, resp_str, strlen(resp_str));
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_lightOn - Done");
#endif
return ESP_OK;
};
esp_err_t handler_lightOff(httpd_req_t *req)
{
LogFile.WriteToFile("handler_lightOff");
printf("handler_lightOff uri:\n"); printf(req->uri); printf("\n");
#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 - Done");
#endif
return ESP_OK;
};
esp_err_t handler_capture(httpd_req_t *req)
{
LogFile.WriteToFile("handler_capture");
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_capture - Start");
#endif
int quality;
framesize_t res;
Camera.GetCameraParameter(req, quality, res);
printf("Size: %d", res); printf(" Quality: %d\n", quality);
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "Size: %d, Quality: %d", res, quality);
#endif
Camera.SetQualitySize(quality, res);
esp_err_t ressult;
ressult = Camera.CaptureToHTTP(req);
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_capture - Done");
#endif
return ressult;
};
esp_err_t handler_capture_with_ligth(httpd_req_t *req)
{
LogFile.WriteToFile("handler_capture_with_ligth");
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_capture_with_ligth - Start");
#endif
char _query[100];
char _delay[10];
@@ -75,10 +112,12 @@ esp_err_t handler_capture_with_ligth(httpd_req_t *req)
if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
{
printf("Query: "); printf(_query); printf("\n");
ESP_LOGD(TAG, "Query: %s", _query);
if (httpd_query_key_value(_query, "delay", _delay, 10) == ESP_OK)
{
printf("Delay: "); printf(_delay); printf("\n");
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "Delay: %s", _delay);
#endif
delay = atoi(_delay);
if (delay < 0)
@@ -87,9 +126,12 @@ esp_err_t handler_capture_with_ligth(httpd_req_t *req)
};
Camera.GetCameraParameter(req, quality, res);
printf("Size: %d", res); printf(" Quality: %d\n", quality);
Camera.SetQualitySize(quality, res);
#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 );
@@ -98,7 +140,11 @@ esp_err_t handler_capture_with_ligth(httpd_req_t *req)
ressult = Camera.CaptureToHTTP(req);
Camera.LightOnOff(false);
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_capture_with_ligth - Done");
#endif
return ressult;
};
@@ -106,7 +152,10 @@ esp_err_t handler_capture_with_ligth(httpd_req_t *req)
esp_err_t handler_capture_save_to_file(httpd_req_t *req)
{
LogFile.WriteToFile("handler_capture_save_to_file");
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_capture_save_to_file - Start");
#endif
char _query[100];
char _delay[10];
int delay = 0;
@@ -119,18 +168,22 @@ esp_err_t handler_capture_save_to_file(httpd_req_t *req)
if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
{
printf("Query: "); printf(_query); printf("\n");
ESP_LOGD(TAG, "Query: %s", _query);
if (httpd_query_key_value(_query, "filename", filename, 100) == ESP_OK)
{
fn.append(filename);
printf("Filename: "); printf(fn.c_str()); printf("\n");
#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)
{
printf("Delay: "); printf(_delay); printf("\n");
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "Delay: %s", _delay);
#endif
delay = atoi(_delay);
if (delay < 0)
@@ -142,7 +195,9 @@ esp_err_t handler_capture_save_to_file(httpd_req_t *req)
fn.append("noname.jpg");
Camera.GetCameraParameter(req, quality, res);
printf("Size: %d", res); printf(" Quality: %d\n", quality);
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "Size: %d, Quality: %d", res, quality);
#endif
Camera.SetQualitySize(quality, res);
esp_err_t ressult;
@@ -151,6 +206,10 @@ esp_err_t handler_capture_save_to_file(httpd_req_t *req)
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;
};
@@ -158,8 +217,10 @@ esp_err_t handler_capture_save_to_file(httpd_req_t *req)
void register_server_camera_uri(httpd_handle_t server)
{
ESP_LOGI(TAGPARTCAMERA, "server_part_camera - Registering URI handlers");
#ifdef DEBUG_DETAIL_ON
ESP_LOGI(TAG, "server_part_camera - Registering URI handlers");
#endif
httpd_uri_t camuri = { };
camuri.method = HTTP_GET;

View File

@@ -7,8 +7,6 @@
//#include "ClassControllCamera.h"
static const char *TAGPARTCAMERA = "server_camera";
void register_server_camera_uri(httpd_handle_t server);
void PowerResetCamera();

View File

@@ -0,0 +1,7 @@
FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
idf_component_register(SRCS ${app_sources}
INCLUDE_DIRS "." "../../include"
REQUIRES tflite-lib esp_http_server app_update esp_http_client nvs_flash jomjol_tfliteclass jomjol_flowcontroll spiffs jomjol_helper jomjol_controlGPIO miniz)

View File

@@ -17,33 +17,51 @@
#include <sys/param.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <dirent.h>
#ifdef __cplusplus
}
#endif
#include "esp_err.h"
#include "esp_log.h"
#include "esp_vfs.h"
#include "esp_spiffs.h"
#include <esp_spiffs.h>
#include "esp_http_server.h"
#include "defines.h"
#include "ClassLogFile.h"
#include "server_tflite.h"
#include "server_help.h"
#include "interface_mqtt.h"
#include "server_GPIO.h"
#include "Helper.h"
#include "miniz.h"
static const char *TAG = "OTA FILE";
/* Max length a file path can have on storage */
// #define FILE_PATH_MAX (ESP_VFS_PATH_MAX + CONFIG_SPIFFS_OBJ_NAME_LEN)
#define FILE_PATH_MAX (255)
/* Max size of an individual file. Make sure this
* value is same as that set in upload_script.html */
#define MAX_FILE_SIZE (2000*1024) // 200 KB
#define MAX_FILE_SIZE_STR "2000KB"
#define MAX_FILE_SIZE (8000*1024) // 8 MB
#define MAX_FILE_SIZE_STR "8MB"
/* Scratch buffer size */
#define SCRATCH_BUFSIZE 8192
#define SCRATCH_BUFSIZE 4096
/* Size of partial log file to return */
#define LOGFILE_LAST_PART_BYTES SCRATCH_BUFSIZE * 20 /* 80 kBytes */
struct file_server_data {
/* Base path of file storage */
@@ -53,38 +71,129 @@ struct file_server_data {
char scratch[SCRATCH_BUFSIZE];
};
static const char *TAG = "file_server";
/* Handler to redirect incoming GET request for /index.html to /
* This can be overridden by uploading file with same name */
static esp_err_t index_html_get_handler(httpd_req_t *req)
#include <iostream>
#include <sys/types.h>
#include <dirent.h>
using namespace std;
string SUFFIX_ZW = "_0xge";
static esp_err_t send_logfile(httpd_req_t *req, bool send_full_file);
static esp_err_t send_datafile(httpd_req_t *req, bool send_full_file);
esp_err_t get_numbers_file_handler(httpd_req_t *req)
{
httpd_resp_set_status(req, "307 Temporary Redirect");
httpd_resp_set_hdr(req, "Location", "/");
httpd_resp_send(req, NULL, 0); // Response body can be empty
std::string ret = tfliteflow.getNumbersName();
// ESP_LOGI(TAG, "Result get_numbers_file_handler: %s", ret.c_str());
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_set_type(req, "text/plain");
httpd_resp_sendstr_chunk(req, ret.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;
}
/* Handler to respond with an icon file embedded in flash.
* Browsers expect to GET website icon at URI /favicon.ico.
* This can be overridden by uploading file with same name */
static esp_err_t favicon_get_handler(httpd_req_t *req)
esp_err_t get_data_file_handler(httpd_req_t *req)
{
extern const unsigned char favicon_ico_start[] asm("_binary_favicon_ico_start");
extern const unsigned char favicon_ico_end[] asm("_binary_favicon_ico_end");
const size_t favicon_ico_size = (favicon_ico_end - favicon_ico_start);
httpd_resp_set_type(req, "image/x-icon");
httpd_resp_send(req, (const char *)favicon_ico_start, favicon_ico_size);
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
struct dirent *entry;
std::string _filename, _fileext;
size_t pos = 0;
const char verz_name[] = "/sdcard/log/data";
ESP_LOGD(TAG, "Suche data files in /sdcard/log/data");
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_set_type(req, "text/plain");
DIR *dir = opendir(verz_name);
while ((entry = readdir(dir)) != NULL)
{
_filename = std::string(entry->d_name);
ESP_LOGD(TAG, "File: %s", _filename.c_str());
// ignore all files with starting dot (hidden files)
if (_filename.rfind(".", 0) == 0) {
continue;
}
_fileext = _filename;
pos = _fileext.find_last_of(".");
if (pos != std::string::npos)
_fileext = _fileext.erase(0, pos + 1);
ESP_LOGD(TAG, " Extension: %s", _fileext.c_str());
if (_fileext == "csv")
{
_filename = _filename + "\t";
httpd_resp_sendstr_chunk(req, _filename.c_str());
}
}
closedir(dir);
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;
}
esp_err_t get_tflite_file_handler(httpd_req_t *req)
{
struct dirent *entry;
std::string _filename, _fileext;
size_t pos = 0;
const char verz_name[] = "/sdcard/config";
ESP_LOGD(TAG, "Suche TFLITE in /sdcard/config/");
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_set_type(req, "text/plain");
DIR *dir = opendir(verz_name);
while ((entry = readdir(dir)) != NULL)
{
_filename = std::string(entry->d_name);
ESP_LOGD(TAG, "File: %s", _filename.c_str());
// ignore all files with starting dot (hidden files)
if (_filename.rfind(".", 0) == 0) {
continue;
}
_fileext = _filename;
pos = _fileext.find_last_of(".");
if (pos != std::string::npos)
_fileext = _fileext.erase(0, pos + 1);
ESP_LOGD(TAG, " Extension: %s", _fileext.c_str());
if ((_fileext == "tfl") || (_fileext == "tflite"))
{
_filename = "/config/" + _filename + "\t";
httpd_resp_sendstr_chunk(req, _filename.c_str());
}
}
closedir(dir);
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;
}
/* Send HTTP response with a run-time generated html consisting of
* a list of all files and folders under the requested path.
* In case of SPIFFS this returns empty list when path is any
* string other than '/', since SPIFFS doesn't support directories */
static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath)
static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const char* uripath, bool readonly)
{
char entrypath[FILE_PATH_MAX];
char entrysize[16];
@@ -103,11 +212,11 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath)
DIR *dir = opendir(dirpath_corrected);
const size_t dirpath_len = strlen(dirpath);
printf("Dirpath: <%s>, Pathlength: %d\n", dirpath, dirpath_len);
ESP_LOGD(TAG, "Dirpath: <%s>, Pathlength: %d", dirpath, dirpath_len);
/* Retrieve the base path of file storage to construct the full path */
strlcpy(entrypath, dirpath, sizeof(entrypath));
printf("entrypath: <%s>\n", entrypath);
ESP_LOGD(TAG, "entrypath: <%s>", entrypath);
if (!dir) {
ESP_LOGE(TAG, "Failed to stat dir : %s", dirpath);
@@ -120,24 +229,24 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath)
httpd_resp_sendstr_chunk(req, "<!DOCTYPE html><html><body>");
/////////////////////////////////////////////////
FILE *fd = fopen("/sdcard/html/upload_script.html", "r");
char *chunk = ((struct file_server_data *)req->user_ctx)->scratch;
size_t chunksize;
do {
chunksize = fread(chunk, 1, SCRATCH_BUFSIZE, fd);
// printf("Chunksize %d\n", chunksize);
if (chunksize > 0){
if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) {
fclose(fd);
ESP_LOGE(TAG, "File sending failed!");
return ESP_FAIL;
if (!readonly) {
FILE *fd = OpenFileAndWait("/sdcard/html/upload_script.html", "r");
char *chunk = ((struct file_server_data *)req->user_ctx)->scratch;
size_t chunksize;
do {
chunksize = fread(chunk, 1, SCRATCH_BUFSIZE, fd);
// ESP_LOGD(TAG, "Chunksize %d", chunksize);
if (chunksize > 0){
if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) {
fclose(fd);
ESP_LOGE(TAG, "File sending failed!");
return ESP_FAIL;
}
}
}
} while (chunksize != 0);
fclose(fd);
// ESP_LOGI(TAG, "File sending complete");
} while (chunksize != 0);
fclose(fd);
// ESP_LOGI(TAG, "File sending complete");
}
///////////////////////////////
std::string _zw = std::string(dirpath);
@@ -149,12 +258,16 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath)
httpd_resp_sendstr_chunk(req,
"<table class=\"fixed\" border=\"1\">"
"<col width=\"800px\" /><col width=\"300px\" /><col width=\"300px\" /><col width=\"100px\" />"
"<thead><tr><th>Name</th><th>Type</th><th>Size (Bytes)</th><th>Delete<br>"
"<form method=\"post\" action=\"");
httpd_resp_sendstr_chunk(req, _zw.c_str());
httpd_resp_sendstr_chunk(req,
"\"><button type=\"submit\">DELETE ALL!</button></form>"
"</th></tr></thead><tbody>\n");
"<thead><tr><th>Name</th><th>Type</th><th>Size (Bytes)</th>");
if (!readonly) {
httpd_resp_sendstr_chunk(req, "<th>Delete<br>"
"<form method=\"post\" action=\"");
httpd_resp_sendstr_chunk(req, _zw.c_str());
httpd_resp_sendstr_chunk(req,
"\"><button type=\"submit\">DELETE ALL!</button></form>"
"</th></tr>");
}
httpd_resp_sendstr_chunk(req, "</thead><tbody>\n");
/* Iterate over all files / folders and fetch their names and sizes */
while ((entry = readdir(dir)) != NULL) {
@@ -163,7 +276,7 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath)
entrytype = (entry->d_type == DT_DIR ? "directory" : "file");
strlcpy(entrypath + dirpath_len, entry->d_name, sizeof(entrypath) - dirpath_len);
printf("Entrypath: %s\n", entrypath);
ESP_LOGD(TAG, "Entrypath: %s", entrypath);
if (stat(entrypath, &entry_stat) == -1) {
ESP_LOGE(TAG, "Failed to stat %s : %s", entrytype, entry->d_name);
continue;
@@ -173,7 +286,8 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath)
/* Send chunk of HTML file containing table entries with file name and size */
httpd_resp_sendstr_chunk(req, "<tr><td><a href=\"");
httpd_resp_sendstr_chunk(req, req->uri);
httpd_resp_sendstr_chunk(req, "/fileserver");
httpd_resp_sendstr_chunk(req, uripath);
httpd_resp_sendstr_chunk(req, entry->d_name);
if (entry->d_type == DT_DIR) {
httpd_resp_sendstr_chunk(req, "/");
@@ -184,11 +298,13 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath)
httpd_resp_sendstr_chunk(req, entrytype);
httpd_resp_sendstr_chunk(req, "</td><td>");
httpd_resp_sendstr_chunk(req, entrysize);
httpd_resp_sendstr_chunk(req, "</td><td>");
httpd_resp_sendstr_chunk(req, "<form method=\"post\" action=\"/delete");
httpd_resp_sendstr_chunk(req, req->uri + strlen("/fileserver"));
httpd_resp_sendstr_chunk(req, entry->d_name);
httpd_resp_sendstr_chunk(req, "\"><button type=\"submit\">Delete</button></form>");
if (!readonly) {
httpd_resp_sendstr_chunk(req, "</td><td>");
httpd_resp_sendstr_chunk(req, "<form method=\"post\" action=\"/delete");
httpd_resp_sendstr_chunk(req, uripath);
httpd_resp_sendstr_chunk(req, entry->d_name);
httpd_resp_sendstr_chunk(req, "\"><button type=\"submit\">Delete</button></form>");
}
httpd_resp_sendstr_chunk(req, "</td></tr>\n");
}
}
@@ -209,48 +325,41 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath)
(strcasecmp(&filename[strlen(filename) - sizeof(ext) + 1], ext) == 0)
/* Handler to download a file kept on the server */
static esp_err_t download_get_handler(httpd_req_t *req)
static esp_err_t logfileact_get_full_handler(httpd_req_t *req) {
return send_logfile(req, true);
}
static esp_err_t logfileact_get_last_part_handler(httpd_req_t *req) {
return send_logfile(req, false);
}
static esp_err_t datafileact_get_full_handler(httpd_req_t *req) {
return send_datafile(req, true);
}
static esp_err_t datafileact_get_last_part_handler(httpd_req_t *req) {
return send_datafile(req, false);
}
static esp_err_t send_datafile(httpd_req_t *req, bool send_full_file)
{
LogFile.WriteToFile("download_get_handler");
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "data_get_last_part_handler");
char filepath[FILE_PATH_MAX];
FILE *fd = NULL;
struct stat file_stat;
printf("uri: %s\n", req->uri);
//struct stat file_stat;
ESP_LOGD(TAG, "uri: %s", req->uri);
const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path,
req->uri + sizeof("/fileserver") - 1, sizeof(filepath));
const char* filename = "";
printf("uri: %s, filename: %s, filepath: %s\n", req->uri, filename, filepath);
std::string currentfilename = LogFile.GetCurrentFileNameData();
// filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path,
// req->uri, sizeof(filepath));
ESP_LOGD(TAG, "uri: %s, filename: %s, filepath: %s", req->uri, filename, filepath);
if (!filename) {
ESP_LOGE(TAG, "Filename is too long");
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Filename too long");
return ESP_FAIL;
}
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
/* If name has trailing '/', respond with directory contents */
if (filename[strlen(filename) - 1] == '/') {
return http_resp_dir_html(req, filepath);
}
std::string testwlan = toUpper(std::string(filename));
if ((stat(filepath, &file_stat) == -1) || (testwlan.compare("/WLAN.INI") == 0 )) { // wlan.ini soll nicht angezeigt werden!
/* If file not present on SPIFFS check if URI
* corresponds to one of the hardcoded paths */
ESP_LOGE(TAG, "Failed to stat file : %s", filepath);
/* Respond with 404 Not Found */
httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, "File does not exist");
return ESP_FAIL;
}
fd = fopen(filepath, "r");
fd = OpenFileAndWait(currentfilename.c_str(), "r");
if (!fd) {
ESP_LOGE(TAG, "Failed to read existing file : %s", filepath);
/* Respond with 500 Internal Server Error */
@@ -258,11 +367,37 @@ static esp_err_t download_get_handler(httpd_req_t *req)
return ESP_FAIL;
}
esp_err_t res = httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
ESP_LOGI(TAG, "Sending file : %s (%ld bytes)...", filename, file_stat.st_size);
// ESP_LOGI(TAG, "Sending file : %s (%ld bytes)...", &filename, file_stat.st_size);
set_content_type_from_file(req, filename);
if (!send_full_file) { // Send only last part of file
ESP_LOGD(TAG, "Sending last %d bytes of the actual datafile!", LOGFILE_LAST_PART_BYTES);
/* Adapted from https://www.geeksforgeeks.org/implement-your-own-tail-read-last-n-lines-of-a-huge-file/ */
if (fseek(fd, 0, SEEK_END)) {
ESP_LOGE(TAG, "Failed to get to end of file!");
return ESP_FAIL;
}
else {
long pos = ftell(fd); // Number of bytes in the file
ESP_LOGI(TAG, "File contains %ld bytes", pos);
if (fseek(fd, pos - std::min((long)LOGFILE_LAST_PART_BYTES, pos), SEEK_SET)) { // Go LOGFILE_LAST_PART_BYTES bytes back from EOF
ESP_LOGE(TAG, "Failed to go back %ld bytes within the file!", std::min((long)LOGFILE_LAST_PART_BYTES, pos));
return ESP_FAIL;
}
}
/* Find end of line */
while (1) {
if (fgetc(fd) == '\n') {
break;
}
}
}
/* Retrieve the pointer to scratch buffer for temporary storage */
char *chunk = ((struct file_server_data *)req->user_ctx)->scratch;
size_t chunksize;
@@ -293,10 +428,197 @@ static esp_err_t download_get_handler(httpd_req_t *req)
return ESP_OK;
}
static esp_err_t send_logfile(httpd_req_t *req, bool send_full_file)
{
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "log_get_last_part_handler");
char filepath[FILE_PATH_MAX];
FILE *fd = NULL;
//struct stat file_stat;
ESP_LOGI(TAG, "uri: %s", req->uri);
const char* filename = "";
std::string currentfilename = LogFile.GetCurrentFileName();
ESP_LOGD(TAG, "uri: %s, filename: %s, filepath: %s", req->uri, filename, filepath);
fd = OpenFileAndWait(currentfilename.c_str(), "r");
if (!fd) {
ESP_LOGE(TAG, "Failed to read existing file : %s", filepath);
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to read existing file");
return ESP_FAIL;
}
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
// ESP_LOGI(TAG, "Sending file : %s (%ld bytes)...", &filename, file_stat.st_size);
set_content_type_from_file(req, filename);
if (!send_full_file) { // Send only last part of file
ESP_LOGD(TAG, "Sending last %d bytes of the actual logfile!", LOGFILE_LAST_PART_BYTES);
/* Adapted from https://www.geeksforgeeks.org/implement-your-own-tail-read-last-n-lines-of-a-huge-file/ */
if (fseek(fd, 0, SEEK_END)) {
ESP_LOGE(TAG, "Failed to get to end of file!");
return ESP_FAIL;
}
else {
long pos = ftell(fd); // Number of bytes in the file
ESP_LOGI(TAG, "File contains %ld bytes", pos);
if (fseek(fd, pos - std::min((long)LOGFILE_LAST_PART_BYTES, pos), SEEK_SET)) { // Go LOGFILE_LAST_PART_BYTES bytes back from EOF
ESP_LOGE(TAG, "Failed to go back %ld bytes within the file!", std::min((long)LOGFILE_LAST_PART_BYTES, pos));
return ESP_FAIL;
}
}
/* Find end of line */
while (1) {
if (fgetc(fd) == '\n') {
break;
}
}
}
/* Retrieve the pointer to scratch buffer for temporary storage */
char *chunk = ((struct file_server_data *)req->user_ctx)->scratch;
size_t chunksize;
do {
/* Read file in chunks into the scratch buffer */
chunksize = fread(chunk, 1, SCRATCH_BUFSIZE, fd);
/* Send the buffer contents as HTTP response chunk */
if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) {
fclose(fd);
ESP_LOGE(TAG, "File sending failed!");
/* Abort sending file */
httpd_resp_sendstr_chunk(req, NULL);
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to send file");
return ESP_FAIL;
}
/* Keep looping till the whole file is sent */
} while (chunksize != 0);
/* Close file after sending complete */
fclose(fd);
ESP_LOGI(TAG, "File sending complete");
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
return ESP_OK;
}
/* Handler to download a file kept on the server */
static esp_err_t download_get_handler(httpd_req_t *req)
{
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "download_get_handler");
char filepath[FILE_PATH_MAX];
FILE *fd = NULL;
struct stat file_stat;
ESP_LOGD(TAG, "uri: %s", req->uri);
const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path,
req->uri + sizeof("/fileserver") - 1, sizeof(filepath));
ESP_LOGD(TAG, "uri: %s, filename: %s, filepath: %s", req->uri, filename, filepath);
// filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path,
// req->uri, sizeof(filepath));
if (!filename) {
ESP_LOGE(TAG, "Filename is too long");
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Filename too long");
return ESP_FAIL;
}
/* If name has trailing '/', respond with directory contents */
if (filename[strlen(filename) - 1] == '/') {
bool readonly = false;
size_t buf_len = httpd_req_get_url_query_len(req) + 1;
if (buf_len > 1) {
char buf[buf_len];
if (httpd_req_get_url_query_str(req, buf, buf_len) == ESP_OK) {
ESP_LOGI(TAG, "Found URL query => %s", buf);
char param[32];
/* Get value of expected key from query string */
if (httpd_query_key_value(buf, "readonly", param, sizeof(param)) == ESP_OK) {
ESP_LOGI(TAG, "Found URL query parameter => readonly=%s", param);
readonly = param && strcmp(param,"true")==0;
}
}
}
ESP_LOGD(TAG, "uri: %s, filename: %s, filepath: %s", req->uri, filename, filepath);
return http_resp_dir_html(req, filepath, filename, readonly);
}
std::string testwlan = toUpper(std::string(filename));
if ((stat(filepath, &file_stat) == -1) || (testwlan.compare("/WLAN.INI") == 0 )) { // wlan.ini soll nicht angezeigt werden!
/* If file not present on SPIFFS check if URI
* corresponds to one of the hardcoded paths */
ESP_LOGE(TAG, "Failed to stat file : %s", filepath);
/* Respond with 404 Not Found */
httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, "File does not exist");
return ESP_FAIL;
}
fd = OpenFileAndWait(filepath, "r");
if (!fd) {
ESP_LOGE(TAG, "Failed to read existing file : %s", filepath);
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to read existing file");
return ESP_FAIL;
}
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
ESP_LOGI(TAG, "Sending file : %s (%ld bytes)...", filename, file_stat.st_size);
set_content_type_from_file(req, filename);
/* Retrieve the pointer to scratch buffer for temporary storage */
char *chunk = ((struct file_server_data *)req->user_ctx)->scratch;
size_t chunksize;
do {
/* Read file in chunks into the scratch buffer */
chunksize = fread(chunk, 1, SCRATCH_BUFSIZE, fd);
/* Send the buffer contents as HTTP response chunk */
if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) {
fclose(fd);
ESP_LOGE(TAG, "File sending failed!");
/* Abort sending file */
httpd_resp_sendstr_chunk(req, NULL);
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to send file");
return ESP_FAIL;
}
/* Keep looping till the whole file is sent */
} while (chunksize != 0);
/* Close file after sending complete */
fclose(fd);
ESP_LOGI(TAG, "File successfully sent");
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
return ESP_OK;
}
/* Handler to upload a file onto the server */
static esp_err_t upload_post_handler(httpd_req_t *req)
{
LogFile.WriteToFile("upload_post_handler");
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "upload_post_handler");
char filepath[FILE_PATH_MAX];
FILE *fd = NULL;
struct stat file_stat;
@@ -337,7 +659,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
return ESP_FAIL;
}
fd = fopen(filepath, "w");
fd = OpenFileAndWait(filepath, "w");
if (!fd) {
ESP_LOGE(TAG, "Failed to create file : %s", filepath);
/* Respond with 500 Internal Server Error */
@@ -409,12 +731,10 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
}
int start_fn = strlen(((struct file_server_data *)req->user_ctx)->base_path);
printf("Directory: %s, start_fn: %d, found: %d\n", directory.c_str(), start_fn, found);
ESP_LOGD(TAG, "Directory: %s, start_fn: %d, found: %d", directory.c_str(), start_fn, found);
directory = directory.substr(start_fn, found - start_fn + 1);
printf("Directory danach: %s\n", directory.c_str());
directory = "/fileserver" + directory;
printf("Directory danach: %s\n", directory.c_str());
// ESP_LOGD(TAG, "Directory danach 2: %s", directory.c_str());
/* Redirect onto root to see the updated file list */
httpd_resp_set_status(req, "303 See Other");
@@ -424,20 +744,28 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
httpd_resp_set_status(req, "303 See Other");
httpd_resp_set_hdr(req, "Location", directory.c_str());
httpd_resp_sendstr(req, "File uploaded successfully");
/*
if (strcmp(filepath, CONFIG_FILE) == 0) {
ESP_LOGD(TAG, "New config found. Reload handler.");
gpio_handler_deinit();
MQTTdestroy();
}
*/
return ESP_OK;
}
/* Handler to delete a file from the server */
static esp_err_t delete_post_handler(httpd_req_t *req)
{
LogFile.WriteToFile("delete_post_handler");
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "delete_post_handler");
char filepath[FILE_PATH_MAX];
struct stat file_stat;
//////////////////////////////////////////////////////////////
char _query[200];
char _filename[30];
char _valuechar[30];
std::string fn = "/sdcard/firmware/";
std::string _task;
@@ -446,11 +774,11 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK)
{
printf("Query: "); printf(_query); printf("\n");
ESP_LOGD(TAG, "Query: %s", _query);
if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK)
{
printf("task is found: "); printf(_valuechar); printf("\n");
ESP_LOGD(TAG, "task is found: %s", _valuechar);
_task = std::string(_valuechar);
}
}
@@ -470,12 +798,12 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
zw = zw.substr(0, zw.length()-1);
directory = "/fileserver" + zw + "/";
zw = "/sdcard" + zw;
printf("Directory to delete: %s\n", zw.c_str());
ESP_LOGD(TAG, "Directory to delete: %s", zw.c_str());
delete_all_in_directory(zw);
// directory = std::string(filepath);
// directory = "/fileserver" + directory;
printf("Location after delete directory content: %s\n", directory.c_str());
ESP_LOGD(TAG, "Location after delete directory content: %s", directory.c_str());
/* Redirect onto root to see the updated file list */
// httpd_resp_set_status(req, "303 See Other");
// httpd_resp_set_hdr(req, "Location", directory.c_str());
@@ -523,12 +851,10 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
}
int start_fn = strlen(((struct file_server_data *)req->user_ctx)->base_path);
printf("Directory: %s, start_fn: %d, found: %d\n", directory.c_str(), start_fn, found);
ESP_LOGD(TAG, "Directory: %s, start_fn: %d, found: %d", directory.c_str(), start_fn, found);
directory = directory.substr(start_fn, found - start_fn + 1);
printf("Directory danach: %s\n", directory.c_str());
directory = "/fileserver" + directory;
printf("Directory danach: %s\n", directory.c_str());
ESP_LOGD(TAG, "Directory danach 4: %s", directory.c_str());
}
@@ -540,7 +866,7 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
/* Redirect onto root to see the updated file list */
httpd_resp_set_status(req, "303 See Other");
httpd_resp_set_hdr(req, "Location", directory.c_str());
httpd_resp_sendstr(req, "File deleted successfully");
httpd_resp_sendstr(req, "File successfully deleted");
return ESP_OK;
}
@@ -570,28 +896,156 @@ void delete_all_in_directory(std::string _directory)
closedir(dir);
}
void unzip(std::string _in_zip_file, std::string _target_directory){
std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::string _target_bin, std::string _main)
{
int i, sort_iter;
mz_bool status;
size_t uncomp_size;
mz_zip_archive zip_archive;
void* p;
const int N = 50;
char data[2048];
char archive_filename[64];
std::string zw;
std::string zw, ret = "";
std::string directory = "";
// static const char* s_Test_archive_filename = "testhtml.zip";
printf("miniz.c version: %s\n", MZ_VERSION);
printf("Zipfile: %s\n", _in_zip_file.c_str());
printf("Target Dir: %s\n", _target_directory.c_str());
ESP_LOGD(TAG, "miniz.c version: %s", MZ_VERSION);
ESP_LOGD(TAG, "Zipfile: %s", _in_zip_file.c_str());
// ESP_LOGD(TAG, "Target Dir ZIP: %s", _target_zip.c_str());
// ESP_LOGD(TAG, "Target Dir BIN: %s", _target_bin.c_str());
// ESP_LOGD(TAG, "Target Dir main: %s", _main.c_str());
// Now try to open the archive.
memset(&zip_archive, 0, sizeof(zip_archive));
status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), 0);
if (!status)
{
printf("mz_zip_reader_init_file() failed!\n");
ESP_LOGD(TAG, "mz_zip_reader_init_file() failed!");
return ret;
}
// 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++)
{
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);
if (!status)
{
ESP_LOGD(TAG, "mz_zip_reader_init_file() failed!");
return ret;
}
for (i = 0; i < numberoffiles; i++)
{
mz_zip_archive_file_stat file_stat;
mz_zip_reader_file_stat(&zip_archive, i, &file_stat);
sprintf(archive_filename, file_stat.m_filename);
if (!file_stat.m_is_directory) {
// Try to extract all the files to the heap.
p = mz_zip_reader_extract_file_to_heap(&zip_archive, archive_filename, &uncomp_size, 0);
if (!p)
{
ESP_LOGE(TAG, "mz_zip_reader_extract_file_to_heap() failed on file %s", archive_filename);
mz_zip_reader_end(&zip_archive);
return ret;
}
// Save to File.
zw = std::string(archive_filename);
ESP_LOGD(TAG, "Rohfilename: %s", zw.c_str());
if (toUpper(zw) == "FIRMWARE.BIN")
{
zw = _target_bin + zw;
ret = zw;
}
else
{
std::string _dir = getDirectory(zw);
if (_dir.length() > 0)
{
zw = _main + zw;
}
else
{
zw = _target_zip + zw;
}
}
string filename_zw = zw + SUFFIX_ZW;
ESP_LOGI(TAG, "Filename to extract: %s, Zwischenfilename: %s", zw.c_str(), filename_zw.c_str());
// extrahieren in zwischendatei
DeleteFile(filename_zw);
FILE* fpTargetFile = OpenFileAndWait(filename_zw.c_str(), "wb");
uint writtenbytes = fwrite(p, 1, (uint)uncomp_size, fpTargetFile);
fclose(fpTargetFile);
bool isokay = true;
if (writtenbytes == (uint)uncomp_size)
{
isokay = true;
}
else
{
isokay = false;
ESP_LOGD(TAG, "ERROR in writting extracted file (function fwrite) extracted file \"%s\", size %u", archive_filename, (uint)uncomp_size);
}
DeleteFile(zw);
if (!isokay)
ESP_LOGE(TAG, "ERROR in fwrite \"%s\", size %u", archive_filename, (uint)uncomp_size);
isokay = isokay && RenameFile(filename_zw, zw);
if (!isokay)
ESP_LOGE(TAG, "ERROR in Rename \"%s\" to \"%s\"", filename_zw.c_str(), zw.c_str());
// isokay = isokay && DeleteFile(filename_zw);
// if (!isokay)
// ESP_LOGE(TAG, "ERROR in Delete \"%s\"", filename_zw.c_str());
if (isokay)
ESP_LOGI(TAG, "Successfully extracted file \"%s\", size %u", archive_filename, (uint)uncomp_size);
else
{
ESP_LOGE(TAG, "ERROR in extracting file \"%s\", size %u", archive_filename, (uint)uncomp_size);
ret = "ERROR";
}
mz_free(p);
}
}
// Close the archive, freeing any resources it was using
mz_zip_reader_end(&zip_archive);
}
ESP_LOGD(TAG, "Success.");
return ret;
}
void unzip(std::string _in_zip_file, std::string _target_directory){
int i, sort_iter;
mz_bool status;
size_t uncomp_size;
mz_zip_archive zip_archive;
void* p;
char archive_filename[64];
std::string zw;
// static const char* s_Test_archive_filename = "testhtml.zip";
ESP_LOGD(TAG, "miniz.c version: %s", MZ_VERSION);
ESP_LOGD(TAG, "Zipfile: %s", _in_zip_file.c_str());
ESP_LOGD(TAG, "Target Dir: %s", _target_directory.c_str());
// Now try to open the archive.
memset(&zip_archive, 0, sizeof(zip_archive));
status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), 0);
if (!status)
{
ESP_LOGD(TAG, "mz_zip_reader_init_file() failed!");
return;
}
@@ -603,7 +1057,7 @@ void unzip(std::string _in_zip_file, std::string _target_directory){
status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), sort_iter ? MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY : 0);
if (!status)
{
printf("mz_zip_reader_init_file() failed!\n");
ESP_LOGD(TAG, "mz_zip_reader_init_file() failed!");
return;
}
@@ -617,7 +1071,7 @@ void unzip(std::string _in_zip_file, std::string _target_directory){
p = mz_zip_reader_extract_file_to_heap(&zip_archive, archive_filename, &uncomp_size, 0);
if (!p)
{
printf("mz_zip_reader_extract_file_to_heap() failed!\n");
ESP_LOGD(TAG, "mz_zip_reader_extract_file_to_heap() failed!");
mz_zip_reader_end(&zip_archive);
return;
}
@@ -625,13 +1079,13 @@ void unzip(std::string _in_zip_file, std::string _target_directory){
// Save to File.
zw = std::string(archive_filename);
zw = _target_directory + zw;
printf("Filename to extract: %s", zw.c_str());
FILE* fpTargetFile = fopen(zw.c_str(), "wb");
ESP_LOGD(TAG, "Filename to extract: %s", zw.c_str());
FILE* fpTargetFile = OpenFileAndWait(zw.c_str(), "wb");
fwrite(p, 1, (uint)uncomp_size, fpTargetFile);
fclose(fpTargetFile);
printf("Successfully extracted file \"%s\", size %u\n", archive_filename, (uint)uncomp_size);
// printf("File data: \"%s\"\n", (const char*)p);
ESP_LOGD(TAG, "Successfully extracted file \"%s\", size %u", archive_filename, (uint)uncomp_size);
// ESP_LOGD(TAG, "File data: \"%s\"", (const char*)p);
// We're done.
mz_free(p);
@@ -641,7 +1095,7 @@ void unzip(std::string _in_zip_file, std::string _target_directory){
mz_zip_reader_end(&zip_archive);
}
printf("Success.\n");
ESP_LOGD(TAG, "Success.");
}
@@ -678,7 +1132,7 @@ void register_server_file_uri(httpd_handle_t server, const char *base_path)
// strcpy(zw, serverprefix);
// zw[strlen(serverprefix)] = '*';
// zw[strlen(serverprefix)+1] = '\0';
// printf("zw: %s\n", zw);
// ESP_LOGD(TAG, "zw: %s", zw);
httpd_uri_t file_download = {
.uri = "/fileserver*", // Match all URIs of type /path/to/file
.method = HTTP_GET,
@@ -687,6 +1141,42 @@ void register_server_file_uri(httpd_handle_t server, const char *base_path)
};
httpd_register_uri_handler(server, &file_download);
httpd_uri_t file_datafileact = {
.uri = "/datafileact", // Match all URIs of type /path/to/file
.method = HTTP_GET,
.handler = datafileact_get_full_handler,
.user_ctx = server_data // Pass server data as context
};
httpd_register_uri_handler(server, &file_datafileact);
httpd_uri_t file_datafile_last_part_handle = {
.uri = "/data", // Match all URIs of type /path/to/file
.method = HTTP_GET,
.handler = datafileact_get_last_part_handler,
.user_ctx = server_data // Pass server data as context
};
httpd_register_uri_handler(server, &file_datafile_last_part_handle);
httpd_uri_t file_logfileact = {
.uri = "/logfileact", // Match all URIs of type /path/to/file
.method = HTTP_GET,
.handler = logfileact_get_full_handler,
.user_ctx = server_data // Pass server data as context
};
httpd_register_uri_handler(server, &file_logfileact);
httpd_uri_t file_logfile_last_part_handle = {
.uri = "/log", // Match all URIs of type /path/to/file
.method = HTTP_GET,
.handler = logfileact_get_last_part_handler,
.user_ctx = server_data // Pass server data as context
};
httpd_register_uri_handler(server, &file_logfile_last_part_handle);
/* URI handler for uploading files to server */
httpd_uri_t file_upload = {
.uri = "/upload/*", // Match all URIs of type /upload/path/to/file

View File

@@ -0,0 +1,15 @@
#include <esp_http_server.h>
#include <string>
void register_server_file_uri(httpd_handle_t server, const char *base_path);
void unzip(std::string _in_zip_file, std::string _target_directory);
std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::string _target_bin, std::string _main = "/sdcard/");
void delete_all_in_directory(std::string _directory);
esp_err_t get_tflite_file_handler(httpd_req_t *req);
esp_err_t get_data_file_handler(httpd_req_t *req);
esp_err_t get_numbers_file_handler(httpd_req_t *req);

View File

@@ -5,15 +5,24 @@
#include <sys/param.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <dirent.h>
#ifdef __cplusplus
}
#endif
#include "esp_err.h"
#include "esp_log.h"
#include "Helper.h"
#include "esp_http_server.h"
static const char *TAG = "serverhelp";
static const char *TAG = "SERVER HELP";
#define SCRATCH_BUFSIZE 8192
char scratch[SCRATCH_BUFSIZE];
@@ -23,9 +32,9 @@ char scratch[SCRATCH_BUFSIZE];
(strcasecmp(&filename[strlen(filename) - sizeof(ext) + 1], ext) == 0)
esp_err_t send_file(httpd_req_t *req, std::string filename, struct stat * file_stat)
esp_err_t send_file(httpd_req_t *req, std::string filename)
{
FILE *fd = fopen(filename.c_str(), "r");
FILE *fd = OpenFileAndWait(filename.c_str(), "r");
if (!fd) {
ESP_LOGE(TAG, "Failed to read existing file : %s", filename.c_str());
/* Respond with 500 Internal Server Error */
@@ -33,7 +42,8 @@ esp_err_t send_file(httpd_req_t *req, std::string filename, struct stat * file_
return ESP_FAIL;
}
ESP_LOGI(TAG, "Sending file : %s (%ld bytes)...", filename.c_str(), file_stat->st_size);
ESP_LOGI(TAG, "Sending file : %s ...", filename.c_str());
// httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
set_content_type_from_file(req, filename.c_str());
/* Retrieve the pointer to scratch buffer for temporary storage */
@@ -65,6 +75,7 @@ esp_err_t send_file(httpd_req_t *req, std::string filename, struct stat * file_
/* Copies the full path into destination buffer and returns
* pointer to path (skipping the preceding base path) */
const char* get_path_from_uri(char *dest, const char *base_path, const char *uri, size_t destsize)
@@ -104,8 +115,14 @@ esp_err_t set_content_type_from_file(httpd_req_t *req, const char *filename)
return httpd_resp_set_type(req, "text/html");
} else if (IS_FILE_EXT(filename, ".jpeg")) {
return httpd_resp_set_type(req, "image/jpeg");
} else if (IS_FILE_EXT(filename, ".jpg")) {
return httpd_resp_set_type(req, "image/jpeg");
} else if (IS_FILE_EXT(filename, ".ico")) {
return httpd_resp_set_type(req, "image/x-icon");
} else if (IS_FILE_EXT(filename, ".js")) {
return httpd_resp_set_type(req, "text/javascript");
} else if (IS_FILE_EXT(filename, ".css")) {
return httpd_resp_set_type(req, "text/css");
}
/* This is a limited set only */
/* For any other type always set as plain text */

View File

@@ -5,6 +5,6 @@
const char* get_path_from_uri(char *dest, const char *base_path, const char *uri, size_t destsize);
esp_err_t send_file(httpd_req_t *req, std::string filename, struct stat * file_stat);
esp_err_t send_file(httpd_req_t *req, std::string filename);
esp_err_t set_content_type_from_file(httpd_req_t *req, const char *filename);

View File

@@ -0,0 +1,647 @@
#include "server_ota.h"
#include <string>
#include "string.h"
#include <esp_int_wdt.h>
#include <esp_task_wdt.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event.h"
#include "esp_log.h"
#include <esp_ota_ops.h>
#include "esp_http_client.h"
#include "esp_flash_partitions.h"
#include "esp_partition.h"
#include <nvs.h>
#include "nvs_flash.h"
#include "driver/gpio.h"
// #include "protocol_examples_common.h"
#include "errno.h"
#include <sys/stat.h>
#include "server_tflite.h"
#include "server_file.h"
#include "server_GPIO.h"
#include "ClassLogFile.h"
#include "Helper.h"
// #define DEBUG_DETAIL_ON
#define BUFFSIZE 1024
#define HASH_LEN 32 /* SHA-256 digest length */
/*an ota data write buffer ready to write to the flash*/
static char ota_write_data[BUFFSIZE + 1] = { 0 };
#define OTA_URL_SIZE 256
static const char *TAG = "OTA";
esp_err_t handler_reboot(httpd_req_t *req);
std::string _file_name_update;
void task_do_Update_ZIP(void *pvParameter)
{
std::string filetype = toUpper(getFileType(_file_name_update));
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "File: " + _file_name_update + " Filetype: " + filetype);
if (filetype == "ZIP")
{
std::string in, out, outbin, zw, retfirmware;
out = "/sdcard/html";
outbin = "/sdcard/firmware";
retfirmware = unzip_new(_file_name_update, out+"/", outbin+"/");
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Files unzipped.");
if (retfirmware.length() > 0)
{
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Found firmware.bin");
ota_update_task(retfirmware);
}
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Trigger reboot due to firmware update.");
doReboot();
}
else
{
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Only ZIP-Files support for update during startup!");
}
}
void CheckUpdate()
{
FILE *pfile;
if ((pfile = fopen("/sdcard/update.txt", "r")) == NULL)
{
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "No update triggered.");
return;
}
char zw[1024] = "";
fgets(zw, 1024, pfile);
_file_name_update = std::string(zw);
fclose(pfile);
DeleteFile("/sdcard/update.txt"); // Prevent Boot Loop!!!
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Update during boot triggered - Update File: " + _file_name_update);
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);
}
}
static bool ota_update_task(std::string fn)
{
esp_err_t err;
/* update handle : set by esp_ota_begin(), must be freed via esp_ota_end() */
esp_ota_handle_t update_handle = 0 ;
const esp_partition_t *update_partition = NULL;
ESP_LOGI(TAG, "Starting OTA update");
const esp_partition_t *configured = esp_ota_get_boot_partition();
const esp_partition_t *running = esp_ota_get_running_partition();
if (configured != running) {
ESP_LOGW(TAG, "Configured OTA boot partition at offset 0x%08x, but running from offset 0x%08x",
configured->address, running->address);
ESP_LOGW(TAG, "(This can happen if either the OTA boot data or preferred boot image become somehow corrupted.)");
}
ESP_LOGI(TAG, "Running partition type %d subtype %d (offset 0x%08x)",
running->type, running->subtype, running->address);
update_partition = esp_ota_get_next_update_partition(NULL);
ESP_LOGI(TAG, "Writing to partition subtype %d at offset 0x%x",
update_partition->subtype, update_partition->address);
// assert(update_partition != NULL);
int binary_file_length = 0;
// deal with all receive packet
bool image_header_was_checked = false;
int data_read;
FILE* f = OpenFileAndWait(fn.c_str(), "rb"); // vorher nur "r"
if (f == NULL) { // File does not exist
return false;
}
data_read = fread(ota_write_data, 1, BUFFSIZE, f);
while (data_read > 0) {
if (data_read < 0) {
ESP_LOGE(TAG, "Error: SSL data read error");
return false;
} else if (data_read > 0) {
if (image_header_was_checked == false) {
esp_app_desc_t new_app_info;
if (data_read > sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t)) {
// check current version with downloading
memcpy(&new_app_info, &ota_write_data[sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t)], sizeof(esp_app_desc_t));
ESP_LOGI(TAG, "New firmware version: %s", new_app_info.version);
esp_app_desc_t running_app_info;
if (esp_ota_get_partition_description(running, &running_app_info) == ESP_OK) {
ESP_LOGI(TAG, "Running firmware version: %s", running_app_info.version);
}
const esp_partition_t* last_invalid_app = esp_ota_get_last_invalid_partition();
esp_app_desc_t invalid_app_info;
if (esp_ota_get_partition_description(last_invalid_app, &invalid_app_info) == ESP_OK) {
ESP_LOGI(TAG, "Last invalid firmware version: %s", invalid_app_info.version);
}
// check current version with last invalid partition
if (last_invalid_app != NULL) {
if (memcmp(invalid_app_info.version, new_app_info.version, sizeof(new_app_info.version)) == 0) {
ESP_LOGW(TAG, "New version is the same as invalid version.");
ESP_LOGW(TAG, "Previously, there was an attempt to launch the firmware with %s version, but it failed.", invalid_app_info.version);
ESP_LOGW(TAG, "The firmware has been rolled back to the previous version.");
infinite_loop();
}
}
/*
if (memcmp(new_app_info.version, running_app_info.version, sizeof(new_app_info.version)) == 0) {
ESP_LOGW(TAG, "Current running version is the same as a new. We will not continue the update.");
infinite_loop();
}
*/
image_header_was_checked = true;
err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle);
if (err != ESP_OK) {
ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err));
return false;
}
ESP_LOGI(TAG, "esp_ota_begin succeeded");
} else {
ESP_LOGE(TAG, "received package is not fit len");
return false;
}
}
err = esp_ota_write( update_handle, (const void *)ota_write_data, data_read);
if (err != ESP_OK) {
return false;
}
binary_file_length += data_read;
ESP_LOGD(TAG, "Written image length %d", binary_file_length);
} else if (data_read == 0) {
//
// * As esp_http_client_read never returns negative error code, we rely on
// * `errno` to check for underlying transport connectivity closure if any
//
if (errno == ECONNRESET || errno == ENOTCONN) {
ESP_LOGE(TAG, "Connection closed, errno = %d", errno);
break;
}
}
data_read = fread(ota_write_data, 1, BUFFSIZE, f);
}
fclose(f);
ESP_LOGI(TAG, "Total Write binary data length: %d", binary_file_length);
err = esp_ota_end(update_handle);
if (err != ESP_OK) {
if (err == ESP_ERR_OTA_VALIDATE_FAILED) {
ESP_LOGE(TAG, "Image validation failed, image is corrupted");
}
ESP_LOGE(TAG, "esp_ota_end failed (%s)!", esp_err_to_name(err));
return false;
}
err = esp_ota_set_boot_partition(update_partition);
if (err != ESP_OK) {
ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err));
}
// ESP_LOGI(TAG, "Prepare to restart system!");
// esp_restart();
return true ;
}
static void print_sha256 (const uint8_t *image_hash, const char *label)
{
char hash_print[HASH_LEN * 2 + 1];
hash_print[HASH_LEN * 2] = 0;
for (int i = 0; i < HASH_LEN; ++i) {
sprintf(&hash_print[i * 2], "%02x", image_hash[i]);
}
ESP_LOGI(TAG, "%s: %s", label, hash_print);
}
static bool diagnostic(void)
{
return true;
}
void CheckOTAUpdate(void)
{
ESP_LOGI(TAG, "Start CheckOTAUpdateCheck...");
uint8_t sha_256[HASH_LEN] = { 0 };
esp_partition_t partition;
// get sha256 digest for the partition table
partition.address = ESP_PARTITION_TABLE_OFFSET;
partition.size = ESP_PARTITION_TABLE_MAX_LEN;
partition.type = ESP_PARTITION_TYPE_DATA;
esp_partition_get_sha256(&partition, sha_256);
print_sha256(sha_256, "SHA-256 for the partition table: ");
// get sha256 digest for bootloader
partition.address = ESP_BOOTLOADER_OFFSET;
partition.size = ESP_PARTITION_TABLE_OFFSET;
partition.type = ESP_PARTITION_TYPE_APP;
esp_partition_get_sha256(&partition, sha_256);
print_sha256(sha_256, "SHA-256 for bootloader: ");
// get sha256 digest for running partition
esp_partition_get_sha256(esp_ota_get_running_partition(), sha_256);
print_sha256(sha_256, "SHA-256 for current firmware: ");
const esp_partition_t *running = esp_ota_get_running_partition();
esp_ota_img_states_t ota_state;
esp_err_t res_stat_partition = esp_ota_get_state_partition(running, &ota_state);
switch (res_stat_partition)
{
case ESP_OK:
ESP_LOGD(TAG, "CheckOTAUpdate Partition: ESP_OK");
if (esp_ota_get_state_partition(running, &ota_state) == ESP_OK) {
if (ota_state == ESP_OTA_IMG_PENDING_VERIFY) {
// run diagnostic function ...
bool diagnostic_is_ok = diagnostic();
if (diagnostic_is_ok) {
ESP_LOGI(TAG, "Diagnostics completed successfully! Continuing execution...");
esp_ota_mark_app_valid_cancel_rollback();
} else {
ESP_LOGE(TAG, "Diagnostics failed! Start rollback to the previous version...");
esp_ota_mark_app_invalid_rollback_and_reboot();
}
}
}
break;
case ESP_ERR_INVALID_ARG:
ESP_LOGD(TAG, "CheckOTAUpdate Partition: ESP_ERR_INVALID_ARG");
break;
case ESP_ERR_NOT_SUPPORTED:
ESP_LOGD(TAG, "CheckOTAUpdate Partition: ESP_ERR_NOT_SUPPORTED");
break;
case ESP_ERR_NOT_FOUND:
ESP_LOGD(TAG, "CheckOTAUpdate Partition: ESP_ERR_NOT_FOUND");
break;
}
if (esp_ota_get_state_partition(running, &ota_state) == ESP_OK) {
if (ota_state == ESP_OTA_IMG_PENDING_VERIFY) {
// run diagnostic function ...
bool diagnostic_is_ok = diagnostic();
if (diagnostic_is_ok) {
ESP_LOGI(TAG, "Diagnostics completed successfully! Continuing execution...");
esp_ota_mark_app_valid_cancel_rollback();
} else {
ESP_LOGE(TAG, "Diagnostics failed! Start rollback to the previous version...");
esp_ota_mark_app_invalid_rollback_and_reboot();
}
}
}
}
esp_err_t handler_ota_update(httpd_req_t *req)
{
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_ota_update - Start");
#endif
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handler_ota_update");
char _query[200];
char _filename[100];
char _valuechar[30];
std::string fn = "/sdcard/firmware/";
bool _file_del = false;
std::string _task = "";
if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK)
{
ESP_LOGD(TAG, "Query: %s", _query);
if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK)
{
ESP_LOGD(TAG, "task is found: %s", _valuechar);
_task = std::string(_valuechar);
}
if (httpd_query_key_value(_query, "file", _filename, 100) == ESP_OK)
{
fn.append(_filename);
ESP_LOGD(TAG, "File: %s", fn.c_str());
}
if (httpd_query_key_value(_query, "delete", _filename, 100) == ESP_OK)
{
fn.append(_filename);
_file_del = true;
ESP_LOGD(TAG, "Delete Default File: %s", fn.c_str());
}
};
if (_task.compare("emptyfirmwaredir") == 0)
{
ESP_LOGD(TAG, "Start empty directory /firmware");
delete_all_in_directory("/sdcard/firmware");
std::string zw = "firmware directory deleted - v2\n";
ESP_LOGD(TAG, "%s", zw.c_str());
printf("Ausgabe: %s\n", zw.c_str());
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_send(req, zw.c_str(), strlen(zw.c_str()));
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
ESP_LOGD(TAG, "Done empty directory /firmware");
return ESP_OK;
}
if (_task.compare("update") == 0)
{
std::string filetype = toUpper(getFileType(fn));
if (filetype.length() == 0)
{
std::string zw = "Update failed - no file specified (zip, bin, tfl, tlite)";
httpd_resp_sendstr_chunk(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;
}
if ((filetype == "TFLITE") || (filetype == "TFL"))
{
std::string out = "/sdcard/config/" + getFileFullFileName(fn);
DeleteFile(out);
CopyFile(fn, out);
DeleteFile(fn);
const char* resp_str = "Neural Network File copied.";
httpd_resp_sendstr_chunk(req, resp_str);
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;
}
if (filetype == "ZIP")
{
FILE *pfile;
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Update for reboot.");
pfile = fopen("/sdcard/update.txt", "w");
fwrite(fn.c_str(), fn.length(), 1, pfile);
fclose(pfile);
std::string zw = "reboot\n";
httpd_resp_sendstr_chunk(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
ESP_LOGD(TAG, "Send reboot");
return ESP_OK;
/*
std::string in, out, outbin, zw, retfirmware;
out = "/sdcard/html";
outbin = "/sdcard/firmware";
retfirmware = unzip_new(fn, out+"/", outbin+"/");
if (retfirmware.length() > 0)
{
filetype = "BIN";
fn = retfirmware;
}
else
{
zw = "Web Interface Update Successfull!\nNo reboot necessary.\n";
httpd_resp_sendstr_chunk(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;
}
*/
}
if (filetype == "BIN")
{
const char* resp_str;
KillTFliteTasks();
gpio_handler_deinit();
if (ota_update_task(fn))
{
std::string zw = "reboot\n";
httpd_resp_sendstr_chunk(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
ESP_LOGD(TAG, "Send reboot");
return ESP_OK;
}
resp_str = "Error during Firmware Update!!!\nPlease check output of console.";
httpd_resp_send(req, resp_str, strlen(resp_str));
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_ota_update - Done");
#endif
return ESP_OK;
}
std::string zw = "Update failed - no valid file specified (zip, bin, tfl, tlite)!";
httpd_resp_sendstr_chunk(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;
}
if (_task.compare("unziphtml") == 0)
{
ESP_LOGD(TAG, "Task unziphtml");
std::string in, out, zw;
in = "/sdcard/firmware/html.zip";
out = "/sdcard/html";
delete_all_in_directory(out);
unzip(in, out+"/");
zw = "Web Interface Update Successfull!\nNo reboot necessary";
httpd_resp_send(req, zw.c_str(), strlen(zw.c_str()));
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;
}
if (_file_del)
{
ESP_LOGD(TAG, "Delete !! _file_del: %s", fn.c_str());
struct stat file_stat;
int _result = stat(fn.c_str(), &file_stat);
ESP_LOGD(TAG, "Ergebnis %d\n", _result);
if (_result == 0) {
ESP_LOGD(TAG, "Deleting file : %s", fn.c_str());
/* Delete file */
unlink(fn.c_str());
}
else
{
ESP_LOGD(TAG, "File does not exist: %s", fn.c_str());
}
/* Respond with an empty chunk to signal HTTP response completion */
std::string zw = "file deleted\n";
ESP_LOGD(TAG, "%s", zw.c_str());
httpd_resp_send(req, zw.c_str(), strlen(zw.c_str()));
httpd_resp_send_chunk(req, NULL, 0);
return ESP_OK;
}
string zw = "ota without parameter - should not be the case!";
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_send(req, zw.c_str(), strlen(zw.c_str()));
httpd_resp_send_chunk(req, NULL, 0);
ESP_LOGE(TAG, "ota without parameter - should not be the case!");
/*
const char* resp_str;
KillTFliteTasks();
gpio_handler_deinit();
if (ota_update_task(fn))
{
resp_str = "Firmware Update Successfull! You can restart now.";
}
else
{
resp_str = "Error during Firmware Update!!! Please check console output.";
}
httpd_resp_send(req, resp_str, strlen(resp_str));
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_ota_update - Done");
#endif
*/
return ESP_OK;
};
void hard_restart() {
esp_task_wdt_init(1,true);
esp_task_wdt_add(NULL);
while(true);
}
void task_reboot(void *pvParameter)
{
while(1)
{
vTaskDelay(5000 / portTICK_PERIOD_MS);
esp_restart();
hard_restart();
}
vTaskDelete(NULL); //Delete this task if it exits from the loop above
}
void doReboot(){
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Reboot triggered by Software (5s).");
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Reboot in 5sec");
xTaskCreate(&task_reboot, "reboot", configMINIMAL_STACK_SIZE * 64, NULL, 10, NULL);
// KillTFliteTasks(); // kills itself
gpio_handler_destroy();
vTaskDelay(5000 / portTICK_PERIOD_MS);
esp_restart();
hard_restart();
}
esp_err_t handler_reboot(httpd_req_t *req)
{
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_reboot - Start");
#endif
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handler_reboot");
ESP_LOGI(TAG, "!!! System will restart within 5 sec!!!");
const char* resp_str = "<body style='font-family: arial'> <h3 id=t></h3></body><script>var h='Rebooting!<br>The page will automatically reload in around 25..60s<br>(in case of a firmware update it can take up to 180s).<br>'; document.getElementById('t').innerHTML=h; setInterval(function (){h +='.'; document.getElementById('t').innerHTML=h; fetch(window.location.hostname,{mode: 'no-cors'}).then(r=>{parent.location.href=('/index.html');})}, 1000);</script>";
httpd_resp_send(req, resp_str, strlen(resp_str));
doReboot();
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_reboot - Done");
#endif
return ESP_OK;
}
void register_server_ota_sdcard_uri(httpd_handle_t server)
{
ESP_LOGI(TAG, "Registering URI handlers");
httpd_uri_t camuri = { };
camuri.method = HTTP_GET;
camuri.uri = "/ota";
camuri.handler = handler_ota_update;
camuri.user_ctx = (void*) "Do OTA";
httpd_register_uri_handler(server, &camuri);
camuri.method = HTTP_GET;
camuri.uri = "/reboot";
camuri.handler = handler_reboot;
camuri.user_ctx = (void*) "Reboot";
httpd_register_uri_handler(server, &camuri);
}

View File

@@ -2,10 +2,12 @@
#include <esp_http_server.h>
//#include "ClassControllCamera.h"
#include <string>
static const char *TAGPARTOTA = "server_ota";
void register_server_ota_sdcard_uri(httpd_handle_t server);
void CheckOTAUpdate();
void doReboot();
void doReboot();
void hard_restart();
void CheckUpdate();
static bool ota_update_task(std::string fn);

View File

@@ -0,0 +1,7 @@
FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
idf_component_register(SRCS ${app_sources}
INCLUDE_DIRS "."
REQUIRES jomjol_tfliteclass jomjol_helper jomjol_controlcamera jomjol_mqtt jomjol_influxdb jomjol_fileserver_ota jomjol_image_proc jomjol_wlan)

View File

@@ -0,0 +1,118 @@
#include "ClassFlow.h"
#include <fstream>
#include <string>
#include <iostream>
#include <string.h>
#include "esp_log.h"
static const char *TAG = "FLOW CLASS";
void ClassFlow::SetInitialParameter(void)
{
ListFlowControll = NULL;
previousElement = NULL;
disabled = false;
}
bool ClassFlow::isNewParagraph(string input)
{
if ((input[0] == '[') || ((input[0] == ';') && (input[1] == '[')))
{
return true;
}
return false;
}
bool ClassFlow::GetNextParagraph(FILE* pfile, string& aktparamgraph)
{
while (getNextLine(pfile, &aktparamgraph) && !isNewParagraph(aktparamgraph));
if (isNewParagraph(aktparamgraph))
return true;
return false;
}
ClassFlow::ClassFlow(void)
{
SetInitialParameter();
}
ClassFlow::ClassFlow(std::vector<ClassFlow*> * lfc)
{
SetInitialParameter();
ListFlowControll = lfc;
}
ClassFlow::ClassFlow(std::vector<ClassFlow*> * lfc, ClassFlow *_prev)
{
SetInitialParameter();
ListFlowControll = lfc;
previousElement = _prev;
}
bool ClassFlow::ReadParameter(FILE* pfile, string &aktparamgraph)
{
return false;
}
bool ClassFlow::doFlow(string time)
{
return false;
}
string ClassFlow::getHTMLSingleStep(string host){
return "";
}
string ClassFlow::getReadout()
{
return string();
}
std::string ClassFlow::GetParameterName(std::string _input)
{
string _param;
int _pospunkt = _input.find_first_of(".");
if (_pospunkt > -1)
{
_param = _input.substr(_pospunkt+1, _input.length() - _pospunkt - 1);
}
else
{
_param = _input;
}
// ESP_LOGD(TAG, "Parameter: %s, Pospunkt: %d", _param.c_str(), _pospunkt);
return _param;
}
bool ClassFlow::getNextLine(FILE* pfile, string *rt)
{
char zw[1024];
if (pfile == NULL)
{
*rt = "";
return false;
}
if (!fgets(zw, 1024, pfile))
{
*rt = "";
ESP_LOGD(TAG, "END OF FILE");
return false;
}
ESP_LOGD(TAG, "%s", zw);
*rt = zw;
*rt = trim(*rt);
while ((zw[0] == ';' || zw[0] == '#' || (rt->size() == 0)) && !(zw[1] == '[')) // Kommentarzeilen (; oder #) und Leerzeilen überspringen, es sei denn es ist ein neuer auskommentierter Paragraph
{
*rt = "";
if (!fgets(zw, 1024, pfile))
return false;
ESP_LOGD(TAG, "%s", zw);
*rt = zw;
*rt = trim(*rt);
}
return true;
}

View File

@@ -5,32 +5,45 @@
#include <vector>
#include "Helper.h"
#include "CFindTemplate.h"
#include "CImageBasis.h"
using namespace std;
#define LOGFILE_TIME_FORMAT "%Y%m%d-%H%M%S"
#define LOGFILE_TIME_FORMAT_DATE_EXTR substr(0, 8)
#define LOGFILE_TIME_FORMAT_HOUR_EXTR substr(9, 2)
struct HTMLInfo
{
float val;
CImageBasis *image = NULL;
CImageBasis *image_org = NULL;
std::string filename;
std::string filename_org;
};
class ClassFlow
{
protected:
std::vector<string> ZerlegeZeile(string input);
bool isNewParagraph(string input);
bool GetNextParagraph(FILE* pfile, string& aktparamgraph);
bool getNextLine(FILE* pfile, string* rt);
std::vector<ClassFlow*>* ListFlowControll;
ClassFlow *previousElement;
virtual void SetInitialParameter(void);
std::string GetParameterName(std::string _input);
bool disabled;
public:
ClassFlow(void);
ClassFlow(std::vector<ClassFlow*> * lfc);
ClassFlow(std::vector<ClassFlow*> * lfc, ClassFlow *_prev);
virtual bool ReadParameter(FILE* pfile, string &aktparamgraph);
virtual bool doFlow(string time);
virtual string getHTMLSingleStep(string host);

View File

@@ -0,0 +1,352 @@
#include "ClassFlowAlignment.h"
#include "ClassFlowMakeImage.h"
#include "ClassFlow.h"
#include "CRotateImage.h"
#include "esp_log.h"
#include "ClassLogFile.h"
static const char *TAG = "FLOW ALIGN";
bool AlignmentExtendedDebugging = true;
// #define DEBUG_DETAIL_ON
void ClassFlowAlignment::SetInitialParameter(void)
{
initalrotate = 0;
anz_ref = 0;
initialmirror = false;
use_antialiasing = false;
initialflip = false;
SaveAllFiles = false;
namerawimage = "/sdcard/img_tmp/raw.jpg";
FileStoreRefAlignment = "/sdcard/config/align.txt";
ListFlowControll = NULL;
AlignAndCutImage = NULL;
ImageBasis = NULL;
ImageTMP = NULL;
previousElement = NULL;
disabled = false;
SAD_criteria = 0.05;
}
ClassFlowAlignment::ClassFlowAlignment(std::vector<ClassFlow*>* lfc)
{
SetInitialParameter();
ListFlowControll = lfc;
for (int i = 0; i < ListFlowControll->size(); ++i)
{
if (((*ListFlowControll)[i])->name().compare("ClassFlowMakeImage") == 0)
{
ImageBasis = ((ClassFlowMakeImage*) (*ListFlowControll)[i])->rawImage;
}
}
if (!ImageBasis) // die Funktion Bilder aufnehmen existiert nicht --> muss erst erzeugt werden NUR ZU TESTZWECKEN
{
if (AlignmentExtendedDebugging) ESP_LOGD(TAG, "CImageBasis had to be created");
ImageBasis = new CImageBasis(namerawimage);
}
}
bool ClassFlowAlignment::ReadParameter(FILE* pfile, string& aktparamgraph)
{
std::vector<string> zerlegt;
int suchex = 40;
int suchey = 40;
int alg_algo = 0;
aktparamgraph = trim(aktparamgraph);
if (aktparamgraph.size() == 0)
if (!this->GetNextParagraph(pfile, aktparamgraph))
return false;
if (aktparamgraph.compare("[Alignment]") != 0) // Paragraph passt nich zu MakeImage
return false;
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
{
zerlegt = ZerlegeZeile(aktparamgraph);
if ((toUpper(zerlegt[0]) == "FLIPIMAGESIZE") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
initialflip = true;
}
if ((toUpper(zerlegt[0]) == "INITIALMIRROR") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
initialmirror = true;
}
if (((toUpper(zerlegt[0]) == "INITALROTATE") || (toUpper(zerlegt[0]) == "INITIALROTATE")) && (zerlegt.size() > 1))
{
this->initalrotate = std::stod(zerlegt[1]);
}
if ((toUpper(zerlegt[0]) == "SEARCHFIELDX") && (zerlegt.size() > 1))
{
suchex = std::stod(zerlegt[1]);
}
if ((toUpper(zerlegt[0]) == "SEARCHFIELDY") && (zerlegt.size() > 1))
{
suchey = std::stod(zerlegt[1]);
}
if ((toUpper(zerlegt[0]) == "ANTIALIASING") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
use_antialiasing = true;
}
if ((zerlegt.size() == 3) && (anz_ref < 2))
{
References[anz_ref].image_file = FormatFileName("/sdcard" + zerlegt[0]);
References[anz_ref].target_x = std::stod(zerlegt[1]);
References[anz_ref].target_y = std::stod(zerlegt[2]);
anz_ref++;
}
if ((toUpper(zerlegt[0]) == "SAVEALLFILES") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
SaveAllFiles = true;
}
if ((toUpper(zerlegt[0]) == "ALIGNMENTALGO") && (zerlegt.size() > 1))
{
#ifdef DEBUG_DETAIL_ON
std::string zw2 = "Alignmentmodus gewählt: " + zerlegt[1];
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, zw2);
#endif
if (toUpper(zerlegt[1]) == "HIGHACCURACY")
alg_algo = 1;
if (toUpper(zerlegt[1]) == "FAST")
alg_algo = 2;
}
}
for (int i = 0; i < anz_ref; ++i)
{
References[i].search_x = suchex;
References[i].search_y = suchey;
References[i].fastalg_SAD_criteria = SAD_criteria;
References[i].alignment_algo = alg_algo;
#ifdef DEBUG_DETAIL_ON
std::string zw2 = "Alignmentmodus geschrieben: " + std::to_string(alg_algo);
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, zw2);
#endif
}
LoadReferenceAlignmentValues();
return true;
}
string ClassFlowAlignment::getHTMLSingleStep(string host)
{
string result;
result = "<p>Rotated Image: </p> <p><img src=\"" + host + "/img_tmp/rot.jpg\"></p>\n";
result = result + "<p>Found Alignment: </p> <p><img src=\"" + host + "/img_tmp/rot_roi.jpg\"></p>\n";
result = result + "<p>Aligned Image: </p> <p><img src=\"" + host + "/img_tmp/alg.jpg\"></p>\n";
return result;
}
bool ClassFlowAlignment::doFlow(string time)
{
if (!ImageTMP)
ImageTMP = new CImageBasis(ImageBasis, 5);
if (AlignAndCutImage)
delete AlignAndCutImage;
AlignAndCutImage = new CAlignAndCutImage(ImageBasis, ImageTMP);
CRotateImage rt(AlignAndCutImage, ImageTMP, initialflip);
if (initialflip)
{
int _zw = ImageBasis->height;
ImageBasis->height = ImageBasis->width;
ImageBasis->width = _zw;
}
if (initialmirror){
ESP_LOGD(TAG, "do mirror");
rt.Mirror();
if (SaveAllFiles) AlignAndCutImage->SaveToFile(FormatFileName("/sdcard/img_tmp/mirror.jpg"));
}
if ((initalrotate != 0) || initialflip)
{
if (use_antialiasing)
rt.RotateAntiAliasing(initalrotate);
else
rt.Rotate(initalrotate);
if (SaveAllFiles) AlignAndCutImage->SaveToFile(FormatFileName("/sdcard/img_tmp/rot.jpg"));
}
if (!AlignAndCutImage->Align(&References[0], &References[1]))
{
SaveReferenceAlignmentValues();
}
if (SaveAllFiles) AlignAndCutImage->SaveToFile(FormatFileName("/sdcard/img_tmp/alg.jpg"));
if (SaveAllFiles)
{
if (initialflip)
{
int _zw = ImageTMP->width;
ImageTMP->width = ImageTMP->height;
ImageTMP->height = _zw;
}
DrawRef(ImageTMP);
ImageTMP->SaveToFile(FormatFileName("/sdcard/img_tmp/alg_roi.jpg"));
}
if (ImageTMP) // nuss gelöscht werden, um Speicherplatz für das Laden von tflite zu haben
{
delete ImageTMP;
ImageTMP = NULL;
}
LoadReferenceAlignmentValues();
return true;
}
void ClassFlowAlignment::SaveReferenceAlignmentValues()
{
FILE* pFile;
std::string zwtime, zwvalue;
pFile = fopen(FileStoreRefAlignment.c_str(), "w");
if (strlen(zwtime.c_str()) == 0)
{
time_t rawtime;
struct tm* timeinfo;
char buffer[80];
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, 80, "%Y-%m-%dT%H:%M:%S", timeinfo);
zwtime = std::string(buffer);
}
fputs(zwtime.c_str(), pFile);
fputs("\n", pFile);
zwvalue = std::to_string(References[0].fastalg_x) + "\t" + std::to_string(References[0].fastalg_y);
zwvalue = zwvalue + "\t" +std::to_string(References[0].fastalg_SAD)+ "\t" +std::to_string(References[0].fastalg_min);
zwvalue = zwvalue + "\t" +std::to_string(References[0].fastalg_max)+ "\t" +std::to_string(References[0].fastalg_avg);
fputs(zwvalue.c_str(), pFile);
fputs("\n", pFile);
zwvalue = std::to_string(References[1].fastalg_x) + "\t" + std::to_string(References[1].fastalg_y);
zwvalue = zwvalue + "\t" +std::to_string(References[1].fastalg_SAD)+ "\t" +std::to_string(References[1].fastalg_min);
zwvalue = zwvalue + "\t" +std::to_string(References[1].fastalg_max)+ "\t" +std::to_string(References[1].fastalg_avg);
fputs(zwvalue.c_str(), pFile);
fputs("\n", pFile);
fclose(pFile);
}
bool ClassFlowAlignment::LoadReferenceAlignmentValues(void)
{
FILE* pFile;
char zw[1024];
string zwvalue;
std::vector<string> zerlegt;
// LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", "LoadReferenceAlignmentValues01");
pFile = fopen(FileStoreRefAlignment.c_str(), "r");
if (pFile == NULL)
return false;
// LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", "LoadReferenceAlignmentValues01");
fgets(zw, 1024, pFile);
ESP_LOGD(TAG, "%s", zw);
// zwvalue = "LoadReferenceAlignmentValues Time: " + std::string(zw);
// LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", zwvalue);
// LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", "LoadReferenceAlignmentValues02");
fgets(zw, 1024, pFile);
zerlegt = ZerlegeZeile(std::string(zw), " \t");
if (zerlegt.size() < 6)
{
// LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", "Exit 01");
fclose(pFile);
return false;
}
// LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", "LoadReferenceAlignmentValues03");
References[0].fastalg_x = stoi(zerlegt[0]);
References[0].fastalg_y = stoi(zerlegt[1]);
References[0].fastalg_SAD = stof(zerlegt[2]);
References[0].fastalg_min = stoi(zerlegt[3]);
References[0].fastalg_max = stoi(zerlegt[4]);
References[0].fastalg_avg = stof(zerlegt[5]);
fgets(zw, 1024, pFile);
zerlegt = ZerlegeZeile(std::string(zw));
if (zerlegt.size() < 6)
{
// LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", "Exit 02");
fclose(pFile);
return false;
}
// LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", "LoadReferenceAlignmentValues03");
References[1].fastalg_x = stoi(zerlegt[0]);
References[1].fastalg_y = stoi(zerlegt[1]);
References[1].fastalg_SAD = stof(zerlegt[2]);
References[1].fastalg_min = stoi(zerlegt[3]);
References[1].fastalg_max = stoi(zerlegt[4]);
References[1].fastalg_avg = stof(zerlegt[5]);
fclose(pFile);
#ifdef DEBUG_DETAIL_ON
std::string _zw = "\tLoadReferences[0]\tx,y:\t" + std::to_string(References[0].fastalg_x) + "\t" + std::to_string(References[0].fastalg_x);
_zw = _zw + "\tSAD, min, max, avg:\t" + std::to_string(References[0].fastalg_SAD) + "\t" + std::to_string(References[0].fastalg_min);
_zw = _zw + "\t" + std::to_string(References[0].fastalg_max) + "\t" + std::to_string(References[0].fastalg_avg);
LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", _zw);
_zw = "\tLoadReferences[1]\tx,y:\t" + std::to_string(References[1].fastalg_x) + "\t" + std::to_string(References[1].fastalg_x);
_zw = _zw + "\tSAD, min, max, avg:\t" + std::to_string(References[1].fastalg_SAD) + "\t" + std::to_string(References[1].fastalg_min);
_zw = _zw + "\t" + std::to_string(References[1].fastalg_max) + "\t" + std::to_string(References[1].fastalg_avg);
LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", _zw);
#endif
return true;
}
void ClassFlowAlignment::DrawRef(CImageBasis *_zw)
{
_zw->drawRect(References[0].target_x, References[0].target_y, References[0].width, References[0].height, 255, 0, 0, 2);
_zw->drawRect(References[1].target_x, References[1].target_y, References[1].width, References[1].height, 255, 0, 0, 2);
}

View File

@@ -0,0 +1,46 @@
#pragma once
#include "ClassFlow.h"
#include "Helper.h"
#include "CAlignAndCutImage.h"
#include "CFindTemplate.h"
#include <string>
using namespace std;
class ClassFlowAlignment :
public ClassFlow
{
protected:
float initalrotate;
bool initialmirror;
bool initialflip;
bool use_antialiasing;
RefInfo References[2];
int anz_ref;
string namerawimage;
bool SaveAllFiles;
CAlignAndCutImage *AlignAndCutImage;
std::string FileStoreRefAlignment;
float SAD_criteria;
void SetInitialParameter(void);
bool LoadReferenceAlignmentValues(void);
void SaveReferenceAlignmentValues();
public:
CImageBasis *ImageBasis, *ImageTMP;
ClassFlowAlignment(std::vector<ClassFlow*>* lfc);
CAlignAndCutImage* GetAlignAndCutImage(){return AlignAndCutImage;};
void DrawRef(CImageBasis *_zw);
bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
string getHTMLSingleStep(string host);
string name(){return "ClassFlowAlignment";};
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,84 @@
#ifndef __CLASSCNNGENERAL__
#define __CLASSCNNGENERAL__
#include"ClassFlowDefineTypes.h"
#include "ClassFlowAlignment.h"
enum t_CNNType {
AutoDetect,
Analogue,
Analogue100,
Digital,
DigitalHyprid10,
DoubleHyprid10,
Digital100,
None
};
class ClassFlowCNNGeneral :
public ClassFlowImage
{
protected:
t_CNNType CNNType;
std::vector<general*> GENERAL;
float CNNGoodThreshold;
float AnalogFehler = 3.0;
float AnalogToDigtalFehler = 0.8;
float DigitalUnschaerfe = 0.2;
int DigitalBand = 3;
float DigitalAnalogerVorgaengerUebergangsbereich = 2;
float DigitalUebergangsbereichVorgaenger = 0.7; // 9.3 - 0.7
float DigitalUebergangsbereichVorlauf = 9.7; // Vorlauf-Nulldurchgang passiert erst ab ca. 9.7
string cnnmodelfile;
int modelxsize, modelysize, modelchannel;
bool isLogImageSelect;
string LogImageSelect;
ClassFlowAlignment* flowpostalignment;
bool SaveAllFiles;
int ZeigerEvalAnalogNeu(float zahl, int ziffer_vorgaenger);
int ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vorgaenger, int eval_vorgaenger, float analogDigitalTransitionStart);
int ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, int eval_vorgaenger, bool AnalogerVorgaenger = false, float analogDigitalTransitionStart=9.2);
bool doNeuralNetwork(string time);
bool doAlignAndCut(string time);
bool getNetworkParameter();
public:
ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNType _cnntype = AutoDetect);
bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
string getHTMLSingleStep(string host);
string getReadout(int _analog, bool _extendedResolution = false, int prev = -1, float _vorgaengerAnalog = -1, float analogDigitalTransitionStart=9.2);
string getReadoutRawString(int _analog);
void DrawROI(CImageBasis *_zw);
std::vector<HTMLInfo*> GetHTMLInfo();
int getAnzahlGENERAL();
general* GetGENERAL(int _analog);
general* GetGENERAL(string _name, bool _create);
general* FindGENERAL(string _name_number);
string getNameGENERAL(int _analog);
bool isExtendedResolution(int _number = 0);
void UpdateNameNumbers(std::vector<std::string> *_name_numbers);
t_CNNType getCNNType(){return CNNType;};
string name(){return "ClassFlowCNNGeneral";};
};
#endif

View File

@@ -0,0 +1,698 @@
#include "ClassFlowControll.h"
#include "connect_wlan.h"
#include "read_wlanini.h"
#include "freertos/task.h"
#include <sys/stat.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <dirent.h>
#ifdef __cplusplus
}
#endif
#include "ClassLogFile.h"
#include "time_sntp.h"
#include "Helper.h"
#include "server_ota.h"
//#include "CImg.h"
#include "server_help.h"
//#define DEBUG_DETAIL_ON
static const char* TAG = "FLOW CTRL";
std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _host){
std::string _classname = "";
std::string result = "";
ESP_LOGD(TAG, "Step %s start", _stepname.c_str());
if ((_stepname.compare("[MakeImage]") == 0) || (_stepname.compare(";[MakeImage]") == 0)){
_classname = "ClassFlowMakeImage";
}
if ((_stepname.compare("[Alignment]") == 0) || (_stepname.compare(";[Alignment]") == 0)){
_classname = "ClassFlowAlignment";
}
if ((_stepname.compare(0, 7, "[Digits") == 0) || (_stepname.compare(0, 8, ";[Digits") == 0)) {
_classname = "ClassFlowCNNGeneral";
}
if ((_stepname.compare("[Analog]") == 0) || (_stepname.compare(";[Analog]") == 0)){
_classname = "ClassFlowCNNGeneral";
}
if ((_stepname.compare("[MQTT]") == 0) || (_stepname.compare(";[MQTT]") == 0)){
_classname = "ClassFlowMQTT";
}
if ((_stepname.compare("[InfluxDB]") == 0) || (_stepname.compare(";[InfluxDB]") == 0)){
_classname = "ClassFlowInfluxDB";
}
for (int i = 0; i < FlowControll.size(); ++i)
if (FlowControll[i]->name().compare(_classname) == 0){
if (!(FlowControll[i]->name().compare("ClassFlowMakeImage") == 0)) // falls es ein MakeImage ist, braucht das Bild nicht extra aufgenommen zu werden, dass passiert bei html-Abfrage automatisch
FlowControll[i]->doFlow("");
result = FlowControll[i]->getHTMLSingleStep(_host);
}
ESP_LOGD(TAG, "Step %s end", _stepname.c_str());
return result;
}
std::string ClassFlowControll::TranslateAktstatus(std::string _input)
{
if (_input.compare("ClassFlowMakeImage") == 0)
return ("Take Image");
if (_input.compare("ClassFlowAlignment") == 0)
return ("Aligning");
if (_input.compare("ClassFlowCNNGeneral") == 0)
return ("Digitalization of ROIs");
if (_input.compare("ClassFlowMQTT") == 0)
return ("Sending MQTT");
if (_input.compare("ClassFlowInfluxDB") == 0)
return ("Sending InfluxDB");
if (_input.compare("ClassFlowPostProcessing") == 0)
return ("Processing");
if (_input.compare("ClassFlowWriteList") == 0)
return ("Processing");
return "Unkown Status";
}
std::vector<HTMLInfo*> ClassFlowControll::GetAllDigital()
{
if (flowdigit)
{
ESP_LOGD(TAG, "ClassFlowControll::GetAllDigital - flowdigit != NULL");
return flowdigit->GetHTMLInfo();
}
std::vector<HTMLInfo*> empty;
return empty;
}
std::vector<HTMLInfo*> ClassFlowControll::GetAllAnalog()
{
if (flowanalog)
return flowanalog->GetHTMLInfo();
std::vector<HTMLInfo*> empty;
return empty;
}
t_CNNType ClassFlowControll::GetTypeDigital()
{
if (flowdigit)
return flowdigit->getCNNType();
return t_CNNType::None;
}
t_CNNType ClassFlowControll::GetTypeAnalog()
{
if (flowanalog)
return flowanalog->getCNNType();
return t_CNNType::None;
}
string ClassFlowControll::GetMQTTMainTopic()
{
for (int i = 0; i < FlowControll.size(); ++i)
if (FlowControll[i]->name().compare("ClassFlowMQTT") == 0)
return ((ClassFlowMQTT*) (FlowControll[i]))->GetMQTTMainTopic();
return "";
}
void ClassFlowControll::SetInitialParameter(void)
{
AutoStart = false;
SetupModeActive = false;
AutoIntervall = 10; // Minutes
flowdigit = NULL;
flowanalog = NULL;
flowpostprocessing = NULL;
disabled = false;
aktRunNr = 0;
aktstatus = "Booting ...";
}
bool ClassFlowControll::isAutoStart(long &_intervall)
{
_intervall = AutoIntervall * 60 * 1000; // AutoIntervall: Minuten -> ms
return AutoStart;
}
ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
{
ClassFlow* cfc = NULL;
_type = trim(_type);
if (toUpper(_type).compare("[MAKEIMAGE]") == 0)
{
cfc = new ClassFlowMakeImage(&FlowControll);
flowmakeimage = (ClassFlowMakeImage*) cfc;
}
if (toUpper(_type).compare("[ALIGNMENT]") == 0)
{
cfc = new ClassFlowAlignment(&FlowControll);
flowalignment = (ClassFlowAlignment*) cfc;
}
if (toUpper(_type).compare("[ANALOG]") == 0)
{
cfc = new ClassFlowCNNGeneral(flowalignment);
flowanalog = (ClassFlowCNNGeneral*) cfc;
}
if (toUpper(_type).compare(0, 7, "[DIGITS") == 0)
{
cfc = new ClassFlowCNNGeneral(flowalignment);
flowdigit = (ClassFlowCNNGeneral*) cfc;
}
if (toUpper(_type).compare("[MQTT]") == 0)
cfc = new ClassFlowMQTT(&FlowControll);
if (toUpper(_type).compare("[INFLUXDB]") == 0)
cfc = new ClassFlowInfluxDB(&FlowControll);
if (toUpper(_type).compare("[WRITELIST]") == 0)
cfc = new ClassFlowWriteList(&FlowControll);
if (toUpper(_type).compare("[POSTPROCESSING]") == 0)
{
cfc = new ClassFlowPostProcessing(&FlowControll, flowanalog, flowdigit);
flowpostprocessing = (ClassFlowPostProcessing*) cfc;
}
if (cfc) // Wird nur angehangen, falls es nicht [AutoTimer] ist, denn dieses ist für FlowControll
FlowControll.push_back(cfc);
if (toUpper(_type).compare("[AUTOTIMER]") == 0)
cfc = this;
if (toUpper(_type).compare("[DATALOGGING]") == 0)
cfc = this;
if (toUpper(_type).compare("[DEBUG]") == 0)
cfc = this;
if (toUpper(_type).compare("[SYSTEM]") == 0)
cfc = this;
return cfc;
}
void ClassFlowControll::InitFlow(std::string config)
{
string line;
flowpostprocessing = NULL;
ClassFlow* cfc;
FILE* pFile;
config = FormatFileName(config);
pFile = OpenFileAndWait(config.c_str(), "r");
line = "";
char zw[1024];
if (pFile != NULL)
{
fgets(zw, 1024, pFile);
ESP_LOGD(TAG, "%s", zw);
line = std::string(zw);
}
while ((line.size() > 0) && !(feof(pFile)))
{
cfc = CreateClassFlow(line);
if (cfc)
{
ESP_LOGD(TAG, "Start ReadParameter (%s)", line.c_str());
cfc->ReadParameter(pFile, line);
}
else
{
line = "";
if (fgets(zw, 1024, pFile) && !feof(pFile))
{
ESP_LOGD(TAG, "Read: %s", zw);
line = std::string(zw);
}
}
}
fclose(pFile);
}
std::string* ClassFlowControll::getActStatus(){
return &aktstatus;
}
void ClassFlowControll::doFlowMakeImageOnly(string time){
std::string zw_time;
for (int i = 0; i < FlowControll.size(); ++i)
{
if (FlowControll[i]->name() == "ClassFlowMakeImage") {
// zw_time = gettimestring("%Y%m%d-%H%M%S");
zw_time = gettimestring("%H:%M:%S");
aktstatus = TranslateAktstatus(FlowControll[i]->name()) + " (" + zw_time + ")";
FlowControll[i]->doFlow(time);
}
}
}
bool ClassFlowControll::doFlow(string time)
{
// CleanTempFolder(); // dazu muss man noch eine Rolling einführen
bool result = true;
std::string zw_time;
int repeat = 0;
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("ClassFlowControll::doFlow - Start");
#endif
/* Check if we have a valid date/time and if not restart the NTP client */
if (! getTimeIsSet()) {
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Time not set, restarting NTP Client!");
restartNtpClient();
}
for (int i = 0; i < FlowControll.size(); ++i)
{
zw_time = gettimestring("%H:%M:%S");
aktstatus = TranslateAktstatus(FlowControll[i]->name()) + " (" + zw_time + ")";
// zw_time = gettimestring("%Y%m%d-%H%M%S");
// aktstatus = zw_time + ": " + FlowControll[i]->name();
string zw = "FlowControll.doFlow - " + FlowControll[i]->name();
LogFile.WriteHeapInfo(zw);
if (!FlowControll[i]->doFlow(time)){
repeat++;
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Fehler im vorheriger Schritt - wird zum " + to_string(repeat) + ". Mal wiederholt");
if (i) i -= 1; // vorheriger Schritt muss wiederholt werden (vermutlich Bilder aufnehmen)
result = false;
if (repeat > 5) {
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Wiederholung 5x nicht erfolgreich --> reboot");
doReboot();
// Schritt wurde 5x wiederholt --> reboot
}
}
else
{
result = true;
}
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("ClassFlowControll::doFlow");
#endif
}
zw_time = gettimestring("%H:%M:%S");
aktstatus = "Flow finished (" + zw_time + ")";
return result;
}
string ClassFlowControll::getReadoutAll(int _type)
{
std::string out = "";
if (flowpostprocessing)
{
std::vector<NumberPost*> *numbers = flowpostprocessing->GetNumbers();
for (int i = 0; i < (*numbers).size(); ++i)
{
out = out + (*numbers)[i]->name + "\t";
switch (_type) {
case READOUT_TYPE_VALUE:
out = out + (*numbers)[i]->ReturnValue;
break;
case READOUT_TYPE_PREVALUE:
if (flowpostprocessing->PreValueUse)
{
if ((*numbers)[i]->PreValueOkay)
out = out + (*numbers)[i]->ReturnPreValue;
else
out = out + "PreValue too old";
}
else
out = out + "PreValue deactivated";
break;
case READOUT_TYPE_RAWVALUE:
out = out + (*numbers)[i]->ReturnRawValue;
break;
case READOUT_TYPE_ERROR:
out = out + (*numbers)[i]->ErrorMessageText;
break;
}
if (i < (*numbers).size()-1)
out = out + "\r\n";
}
// ESP_LOGD(TAG, "OUT: %s", out.c_str());
}
return out;
}
string ClassFlowControll::getReadout(bool _rawvalue = false, bool _noerror = false)
{
if (flowpostprocessing)
return flowpostprocessing->getReadoutParam(_rawvalue, _noerror);
string zw = "";
string result = "";
for (int i = 0; i < FlowControll.size(); ++i)
{
zw = FlowControll[i]->getReadout();
if (zw.length() > 0)
{
if (result.length() == 0)
result = zw;
else
result = result + "\t" + zw;
}
}
return result;
}
string ClassFlowControll::GetPrevalue(std::string _number)
{
if (flowpostprocessing)
{
return flowpostprocessing->GetPreValue(_number);
}
return std::string("");
}
std::string ClassFlowControll::UpdatePrevalue(std::string _newvalue, std::string _numbers, bool _extern)
{
float zw;
char* p;
_newvalue = trim(_newvalue);
// ESP_LOGD(TAG, "Input UpdatePreValue: %s", _newvalue.c_str());
if (_newvalue.compare("0.0") == 0)
{
zw = 0;
}
else
{
zw = strtof(_newvalue.c_str(), &p);
if (zw == 0)
return "- Error in String to Value Conversion!!! Must be of format value=123.456";
}
if (flowpostprocessing)
{
flowpostprocessing->SetPreValue(zw, _numbers, _extern);
return _newvalue;
}
return std::string();
}
bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
{
std::vector<string> zerlegt;
aktparamgraph = trim(aktparamgraph);
if (aktparamgraph.size() == 0)
if (!this->GetNextParagraph(pfile, aktparamgraph))
return false;
if ((toUpper(aktparamgraph).compare("[AUTOTIMER]") != 0) && (toUpper(aktparamgraph).compare("[DEBUG]") != 0) &&
(toUpper(aktparamgraph).compare("[SYSTEM]") != 0 && (toUpper(aktparamgraph).compare("[DATALOGGING]") != 0))) // Paragraph passt nicht zu MakeImage
return false;
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
{
zerlegt = ZerlegeZeile(aktparamgraph, " =");
if ((toUpper(zerlegt[0]) == "AUTOSTART") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
{
AutoStart = true;
}
}
if ((toUpper(zerlegt[0]) == "INTERVALL") && (zerlegt.size() > 1))
{
AutoIntervall = std::stof(zerlegt[1]);
}
if ((toUpper(zerlegt[0]) == "DATALOGACTIVE") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
{
LogFile.SetDataLogToSD(true);
}
else {
LogFile.SetDataLogToSD(false);
}
}
if ((toUpper(zerlegt[0]) == "DATALOGRETENTIONINDAYS") && (zerlegt.size() > 1))
{
LogFile.SetDataLogRetention(std::stoi(zerlegt[1]));
}
if ((toUpper(zerlegt[0]) == "LOGFILE") && (zerlegt.size() > 1))
{
/* matches esp_log_level_t */
if ((toUpper(zerlegt[1]) == "TRUE") || (toUpper(zerlegt[1]) == "2"))
{
LogFile.setLogLevel(ESP_LOG_WARN);
}
else if ((toUpper(zerlegt[1]) == "FALSE") || (toUpper(zerlegt[1]) == "0") || (toUpper(zerlegt[1]) == "1"))
{
LogFile.setLogLevel(ESP_LOG_ERROR);
}
else if (toUpper(zerlegt[1]) == "3")
{
LogFile.setLogLevel(ESP_LOG_INFO);
}
else if (toUpper(zerlegt[1]) == "4")
{
LogFile.setLogLevel(ESP_LOG_DEBUG);
}
}
if ((toUpper(zerlegt[0]) == "LOGFILERETENTIONINDAYS") && (zerlegt.size() > 1))
{
LogFile.SetLogFileRetention(std::stoi(zerlegt[1]));
}
if ((toUpper(zerlegt[0]) == "TIMEZONE") && (zerlegt.size() > 1))
{
string zw = "Set TimeZone: " + zerlegt[1];
setTimeZone(zerlegt[1]);
}
if ((toUpper(zerlegt[0]) == "TIMESERVER") && (zerlegt.size() > 1))
{
string zw = "Set TimeZone: " + zerlegt[1];
reset_servername(zerlegt[1]);
}
if ((toUpper(zerlegt[0]) == "HOSTNAME") && (zerlegt.size() > 1))
{
if (ChangeHostName("/sdcard/wlan.ini", zerlegt[1]))
{
// reboot notwendig damit die neue wlan.ini auch benutzt wird !!!
fclose(pfile);
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Rebooting to activate new HOSTNAME...");
esp_restart();
hard_restart();
doReboot();
}
}
if ((toUpper(zerlegt[0]) == "SETUPMODE") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
{
SetupModeActive = true;
}
}
}
/* Start the MQTT service */
for (int i = 0; i < FlowControll.size(); ++i)
if (FlowControll[i]->name().compare("ClassFlowMQTT") == 0)
return ((ClassFlowMQTT*) (FlowControll[i]))->Start(AutoIntervall);
return true;
}
int ClassFlowControll::CleanTempFolder() {
const char* folderPath = "/sdcard/img_tmp";
ESP_LOGI(TAG, "Clean up temporary folder to avoid damage of sdcard sectors : %s", folderPath);
DIR *dir = opendir(folderPath);
if (!dir) {
ESP_LOGE(TAG, "Failed to stat dir : %s", folderPath);
return -1;
}
struct dirent *entry;
int deleted = 0;
while ((entry = readdir(dir)) != NULL) {
std::string path = string(folderPath) + "/" + entry->d_name;
if (entry->d_type == DT_REG) {
if (unlink(path.c_str()) == 0) {
deleted ++;
} else {
ESP_LOGE(TAG, "can't delete file : %s", path.c_str());
}
} else if (entry->d_type == DT_DIR) {
deleted += removeFolder(path.c_str(), TAG);
}
}
closedir(dir);
ESP_LOGI(TAG, "%d files deleted", deleted);
return 0;
}
esp_err_t ClassFlowControll::SendRawJPG(httpd_req_t *req)
{
return flowmakeimage != NULL ? flowmakeimage->SendRawJPG(req) : ESP_FAIL;
}
esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
{
ESP_LOGD(TAG, "ClassFlowControll::GetJPGStream %s", _fn.c_str());
CImageBasis *_send = NULL;
esp_err_t result = ESP_FAIL;
bool Dodelete = false;
if (flowalignment == NULL)
{
ESP_LOGD(TAG, "Can't continue, flowalignment is NULL");
return ESP_FAIL;
}
if (_fn == "alg.jpg")
{
_send = flowalignment->ImageBasis;
}
else
{
if (_fn == "alg_roi.jpg")
{
CImageBasis* _imgzw = new CImageBasis(flowalignment->ImageBasis);
flowalignment->DrawRef(_imgzw);
if (flowdigit) flowdigit->DrawROI(_imgzw);
if (flowanalog) flowanalog->DrawROI(_imgzw);
_send = _imgzw;
Dodelete = true;
}
else
{
std::vector<HTMLInfo*> htmlinfo;
htmlinfo = GetAllDigital();
ESP_LOGD(TAG, "After getClassFlowControll::GetAllDigital");
for (int i = 0; i < htmlinfo.size(); ++i)
{
if (_fn == htmlinfo[i]->filename)
{
if (htmlinfo[i]->image)
_send = htmlinfo[i]->image;
}
if (_fn == htmlinfo[i]->filename_org)
{
if (htmlinfo[i]->image_org)
_send = htmlinfo[i]->image_org;
}
delete htmlinfo[i];
}
htmlinfo.clear();
if (!_send)
{
htmlinfo = GetAllAnalog();
for (int i = 0; i < htmlinfo.size(); ++i)
{
if (_fn == htmlinfo[i]->filename)
{
if (htmlinfo[i]->image)
_send = htmlinfo[i]->image;
}
if (_fn == htmlinfo[i]->filename_org)
{
if (htmlinfo[i]->image_org)
_send = htmlinfo[i]->image_org;
}
delete htmlinfo[i];
}
htmlinfo.clear();
}
}
}
if (_send)
{
ESP_LOGI(TAG, "Sending file : %s ...", _fn.c_str());
set_content_type_from_file(req, _fn.c_str());
result = _send->SendJPGtoHTTP(req);
ESP_LOGI(TAG, "File sending complete");
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
}
if (Dodelete)
{
delete _send;
}
return result;
}
string ClassFlowControll::getNumbersName()
{
return flowpostprocessing->getNumbersName();
}
string ClassFlowControll::getJSON(std::string _id, std::string _mac)
{
return flowpostprocessing->GetJSON(_id, _mac);
}

View File

@@ -0,0 +1,82 @@
#ifndef __FLOWCONTROLL__
#define __FLOWCONTROLL__
#include <string>
#include "ClassFlow.h"
#include "ClassFlowMakeImage.h"
#include "ClassFlowAlignment.h"
#include "ClassFlowCNNGeneral.h"
#include "ClassFlowPostProcessing.h"
#include "ClassFlowMQTT.h"
#include "ClassFlowInfluxDB.h"
#include "ClassFlowCNNGeneral.h"
#include "ClassFlowWriteList.h"
#define READOUT_TYPE_VALUE 0
#define READOUT_TYPE_PREVALUE 1
#define READOUT_TYPE_RAWVALUE 2
#define READOUT_TYPE_ERROR 3
class ClassFlowControll :
public ClassFlow
{
protected:
std::vector<ClassFlow*> FlowControll;
ClassFlowPostProcessing* flowpostprocessing;
ClassFlowAlignment* flowalignment;
ClassFlowCNNGeneral* flowanalog;
ClassFlowCNNGeneral* flowdigit;
// ClassFlowDigit* flowdigit;
ClassFlowMakeImage* flowmakeimage;
ClassFlow* CreateClassFlow(std::string _type);
bool AutoStart;
float AutoIntervall;
bool SetupModeActive;
void SetInitialParameter(void);
std::string aktstatus;
int aktRunNr;
public:
void InitFlow(std::string config);
bool doFlow(string time);
void doFlowMakeImageOnly(string time);
bool getStatusSetupModus(){return SetupModeActive;};
string getReadout(bool _rawvalue, bool _noerror);
string getReadoutAll(int _type);
string UpdatePrevalue(std::string _newvalue, std::string _numbers, bool _extern);
string GetPrevalue(std::string _number = "");
bool ReadParameter(FILE* pfile, string& aktparamgraph);
string getJSON(std::string _id = "", std::string _mac = "");
string getNumbersName();
string TranslateAktstatus(std::string _input);
string GetMQTTMainTopic();
esp_err_t GetJPGStream(std::string _fn, httpd_req_t *req);
esp_err_t SendRawJPG(httpd_req_t *req);
std::string doSingleStep(std::string _stepname, std::string _host);
bool isAutoStart(long &_intervall);
std::string* getActStatus();
std::vector<HTMLInfo*> GetAllDigital();
std::vector<HTMLInfo*> GetAllAnalog();
t_CNNType GetTypeDigital();
t_CNNType GetTypeAnalog();
int CleanTempFolder();
string name(){return "ClassFlowControll";};
};
#endif

View File

@@ -0,0 +1,61 @@
#ifndef __CLASSFLOWIMAGE_CLASS__
#define __CLASSFLOWIMAGE_CLASS__
#include "ClassFlowImage.h"
struct roi {
int posx, posy, deltax, deltay;
float result_float;
int result_klasse;
bool isReject, CCW;
string name;
CImageBasis *image, *image_org;
};
struct general {
string name;
std::vector<roi*> ROI;
};
enum t_RateType {
AbsoluteChange,
RateChange
};
struct NumberPost {
float MaxRateValue;
bool useMaxRateValue;
t_RateType RateType;
bool ErrorMessage;
bool PreValueOkay;
bool AllowNegativeRates;
bool checkDigitIncreaseConsistency;
time_t lastvalue;
string timeStamp;
double FlowRateAct; // m3 / min
double PreValue; // letzter Wert, der gut ausgelesen wurde
double Value; // letzer ausgelesener Wert, inkl. Korrekturen
string ReturnRateValue; // RückgabewertRate
string ReturnChangeAbsolute; // RückgabewertRate
string ReturnRawValue; // Rohwert (mit N & führenden 0)
string ReturnValue; // korrigierter Rückgabewert, ggf. mit Fehlermeldung
string ReturnPreValue; // korrigierter Rückgabewert ohne Fehlermeldung
string ErrorMessageText; // Fehlermeldung bei Consistency Check
int AnzahlAnalog;
int AnzahlDigital;
int DecimalShift;
int DecimalShiftInitial;
float AnalogDigitalTransitionStart; // Wann ist das digit > x.1, also wann fängt es an zu kippen
int Nachkomma;
bool isExtendedResolution;
general *digit_roi;
general *analog_roi;
string name;
};
#endif

View File

@@ -0,0 +1,138 @@
#include "ClassFlowImage.h"
#include <string>
#include <string.h>
#include <sys/stat.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <dirent.h>
#ifdef __cplusplus
}
#endif
#include "time_sntp.h"
#include "ClassLogFile.h"
#include "CImageBasis.h"
#include "esp_log.h"
static const char* TAG = "FLOW IMG";
ClassFlowImage::ClassFlowImage(const char* logTag)
{
this->logTag = logTag;
isLogImage = false;
disabled = false;
this->logfileRetentionInDays = 5;
}
ClassFlowImage::ClassFlowImage(std::vector<ClassFlow*> * lfc, const char* logTag) : ClassFlow(lfc)
{
this->logTag = logTag;
isLogImage = false;
disabled = false;
this->logfileRetentionInDays = 5;
}
ClassFlowImage::ClassFlowImage(std::vector<ClassFlow*> * lfc, ClassFlow *_prev, const char* logTag) : ClassFlow(lfc, _prev)
{
this->logTag = logTag;
isLogImage = false;
disabled = false;
this->logfileRetentionInDays = 5;
}
string ClassFlowImage::CreateLogFolder(string time) {
if (!isLogImage)
return "";
string logPath = LogImageLocation + "/" + time.LOGFILE_TIME_FORMAT_DATE_EXTR + "/" + time.LOGFILE_TIME_FORMAT_HOUR_EXTR;
isLogImage = mkdir_r(logPath.c_str(), S_IRWXU) == 0;
if (!isLogImage) {
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Can't create log folder for analog images. Path " + logPath);
}
return logPath;
}
void ClassFlowImage::LogImage(string logPath, string name, float *resultFloat, int *resultInt, string time, CImageBasis *_img) {
if (!isLogImage)
return;
char buf[10];
if (resultFloat != NULL) {
if (*resultFloat < 0)
sprintf(buf, "N.N_");
else
{
sprintf(buf, "%.1f_", *resultFloat);
if (strcmp(buf, "10.0_") == 0)
sprintf(buf, "0.0_");
}
} else if (resultInt != NULL) {
sprintf(buf, "%d_", *resultInt);
} else {
buf[0] = '\0';
}
string nm = logPath + "/" + buf + name + "_" + time + ".jpg";
nm = FormatFileName(nm);
string output = "/sdcard/img_tmp/" + name + ".jpg";
output = FormatFileName(output);
ESP_LOGD(logTag, "save to file: %s", nm.c_str());
_img->SaveToFile(nm);
// CopyFile(output, nm);
}
void ClassFlowImage::RemoveOldLogs()
{
if (!isLogImage)
return;
ESP_LOGI(TAG, "remove old images");
if (logfileRetentionInDays == 0) {
return;
}
time_t rawtime;
struct tm* timeinfo;
char cmpfilename[30];
time(&rawtime);
rawtime = addDays(rawtime, -logfileRetentionInDays + 1);
timeinfo = localtime(&rawtime);
//ESP_LOGD(TAG, "ImagefileRetentionInDays: %d", logfileRetentionInDays);
strftime(cmpfilename, 30, LOGFILE_TIME_FORMAT, timeinfo);
//ESP_LOGD(TAG, "file name to compare: %s", cmpfilename);
string folderName = string(cmpfilename).LOGFILE_TIME_FORMAT_DATE_EXTR;
DIR *dir = opendir(LogImageLocation.c_str());
if (!dir) {
ESP_LOGE(TAG, "Failed to stat dir : %s", LogImageLocation.c_str());
return;
}
struct dirent *entry;
int deleted = 0;
int notDeleted = 0;
while ((entry = readdir(dir)) != NULL) {
string folderPath = LogImageLocation + "/" + entry->d_name;
if (entry->d_type == DT_DIR) {
//ESP_LOGD(TAG, "Compare %s to %s", entry->d_name, folderName.c_str());
if ((strlen(entry->d_name) == folderName.length()) && (strcmp(entry->d_name, folderName.c_str()) < 0)) {
removeFolder(folderPath.c_str(), logTag);
deleted++;
} else {
notDeleted ++;
}
}
}
ESP_LOGI(TAG, "Image folder deleted: %d | Image folder not deleted: %d", deleted, notDeleted);
closedir(dir);
}

View File

@@ -0,0 +1,24 @@
#pragma once
#include "ClassFlow.h"
using namespace std;
class ClassFlowImage : public ClassFlow
{
protected:
string LogImageLocation;
bool isLogImage;
unsigned short logfileRetentionInDays;
const char* logTag;
string CreateLogFolder(string time);
void LogImage(string logPath, string name, float *resultFloat, int *resultInt, string time, CImageBasis *_img);
public:
ClassFlowImage(const char* logTag);
ClassFlowImage(std::vector<ClassFlow*> * lfc, const char* logTag);
ClassFlowImage(std::vector<ClassFlow*> * lfc, ClassFlow *_prev, const char* logTag);
void RemoveOldLogs();
};

View File

@@ -0,0 +1,164 @@
#include <sstream>
#include "ClassFlowInfluxDB.h"
#include "Helper.h"
#include "connect_wlan.h"
#include "time_sntp.h"
#include "interface_influxdb.h"
#include "ClassFlowPostProcessing.h"
#include "esp_log.h"
#include <time.h>
static const char* TAG = "class_flow_influxDb";
void ClassFlowInfluxDB::SetInitialParameter(void)
{
uri = "";
database = "";
measurement = "";
OldValue = "";
flowpostprocessing = NULL;
user = "";
password = "";
previousElement = NULL;
ListFlowControll = NULL;
disabled = false;
InfluxDBenable = false;
}
ClassFlowInfluxDB::ClassFlowInfluxDB()
{
SetInitialParameter();
}
ClassFlowInfluxDB::ClassFlowInfluxDB(std::vector<ClassFlow*>* lfc)
{
SetInitialParameter();
ListFlowControll = lfc;
for (int i = 0; i < ListFlowControll->size(); ++i)
{
if (((*ListFlowControll)[i])->name().compare("ClassFlowPostProcessing") == 0)
{
flowpostprocessing = (ClassFlowPostProcessing*) (*ListFlowControll)[i];
}
}
}
ClassFlowInfluxDB::ClassFlowInfluxDB(std::vector<ClassFlow*>* lfc, ClassFlow *_prev)
{
SetInitialParameter();
previousElement = _prev;
ListFlowControll = lfc;
for (int i = 0; i < ListFlowControll->size(); ++i)
{
if (((*ListFlowControll)[i])->name().compare("ClassFlowPostProcessing") == 0)
{
flowpostprocessing = (ClassFlowPostProcessing*) (*ListFlowControll)[i];
}
}
}
bool ClassFlowInfluxDB::ReadParameter(FILE* pfile, string& aktparamgraph)
{
std::vector<string> zerlegt;
aktparamgraph = trim(aktparamgraph);
if (aktparamgraph.size() == 0)
if (!this->GetNextParagraph(pfile, aktparamgraph))
return false;
if (toUpper(aktparamgraph).compare("[INFLUXDB]") != 0)
return false;
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
{
ESP_LOGD(TAG, "while loop reading line: %s", aktparamgraph.c_str());
zerlegt = ZerlegeZeile(aktparamgraph);
if ((toUpper(zerlegt[0]) == "USER") && (zerlegt.size() > 1))
{
this->user = zerlegt[1];
}
if ((toUpper(zerlegt[0]) == "PASSWORD") && (zerlegt.size() > 1))
{
this->password = zerlegt[1];
}
if ((toUpper(zerlegt[0]) == "URI") && (zerlegt.size() > 1))
{
this->uri = zerlegt[1];
}
if (((toUpper(zerlegt[0]) == "MEASUREMENT")) && (zerlegt.size() > 1))
{
this->measurement = zerlegt[1];
}
if (((toUpper(zerlegt[0]) == "DATABASE")) && (zerlegt.size() > 1))
{
this->database = zerlegt[1];
}
}
if ((uri.length() > 0) && (database.length() > 0) && (measurement.length() > 0))
{
ESP_LOGD(TAG, "Init InfluxDB with uri: %s, measurement: %s, user: %s, password: %s", uri.c_str(), measurement.c_str(), user.c_str(), password.c_str());
InfluxDBInit(uri, database, measurement, user, password);
InfluxDBenable = true;
} else {
ESP_LOGD(TAG, "InfluxDB init skipped as we are missing some parameters");
}
return true;
}
string ClassFlowInfluxDB::GetInfluxDBMeasurement()
{
return measurement;
}
bool ClassFlowInfluxDB::doFlow(string zwtime)
{
if (!InfluxDBenable)
return true;
std::string result;
std::string resulterror = "";
std::string resultraw = "";
std::string resultrate = "";
std::string resulttimestamp = "";
string zw = "";
string namenumber = "";
if (flowpostprocessing)
{
std::vector<NumberPost*>* NUMBERS = flowpostprocessing->GetNumbers();
for (int i = 0; i < (*NUMBERS).size(); ++i)
{
result = (*NUMBERS)[i]->ReturnValue;
resultraw = (*NUMBERS)[i]->ReturnRawValue;
resulterror = (*NUMBERS)[i]->ErrorMessageText;
resultrate = (*NUMBERS)[i]->ReturnRateValue;
resulttimestamp = (*NUMBERS)[i]->timeStamp;
namenumber = (*NUMBERS)[i]->name;
if (namenumber == "default")
namenumber = "value";
else
namenumber = namenumber + "/value";
if (result.length() > 0 && resulttimestamp.length() > 0)
InfluxDBPublish(namenumber, result, resulttimestamp);
}
}
OldValue = result;
return true;
}

View File

@@ -0,0 +1,31 @@
#pragma once
#include "ClassFlow.h"
#include "ClassFlowPostProcessing.h"
#include <string>
class ClassFlowInfluxDB :
public ClassFlow
{
protected:
std::string uri, database, measurement;
std::string OldValue;
ClassFlowPostProcessing* flowpostprocessing;
std::string user, password;
bool InfluxDBenable;
void SetInitialParameter(void);
public:
ClassFlowInfluxDB();
ClassFlowInfluxDB(std::vector<ClassFlow*>* lfc);
ClassFlowInfluxDB(std::vector<ClassFlow*>* lfc, ClassFlow *_prev);
string GetInfluxDBMeasurement();
bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
string name(){return "ClassFlowInfluxDB";};
};

View File

@@ -0,0 +1,320 @@
#include <sstream>
#include <iomanip>
#include "ClassFlowMQTT.h"
#include "Helper.h"
#include "connect_wlan.h"
#include "ClassLogFile.h"
#include "time_sntp.h"
#include "interface_mqtt.h"
#include "ClassFlowPostProcessing.h"
#include "ClassFlowControll.h"
#include "server_mqtt.h"
#include <time.h>
#define __HIDE_PASSWORD
static const char *TAG = "FLOW MQTT";
#define LWT_TOPIC "connection"
#define LWT_CONNECTED "connected"
#define LWT_DISCONNECTED "connection lost"
extern const char* libfive_git_version(void);
extern const char* libfive_git_revision(void);
extern const char* libfive_git_branch(void);
void ClassFlowMQTT::SetInitialParameter(void)
{
uri = "";
topic = "";
topicError = "";
topicRate = "";
topicTimeStamp = "";
maintopic = hostname;
topicUptime = "";
topicFreeMem = "";
clientname = "AIOTED-" + getMac();
OldValue = "";
flowpostprocessing = NULL;
user = "";
password = "";
SetRetainFlag = 0;
previousElement = NULL;
ListFlowControll = NULL;
disabled = false;
keepAlive = 25*60;
}
ClassFlowMQTT::ClassFlowMQTT()
{
SetInitialParameter();
}
ClassFlowMQTT::ClassFlowMQTT(std::vector<ClassFlow*>* lfc)
{
SetInitialParameter();
ListFlowControll = lfc;
for (int i = 0; i < ListFlowControll->size(); ++i)
{
if (((*ListFlowControll)[i])->name().compare("ClassFlowPostProcessing") == 0)
{
flowpostprocessing = (ClassFlowPostProcessing*) (*ListFlowControll)[i];
}
}
}
ClassFlowMQTT::ClassFlowMQTT(std::vector<ClassFlow*>* lfc, ClassFlow *_prev)
{
SetInitialParameter();
previousElement = _prev;
ListFlowControll = lfc;
for (int i = 0; i < ListFlowControll->size(); ++i)
{
if (((*ListFlowControll)[i])->name().compare("ClassFlowPostProcessing") == 0)
{
flowpostprocessing = (ClassFlowPostProcessing*) (*ListFlowControll)[i];
}
}
}
bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
{
std::vector<string> zerlegt;
aktparamgraph = trim(aktparamgraph);
if (aktparamgraph.size() == 0)
if (!this->GetNextParagraph(pfile, aktparamgraph))
return false;
if (toUpper(aktparamgraph).compare("[MQTT]") != 0) // Paragraph passt nich zu MakeImage
return false;
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
{
zerlegt = ZerlegeZeile(aktparamgraph);
if ((toUpper(zerlegt[0]) == "USER") && (zerlegt.size() > 1))
{
this->user = zerlegt[1];
}
if ((toUpper(zerlegt[0]) == "PASSWORD") && (zerlegt.size() > 1))
{
this->password = zerlegt[1];
}
if ((toUpper(zerlegt[0]) == "URI") && (zerlegt.size() > 1))
{
this->uri = zerlegt[1];
}
if ((toUpper(zerlegt[0]) == "SETRETAINFLAG") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE") {
SetRetainFlag = 1;
setMqtt_Server_Retain(SetRetainFlag);
}
}
if ((toUpper(zerlegt[0]) == "HOMEASSISTANTDISCOVERY") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
SetHomeassistantDiscoveryEnabled(true);
}
if ((toUpper(zerlegt[0]) == "METERTYPE") && (zerlegt.size() > 1)) {
/* Use meter type for the device class
Make sure it is a listed one on https://developers.home-assistant.io/docs/core/entity/sensor/#available-device-classes */
if (toUpper(zerlegt[1]) == "WATER_M3") {
mqttServer_setMeterType("water", "", "h", "m³/h");
}
else if (toUpper(zerlegt[1]) == "WATER_L") {
mqttServer_setMeterType("water", "L", "h", "L/h");
}
else if (toUpper(zerlegt[1]) == "WATER_FT3") {
mqttServer_setMeterType("water", "ft³", "m", "ft³/m"); // Minutes
}
else if (toUpper(zerlegt[1]) == "WATER_GAL") {
mqttServer_setMeterType("water", "gal", "h", "gal/h");
}
else if (toUpper(zerlegt[1]) == "GAS_M3") {
mqttServer_setMeterType("gas", "", "h", "m³/h");
}
else if (toUpper(zerlegt[1]) == "GAS_FT3") {
mqttServer_setMeterType("gas", "ft³", "m", "ft³/m"); // Minutes
}
else if (toUpper(zerlegt[1]) == "ENERGY_WH") {
mqttServer_setMeterType("energy", "Wh", "h", "W");
}
else if (toUpper(zerlegt[1]) == "ENERGY_KWH") {
mqttServer_setMeterType("energy", "kWh", "h", "kW");
}
else if (toUpper(zerlegt[1]) == "ENERGY_MWH") {
mqttServer_setMeterType("energy", "MWh", "h", "MW");
}
}
if ((toUpper(zerlegt[0]) == "CLIENTID") && (zerlegt.size() > 1))
{
this->clientname = zerlegt[1];
}
if (((toUpper(zerlegt[0]) == "TOPIC") || (toUpper(zerlegt[0]) == "MAINTOPIC")) && (zerlegt.size() > 1))
{
maintopic = zerlegt[1];
mqttServer_setMainTopic(maintopic);
}
}
/* Note:
* Originally, we started the MQTT client here.
* How ever we need the interval parameter from the ClassFlowControll, but that only gets started later.
* To work around this, we delay the start and trigger it from ClassFlowControll::ReadParameter() */
return true;
}
string ClassFlowMQTT::GetMQTTMainTopic()
{
return maintopic;
}
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());
mqttServer_setParameter(flowpostprocessing->GetNumbers(), keepAlive, roundInterval);
MQTT_Configure(uri, clientname, user, password, maintopic, LWT_TOPIC, LWT_CONNECTED, LWT_DISCONNECTED,
keepAlive, SetRetainFlag, (void *)&GotConnected);
if (!MQTT_Init()) {
if (!MQTT_Init()) { // Retry
return false;
}
}
return true;
}
bool ClassFlowMQTT::doFlow(string zwtime)
{
std::string result;
std::string resulterror = "";
std::string resultraw = "";
std::string resultrate = ""; // Always Unit / Minute
std::string resultRatePerTimeUnit = ""; // According to selection
std::string resulttimestamp = "";
std::string resultchangabs = "";
string zw = "";
string namenumber = "";
publishSystemData();
if (flowpostprocessing)
{
std::vector<NumberPost*>* NUMBERS = flowpostprocessing->GetNumbers();
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Publishing MQTT topics...");
for (int i = 0; i < (*NUMBERS).size(); ++i)
{
result = (*NUMBERS)[i]->ReturnValue;
resultraw = (*NUMBERS)[i]->ReturnRawValue;
resulterror = (*NUMBERS)[i]->ErrorMessageText;
resultrate = (*NUMBERS)[i]->ReturnRateValue; // Unit per minutes
resultchangabs = (*NUMBERS)[i]->ReturnChangeAbsolute; // Units per round
resulttimestamp = (*NUMBERS)[i]->timeStamp;
namenumber = (*NUMBERS)[i]->name;
if (namenumber == "default")
namenumber = maintopic + "/";
else
namenumber = maintopic + "/" + namenumber + "/";
if (result.length() > 0)
MQTTPublish(namenumber + "value", result, SetRetainFlag);
if (resulterror.length() > 0)
MQTTPublish(namenumber + "error", resulterror, SetRetainFlag);
if (resultrate.length() > 0) {
MQTTPublish(namenumber + "rate", resultrate, SetRetainFlag);
std::string resultRatePerTimeUnit;
if (getTimeUnit() == "h") { // Need conversion to be per hour
resultRatePerTimeUnit = resultRatePerTimeUnit = to_string((*NUMBERS)[i]->FlowRateAct * 60); // per minutes => per hour
}
else { // Keep per minute
resultRatePerTimeUnit = resultrate;
}
MQTTPublish(namenumber + "rate_per_time_unit", resultRatePerTimeUnit, SetRetainFlag);
}
if (resultchangabs.length() > 0) {
MQTTPublish(namenumber + "changeabsolut", resultchangabs, SetRetainFlag); // Legacy API
MQTTPublish(namenumber + "rate_per_digitalization_round", resultchangabs, SetRetainFlag);
}
if (resultraw.length() > 0)
MQTTPublish(namenumber + "raw", resultraw, SetRetainFlag);
if (resulttimestamp.length() > 0)
MQTTPublish(namenumber + "timestamp", resulttimestamp, SetRetainFlag);
std::string json = "";
if (result.length() > 0)
json += "{\"value\":"+result;
else
json += "{\"value\":\"\"";
json += ",\"raw\":\""+resultraw;
json += "\",\"error\":\""+resulterror;
if (resultrate.length() > 0)
json += "\",\"rate\":"+resultrate;
else
json += "\",\"rate\":\"\"";
json += ",\"timestamp\":\""+resulttimestamp+"\"}";
MQTTPublish(namenumber + "json", json, SetRetainFlag);
}
}
else
{
for (int i = 0; i < ListFlowControll->size(); ++i)
{
zw = (*ListFlowControll)[i]->getReadout();
if (zw.length() > 0)
{
if (result.length() == 0)
result = zw;
else
result = result + "\t" + zw;
}
}
MQTTPublish(topic, result, SetRetainFlag);
}
OldValue = result;
return true;
}

View File

@@ -0,0 +1,35 @@
#pragma once
#include "ClassFlow.h"
#include "ClassFlowPostProcessing.h"
#include <string>
class ClassFlowMQTT :
public ClassFlow
{
protected:
std::string uri, topic, topicError, clientname, topicRate, topicTimeStamp, topicUptime, topicFreeMem;
std::string OldValue;
ClassFlowPostProcessing* flowpostprocessing;
std::string user, password;
int SetRetainFlag;
int keepAlive; // Seconds
float roundInterval; // Minutes
std::string maintopic;
void SetInitialParameter(void);
public:
ClassFlowMQTT();
ClassFlowMQTT(std::vector<ClassFlow*>* lfc);
ClassFlowMQTT(std::vector<ClassFlow*>* lfc, ClassFlow *_prev);
string GetMQTTMainTopic();
bool Start(float AutoIntervall);
bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
string name(){return "ClassFlowMQTT";};
};

View File

@@ -0,0 +1,244 @@
#include "ClassFlowMakeImage.h"
#include "Helper.h"
#include "ClassLogFile.h"
#include "CImageBasis.h"
#include "ClassControllCamera.h"
#include "esp_wifi.h"
#include "esp_log.h"
#include <time.h>
// #define DEBUG_DETAIL_ON
// #define WIFITURNOFF
static const char* TAG = "flow_make_image";
esp_err_t ClassFlowMakeImage::camera_capture(){
string nm = namerawimage;
Camera.CaptureToFile(nm);
time(&TimeImageTaken);
localtime(&TimeImageTaken);
return ESP_OK;
}
void ClassFlowMakeImage::takePictureWithFlash(int flashdauer)
{
// für den Fall, dass das Bild geflippt wird, muss es hier zurück gesetzt werden ////
rawImage->width = image_width;
rawImage->height = image_height;
/////////////////////////////////////////////////////////////////////////////////////
ESP_LOGD(TAG, "Flashdauer: %d", flashdauer);
Camera.CaptureToBasisImage(rawImage, flashdauer);
time(&TimeImageTaken);
localtime(&TimeImageTaken);
if (SaveAllFiles) rawImage->SaveToFile(namerawimage);
}
void ClassFlowMakeImage::SetInitialParameter(void)
{
waitbeforepicture = 5;
isImageSize = false;
ImageQuality = -1;
TimeImageTaken = 0;
ImageQuality = 5;
rawImage = NULL;
ImageSize = FRAMESIZE_VGA;
SaveAllFiles = false;
disabled = false;
FixedExposure = false;
namerawimage = "/sdcard/img_tmp/raw.jpg";
}
ClassFlowMakeImage::ClassFlowMakeImage(std::vector<ClassFlow*>* lfc) : ClassFlowImage(lfc, TAG)
{
LogImageLocation = "/log/source";
logfileRetentionInDays = 5;
SetInitialParameter();
}
bool ClassFlowMakeImage::ReadParameter(FILE* pfile, string& aktparamgraph)
{
std::vector<string> zerlegt;
aktparamgraph = trim(aktparamgraph);
int _brightness = -100;
int _contrast = -100;
int _saturation = -100;
if (aktparamgraph.size() == 0)
if (!this->GetNextParagraph(pfile, aktparamgraph))
return false;
if (aktparamgraph.compare("[MakeImage]") != 0) // Paragraph passt nich zu MakeImage
return false;
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
{
zerlegt = ZerlegeZeile(aktparamgraph);
if ((zerlegt[0] == "LogImageLocation") && (zerlegt.size() > 1))
{
LogImageLocation = "/sdcard" + zerlegt[1];
isLogImage = true;
}
if ((zerlegt[0] == "ImageQuality") && (zerlegt.size() > 1))
ImageQuality = std::stod(zerlegt[1]);
if ((zerlegt[0] == "ImageSize") && (zerlegt.size() > 1))
{
ImageSize = Camera.TextToFramesize(zerlegt[1].c_str());
isImageSize = true;
}
if ((toUpper(zerlegt[0]) == "SAVEALLFILES") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
SaveAllFiles = true;
}
if ((toUpper(zerlegt[0]) == "WAITBEFORETAKINGPICTURE") && (zerlegt.size() > 1))
{
waitbeforepicture = stoi(zerlegt[1]);
}
if ((toUpper(zerlegt[0]) == "LOGFILERETENTIONINDAYS") && (zerlegt.size() > 1))
{
this->logfileRetentionInDays = std::stoi(zerlegt[1]);
}
if ((toUpper(zerlegt[0]) == "BRIGHTNESS") && (zerlegt.size() > 1))
{
_brightness = stoi(zerlegt[1]);
}
if ((toUpper(zerlegt[0]) == "CONTRAST") && (zerlegt.size() > 1))
{
_contrast = stoi(zerlegt[1]);
}
if ((toUpper(zerlegt[0]) == "SATURATION") && (zerlegt.size() > 1))
{
_saturation = stoi(zerlegt[1]);
}
if ((toUpper(zerlegt[0]) == "FIXEDEXPOSURE") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
FixedExposure = true;
}
if ((toUpper(zerlegt[0]) == "LEDINTENSITY") && (zerlegt.size() > 1))
{
float ledintensity = stof(zerlegt[1]);
ledintensity = min((float) 100, ledintensity);
ledintensity = max((float) 0, ledintensity);
Camera.SetLEDIntensity(ledintensity);
}
}
Camera.SetBrightnessContrastSaturation(_brightness, _contrast, _saturation);
Camera.SetQualitySize(ImageQuality, ImageSize);
image_width = Camera.image_width;
image_height = Camera.image_height;
rawImage = new CImageBasis();
rawImage->CreateEmptyImage(image_width, image_height, 3);
waitbeforepicture_store = waitbeforepicture;
if (FixedExposure && (waitbeforepicture > 0))
{
// ESP_LOGD(TAG, "Fixed Exposure enabled!");
int flashdauer = (int) (waitbeforepicture * 1000);
Camera.EnableAutoExposure(flashdauer);
waitbeforepicture = 0.2;
// flashdauer = (int) (waitbeforepicture * 1000);
// takePictureWithFlash(flashdauer);
// rawImage->SaveToFile("/sdcard/init2.jpg");
}
return true;
}
string ClassFlowMakeImage::getHTMLSingleStep(string host)
{
string result;
result = "Raw Image: <br>\n<img src=\"" + host + "/img_tmp/raw.jpg\">\n";
return result;
}
bool ClassFlowMakeImage::doFlow(string zwtime)
{
string logPath = CreateLogFolder(zwtime);
int flashdauer = (int) (waitbeforepicture * 1000);
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - Before takePictureWithFlash");
#endif
#ifdef WIFITURNOFF
esp_wifi_stop(); // to save power usage and
#endif
takePictureWithFlash(flashdauer);
#ifdef WIFITURNOFF
esp_wifi_start();
#endif
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - After takePictureWithFlash");
#endif
LogImage(logPath, "raw", NULL, NULL, zwtime, rawImage);
RemoveOldLogs();
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - After RemoveOldLogs");
#endif
return true;
}
esp_err_t ClassFlowMakeImage::SendRawJPG(httpd_req_t *req)
{
int flashdauer = (int) (waitbeforepicture * 1000);
time(&TimeImageTaken);
localtime(&TimeImageTaken);
return Camera.CaptureToHTTP(req, flashdauer);
}
ImageData* ClassFlowMakeImage::SendRawImage()
{
CImageBasis *zw = new CImageBasis(rawImage);
ImageData *id;
int flashdauer = (int) (waitbeforepicture * 1000);
Camera.CaptureToBasisImage(zw, flashdauer);
time(&TimeImageTaken);
localtime(&TimeImageTaken);
id = zw->writeToMemoryAsJPG();
delete zw;
return id;
}
time_t ClassFlowMakeImage::getTimeImageTaken()
{
return TimeImageTaken;
}
ClassFlowMakeImage::~ClassFlowMakeImage(void)
{
delete rawImage;
}

View File

@@ -1,11 +1,9 @@
#pragma once
#include "ClassFlow.h"
#include "ClassFlowImage.h"
#include "ClassControllCamera.h"
#include <string>
static const char* TAG2 = "example";
#define BLINK_GPIO GPIO_NUM_4
#define CAMERA_MODEL_AI_THINKER
@@ -13,30 +11,45 @@ static const char* TAG2 = "example";
class ClassFlowMakeImage :
public ClassFlow
public ClassFlowImage
{
protected:
string LogImageLocation;
bool isLogImage;
float waitbeforepicture;
float waitbeforepicture_store;
framesize_t ImageSize;
bool isImageSize;
int ImageQuality;
time_t TimeImageTaken;
string namerawimage;
int image_height, image_width;
bool SaveAllFiles;
bool FixedExposure;
void CopyFile(string input, string output);
esp_err_t camera_capture();
void takePictureWithFlash(int flashdauer);
void takePictureWithFlash(int flashdauer);
void SetInitialParameter(void);
public:
ClassFlowMakeImage();
CImageBasis *rawImage;
ClassFlowMakeImage(std::vector<ClassFlow*>* lfc);
bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
string getHTMLSingleStep(string host);
time_t getTimeImageTaken();
string name(){return "ClassFlowMakeImage";};
ImageData* SendRawImage();
esp_err_t SendRawJPG(httpd_req_t *req);
~ClassFlowMakeImage(void);
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,78 @@
#ifndef __FLOWPOSTPROCESSING__
#define __FLOWPOSTPROCESSING__
#include "ClassFlow.h"
#include "ClassFlowMakeImage.h"
#include "ClassFlowCNNGeneral.h"
#include "ClassFlowDefineTypes.h"
#include <string>
class ClassFlowPostProcessing :
public ClassFlow
{
protected:
std::vector<NumberPost*> NUMBERS;
bool UpdatePreValueINI;
int PreValueAgeStartup;
bool ErrorMessage;
bool IgnoreLeadingNaN; // SPEZIALFALL für User Gustl
ClassFlowCNNGeneral* flowAnalog;
ClassFlowCNNGeneral* flowDigit;
string FilePreValue;
ClassFlowMakeImage *flowMakeImage;
bool LoadPreValue(void);
string ShiftDecimal(string in, int _decShift);
string ErsetzteN(string, double _prevalue);
float checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue);
void InitNUMBERS();
void handleDecimalSeparator(string _decsep, string _value);
void handleMaxRateValue(string _decsep, string _value);
void handleDecimalExtendedResolution(string _decsep, string _value);
void handleMaxRateType(string _decsep, string _value);
void handleAnalogDigitalTransitionStart(string _decsep, string _value);
std::string GetStringReadouts(general);
void WriteDataLog(int _index);
public:
bool PreValueUse;
ClassFlowPostProcessing(std::vector<ClassFlow*>* lfc, ClassFlowCNNGeneral *_analog, ClassFlowCNNGeneral *_digit);
virtual ~ClassFlowPostProcessing(){};
bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
string getReadout(int _number);
string getReadoutParam(bool _rawValue, bool _noerror, int _number = 0);
string getReadoutError(int _number = 0);
string getReadoutRate(int _number = 0);
string getReadoutTimeStamp(int _number = 0);
void SavePreValue();
string GetPreValue(std::string _number = "");
void SetPreValue(double zw, string _numbers, bool _extern = false);
std::string GetJSON(std::string _id = "", std::string _mac = "", std::string _lineend = "\n");
std::string getNumbersName();
void UpdateNachkommaDecimalShift();
std::vector<NumberPost*>* GetNumbers(){return &NUMBERS;};
string name(){return "ClassFlowPostProcessing";};
};
#endif

View File

@@ -0,0 +1,97 @@
#include <sstream>
#include "ClassFlowWriteList.h"
#include "Helper.h"
#include "time_sntp.h"
#include <time.h>
void ClassFlowWriteList::SetInitialParameter(void)
{
flowpostprocessing = NULL;
previousElement = NULL;
ListFlowControll = NULL;
disabled = false;
}
ClassFlowWriteList::ClassFlowWriteList()
{
SetInitialParameter();
}
ClassFlowWriteList::ClassFlowWriteList(std::vector<ClassFlow*>* lfc)
{
SetInitialParameter();
ListFlowControll = lfc;
for (int i = 0; i < ListFlowControll->size(); ++i)
{
if (((*ListFlowControll)[i])->name().compare("ClassFlowPostProcessing") == 0)
{
flowpostprocessing = (ClassFlowPostProcessing*) (*ListFlowControll)[i];
}
}
}
bool ClassFlowWriteList::ReadParameter(FILE* pfile, string& aktparamgraph)
{
std::vector<string> zerlegt;
aktparamgraph = trim(aktparamgraph);
if (aktparamgraph.size() == 0)
if (!this->GetNextParagraph(pfile, aktparamgraph))
return false;
if (toUpper(aktparamgraph).compare("[MQTT]") != 0) // Paragraph passt nich zu MakeImage
return false;
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
{
zerlegt = ZerlegeZeile(aktparamgraph);
/*
if ((toUpper(zerlegt[0]) == "USER") && (zerlegt.size() > 1))
{
this->user = zerlegt[1];
}
*/
}
return true;
}
bool ClassFlowWriteList::doFlow(string zwtime)
{
std::string line = "";
std::string result;
std::string resulterror = "";
std::string resultraw = "";
std::string resultrate = "";
std::string resulttimestamp = "";
string zw = "";
string namenumber = "";
if (flowpostprocessing)
{
std::vector<NumberPost*>* NUMBERS = flowpostprocessing->GetNumbers();
for (int i = 0; i < (*NUMBERS).size(); ++i)
{
result = (*NUMBERS)[i]->ReturnValue;
resultraw = (*NUMBERS)[i]->ReturnRawValue;
resulterror = (*NUMBERS)[i]->ErrorMessageText;
resultrate = (*NUMBERS)[i]->ReturnRateValue;
resulttimestamp = (*NUMBERS)[i]->timeStamp;
line = line + resulttimestamp + "\t" + resultraw + "\t" + result + "\t" + resultraw + "\t" + resultrate + "\t" + resulttimestamp + "\t";
}
}
return true;
}

View File

@@ -0,0 +1,22 @@
#pragma once
#include "ClassFlow.h"
#include "ClassFlowPostProcessing.h"
#include <string>
class ClassFlowWriteList :
public ClassFlow
{
protected:
ClassFlowPostProcessing* flowpostprocessing;
void SetInitialParameter(void);
public:
ClassFlowWriteList();
ClassFlowWriteList(std::vector<ClassFlow*>* lfc);
bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
string name(){return "ClassFlowWriteList";};
};

View File

@@ -0,0 +1,7 @@
FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
idf_component_register(SRCS ${app_sources}
INCLUDE_DIRS "."
REQUIRES tflite-lib jomjol_logfile fatfs sdmmc)

View File

@@ -0,0 +1,793 @@
//#pragma warning(disable : 4996)
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "Helper.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <iostream>
#ifdef __cplusplus
extern "C" {
#endif
#include <dirent.h>
#ifdef __cplusplus
}
#endif
#include <string.h>
#include <esp_log.h>
#include "ClassLogFile.h"
#include "esp_vfs_fat.h"
static const char* TAG = "HELPER";
//#define ISWINDOWS_TRUE
#define PATH_MAX_STRING_SIZE 256
using namespace std;
sdmmc_cid_t SDCardCid;
sdmmc_csd_t SDCardCsd;
/////////////////////////////////////////////////////////////////////////////////////////////
string getESPHeapInfo(){
string espInfoResultStr = "";
char aMsgBuf[80];
multi_heap_info_t aMultiHead_info ;
heap_caps_get_info (&aMultiHead_info,MALLOC_CAP_8BIT);
size_t aFreeHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT);
size_t aMinFreeHeadSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT);
size_t aMinFreeHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT);
size_t aHeapLargestFreeBlockSize = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
sprintf(aMsgBuf," Free Heap Size: %ld", (long) aFreeHeapSize);
size_t aFreeSPIHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_SPIRAM);
size_t aFreeInternalHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_INTERNAL);
size_t aMinFreeInternalHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_INTERNAL);
sprintf(aMsgBuf," Heap: %ld", (long) aFreeHeapSize);
espInfoResultStr += string(aMsgBuf);
sprintf(aMsgBuf," Min Free: %ld", (long) aMinFreeHeapSize);
espInfoResultStr += string(aMsgBuf);
sprintf(aMsgBuf," larg. Block: %ld", (long) aHeapLargestFreeBlockSize);
espInfoResultStr += string(aMsgBuf);
sprintf(aMsgBuf," SPI Heap: %ld", (long) aFreeSPIHeapSize);
espInfoResultStr += string(aMsgBuf);
sprintf(aMsgBuf," Min Free Heap Size: %ld", (long) aMinFreeHeadSize);
sprintf(aMsgBuf," NOT_SPI Heap: %ld", (long) (aFreeHeapSize - aFreeSPIHeapSize));
espInfoResultStr += string(aMsgBuf);
sprintf(aMsgBuf," largest Block Size: %ld", (long) aHeapLargestFreeBlockSize);
sprintf(aMsgBuf," Internal Heap: %ld", (long) (aFreeInternalHeapSize));
espInfoResultStr += string(aMsgBuf);
sprintf(aMsgBuf," Internal Min Heap free: %ld", (long) (aMinFreeInternalHeapSize));
espInfoResultStr += string(aMsgBuf);
return espInfoResultStr;
}
size_t getESPHeapSize(){
size_t aFreeHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT);
return aFreeHeapSize;
}
size_t getInternalESPHeapSize() {
size_t aFreeInternalHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_INTERNAL);
return aFreeInternalHeapSize;
}
string getSDCardPartitionSize(){
FATFS *fs;
uint32_t fre_clust, tot_sect;
/* Get volume information and free clusters of drive 0 */
f_getfree("0:", (DWORD *)&fre_clust, &fs);
tot_sect = ((fs->n_fatent - 2) * fs->csize) /1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB
//ESP_LOGD(TAG, "%d MB total drive space (Sector size [bytes]: %d)", (int)tot_sect, (int)fs->ssize);
return std::to_string(tot_sect);
}
string getSDCardFreePartitionSpace(){
FATFS *fs;
uint32_t fre_clust, fre_sect;
/* Get volume information and free clusters of drive 0 */
f_getfree("0:", (DWORD *)&fre_clust, &fs);
fre_sect = (fre_clust * fs->csize) / 1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB
//ESP_LOGD(TAG, "%d MB free drive space (Sector size [bytes]: %d)", (int)fre_sect, (int)fs->ssize);
return std::to_string(fre_sect);
}
string getSDCardPartitionAllocationSize(){
FATFS *fs;
uint32_t fre_clust, allocation_size;
/* Get volume information and free clusters of drive 0 */
f_getfree("0:", (DWORD *)&fre_clust, &fs);
allocation_size = fs->ssize;
//ESP_LOGD(TAG, "SD Card Partition Allocation Size: %d bytes", allocation_size);
return std::to_string(allocation_size);
}
void SaveSDCardInfo(sdmmc_card_t* card) {
SDCardCid = card->cid;
SDCardCsd = card->csd;
}
string getSDCardManufacturer(){
string SDCardManufacturer = SDCardParseManufacturerIDs(SDCardCid.mfg_id);
//ESP_LOGD(TAG, "SD Card Manufacturer: %s", SDCardManufacturer.c_str());
return (SDCardManufacturer + " (ID: " + std::to_string(SDCardCid.mfg_id) + ")");
}
string getSDCardName(){
char *SDCardName = SDCardCid.name;
//ESP_LOGD(TAG, "SD Card Name: %s", SDCardName);
return std::string(SDCardName);
}
string getSDCardCapacity(){
int SDCardCapacity = SDCardCsd.capacity / (1024/SDCardCsd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024)
//ESP_LOGD(TAG, "SD Card Capacity: %s", std::to_string(SDCardCapacity).c_str());
return std::to_string(SDCardCapacity);
}
string getSDCardSectorSize(){
int SDCardSectorSize = SDCardCsd.sector_size;
//ESP_LOGD(TAG, "SD Card Sector Size: %s bytes", std::to_string(SDCardSectorSize).c_str());
return std::to_string(SDCardSectorSize);
}
///////////////////////////////////////////////////////////////////////////////////////////////
void memCopyGen(uint8_t* _source, uint8_t* _target, int _size)
{
for (int i = 0; i < _size; ++i)
*(_target + i) = *(_source + i);
}
FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec, bool silent)
{
FILE *pfile;
ESP_LOGD(TAG, "open file %s in mode %s", nm, _mode);
if ((pfile = fopen(nm, _mode)) != NULL) {
if (!silent) ESP_LOGE(TAG, "File %s successfully opened", nm);
}
else {
if (!silent) ESP_LOGE(TAG, "Error: file %s does not exist!", nm);
return NULL;
}
return pfile;
}
std::string FormatFileName(std::string input)
{
#ifdef ISWINDOWS_TRUE
input.erase(0, 1);
std::string os = "/";
std::string ns = "\\";
FindReplace(input, os, ns);
#endif
return input;
}
std::size_t file_size(const std::string& file_name) {
std::ifstream file(file_name.c_str(),std::ios::in | std::ios::binary);
if (!file) return 0;
file.seekg (0, std::ios::end);
return static_cast<std::size_t>(file.tellg());
}
void FindReplace(std::string& line, std::string& oldString, std::string& newString) {
const size_t oldSize = oldString.length();
// do nothing if line is shorter than the string to find
if (oldSize > line.length()) return;
const size_t newSize = newString.length();
for (size_t pos = 0; ; pos += newSize) {
// Locate the substring to replace
pos = line.find(oldString, pos);
if (pos == std::string::npos) return;
if (oldSize == newSize) {
// if they're same size, use std::string::replace
line.replace(pos, oldSize, newString);
}
else {
// if not same size, replace by erasing and inserting
line.erase(pos, oldSize);
line.insert(pos, newString);
}
}
}
bool MakeDir(std::string _what)
{
int mk_ret = mkdir(_what.c_str(), 0775);
if (mk_ret)
{
ESP_LOGD(TAG, "error with mkdir %s ret %d", _what.c_str(), mk_ret);
return false;
}
return true;
}
bool ctype_space(const char c, string adddelimiter)
{
if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == 11)
{
return true;
}
if (adddelimiter.find(c) != string::npos)
return true;
return false;
}
string trim(string istring, string adddelimiter)
{
bool trimmed = false;
if (ctype_space(istring[istring.length() - 1], adddelimiter))
{
istring.erase(istring.length() - 1);
trimmed = true;
}
if (ctype_space(istring[0], adddelimiter))
{
istring.erase(0, 1);
trimmed = true;
}
if ((trimmed == false) || (istring.size() == 0))
{
return istring;
}
else
{
return trim(istring, adddelimiter);
}
}
size_t findDelimiterPos(string input, string delimiter)
{
size_t pos = std::string::npos;
size_t zw;
string akt_del;
for (int anz = 0; anz < delimiter.length(); ++anz)
{
akt_del = delimiter[anz];
if ((zw = input.find(akt_del)) != std::string::npos)
{
if (pos != std::string::npos)
{
if (zw < pos)
pos = zw;
}
else
pos = zw;
}
}
return pos;
}
bool RenameFile(string from, string to)
{
// ESP_LOGI(logTag, "Deleting file : %s", fn.c_str());
/* Delete file */
FILE* fpSourceFile = OpenFileAndWait(from.c_str(), "rb");
if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
{
ESP_LOGE(TAG, "DeleteFile: File %s existiert nicht!", from.c_str());
return false;
}
fclose(fpSourceFile);
rename(from.c_str(), to.c_str());
return true;
}
bool DeleteFile(string fn)
{
// ESP_LOGI(logTag, "Deleting file : %s", fn.c_str());
/* Delete file */
FILE* fpSourceFile = OpenFileAndWait(fn.c_str(), "rb");
if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
{
ESP_LOGD(TAG, "DeleteFile: File %s existiert nicht!", fn.c_str());
return false;
}
fclose(fpSourceFile);
unlink(fn.c_str());
return true;
}
bool CopyFile(string input, string output)
{
input = FormatFileName(input);
output = FormatFileName(output);
if (toUpper(input).compare("/SDCARD/WLAN.INI") == 0)
{
ESP_LOGD(TAG, "wlan.ini kann nicht kopiert werden!");
return false;
}
char cTemp;
FILE* fpSourceFile = OpenFileAndWait(input.c_str(), "rb");
if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
{
ESP_LOGD(TAG, "File %s existiert nicht!", input.c_str());
return false;
}
FILE* fpTargetFile = OpenFileAndWait(output.c_str(), "wb");
// Code Section
// Read From The Source File - "Copy"
while (fread(&cTemp, 1, 1, fpSourceFile) == 1)
{
// Write To The Target File - "Paste"
fwrite(&cTemp, 1, 1, fpTargetFile);
}
// Close The Files
fclose(fpSourceFile);
fclose(fpTargetFile);
ESP_LOGD(TAG, "File copied: %s to %s", input.c_str(), output.c_str());
return true;
}
string getFileFullFileName(string filename)
{
size_t lastpos = filename.find_last_of('/');
if (lastpos == string::npos)
return "";
// ESP_LOGD(TAG, "Last position: %d", lastpos);
string zw = filename.substr(lastpos + 1, filename.size() - lastpos);
return zw;
}
string getDirectory(string filename)
{
size_t lastpos = filename.find('/');
if (lastpos == string::npos)
lastpos = filename.find('\\');
if (lastpos == string::npos)
return "";
// ESP_LOGD(TAG, "Directory: %d", lastpos);
string zw = filename.substr(0, lastpos - 1);
return zw;
}
string getFileType(string filename)
{
size_t lastpos = filename.rfind(".", filename.length());
size_t neu_pos;
while ((neu_pos = filename.find(".", lastpos + 1)) > -1)
{
lastpos = neu_pos;
}
if (lastpos == string::npos)
return "";
string zw = filename.substr(lastpos + 1, filename.size() - lastpos);
zw = toUpper(zw);
return zw;
}
/* recursive mkdir */
int mkdir_r(const char *dir, const mode_t mode) {
char tmp[PATH_MAX_STRING_SIZE];
char *p = NULL;
struct stat sb;
size_t len;
/* copy path */
len = strnlen (dir, PATH_MAX_STRING_SIZE);
if (len == 0 || len == PATH_MAX_STRING_SIZE) {
return -1;
}
memcpy (tmp, dir, len);
tmp[len] = '\0';
/* remove trailing slash */
if(tmp[len - 1] == '/') {
tmp[len - 1] = '\0';
}
/* check if path exists and is a directory */
if (stat (tmp, &sb) == 0) {
if (S_ISDIR (sb.st_mode)) {
return 0;
}
}
/* recursive mkdir */
for(p = tmp + 1; *p; p++) {
if(*p == '/') {
*p = 0;
/* test path */
if (stat(tmp, &sb) != 0) {
/* path does not exist - create directory */
if (mkdir(tmp, mode) < 0) {
return -1;
}
} else if (!S_ISDIR(sb.st_mode)) {
/* not a directory */
return -1;
}
*p = '/';
}
}
/* test path */
if (stat(tmp, &sb) != 0) {
/* path does not exist - create directory */
if (mkdir(tmp, mode) < 0) {
return -1;
}
} else if (!S_ISDIR(sb.st_mode)) {
/* not a directory */
return -1;
}
return 0;
}
string toUpper(string in)
{
for (int i = 0; i < in.length(); ++i)
in[i] = toupper(in[i]);
return in;
}
string toLower(string in)
{
for (int i = 0; i < in.length(); ++i)
in[i] = tolower(in[i]);
return in;
}
// CPU Temp
extern "C" uint8_t temprature_sens_read();
float temperatureRead()
{
return (temprature_sens_read() - 32) / 1.8;
}
time_t addDays(time_t startTime, int days) {
struct tm* tm = localtime(&startTime);
tm->tm_mday += days;
return mktime(tm);
}
int removeFolder(const char* folderPath, const char* logTag) {
//ESP_LOGD(logTag, "Delete content in path %s", folderPath);
DIR *dir = opendir(folderPath);
if (!dir) {
ESP_LOGE(logTag, "Failed to stat dir : %s", folderPath);
return -1;
}
struct dirent *entry;
int deleted = 0;
while ((entry = readdir(dir)) != NULL) {
std::string path = string(folderPath) + "/" + entry->d_name;
if (entry->d_type == DT_REG) {
//ESP_LOGD(logTag, "Delete file %s", path.c_str());
if (unlink(path.c_str()) == 0) {
deleted ++;
} else {
ESP_LOGE(logTag, "can't delete file : %s", path.c_str());
}
} else if (entry->d_type == DT_DIR) {
deleted += removeFolder(path.c_str(), logTag);
}
}
closedir(dir);
if (rmdir(folderPath) != 0) {
ESP_LOGE(logTag, "can't delete folder : %s", folderPath);
}
ESP_LOGD(logTag, "%d files in folder %s deleted.", deleted, folderPath);
return deleted;
}
std::vector<string> HelperZerlegeZeile(std::string input, std::string _delimiter = "")
{
std::vector<string> Output;
std::string delimiter = " =,";
if (_delimiter.length() > 0){
delimiter = _delimiter;
}
return ZerlegeZeile(input, delimiter);
}
std::vector<string> ZerlegeZeile(std::string input, std::string delimiter)
{
std::vector<string> Output;
input = trim(input, delimiter);
/* The input can have multiple formats:
* - key = value
* - key = value1 value2 value3 ...
* - key value1 value2 value3 ...
*
* Examples:
* - ImageSize = VGA
* - IO0 = input disabled 10 false false
* - main.dig1 28 144 55 100 false
*
* This causes issues eg. if a password key has a whitespace or equal sign in its value.
* As a workaround and to not break any legacy usage, we enforce to only use the
* equal sign, if the key is "password"
*/
if (input.find("password") != string::npos) { // Line contains a password, use the equal sign as the only delimiter and only split on first occurrence
size_t pos = input.find("=");
Output.push_back(trim(input.substr(0, pos), ""));
Output.push_back(trim(input.substr(pos +1, string::npos), ""));
}
else { // Legacy Mode
size_t pos = findDelimiterPos(input, delimiter);
std::string token;
while (pos != std::string::npos) {
token = input.substr(0, pos);
token = trim(token, delimiter);
Output.push_back(token);
input.erase(0, pos + 1);
input = trim(input, delimiter);
pos = findDelimiterPos(input, delimiter);
}
Output.push_back(input);
}
return Output;
}
/* Source: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/tree/lsmmc.c */
/* SD Card Manufacturer Database */
struct SDCard_Manufacturer_database {
string type;
int id;
string manufacturer;
};
/* Source: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/tree/lsmmc.c */
/* SD Card Manufacturer Database */
struct SDCard_Manufacturer_database database[] = {
{
.type = "sd",
.id = 0x01,
.manufacturer = "Panasonic",
},
{
.type = "sd",
.id = 0x02,
.manufacturer = "Toshiba/Kingston/Viking",
},
{
.type = "sd",
.id = 0x03,
.manufacturer = "SanDisk",
},
{
.type = "sd",
.id = 0x08,
.manufacturer = "Silicon Power",
},
{
.type = "sd",
.id = 0x18,
.manufacturer = "Infineon",
},
{
.type = "sd",
.id = 0x1b,
.manufacturer = "Transcend/Samsung",
},
{
.type = "sd",
.id = 0x1c,
.manufacturer = "Transcend",
},
{
.type = "sd",
.id = 0x1d,
.manufacturer = "Corsair/AData",
},
{
.type = "sd",
.id = 0x1e,
.manufacturer = "Transcend",
},
{
.type = "sd",
.id = 0x1f,
.manufacturer = "Kingston",
},
{
.type = "sd",
.id = 0x27,
.manufacturer = "Delkin/Phison",
},
{
.type = "sd",
.id = 0x28,
.manufacturer = "Lexar",
},
{
.type = "sd",
.id = 0x30,
.manufacturer = "SanDisk",
},
{
.type = "sd",
.id = 0x31,
.manufacturer = "Silicon Power",
},
{
.type = "sd",
.id = 0x33,
.manufacturer = "STMicroelectronics",
},
{
.type = "sd",
.id = 0x41,
.manufacturer = "Kingston",
},
{
.type = "sd",
.id = 0x6f,
.manufacturer = "STMicroelectronics",
},
{
.type = "sd",
.id = 0x74,
.manufacturer = "Transcend",
},
{
.type = "sd",
.id = 0x76,
.manufacturer = "Patriot",
},
{
.type = "sd",
.id = 0x82,
.manufacturer = "Gobe/Sony",
},
{
.type = "sd",
.id = 0x89,
.manufacturer = "Unknown",
}
};
/* Parse SD Card Manufacturer Database */
string SDCardParseManufacturerIDs(int id)
{
unsigned int id_cnt = sizeof(database) / sizeof(struct SDCard_Manufacturer_database);
string ret_val = "";
for (int i = 0; i < id_cnt; i++) {
if (database[i].id == id) {
return database[i].manufacturer;
}
else {
ret_val = "ID unknown (not in DB)";
}
}
return ret_val;
}
string RundeOutput(double _in, int _anzNachkomma)
{
std::stringstream stream;
int _zw = _in;
// ESP_LOGD(TAG, "AnzNachkomma: %d", _anzNachkomma);
if (_anzNachkomma < 0) {
_anzNachkomma = 0;
}
if (_anzNachkomma > 0)
{
stream << std::fixed << std::setprecision(_anzNachkomma) << _in;
return stream.str();
}
else
{
stream << _zw;
}
return stream.str();
}
string getMac(void) {
uint8_t macInt[6];
char macFormated[6*2 + 5 + 1]; // AA:BB:CC:DD:EE:FF
esp_read_mac(macInt, ESP_MAC_WIFI_STA);
sprintf(macFormated, "%02X:%02X:%02X:%02X:%02X:%02X", macInt[0], macInt[1], macInt[2], macInt[3], macInt[4], macInt[5]);
return macFormated;
}
string getResetReason(void) {
std::string reasonText;
switch(esp_reset_reason()) {
case ESP_RST_POWERON: reasonText = "Power-on event"; break; //!< Reset due to power-on event
case ESP_RST_EXT: reasonText = "External pin"; break; //!< Reset by external pin (not applicable for ESP32)
case ESP_RST_SW: reasonText = "Via esp_restart"; break; //!< Software reset via esp_restart
case ESP_RST_PANIC: reasonText = "Exception/panic"; break; //!< Software reset due to exception/panic
case ESP_RST_INT_WDT: reasonText = "Interrupt watchdog"; break; //!< Reset (software or hardware) due to interrupt watchdog
case ESP_RST_TASK_WDT: reasonText = "Task watchdog"; break; //!< Reset due to task watchdog
case ESP_RST_WDT: reasonText = "Other watchdogs"; break; //!< Reset due to other watchdogs
case ESP_RST_DEEPSLEEP: reasonText = "Exiting deep sleep mode"; break; //!< Reset after exiting deep sleep mode
case ESP_RST_BROWNOUT: reasonText = "Brownout"; break; //!< Brownout reset (software or hardware)
case ESP_RST_SDIO: reasonText = "SDIO"; break; //!< Reset over SDIO
case ESP_RST_UNKNOWN: //!< Reset reason can not be determined
default:
reasonText = "Unknown";
}
return reasonText;
}

View File

@@ -0,0 +1,66 @@
#pragma once
#include <string>
#include <fstream>
#include <vector>
#include "sdmmc_cmd.h"
using namespace std;
std::string FormatFileName(std::string input);
std::size_t file_size(const std::string& file_name);
void FindReplace(std::string& line, std::string& oldString, std::string& newString);
bool CopyFile(string input, string output);
bool DeleteFile(string fn);
bool RenameFile(string from, string to);
bool MakeDir(std::string _what);
string RundeOutput(double _in, int _anzNachkomma);
FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec = 1, bool silent = true);
size_t findDelimiterPos(string input, string delimiter);
//string trim(string istring);
string trim(string istring, string adddelimiter = "");
bool ctype_space(const char c, string adddelimiter);
string getFileType(string filename);
string getFileFullFileName(string filename);
string getDirectory(string filename);
int mkdir_r(const char *dir, const mode_t mode);
int removeFolder(const char* folderPath, const char* logTag);
string toLower(string in);
string toUpper(string in);
float temperatureRead();
time_t addDays(time_t startTime, int days);
void memCopyGen(uint8_t* _source, uint8_t* _target, int _size);
std::vector<string> HelperZerlegeZeile(std::string input, std::string _delimiter);
std::vector<std::string> ZerlegeZeile(std::string input, std::string delimiter = " =, \t");
///////////////////////////
size_t getInternalESPHeapSize();
size_t getESPHeapSize();
string getESPHeapInfo();
/////////////////////////////
string getSDCardPartitionSize();
string getSDCardFreePartitionSpace();
string getSDCardPartitionAllocationSize();
void SaveSDCardInfo(sdmmc_card_t* card);
string SDCardParseManufacturerIDs(int);
string getSDCardManufacturer();
string getSDCardName();
string getSDCardCapacity();
string getSDCardSectorSize();
string getMac(void);
string getResetReason(void);

View File

@@ -0,0 +1,210 @@
#include "CAlignAndCutImage.h"
#include "CRotateImage.h"
#include "ClassLogFile.h"
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#include <esp_log.h>
static const char* TAG = "c_align_and_cut_image";
//#define GET_MEMORY malloc
#define GET_MEMORY(X) heap_caps_malloc(X, MALLOC_CAP_SPIRAM)
CAlignAndCutImage::CAlignAndCutImage(CImageBasis *_org, CImageBasis *_temp)
{
rgb_image = _org->rgb_image;
channels = _org->channels;
width = _org->width;
height = _org->height;
bpp = _org->bpp;
externalImage = true;
islocked = false;
ImageTMP = _temp;
}
void CAlignAndCutImage::GetRefSize(int *ref_dx, int *ref_dy)
{
ref_dx[0] = t0_dx;
ref_dy[0] = t0_dy;
ref_dx[1] = t1_dx;
ref_dy[1] = t1_dy;
}
bool CAlignAndCutImage::Align(RefInfo *_temp1, RefInfo *_temp2)
{
int dx, dy;
int r0_x, r0_y, r1_x, r1_y;
bool isSimilar1, isSimilar2;
CFindTemplate* ft = new CFindTemplate(rgb_image, channels, width, height, bpp);
r0_x = _temp1->target_x;
r0_y = _temp1->target_y;
ESP_LOGD(TAG, "Vor ft->FindTemplate(_temp1); %s", _temp1->image_file.c_str());
isSimilar1 = ft->FindTemplate(_temp1);
_temp1->width = ft->tpl_width;
_temp1->height = ft->tpl_height;
r1_x = _temp2->target_x;
r1_y = _temp2->target_y;
ESP_LOGD(TAG, "Vor ft->FindTemplate(_temp2); %s", _temp2->image_file.c_str());
isSimilar2 = ft->FindTemplate(_temp2);
_temp2->width = ft->tpl_width;
_temp2->height = ft->tpl_height;
delete ft;
dx = _temp1->target_x - _temp1->found_x;
dy = _temp1->target_y - _temp1->found_y;
r0_x += dx;
r0_y += dy;
r1_x += dx;
r1_y += dy;
float w_org, w_ist, d_winkel;
w_org = atan2(_temp2->found_y - _temp1->found_y, _temp2->found_x - _temp1->found_x);
w_ist = atan2(r1_y - r0_y, r1_x - r0_x);
d_winkel = (w_ist - w_org) * 180 / M_PI;
#ifdef DEBUG_DETAIL_ON
std::string zw = "\tdx:\t" + std::to_string(dx) + "\tdy:\t" + std::to_string(dy) + "\td_winkel:\t" + std::to_string(d_winkel);
zw = zw + "\tt1_x_y:\t" + std::to_string(_temp1->found_x) + "\t" + std::to_string(_temp1->found_y);
zw = zw + "\tpara1_found_min_avg_max_SAD:\t" + std::to_string(_temp1->fastalg_min) + "\t" + std::to_string(_temp1->fastalg_avg) + "\t" + std::to_string(_temp1->fastalg_max) + "\t"+ std::to_string(_temp1->fastalg_SAD);
zw = zw + "\tt2_x_y:\t" + std::to_string(_temp2->found_x) + "\t" + std::to_string(_temp2->found_y);
zw = zw + "\tpara2_found_min_avg_max:\t" + std::to_string(_temp2->fastalg_min) + "\t" + std::to_string(_temp2->fastalg_avg) + "\t" + std::to_string(_temp2->fastalg_max) + "\t"+ std::to_string(_temp2->fastalg_SAD);
LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", zw);
#endif
CRotateImage rt(this, ImageTMP);
rt.Translate(dx, dy);
rt.Rotate(d_winkel, _temp1->target_x, _temp1->target_y);
ESP_LOGD(TAG, "Alignment: dx %d - dy %d - rot %f", dx, dy, d_winkel);
return (isSimilar1 && isSimilar2);
}
void CAlignAndCutImage::CutAndSave(std::string _template1, int x1, int y1, int dx, int dy)
{
int x2, y2;
x2 = x1 + dx;
y2 = y1 + dy;
x2 = std::min(x2, width - 1);
y2 = std::min(y2, height - 1);
dx = x2 - x1;
dy = y2 - y1;
int memsize = dx * dy * channels;
uint8_t* odata = (unsigned char*) GET_MEMORY(memsize);
stbi_uc* p_target;
stbi_uc* p_source;
RGBImageLock();
for (int x = x1; x < x2; ++x)
for (int y = y1; y < y2; ++y)
{
p_target = odata + (channels * ((y - y1) * dx + (x - x1)));
p_source = rgb_image + (channels * (y * width + x));
for (int _channels = 0; _channels < channels; ++_channels)
p_target[_channels] = p_source[_channels];
}
// stbi_write_jpg(_template1.c_str(), dx, dy, channels, odata, 0);
stbi_write_bmp(_template1.c_str(), dx, dy, channels, odata);
RGBImageRelease();
stbi_image_free(odata);
}
void CAlignAndCutImage::CutAndSave(int x1, int y1, int dx, int dy, CImageBasis *_target)
{
int x2, y2;
x2 = x1 + dx;
y2 = y1 + dy;
x2 = std::min(x2, width - 1);
y2 = std::min(y2, height - 1);
dx = x2 - x1;
dy = y2 - y1;
if ((_target->height != dy) || (_target->width != dx) || (_target->channels != channels))
{
ESP_LOGD(TAG, "CAlignAndCutImage::CutAndSave - Image size does not match!");
return;
}
uint8_t* odata = _target->RGBImageLock();
RGBImageLock();
stbi_uc* p_target;
stbi_uc* p_source;
for (int x = x1; x < x2; ++x)
for (int y = y1; y < y2; ++y)
{
p_target = odata + (channels * ((y - y1) * dx + (x - x1)));
p_source = rgb_image + (channels * (y * width + x));
for (int _channels = 0; _channels < channels; ++_channels)
p_target[_channels] = p_source[_channels];
}
RGBImageRelease();
_target->RGBImageRelease();
}
CImageBasis* CAlignAndCutImage::CutAndSave(int x1, int y1, int dx, int dy)
{
int x2, y2;
x2 = x1 + dx;
y2 = y1 + dy;
x2 = std::min(x2, width - 1);
y2 = std::min(y2, height - 1);
dx = x2 - x1;
dy = y2 - y1;
int memsize = dx * dy * channels;
uint8_t* odata = (unsigned char*)GET_MEMORY(memsize);
stbi_uc* p_target;
stbi_uc* p_source;
RGBImageLock();
for (int x = x1; x < x2; ++x)
for (int y = y1; y < y2; ++y)
{
p_target = odata + (channels * ((y - y1) * dx + (x - x1)));
p_source = rgb_image + (channels * (y * width + x));
for (int _channels = 0; _channels < channels; ++_channels)
p_target[_channels] = p_source[_channels];
}
CImageBasis* rs = new CImageBasis(odata, channels, dx, dy, bpp);
RGBImageRelease();
rs->SetIndepended();
return rs;
}

View File

@@ -0,0 +1,21 @@
#include "CImageBasis.h"
#include "CFindTemplate.h"
class CAlignAndCutImage : public CImageBasis
{
public:
int t0_dx, t0_dy, t1_dx, t1_dy;
CImageBasis *ImageTMP;
CAlignAndCutImage(std::string _image) : CImageBasis(_image) {ImageTMP = NULL;};
CAlignAndCutImage(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp) : CImageBasis(_rgb_image, _channels, _width, _height, _bpp) {ImageTMP = NULL;};
CAlignAndCutImage(CImageBasis *_org, CImageBasis *_temp);
bool Align(RefInfo *_temp1, RefInfo *_temp2);
// void Align(std::string _template1, int x1, int y1, std::string _template2, int x2, int y2, int deltax = 40, int deltay = 40, std::string imageROI = "");
void CutAndSave(std::string _template1, int x1, int y1, int dx, int dy);
CImageBasis* CutAndSave(int x1, int y1, int dx, int dy);
void CutAndSave(int x1, int y1, int dx, int dy, CImageBasis *_target);
void GetRefSize(int *ref_dx, int *ref_dy);
};

View File

@@ -0,0 +1,205 @@
#include "CFindTemplate.h"
#include "ClassLogFile.h"
#include "Helper.h"
#include <esp_log.h>
static const char* TAG = "C FIND TEMPL";
// #define DEBUG_DETAIL_ON
bool CFindTemplate::FindTemplate(RefInfo *_ref)
{
uint8_t* rgb_template;
if (file_size(_ref->image_file.c_str()) == 0) {
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _ref->image_file + " is empty!");
return false;
}
rgb_template = stbi_load(_ref->image_file.c_str(), &tpl_width, &tpl_height, &tpl_bpp, channels);
if (rgb_template == NULL) {
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to load " + _ref->image_file + "! Is it corrupted?");
return false;
}
// ESP_LOGD(TAG, "FindTemplate 01");
int ow, ow_start, ow_stop;
int oh, oh_start, oh_stop;
if (_ref->search_x == 0)
{
_ref->search_x = width;
_ref->found_x = 0;
}
if (_ref->search_y == 0)
{
_ref->search_y = height;
_ref->found_y = 0;
}
ow_start = _ref->target_x - _ref->search_x;
ow_start = std::max(ow_start, 0);
ow_stop = _ref->target_x + _ref->search_x;
if ((ow_stop + tpl_width) > width)
ow_stop = width - tpl_width;
ow = ow_stop - ow_start + 1;
oh_start = _ref->target_y - _ref->search_y;
oh_start = std::max(oh_start, 0);
oh_stop = _ref->target_y + _ref->search_y;
if ((oh_stop + tpl_height) > height)
oh_stop = height - tpl_height;
oh = oh_stop - oh_start + 1;
float avg, SAD;
int min, max;
bool isSimilar = false;
// ESP_LOGD(TAG, "FindTemplate 02");
if ((_ref->alignment_algo == 2) && (_ref->fastalg_x > -1) && (_ref->fastalg_y > -1)) // für Testzwecke immer Berechnen
{
isSimilar = CalculateSimularities(rgb_template, _ref->fastalg_x, _ref->fastalg_y, ow, oh, min, avg, max, SAD, _ref->fastalg_SAD, _ref->fastalg_SAD_criteria);
#ifdef DEBUG_DETAIL_ON
std::string zw = "\t" + _ref->image_file + "\tt1_x_y:\t" + std::to_string(_ref->fastalg_x) + "\t" + std::to_string(_ref->fastalg_y);
zw = zw + "\tpara1_found_min_avg_max_SAD:\t" + std::to_string(min) + "\t" + std::to_string(avg) + "\t" + std::to_string(max) + "\t"+ std::to_string(SAD);
LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", zw);
#endif
}
// ESP_LOGD(TAG, "FindTemplate 03");
if (isSimilar)
{
#ifdef DEBUG_DETAIL_ON
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Use FastAlignment sucessfull");
#endif
_ref->found_x = _ref->fastalg_x;
_ref->found_y = _ref->fastalg_y;
stbi_image_free(rgb_template);
return true;
}
// ESP_LOGD(TAG, "FindTemplate 04");
double aktSAD;
double minSAD = pow(tpl_width * tpl_height * 255, 2);
RGBImageLock();
// ESP_LOGD(TAG, "FindTemplate 05");
int xouter, youter, tpl_x, tpl_y, _ch;
int _anzchannels = channels;
if (_ref->alignment_algo == 0) // 0 = "Default" (nur R-Kanal)
_anzchannels = 1;
for (xouter = ow_start; xouter <= ow_stop; xouter++)
for (youter = oh_start; youter <= oh_stop; ++youter)
{
aktSAD = 0;
for (tpl_x = 0; tpl_x < tpl_width; tpl_x++)
for (tpl_y = 0; tpl_y < tpl_height; tpl_y++)
{
stbi_uc* p_org = rgb_image + (channels * ((youter + tpl_y) * width + (xouter + tpl_x)));
stbi_uc* p_tpl = rgb_template + (channels * (tpl_y * tpl_width + tpl_x));
for (_ch = 0; _ch < _anzchannels; ++_ch)
{
aktSAD += pow(p_tpl[_ch] - p_org[_ch], 2);
}
}
if (aktSAD < minSAD)
{
minSAD = aktSAD;
_ref->found_x = xouter;
_ref->found_y = youter;
}
}
// ESP_LOGD(TAG, "FindTemplate 06");
if (_ref->alignment_algo == 2)
CalculateSimularities(rgb_template, _ref->found_x, _ref->found_y, ow, oh, min, avg, max, SAD, _ref->fastalg_SAD, _ref->fastalg_SAD_criteria);
// ESP_LOGD(TAG, "FindTemplate 07");
_ref->fastalg_x = _ref->found_x;
_ref->fastalg_y = _ref->found_y;
_ref->fastalg_min = min;
_ref->fastalg_avg = avg;
_ref->fastalg_max = max;
_ref->fastalg_SAD = SAD;
#ifdef DEBUG_DETAIL_ON
std::string zw = "\t" + _ref->image_file + "\tt1_x_y:\t" + std::to_string(_ref->fastalg_x) + "\t" + std::to_string(_ref->fastalg_y);
zw = zw + "\tpara1_found_min_avg_max_SAD:\t" + std::to_string(min) + "\t" + std::to_string(avg) + "\t" + std::to_string(max) + "\t"+ std::to_string(SAD);
LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", zw);
#endif
RGBImageRelease();
stbi_image_free(rgb_template);
// ESP_LOGD(TAG, "FindTemplate 08");
return false;
}
bool CFindTemplate::CalculateSimularities(uint8_t* _rgb_tmpl, int _startx, int _starty, int _sizex, int _sizey, int &min, float &avg, int &max, float &SAD, float _SADold, float _SADcrit)
{
int dif;
int minDif = 255;
int maxDif = -255;
double avgDifSum = 0;
long int anz = 0;
double aktSAD = 0;
int xouter, youter, _ch;
for (xouter = 0; xouter <= _sizex; xouter++)
for (youter = 0; youter <= _sizey; ++youter)
{
stbi_uc* p_org = rgb_image + (channels * ((youter + _starty) * width + (xouter + _startx)));
stbi_uc* p_tpl = _rgb_tmpl + (channels * (youter * tpl_width + xouter));
for (_ch = 0; _ch < channels; ++_ch)
{
dif = p_tpl[_ch] - p_org[_ch];
aktSAD += pow(p_tpl[_ch] - p_org[_ch], 2);
if (dif < minDif) minDif = dif;
if (dif > maxDif) maxDif = dif;
avgDifSum += dif;
anz++;
}
}
avg = avgDifSum / anz;
min = minDif;
max = maxDif;
SAD = sqrt(aktSAD) / anz;
float _SADdif = abs(SAD - _SADold);
ESP_LOGD(TAG, "Anzahl %ld, avgDifSum %fd, avg %f, SAD_neu: %fd, _SAD_old: %f, _SAD_crit:%f", anz, avgDifSum, avg, SAD, _SADold, _SADdif);
if (_SADdif <= _SADcrit)
return true;
return false;
}

View File

@@ -0,0 +1,40 @@
#ifndef __CFINDTEMPLATE_CLASS
#define __CFINDTEMPLATE_CLASS
#include "CImageBasis.h"
struct RefInfo {
std::string image_file;
int target_x = 0;
int target_y = 0;
int width = 0;
int height = 0;
int found_x;
int found_y;
int search_x;
int search_y;
int fastalg_x = -1;
int fastalg_y = -1;
int fastalg_min = -256;
float fastalg_avg = -1;
int fastalg_max = -1;
float fastalg_SAD = -1;
float fastalg_SAD_criteria = -1;
int alignment_algo = 0; // 0 = "Default" (nur R-Kanal), 1 = "HighAccuracy" (RGB-Kanal), 2 = "Fast" (1.x RGB, dann isSimilar)
};
class CFindTemplate : public CImageBasis
{
public:
int tpl_width, tpl_height, tpl_bpp;
CFindTemplate(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp) : CImageBasis(_rgb_image, _channels, _width, _height, _bpp) {};
bool FindTemplate(RefInfo *_ref);
bool CalculateSimularities(uint8_t* _rgb_tmpl, int _startx, int _starty, int _sizex, int _sizey, int &min, float &avg, int &max, float &SAD, float _SADold, float _SADcrit);
};
#endif

View File

@@ -0,0 +1,564 @@
#include "CImageBasis.h"
#include "Helper.h"
#include "ClassLogFile.h"
#include "server_ota.h"
#include <esp_log.h>
#include "esp_system.h"
#include <cstring>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define _ESP32_PSRAM
using namespace std;
static const char *TAG = "C IMG BASIS";
//#define DEBUG_DETAIL_ON
uint8_t * CImageBasis::RGBImageLock(int _waitmaxsec)
{
if (islocked)
{
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "Image is locked: sleep for: %ds", _waitmaxsec);
#endif
TickType_t xDelay;
xDelay = 1000 / portTICK_PERIOD_MS;
for (int i = 0; i <= _waitmaxsec; ++i)
{
vTaskDelay( xDelay );
if (!islocked)
break;
}
}
if (islocked)
return NULL;
return rgb_image;
}
void CImageBasis::RGBImageRelease()
{
islocked = false;
}
uint8_t * CImageBasis::RGBImageGet()
{
return rgb_image;
}
void writejpghelp(void *context, void *data, int size)
{
// ESP_LOGD(TAG, "Size all: %d, size %d", ((ImageData*)context)->size, size);
ImageData* _zw = (ImageData*) context;
uint8_t *voidstart = _zw->data;
uint8_t *datastart = (uint8_t*) data;
voidstart += _zw->size;
for (int i = 0; i < size; ++i)
*(voidstart + i) = *(datastart + i);
_zw->size += size;
}
ImageData* CImageBasis::writeToMemoryAsJPG(const int quality)
{
ImageData* ii = new ImageData;
RGBImageLock();
stbi_write_jpg_to_func(writejpghelp, ii, width, height, channels, rgb_image, quality);
RGBImageRelease();
return ii;
}
#define HTTP_BUFFER_SENT 1024
struct SendJPGHTTP
{
httpd_req_t *req;
esp_err_t res;
char buf[HTTP_BUFFER_SENT];
int size = 0;
};
inline void writejpgtohttphelp(void *context, void *data, int size)
{
SendJPGHTTP* _send = (SendJPGHTTP*) context;
if ((_send->size + size) >= HTTP_BUFFER_SENT) // data passt nich mehr in buffer
{
httpd_req_t *_req = _send->req;
if (httpd_resp_send_chunk(_req, _send->buf, _send->size) != ESP_OK)
{
ESP_LOGE(TAG, "File sending failed!");
_send->res = ESP_FAIL;
}
_send->size = 0;
}
std::memcpy((void*) (&(_send->buf[0]) + _send->size), data, size);
_send->size+= size;
}
esp_err_t CImageBasis::SendJPGtoHTTP(httpd_req_t *_req, const int quality)
{
SendJPGHTTP ii;
ii.req = _req;
ii.res = ESP_OK;
ii.size = 0;
RGBImageLock();
stbi_write_jpg_to_func(writejpgtohttphelp, &ii, width, height, channels, rgb_image, quality);
RGBImageRelease();
if (ii.size > 0)
{
if (httpd_resp_send_chunk(_req, (char*) ii.buf, ii.size) != ESP_OK) // verschicke noch den Rest
{
ESP_LOGE(TAG, "File sending failed!");
ii.res = ESP_FAIL;
}
}
return ii.res;
}
bool CImageBasis::CopyFromMemory(uint8_t* _source, int _size)
{
int gr = height * width * channels;
if (gr != _size) // Größe passt nicht
{
ESP_LOGD(TAG, "Cannot copy image from memory - sizes do not match: should be %d, but is %d", _size, gr);
return false;
}
RGBImageLock();
memCopy(_source, rgb_image, _size);
RGBImageRelease();
return true;
}
uint8_t CImageBasis::GetPixelColor(int x, int y, int ch)
{
stbi_uc* p_source;
p_source = rgb_image + (channels * (y * width + x));
return p_source[ch];
}
void CImageBasis::memCopy(uint8_t* _source, uint8_t* _target, int _size)
{
#ifdef _ESP32_PSRAM
for (int i = 0; i < _size; ++i)
*(_target + i) = *(_source + i);
#else
memcpy(_target, _source, _size);
#endif
}
bool CImageBasis::isInImage(int x, int y)
{
if ((x < 0) || (x > width - 1))
return false;
if ((y < 0) || (y > height- 1))
return false;
return true;
}
void CImageBasis::setPixelColor(int x, int y, int r, int g, int b)
{
stbi_uc* p_source;
RGBImageLock();
p_source = rgb_image + (channels * (y * width + x));
p_source[0] = r;
if ( channels > 2)
{
p_source[1] = g;
p_source[2] = b;
}
RGBImageRelease();
}
void CImageBasis::drawRect(int x, int y, int dx, int dy, int r, int g, int b, int thickness)
{
int zwx1, zwx2, zwy1, zwy2;
int _x, _y, _thick;
zwx1 = x - thickness + 1;
zwx2 = x + dx + thickness - 1;
zwy1 = y;
zwy2 = y;
for (_thick = 0; _thick < thickness; _thick++)
for (_x = zwx1; _x <= zwx2; ++_x)
for (_y = zwy1; _y <= zwy2; _y++)
if (isInImage(_x, _y))
setPixelColor(_x, _y - _thick, r, g, b);
zwx1 = x - thickness + 1;
zwx2 = x + dx + thickness - 1;
zwy1 = y + dy;
zwy2 = y + dy;
for (_thick = 0; _thick < thickness; _thick++)
for (_x = zwx1; _x <= zwx2; ++_x)
for (_y = zwy1; _y <= zwy2; _y++)
if (isInImage(_x, _y))
setPixelColor(_x, _y + _thick, r, g, b);
zwx1 = x;
zwx2 = x;
zwy1 = y;
zwy2 = y + dy;
for (_thick = 0; _thick < thickness; _thick++)
for (_x = zwx1; _x <= zwx2; ++_x)
for (_y = zwy1; _y <= zwy2; _y++)
if (isInImage(_x, _y))
setPixelColor(_x - _thick, _y, r, g, b);
zwx1 = x + dx;
zwx2 = x + dx;
zwy1 = y;
zwy2 = y + dy;
for (_thick = 0; _thick < thickness; _thick++)
for (_x = zwx1; _x <= zwx2; ++_x)
for (_y = zwy1; _y <= zwy2; _y++)
if (isInImage(_x, _y))
setPixelColor(_x + _thick, _y, r, g, b);
}
void CImageBasis::drawLine(int x1, int y1, int x2, int y2, int r, int g, int b, int thickness)
{
int _x, _y, _thick;
int _zwy1, _zwy2;
thickness = (thickness-1) / 2;
for (_thick = 0; _thick <= thickness; ++_thick)
for (_x = x1 - _thick; _x <= x2 + _thick; ++_x)
{
if (x2 == x1)
{
_zwy1 = y1;
_zwy2 = y2;
}
else
{
_zwy1 = (y2 - y1) * (float)(_x - x1) / (float)(x2 - x1) + y1;
_zwy2 = (y2 - y1) * (float)(_x + 1 - x1) / (float)(x2 - x1) + y1;
}
for (_y = _zwy1 - _thick; _y <= _zwy2 + _thick; _y++)
if (isInImage(_x, _y))
setPixelColor(_x, _y, r, g, b);
}
}
void CImageBasis::drawEllipse(int x1, int y1, int radx, int rady, int r, int g, int b, int thickness)
{
float deltarad, aktrad;
int _thick, _x, _y;
int rad = radx;
if (rady > radx)
rad = rady;
deltarad = 1 / (4 * M_PI * (rad + thickness - 1));
for (aktrad = 0; aktrad <= (2 * M_PI); aktrad += deltarad)
for (_thick = 0; _thick < thickness; ++_thick)
{
_x = sin(aktrad) * (radx + _thick) + x1;
_y = cos(aktrad) * (rady + _thick) + y1;
if (isInImage(_x, _y))
setPixelColor(_x, _y, r, g, b);
}
}
void CImageBasis::drawCircle(int x1, int y1, int rad, int r, int g, int b, int thickness)
{
float deltarad, aktrad;
int _thick, _x, _y;
deltarad = 1 / (4 * M_PI * (rad + thickness - 1));
for (aktrad = 0; aktrad <= (2 * M_PI); aktrad += deltarad)
for (_thick = 0; _thick < thickness; ++_thick)
{
_x = sin(aktrad) * (rad + _thick) + x1;
_y = cos(aktrad) * (rad + _thick) + y1;
if (isInImage(_x, _y))
setPixelColor(_x, _y, r, g, b);
}
}
CImageBasis::CImageBasis()
{
externalImage = false;
rgb_image = NULL;
width = 0;
height = 0;
channels = 0;
islocked = false;
}
void CImageBasis::CreateEmptyImage(int _width, int _height, int _channels)
{
bpp = _channels;
width = _width;
height = _height;
channels = _channels;
RGBImageLock();
int memsize = width * height * channels;
rgb_image = (unsigned char*)GET_MEMORY(memsize);
stbi_uc* p_source;
for (int x = 0; x < width; ++x)
for (int y = 0; y < height; ++y)
{
p_source = rgb_image + (channels * (y * width + x));
for (int _channels = 0; _channels < channels; ++_channels)
p_source[_channels] = (uint8_t) 0;
}
RGBImageRelease();
}
void CImageBasis::LoadFromMemory(stbi_uc *_buffer, int len)
{
RGBImageLock();
if (rgb_image)
stbi_image_free(rgb_image);
rgb_image = stbi_load_from_memory(_buffer, len, &width, &height, &channels, 3);
bpp = channels;
ESP_LOGD(TAG, "Image loaded from memory: %d, %d, %d", width, height, channels);
if ((width * height * channels) == 0)
{
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Image with size 0 loaded --> reboot to be done! "
"Check that your camera module is working and connected properly.");
doReboot();
}
RGBImageRelease();
}
CImageBasis::CImageBasis(CImageBasis *_copyfrom, int _anzrepeat)
{
islocked = false;
externalImage = false;
channels = _copyfrom->channels;
width = _copyfrom->width;
height = _copyfrom->height;
bpp = _copyfrom->bpp;
RGBImageLock();
int memsize = width * height * channels;
rgb_image = (unsigned char*)GET_MEMORY(memsize);
int anz = 1;
while (!rgb_image && (anz < _anzrepeat))
{
ESP_LOGD(TAG, "Create Image from Copy - Memory is full - try again: %d", anz);
rgb_image = (unsigned char*) malloc(memsize);
anz++;
}
if (!rgb_image)
{
ESP_LOGD(TAG, "%s", getESPHeapInfo().c_str());
ESP_LOGD(TAG, "No more free memory!! Needed: %d %d %d %d", width, height, channels, memsize);
RGBImageRelease();
return;
}
memCopy(_copyfrom->rgb_image, rgb_image, memsize);
RGBImageRelease();
}
CImageBasis::CImageBasis(int _width, int _height, int _channels)
{
islocked = false;
externalImage = false;
channels = _channels;
width = _width;
height = _height;
bpp = _channels;
int memsize = width * height * channels;
rgb_image = (unsigned char*)GET_MEMORY(memsize);
if (!rgb_image)
{
ESP_LOGD(TAG, "%s", getESPHeapInfo().c_str());
ESP_LOGD(TAG, "No more free memory!! Needed: %d %d %d %d", width, height, channels, memsize);
return;
}
}
CImageBasis::CImageBasis(std::string _image)
{
islocked = false;
channels = 3;
externalImage = false;
filename = _image;
long zwld = esp_get_free_heap_size();
ESP_LOGD(TAG, "freeheapsize before: %ld", zwld);
if (file_size(_image.c_str()) == 0) {
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _image + " is empty!");
return;
}
RGBImageLock();
rgb_image = stbi_load(_image.c_str(), &width, &height, &bpp, channels);
if (rgb_image == NULL) {
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to load " + _image + "! Is it corrupted?");
RGBImageRelease();
return;
}
RGBImageRelease();
zwld = esp_get_free_heap_size();
ESP_LOGD(TAG, "freeheapsize after : %ld", zwld);
std::string zw = "Image Load failed:" + _image;
if (rgb_image == NULL)
ESP_LOGD(TAG, "%s", zw.c_str());
zw = "CImageBasis after load " + _image + "\n";
ESP_LOGD(TAG, "%s", zw.c_str());
ESP_LOGD(TAG, "w %d, h %d, b %d, c %d", width, height, bpp, channels);
}
bool CImageBasis::ImageOkay(){
return rgb_image != NULL;
}
CImageBasis::CImageBasis(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp)
{
islocked = false;
rgb_image = _rgb_image;
channels = _channels;
width = _width;
height = _height;
bpp = _bpp;
externalImage = true;
}
void CImageBasis::Contrast(float _contrast) //input range [-100..100]
{
stbi_uc* p_source;
float contrast = (_contrast/100) + 1; //convert to decimal & shift range: [0..2]
float intercept = 128 * (1 - contrast);
RGBImageLock();
for (int x = 0; x < width; ++x)
for (int y = 0; y < height; ++y)
{
p_source = rgb_image + (channels * (y * width + x));
for (int _channels = 0; _channels < channels; ++_channels)
p_source[_channels] = (uint8_t) std::min(255, std::max(0, (int) (p_source[_channels] * contrast + intercept)));
}
RGBImageRelease();
}
CImageBasis::~CImageBasis()
{
RGBImageLock();
if (!externalImage)
stbi_image_free(rgb_image);
}
void CImageBasis::SaveToFile(std::string _imageout)
{
string typ = getFileType(_imageout);
RGBImageLock();
if ((typ == "jpg") || (typ == "JPG")) // ACHTUNG PROBLEMATISCH IM ESP32
{
stbi_write_jpg(_imageout.c_str(), width, height, channels, rgb_image, 0);
}
if ((typ == "bmp") || (typ == "BMP"))
{
stbi_write_bmp(_imageout.c_str(), width, height, channels, rgb_image);
}
RGBImageRelease();
}
void CImageBasis::Resize(int _new_dx, int _new_dy)
{
int memsize = _new_dx * _new_dy * channels;
uint8_t* odata = (unsigned char*)GET_MEMORY(memsize);
RGBImageLock();
stbir_resize_uint8(rgb_image, width, height, 0, odata, _new_dx, _new_dy, 0, channels);
stbi_image_free(rgb_image);
rgb_image = (unsigned char*)GET_MEMORY(memsize);
memCopy(odata, rgb_image, memsize);
RGBImageRelease();
width = _new_dx;
height = _new_dy;
stbi_image_free(odata);
}
void CImageBasis::Resize(int _new_dx, int _new_dy, CImageBasis *_target)
{
if ((_target->height != _new_dy) || (_target->width != _new_dx) || (_target->channels != channels))
{
ESP_LOGD(TAG, "CImageBasis::Resize - Target image size does not fit!");
return;
}
RGBImageLock();
uint8_t* odata = _target->rgb_image;
stbir_resize_uint8(rgb_image, width, height, 0, odata, _new_dx, _new_dy, 0, channels);
RGBImageRelease();
}

View File

@@ -0,0 +1,96 @@
#pragma once
#ifndef __CIMAGEBASIS
#define __CIMAGEBASIS
#include <stdint.h>
#include <string>
#include <esp_http_server.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include "stb_image.h"
#include "stb_image_write.h"
#include "stb_image_resize.h"
#include "esp_heap_caps.h"
//#define GET_MEMORY malloc
#define GET_MEMORY(X) heap_caps_malloc(X, MALLOC_CAP_SPIRAM)
#define MAX_JPG_SIZE 128000
struct ImageData
{
uint8_t data[MAX_JPG_SIZE];
size_t size = 0;
};
class CImageBasis
{
protected:
bool externalImage;
std::string filename;
void memCopy(uint8_t* _source, uint8_t* _target, int _size);
bool isInImage(int x, int y);
bool islocked;
public:
uint8_t* rgb_image;
int channels;
int width, height, bpp;
uint8_t * RGBImageLock(int _waitmaxsec = 60);
void RGBImageRelease();
uint8_t * RGBImageGet();
int getWidth(){return this->width;};
int getHeight(){return this->height;};
int getChannels(){return this->channels;};
void drawRect(int x, int y, int dx, int dy, int r = 255, int g = 255, int b = 255, int thickness = 1);
void drawLine(int x1, int y1, int x2, int y2, int r, int g, int b, int thickness = 1);
void drawCircle(int x1, int y1, int rad, int r, int g, int b, int thickness = 1);
void drawEllipse(int x1, int y1, int radx, int rady, int r, int g, int b, int thickness = 1);
void setPixelColor(int x, int y, int r, int g, int b);
void Contrast(float _contrast);
bool ImageOkay();
bool CopyFromMemory(uint8_t* _source, int _size);
void SetIndepended(){externalImage = false;};
void CreateEmptyImage(int _width, int _height, int _channels);
CImageBasis();
CImageBasis(std::string _image);
CImageBasis(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp);
CImageBasis(int _width, int _height, int _channels);
CImageBasis(CImageBasis *_copyfrom, int _anzrepeat = 0);
void Resize(int _new_dx, int _new_dy);
void Resize(int _new_dx, int _new_dy, CImageBasis *_target);
void LoadFromMemory(stbi_uc *_buffer, int len);
ImageData* writeToMemoryAsJPG(const int quality = 90);
esp_err_t SendJPGtoHTTP(httpd_req_t *req, const int quality = 90);
uint8_t GetPixelColor(int x, int y, int ch);
~CImageBasis();
void SaveToFile(std::string _imageout);
};
#endif

View File

@@ -0,0 +1,7 @@
FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
idf_component_register(SRCS ${app_sources}
INCLUDE_DIRS "."
REQUIRES jomjol_helper jomjol_logfile esp_http_server jomjol_fileserver_ota)

View File

@@ -0,0 +1,349 @@
#include "CRotateImage.h"
CRotateImage::CRotateImage(CImageBasis *_org, CImageBasis *_temp, bool _flip)
{
rgb_image = _org->rgb_image;
channels = _org->channels;
width = _org->width;
height = _org->height;
bpp = _org->bpp;
externalImage = true;
ImageTMP = _temp;
ImageOrg = _org;
islocked = false;
doflip = _flip;
}
void CRotateImage::Mirror(){
int memsize = width * height * channels;
uint8_t* odata;
if (ImageTMP)
{
odata = ImageTMP->RGBImageLock();
}
else
{
odata = (unsigned char*)GET_MEMORY(memsize);
}
int x_source, y_source;
stbi_uc* p_target;
stbi_uc* p_source;
RGBImageLock();
for (int x = 0; x < width; ++x)
for (int y = 0; y < height; ++y)
{
p_target = odata + (channels * (y * width + x));
x_source = width - x;
y_source = y;
p_source = rgb_image + (channels * (y_source * width + x_source));
for (int _channels = 0; _channels < channels; ++_channels)
p_target[_channels] = p_source[_channels];
}
// memcpy(rgb_image, odata, memsize);
memCopy(odata, rgb_image, memsize);
if (!ImageTMP)
stbi_image_free(odata);
if (ImageTMP)
ImageTMP->RGBImageRelease();
RGBImageRelease();
}
void CRotateImage::Rotate(float _angle, int _centerx, int _centery)
{
int org_width, org_height;
float m[2][3];
float x_center = _centerx;
float y_center = _centery;
_angle = _angle / 180 * M_PI;
if (doflip)
{
org_width = width;
org_height = height;
height = org_width;
width = org_height;
x_center = x_center - (org_width/2) + (org_height/2);
y_center = y_center + (org_width/2) - (org_height/2);
if (ImageOrg)
{
ImageOrg->height = height;
ImageOrg->width = width;
}
}
else
{
org_width = width;
org_height = height;
}
m[0][0] = cos(_angle);
m[0][1] = sin(_angle);
m[0][2] = (1 - m[0][0]) * x_center - m[0][1] * y_center;
m[1][0] = -m[0][1];
m[1][1] = m[0][0];
m[1][2] = m[0][1] * x_center + (1 - m[0][0]) * y_center;
if (doflip)
{
m[0][2] = m[0][2] + (org_width/2) - (org_height/2);
m[1][2] = m[1][2] - (org_width/2) + (org_height/2);
}
int memsize = width * height * channels;
uint8_t* odata;
if (ImageTMP)
{
odata = ImageTMP->RGBImageLock();
}
else
{
odata = (unsigned char*)GET_MEMORY(memsize);
}
int x_source, y_source;
stbi_uc* p_target;
stbi_uc* p_source;
RGBImageLock();
for (int x = 0; x < width; ++x)
for (int y = 0; y < height; ++y)
{
p_target = odata + (channels * (y * width + x));
x_source = int(m[0][0] * x + m[0][1] * y);
y_source = int(m[1][0] * x + m[1][1] * y);
x_source += int(m[0][2]);
y_source += int(m[1][2]);
if ((x_source >= 0) && (x_source < org_width) && (y_source >= 0) && (y_source < org_height))
{
p_source = rgb_image + (channels * (y_source * org_width + x_source));
for (int _channels = 0; _channels < channels; ++_channels)
p_target[_channels] = p_source[_channels];
}
else
{
for (int _channels = 0; _channels < channels; ++_channels)
p_target[_channels] = 255;
}
}
// memcpy(rgb_image, odata, memsize);
memCopy(odata, rgb_image, memsize);
if (!ImageTMP)
{
stbi_image_free(odata);
}
if (ImageTMP)
ImageTMP->RGBImageRelease();
RGBImageRelease();
}
void CRotateImage::RotateAntiAliasing(float _angle, int _centerx, int _centery)
{
int org_width, org_height;
float m[2][3];
float x_center = _centerx;
float y_center = _centery;
_angle = _angle / 180 * M_PI;
if (doflip)
{
org_width = width;
org_height = height;
height = org_width;
width = org_height;
x_center = x_center - (org_width/2) + (org_height/2);
y_center = y_center + (org_width/2) - (org_height/2);
if (ImageOrg)
{
ImageOrg->height = height;
ImageOrg->width = width;
}
}
else
{
org_width = width;
org_height = height;
}
m[0][0] = cos(_angle);
m[0][1] = sin(_angle);
m[0][2] = (1 - m[0][0]) * x_center - m[0][1] * y_center;
m[1][0] = -m[0][1];
m[1][1] = m[0][0];
m[1][2] = m[0][1] * x_center + (1 - m[0][0]) * y_center;
if (doflip)
{
m[0][2] = m[0][2] + (org_width/2) - (org_height/2);
m[1][2] = m[1][2] - (org_width/2) + (org_height/2);
}
int memsize = width * height * channels;
uint8_t* odata;
if (ImageTMP)
{
odata = ImageTMP->RGBImageLock();
}
else
{
odata = (unsigned char*)GET_MEMORY(memsize);
}
int x_source_1, y_source_1, x_source_2, y_source_2;
float x_source, y_source;
float quad_ul, quad_ur, quad_ol, quad_or;
stbi_uc* p_target;
stbi_uc *p_source_ul, *p_source_ur, *p_source_ol, *p_source_or;
RGBImageLock();
for (int x = 0; x < width; ++x)
for (int y = 0; y < height; ++y)
{
p_target = odata + (channels * (y * width + x));
x_source = (m[0][0] * x + m[0][1] * y);
y_source = (m[1][0] * x + m[1][1] * y);
x_source += (m[0][2]);
y_source += (m[1][2]);
x_source_1 = (int)x_source;
x_source_2 = x_source_1 + 1;
y_source_1 = (int)y_source;
y_source_2 = y_source_1 + 1;
quad_ul = (x_source_2 - x_source) * (y_source_2 - y_source);
quad_ur = (1- (x_source_2 - x_source)) * (y_source_2 - y_source);
quad_or = (x_source_2 - x_source) * (1-(y_source_2 - y_source));
quad_ol = (1- (x_source_2 - x_source)) * (1-(y_source_2 - y_source));
if ((x_source_1 >= 0) && (x_source_2 < org_width) && (y_source_1 >= 0) && (y_source_2 < org_height))
{
p_source_ul = rgb_image + (channels * (y_source_1 * org_width + x_source_1));
p_source_ur = rgb_image + (channels * (y_source_1 * org_width + x_source_2));
p_source_or = rgb_image + (channels * (y_source_2 * org_width + x_source_1));
p_source_ol = rgb_image + (channels * (y_source_2 * org_width + x_source_2));
for (int _channels = 0; _channels < channels; ++_channels)
{
p_target[_channels] = (int)((float)p_source_ul[_channels] * quad_ul
+ (float)p_source_ur[_channels] * quad_ur
+ (float)p_source_or[_channels] * quad_or
+ (float)p_source_ol[_channels] * quad_ol);
}
}
else
{
for (int _channels = 0; _channels < channels; ++_channels)
p_target[_channels] = 255;
}
}
// memcpy(rgb_image, odata, memsize);
memCopy(odata, rgb_image, memsize);
if (!ImageTMP)
{
stbi_image_free(odata);
}
if (ImageTMP)
ImageTMP->RGBImageRelease();
RGBImageRelease();
}
void CRotateImage::Rotate(float _angle)
{
// ESP_LOGD(TAG, "width %d, height %d", width, height);
Rotate(_angle, width / 2, height / 2);
}
void CRotateImage::RotateAntiAliasing(float _angle)
{
// ESP_LOGD(TAG, "width %d, height %d", width, height);
RotateAntiAliasing(_angle, width / 2, height / 2);
}
void CRotateImage::Translate(int _dx, int _dy)
{
int memsize = width * height * channels;
uint8_t* odata;
if (ImageTMP)
{
odata = ImageTMP->RGBImageLock();
}
else
{
odata = (unsigned char*)GET_MEMORY(memsize);
}
int x_source, y_source;
stbi_uc* p_target;
stbi_uc* p_source;
RGBImageLock();
for (int x = 0; x < width; ++x)
for (int y = 0; y < height; ++y)
{
p_target = odata + (channels * (y * width + x));
x_source = x - _dx;
y_source = y - _dy;
if ((x_source >= 0) && (x_source < width) && (y_source >= 0) && (y_source < height))
{
p_source = rgb_image + (channels * (y_source * width + x_source));
for (int _channels = 0; _channels < channels; ++_channels)
p_target[_channels] = p_source[_channels];
}
else
{
for (int _channels = 0; _channels < channels; ++_channels)
p_target[_channels] = 255;
}
}
// memcpy(rgb_image, odata, memsize);
memCopy(odata, rgb_image, memsize);
if (!ImageTMP)
{
stbi_image_free(odata);
}
if (ImageTMP)
{
ImageTMP->RGBImageRelease();
}
RGBImageRelease();
}

View File

@@ -0,0 +1,21 @@
#include "CImageBasis.h"
class CRotateImage: public CImageBasis
{
public:
CImageBasis *ImageTMP, *ImageOrg;
bool doflip;
CRotateImage(std::string _image, bool _flip = false) : CImageBasis(_image) {ImageTMP = NULL; ImageOrg = NULL; doflip = _flip;};
CRotateImage(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp, bool _flip = false) : CImageBasis(_rgb_image, _channels, _width, _height, _bpp) {ImageTMP = NULL; ImageOrg = NULL; doflip = _flip;};
CRotateImage(CImageBasis *_org, CImageBasis *_temp, bool _flip = false);
void Rotate(float _angle);
void RotateAntiAliasing(float _angle);
void Rotate(float _angle, int _centerx, int _centery);
void RotateAntiAliasing(float _angle, int _centerx, int _centery);
void Translate(int _dx, int _dy);
void Mirror();
};

View File

@@ -0,0 +1,7 @@
FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
idf_component_register(SRCS ${app_sources}
INCLUDE_DIRS "."
REQUIRES tflite-lib esp_http_client jomjol_logfile)

View File

@@ -0,0 +1,114 @@
#include "interface_influxdb.h"
//#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
#include "esp_log.h"
#include <time.h>
#include "ClassLogFile.h"
#include "esp_http_client.h"
#define MAX_HTTP_OUTPUT_BUFFER 2048
static const char *TAG = "INFLUXDB";
std::string _influxDBURI;
std::string _influxDBDatabase;
std::string _influxDBMeasurement;
std::string _influxDBUser;
std::string _influxDBPassword;
static esp_err_t http_event_handler(esp_http_client_event_t *evt)
{
switch(evt->event_id)
{
case HTTP_EVENT_ERROR:
ESP_LOGE(TAG, "HTTP Client Error encountered");
break;
case HTTP_EVENT_ON_CONNECTED:
ESP_LOGI(TAG, "HTTP Client Connected");
break;
case HTTP_EVENT_HEADERS_SENT:
ESP_LOGV(TAG, "HTTP Client sent all request headers");
break;
case HTTP_EVENT_ON_HEADER:
ESP_LOGV(TAG, "Header: key=%s, value=%s", evt->header_key, evt->header_value);
break;
case HTTP_EVENT_ON_DATA:
ESP_LOGV(TAG, "HTTP Client data recevied: len=%d", evt->data_len);
break;
case HTTP_EVENT_ON_FINISH:
ESP_LOGI(TAG, "HTTP Client finished");
break;
case HTTP_EVENT_DISCONNECTED:
ESP_LOGI(TAG, "HTTP Client Disconnected");
break;
}
return ESP_OK;
}
void InfluxDBPublish(std::string _key, std::string _content, std::string _timestamp) {
char response_buffer[MAX_HTTP_OUTPUT_BUFFER] = {0};
esp_http_client_config_t http_config = {
.user_agent = "ESP32 Meter reader",
.method = HTTP_METHOD_POST,
.event_handler = http_event_handler,
.buffer_size = MAX_HTTP_OUTPUT_BUFFER,
.user_data = response_buffer
};
if (_influxDBUser.length() && _influxDBPassword.length()){
http_config.username = _influxDBUser.c_str();
http_config.password = _influxDBPassword.c_str();
http_config.auth_type = HTTP_AUTH_TYPE_BASIC;
}
// generate timestamp (TODO: parse result timestamp passed as string and convert it to POSIX timestamp?)
time_t now = time(NULL);
char nowTimestamp[21];
// pad with zeroes to get nanoseconds
sprintf(nowTimestamp,"%jd000000000", (intmax_t)now);
std::string payload = _influxDBMeasurement + " " + _key + "=" + _content + " " + nowTimestamp;
payload.shrink_to_fit();
ESP_LOGI(TAG, "sending line to influxdb: %s\n", payload.c_str());
// use the default retention policy of the database
std::string apiURI = _influxDBURI + "/api/v2/write?bucket=" + _influxDBDatabase + "/";
apiURI.shrink_to_fit();
http_config.url = apiURI.c_str();
ESP_LOGI(TAG, "API URI: %s", apiURI.c_str());
esp_http_client_handle_t http_client = esp_http_client_init(&http_config);
ESP_LOGI(TAG, "client is initialized%s\n", "");
esp_http_client_set_header(http_client, "Content-Type", "text/plain");
ESP_LOGI(TAG, "header is set%s\n", "");
ESP_ERROR_CHECK(esp_http_client_set_post_field(http_client, payload.c_str(), payload.length()));
ESP_LOGI(TAG, "post payload is set%s\n", "");
esp_err_t err = ESP_ERROR_CHECK_WITHOUT_ABORT(esp_http_client_perform(http_client));
if( err == ESP_OK ) {
ESP_LOGI(TAG, "HTTP request was performed%s\n", "");
int status_code = esp_http_client_get_status_code(http_client);
ESP_LOGI(TAG, "HTTP status code %d\n", status_code);
} else {
ESP_LOGW(TAG, "HTTP request failed%s\n", "");
}
esp_http_client_cleanup(http_client);
}
void InfluxDBInit(std::string _uri, std::string _database, std::string _measurement, std::string _user, std::string _password){
_influxDBURI = _uri;
_influxDBDatabase = _database;
_influxDBMeasurement = _measurement;
_influxDBUser = _user;
_influxDBPassword = _password;
}
void InfluxDBdestroy() {
}

View File

@@ -0,0 +1,13 @@
#ifndef INTERFACE_INFLUXDB_H
#define INTERFACE_INFLUXDB_H
#include <string>
#include <map>
#include <functional>
void InfluxDBInit(std::string _influxDBURI, std::string _database, std::string _measurement, std::string _user, std::string _password);
void InfluxDBdestroy();
void InfluxDBPublish(std::string _key, std::string _content, std::string _timestamp);
#endif //INTERFACE_INFLUXDB_H

View File

@@ -0,0 +1,7 @@
FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
idf_component_register(SRCS ${app_sources}
INCLUDE_DIRS "."
REQUIRES jomjol_time_sntp jomjol_helper)

View File

@@ -0,0 +1,417 @@
#include "ClassLogFile.h"
#include "time_sntp.h"
#include "esp_log.h"
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <algorithm>
#ifdef __cplusplus
extern "C" {
#endif
#include <dirent.h>
#ifdef __cplusplus
}
#endif
#include "Helper.h"
static const char *TAG = "LOGFILE";
ClassLogFile LogFile("/sdcard/log/message", "log_%Y-%m-%d.txt", "/sdcard/log/data", "data_%Y-%m-%d.csv");
void ClassLogFile::WriteHeapInfo(std::string _id)
{
std::string _zw = _id;
if (loglevel > ESP_LOG_WARN)
_zw = _zw + "\t" + getESPHeapInfo();
WriteToFile(ESP_LOG_DEBUG, "HEAP", _zw);
}
std::string ClassLogFile::getESPHeapInfo(){
string espInfoResultStr = "";
char aMsgBuf[80];
multi_heap_info_t aMultiHead_info ;
heap_caps_get_info (&aMultiHead_info,MALLOC_CAP_8BIT);
size_t aFreeHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT);
size_t aMinFreeHeadSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT);
size_t aMinFreeHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT);
size_t aHeapLargestFreeBlockSize = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
sprintf(aMsgBuf,"Free Heap Size: \t%ld", (long) aFreeHeapSize);
size_t aFreeSPIHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_SPIRAM);
size_t aFreeInternalHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_INTERNAL);
size_t aMinFreeInternalHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_INTERNAL);
sprintf(aMsgBuf,"\tHeap:\t%ld", (long) aFreeHeapSize);
espInfoResultStr += string(aMsgBuf);
sprintf(aMsgBuf,"\tMin Free:\t%ld", (long) aMinFreeHeapSize);
espInfoResultStr += string(aMsgBuf);
sprintf(aMsgBuf,"\tlarg. Block: \t%ld", (long) aHeapLargestFreeBlockSize);
espInfoResultStr += string(aMsgBuf);
sprintf(aMsgBuf,"\tSPI Heap:\t%ld", (long) aFreeSPIHeapSize);
espInfoResultStr += string(aMsgBuf);
sprintf(aMsgBuf,"\tMin Free Heap Size:\t%ld", (long) aMinFreeHeadSize);
sprintf(aMsgBuf,"\tNOT_SPI Heap:\t%ld", (long) (aFreeHeapSize - aFreeSPIHeapSize));
espInfoResultStr += string(aMsgBuf);
sprintf(aMsgBuf,"\tlargest Block Size: \t%ld", (long) aHeapLargestFreeBlockSize);
sprintf(aMsgBuf,"\tInternal Heap:\t%ld", (long) (aFreeInternalHeapSize));
espInfoResultStr += string(aMsgBuf);
sprintf(aMsgBuf,"\tInternal Min Heap free:\t%ld", (long) (aMinFreeInternalHeapSize));
espInfoResultStr += string(aMsgBuf);
return espInfoResultStr;
}
void ClassLogFile::WriteToData(std::string _timestamp, std::string _name, std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ReturnRateValue, std::string _ReturnChangeAbsolute, std::string _ErrorMessageText, std::string _digital, std::string _analog)
{
ESP_LOGD(TAG, "Start WriteToData");
time_t rawtime;
struct tm* timeinfo;
char buffer[30];
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, 30, datafile.c_str(), timeinfo);
std::string logpath = dataroot + "/" + buffer;
FILE* pFile;
std::string zwtime;
ESP_LOGD(TAG, "Datalogfile: %s", logpath.c_str());
pFile = fopen(logpath.c_str(), "a+");
if (pFile!=NULL) {
fputs(_timestamp.c_str(), pFile);
fputs(",", pFile);
fputs(_name.c_str(), pFile);
fputs(",", pFile);
fputs(_ReturnRawValue.c_str(), pFile);
fputs(",", pFile);
fputs(_ReturnValue.c_str(), pFile);
fputs(",", pFile);
fputs(_ReturnPreValue.c_str(), pFile);
fputs(",", pFile);
fputs(_ReturnRateValue.c_str(), pFile);
fputs(",", pFile);
fputs(_ReturnChangeAbsolute.c_str(), pFile);
fputs(",", pFile);
fputs(_ErrorMessageText.c_str(), pFile);
fputs(_digital.c_str(), pFile);
fputs(_analog.c_str(), pFile);
fputs("\n", pFile);
fclose(pFile);
} else {
ESP_LOGE(TAG, "Can't open data file %s", logpath.c_str());
}
}
void ClassLogFile::WriteToDedicatedFile(std::string _fn, esp_log_level_t level, std::string message, bool _time)
{
FILE* pFile;
std::string zwtime;
std::string logline = "";
if (level > loglevel) {// Only write to file if loglevel is below threshold
return;
}
// pFile = OpenFileAndWait(_fn.c_str(), "a");
pFile = fopen(_fn.c_str(), "a+");
// ESP_LOGD(TAG, "Logfile opened: %s", _fn.c_str());
if (pFile!=NULL) {
if (_time)
{
time_t rawtime;
struct tm* timeinfo;
char buffer[80];
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, 80, "%Y-%m-%dT%H:%M:%S", timeinfo);
zwtime = std::string(buffer);
logline = zwtime;
}
std::string loglevelString;
switch(level) {
case ESP_LOG_ERROR:
loglevelString = "ERR";
break;
case ESP_LOG_WARN:
loglevelString = "WRN";
break;
case ESP_LOG_INFO:
loglevelString = "INF";
break;
case ESP_LOG_DEBUG:
loglevelString = "DBG";
break;
case ESP_LOG_VERBOSE:
loglevelString = "VER";
break;
case ESP_LOG_NONE:
default:
loglevelString = "NONE";
break;
}
logline = logline + "\t<" + loglevelString + ">\t" + message.c_str() + "\n";
fputs(logline.c_str(), pFile);
fclose(pFile);
} else {
ESP_LOGE(TAG, "Can't open log file %s", _fn.c_str());
}
}
void ClassLogFile::setLogLevel(esp_log_level_t _logLevel){
loglevel = _logLevel;
std::string levelText;
switch(_logLevel) {
case ESP_LOG_WARN:
levelText = "WARNING";
break;
case ESP_LOG_INFO:
levelText = "INFO";
break;
case ESP_LOG_DEBUG:
levelText = "DEBUG";
break;
case ESP_LOG_ERROR:
default:
levelText = "ERROR";
break;
}
ESP_LOGI(TAG, "Log Level set to %s", levelText.c_str());
/*
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Test");
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Test");
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Test");
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Test");
*/
}
void ClassLogFile::SetLogFileRetention(unsigned short _LogFileRetentionInDays){
logFileRetentionInDays = _LogFileRetentionInDays;
}
void ClassLogFile::SetDataLogRetention(unsigned short _DataLogRetentionInDays){
dataLogRetentionInDays = _DataLogRetentionInDays;
}
void ClassLogFile::SetDataLogToSD(bool _doDataLogToSD){
doDataLogToSD = _doDataLogToSD;
}
bool ClassLogFile::GetDataLogToSD(){
return doDataLogToSD;
}
void ClassLogFile::WriteToFile(esp_log_level_t level, std::string tag, std::string message, bool _time)
{
/*
struct stat path_stat;
if (stat(logroot.c_str(), &path_stat) != 0) {
ESP_LOGI(TAG, "Create log folder: %s", logroot.c_str());
if (mkdir_r(logroot.c_str(), S_IRWXU) == -1) {
ESP_LOGE(TAG, "Can't create log folder");
}
}
*/
time_t rawtime;
struct tm* timeinfo;
char buffer[30];
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, 30, logfile.c_str(), timeinfo);
std::string logpath = logroot + "/" + buffer;
std::replace(message.begin(), message.end(), '\n', ' '); // Replace all newline characters
if (tag != "") {
ESP_LOG_LEVEL(level, tag.c_str(), "%s", message.c_str());
message = "[" + tag + "] " + message;
}
else {
ESP_LOG_LEVEL(level, "", "%s", message.c_str());
}
WriteToDedicatedFile(logpath, level, message, _time);
}
void ClassLogFile::WriteToFile(esp_log_level_t level, std::string tag, std::string message) {
LogFile.WriteToFile(level, tag, message, true);
}
std::string ClassLogFile::GetCurrentFileNameData()
{
time_t rawtime;
struct tm* timeinfo;
char buffer[60];
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, 60, datafile.c_str(), timeinfo);
std::string logpath = dataroot + "/" + buffer;
return logpath;
}
std::string ClassLogFile::GetCurrentFileName()
{
time_t rawtime;
struct tm* timeinfo;
char buffer[60];
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, 60, logfile.c_str(), timeinfo);
std::string logpath = logroot + "/" + buffer;
return logpath;
}
void ClassLogFile::RemoveOldLogFile()
{
if (logFileRetentionInDays == 0) {
return;
}
ESP_LOGI(TAG, "Remove old log files");
time_t rawtime;
struct tm* timeinfo;
char cmpfilename[30];
time(&rawtime);
rawtime = addDays(rawtime, -logFileRetentionInDays + 1);
timeinfo = localtime(&rawtime);
//ESP_LOGD(TAG, "logFileRetentionInDays: %d", logFileRetentionInDays);
strftime(cmpfilename, 30, logfile.c_str(), timeinfo);
//ESP_LOGD(TAG, "log file name to compare: %s", cmpfilename);
DIR *dir = opendir(logroot.c_str());
if (!dir) {
ESP_LOGE(TAG, "Failed to stat dir : %s", logroot.c_str());
return;
}
struct dirent *entry;
int deleted = 0;
int notDeleted = 0;
while ((entry = readdir(dir)) != NULL) {
if (entry->d_type == DT_REG) {
//ESP_LOGD(TAG, "compare log file : %s to %s", entry->d_name, cmpfilename);
if ((strlen(entry->d_name) == strlen(cmpfilename)) && (strcmp(entry->d_name, cmpfilename) < 0)) {
//ESP_LOGD(TAG, "delete log file : %s", entry->d_name);
std::string filepath = logroot + "/" + entry->d_name;
if (unlink(filepath.c_str()) == 0) {
deleted ++;
} else {
ESP_LOGE(TAG, "can't delete file : %s", entry->d_name);
notDeleted ++;
}
} else {
notDeleted ++;
}
}
}
ESP_LOGI(TAG, "log files deleted: %d | files not deleted (incl. leer.txt): %d", deleted, notDeleted);
closedir(dir);
}
void ClassLogFile::RemoveOldDataLog()
{
if (dataLogRetentionInDays == 0 || !doDataLogToSD) {
return;
}
ESP_LOGI(TAG, "Remove old data files");
time_t rawtime;
struct tm* timeinfo;
char cmpfilename[30];
time(&rawtime);
rawtime = addDays(rawtime, -dataLogRetentionInDays + 1);
timeinfo = localtime(&rawtime);
//ESP_LOGD(TAG, "dataLogRetentionInDays: %d", dataLogRetentionInDays);
strftime(cmpfilename, 30, datafile.c_str(), timeinfo);
//ESP_LOGD(TAG, "data file name to compare: %s", cmpfilename);
DIR *dir = opendir(dataroot.c_str());
if (!dir) {
ESP_LOGE(TAG, "Failed to stat dir : %s", dataroot.c_str());
return;
}
struct dirent *entry;
int deleted = 0;
int notDeleted = 0;
while ((entry = readdir(dir)) != NULL) {
if (entry->d_type == DT_REG) {
//ESP_LOGD(TAG, "Compare data file : %s to %s", entry->d_name, cmpfilename);
if ((strlen(entry->d_name) == strlen(cmpfilename)) && (strcmp(entry->d_name, cmpfilename) < 0)) {
//ESP_LOGD(TAG, "delete data file : %s", entry->d_name);
std::string filepath = dataroot + "/" + entry->d_name;
if (unlink(filepath.c_str()) == 0) {
deleted ++;
} else {
ESP_LOGE(TAG, "can't delete file : %s", entry->d_name);
notDeleted ++;
}
} else {
notDeleted ++;
}
}
}
ESP_LOGI(TAG, "data files deleted: %d | files not deleted (incl. leer.txt): %d", deleted, notDeleted);
closedir(dir);
}
void ClassLogFile::CreateLogDirectories()
{
MakeDir("/sdcard/log");
MakeDir("/sdcard/log/data");
MakeDir("/sdcard/log/analog");
MakeDir("/sdcard/log/digit");
MakeDir("/sdcard/log/message");
MakeDir("/sdcard/log/source");
}
ClassLogFile::ClassLogFile(std::string _logroot, std::string _logfile, std::string _logdatapath, std::string _datafile)
{
logroot = _logroot;
logfile = _logfile;
datafile = _datafile;
dataroot = _logdatapath;
logFileRetentionInDays = 3;
dataLogRetentionInDays = 3;
doDataLogToSD = true;
loglevel = ESP_LOG_INFO;
}

View File

@@ -0,0 +1,47 @@
#include <string>
#include "esp_log.h"
class ClassLogFile
{
private:
std::string logroot;
std::string logfile;
std::string dataroot;
std::string datafile;
unsigned short logFileRetentionInDays;
unsigned short dataLogRetentionInDays;
bool doDataLogToSD;
esp_log_level_t loglevel;
public:
ClassLogFile(std::string _logpath, std::string _logfile, std::string _logdatapath, std::string _datafile);
std::string getESPHeapInfo();
void WriteHeapInfo(std::string _id);
void setLogLevel(esp_log_level_t _logLevel);
void SetLogFileRetention(unsigned short _LogFileRetentionInDays);
void SetDataLogRetention(unsigned short _DataLogRetentionInDays);
void SetDataLogToSD(bool _doDataLogToSD);
bool GetDataLogToSD();
void WriteToFile(esp_log_level_t level, std::string tag, std::string message, bool _time);
void WriteToFile(esp_log_level_t level, std::string tag, std::string message);
void WriteToDedicatedFile(std::string _fn, esp_log_level_t level, std::string message, bool _time = true);
void CreateLogDirectories();
void RemoveOldLogFile();
void RemoveOldDataLog();
// void WriteToData(std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ErrorMessageText, std::string _digital, std::string _analog);
void WriteToData(std::string _timestamp, std::string _name, std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ReturnRateValue, std::string _ReturnChangeAbsolute, std::string _ErrorMessageText, std::string _digital, std::string _analog);
std::string GetCurrentFileName();
std::string GetCurrentFileNameData();
};
extern ClassLogFile LogFile;

View File

@@ -0,0 +1,5 @@
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)

View File

@@ -0,0 +1,315 @@
#include "interface_mqtt.h"
//#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
#include "esp_log.h"
#include "mqtt_client.h"
#include "ClassLogFile.h"
#include "server_tflite.h"
#define __HIDE_PASSWORD
static const char *TAG = "MQTT INTERFACE";
std::map<std::string, std::function<void()>>* connectFunktionMap = NULL;
std::map<std::string, std::function<bool(std::string, char*, int)>>* subscribeFunktionMap = NULL;
int failedOnRound = -1;
esp_mqtt_event_id_t esp_mmqtt_ID = MQTT_EVENT_ANY;
// ESP_EVENT_ANY_ID
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;
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
}
LogFile.WriteHeapInfo("MQTT Publish");
if (!mqtt_connected) {
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Not connected, trying to re-connect...");
if (!MQTT_Init()) {
if (!MQTT_Init()) { // Retry
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to init, 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...");
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!");
mqtt_connected = false; // Force re-init on next call
failedOnRound = getCountFlowRounds();
return false;
}
}
if (_content.length() > 80) { // Truncate message if too long
_content.resize(80);
_content.append("..");
}
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)
{
int msg_id;
std::string topic = "";
switch (event->event_id) {
case MQTT_EVENT_BEFORE_CONNECT:
ESP_LOGD(TAG, "MQTT_EVENT_BEFORE_CONNECT");
break;
case MQTT_EVENT_CONNECTED:
ESP_LOGD(TAG, "MQTT_EVENT_CONNECTED");
mqtt_connected = true;
MQTTconnected();
break;
case MQTT_EVENT_DISCONNECTED:
ESP_LOGD(TAG, "MQTT_EVENT_DISCONNECTED");
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Disconnected! Going to re-connect...");
mqtt_connected = false; // Force re-init on next call
esp_mqtt_client_reconnect(client);
break;
case MQTT_EVENT_SUBSCRIBED:
ESP_LOGD(TAG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
msg_id = esp_mqtt_client_publish(client, "/topic/qos0", "data", 0, 0, 0);
ESP_LOGD(TAG, "sent publish successful, msg_id=%d", msg_id);
break;
case MQTT_EVENT_UNSUBSCRIBED:
ESP_LOGD(TAG, "MQTT_EVENT_UNSUBSCRIBED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_PUBLISHED:
ESP_LOGD(TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_DATA:
ESP_LOGD(TAG, "MQTT_EVENT_DATA");
ESP_LOGD(TAG, "TOPIC=%.*s\r\n", event->topic_len, event->topic);
ESP_LOGD(TAG, "DATA=%.*s\r\n", event->data_len, event->data);
topic.assign(event->topic, event->topic_len);
if (subscribeFunktionMap != NULL) {
if (subscribeFunktionMap->find(topic) != subscribeFunktionMap->end()) {
ESP_LOGD(TAG, "call handler function\r\n");
(*subscribeFunktionMap)[topic](topic, event->data, event->data_len);
}
} else {
ESP_LOGW(TAG, "no handler available\r\n");
}
break;
case MQTT_EVENT_ERROR:
ESP_LOGD(TAG, "MQTT_EVENT_ERROR");
mqtt_connected = false; // Force re-init on next call
break;
default:
ESP_LOGD(TAG, "Other event id:%d", event->event_id);
break;
}
return ESP_OK;
}
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) {
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id);
mqtt_event_handler_cb((esp_mqtt_event_handle_t) event_data);
}
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){
#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
uri = _mqttURI;
client_id = _clientid;
lwt_topic = _maintopic + "/" + _lwt;
lwt_connected = _lwt_connected;
lwt_disconnected = _lwt_disconnected;
keepalive = _keepalive;
SetRetainFlag = _SetRetainFlag;
maintopic = _maintopic;
callbackOnConnected = ( void (*)(std::string, int) )(_callbackOnConnected);
if (_user.length() && _password.length()){
user = _user;
password = _password;
}
}
bool MQTT_Init() {
esp_err_t ret;
LogFile.WriteToFile(ESP_LOG_INFO, TAG, std::string("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_retain = 1,
.lwt_msg_len = (int)(lw.length()),
.keepalive = keepalive
};
if (user.length() && password.length()){
mqtt_cfg.username = user.c_str();
mqtt_cfg.password = password.c_str();
};
LogFile.WriteHeapInfo("MQTT Client Init");
client = esp_mqtt_client_init(&mqtt_cfg);
if (client)
{
ret = esp_mqtt_client_register_event(client, esp_mmqtt_ID, mqtt_event_handler, client);
if (ret != ESP_OK)
{
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Could not register event (ret=" + std::to_string(ret) + ")!");
return false;
}
LogFile.WriteHeapInfo("MQTT Client Start");
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) + ")!");
return false;
}
}
}
else
{
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Could not init client!");
return false;
}
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Init successful");
return true;
}
void MQTTdestroy_client() {
if (client != NULL) {
esp_mqtt_client_stop(client);
esp_mqtt_client_destroy(client);
}
}
bool MQTTisConnected() {
return mqtt_connected;
}
void MQTTregisterConnectFunction(std::string name, std::function<void()> func){
ESP_LOGD(TAG, "MQTTregisteronnectFunction %s\r\n", name.c_str());
if (connectFunktionMap == NULL) {
connectFunktionMap = new std::map<std::string, std::function<void()>>();
}
if ((*connectFunktionMap)[name] != NULL) {
ESP_LOGW(TAG, "connect function %s already registred", name.c_str());
return;
}
(*connectFunktionMap)[name] = func;
if (mqtt_connected) {
func();
}
}
void MQTTunregisterConnectFunction(std::string name){
ESP_LOGD(TAG, "unregisterConnnectFunction %s\r\n", name.c_str());
if ((connectFunktionMap != NULL) && (connectFunktionMap->find(name) != connectFunktionMap->end())) {
connectFunktionMap->erase(name);
}
}
void MQTTregisterSubscribeFunction(std::string topic, std::function<bool(std::string, char*, int)> func){
ESP_LOGD(TAG, "registerSubscribeFunction %s\r\n", topic.c_str());
if (subscribeFunktionMap == NULL) {
subscribeFunktionMap = new std::map<std::string, std::function<bool(std::string, char*, int)>>();
}
if ((*subscribeFunktionMap)[topic] != NULL) {
ESP_LOGW(TAG, "topic %s already registered for subscription", topic.c_str());
return;
}
(*subscribeFunktionMap)[topic] = func;
if (mqtt_connected) {
int msg_id = esp_mqtt_client_subscribe(client, topic.c_str(), 0);
ESP_LOGD(TAG, "topic %s subscribe successful, msg_id=%d", topic.c_str(), msg_id);
}
}
void MQTTconnected(){
if (mqtt_connected) {
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Connected");
MQTTPublish(lwt_topic, lwt_connected, true);
if (connectFunktionMap != NULL) {
for(std::map<std::string, std::function<void()>>::iterator it = connectFunktionMap->begin(); it != connectFunktionMap->end(); ++it) {
it->second();
ESP_LOGD(TAG, "call connect function %s", it->first.c_str());
}
}
if (subscribeFunktionMap != NULL) {
for(std::map<std::string, std::function<bool(std::string, char*, int)>>::iterator it = subscribeFunktionMap->begin(); it != subscribeFunktionMap->end(); ++it) {
int msg_id = esp_mqtt_client_subscribe(client, it->first.c_str(), 0);
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "topic " + it->first + " subscribe successful, msg_id=" + std::to_string(msg_id));
}
}
if (callbackOnConnected) {
callbackOnConnected(maintopic, SetRetainFlag);
}
}
}
void MQTTdestroySubscribeFunction(){
if (subscribeFunktionMap != NULL) {
if (mqtt_connected) {
for(std::map<std::string, std::function<bool(std::string, char*, int)>>::iterator it = subscribeFunktionMap->begin(); it != subscribeFunktionMap->end(); ++it) {
int msg_id = esp_mqtt_client_unsubscribe(client, it->first.c_str());
ESP_LOGI(TAG, "topic %s unsubscribe successful, msg_id=%d", it->first.c_str(), msg_id);
}
}
subscribeFunktionMap->clear();
delete subscribeFunktionMap;
subscribeFunktionMap = NULL;
}
}

View File

@@ -0,0 +1,24 @@
#ifndef INTERFACE_MQTT_H
#define INTERFACE_MQTT_H
#include <string>
#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();
void MQTTdestroy_client();
bool MQTTPublish(std::string _key, std::string _content, int retained_flag = 1); // retained Flag as Standart
bool MQTTisConnected();
void MQTTregisterConnectFunction(std::string name, std::function<void()> func);
void MQTTunregisterConnectFunction(std::string name);
void MQTTregisterSubscribeFunction(std::string topic, std::function<bool(std::string, char*, int)> func);
void MQTTdestroySubscribeFunction();
void MQTTconnected();
#endif //INTERFACE_MQTT_H

View File

@@ -0,0 +1,242 @@
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include "esp_log.h"
#include "ClassLogFile.h"
#include "connect_wlan.h"
#include "server_mqtt.h"
#include "interface_mqtt.h"
#include "time_sntp.h"
static const char *TAG = "MQTT SERVER";
extern const char* libfive_git_version(void);
extern const char* libfive_git_revision(void);
extern const char* libfive_git_branch(void);
std::vector<NumberPost*>* NUMBERS;
bool HomeassistantDiscovery = false;
std::string meterType = "";
std::string valueUnit = "";
std::string timeUnit = "";
std::string rateUnit = "Unit/Minute";
float roundInterval; // Minutes
int keepAlive = 0; // Seconds
int retainFlag;
static std::string maintopic;
void mqttServer_setParameter(std::vector<NumberPost*>* _NUMBERS, int _keepAlive, float _roundInterval) {
NUMBERS = _NUMBERS;
keepAlive = _keepAlive;
roundInterval = _roundInterval;
}
void mqttServer_setMeterType(std::string _meterType, std::string _valueUnit, std::string _timeUnit,std::string _rateUnit) {
meterType = _meterType;
valueUnit = _valueUnit;
timeUnit = _timeUnit;
rateUnit = _rateUnit;
}
void sendHomeAssistantDiscoveryTopic(std::string group, std::string field,
std::string name, std::string icon, std::string unit, std::string deviceClass, std::string stateClass, std::string entityCategory) {
std::string version = std::string(libfive_git_version());
if (version == "") {
version = std::string(libfive_git_branch()) + " (" + std::string(libfive_git_revision()) + ")";
}
std::string topicFull;
std::string configTopic;
std::string payload;
std::string nl = "\n";
configTopic = field;
if (group != "" && (*NUMBERS).size() > 1) { // There is more than one meter, prepend the group so we can differentiate them
configTopic = group + "_" + field;
name = group + " " + name;
}
if (field == "problem") { // Special binary sensor which is based on error topic
topicFull = "homeassistant/binary_sensor/" + maintopic + "/" + configTopic + "/config";
}
else {
topicFull = "homeassistant/sensor/" + maintopic + "/" + configTopic + "/config";
}
/* See https://www.home-assistant.io/docs/mqtt/discovery/ */
payload = "{" + nl +
"\"~\": \"" + maintopic + "\"," + nl +
"\"unique_id\": \"" + maintopic + "-" + configTopic + "\"," + nl +
"\"object_id\": \"" + maintopic + "_" + configTopic + "\"," + nl + // This used to generate the Entity ID
"\"name\": \"" + name + "\"," + nl +
"\"icon\": \"mdi:" + icon + "\"," + nl;
if (group != "") {
if (field == "problem") { // Special binary sensor which is based on error topic
payload += "\"state_topic\": \"~/" + group + "/error\"," + nl;
payload += "\"value_template\": \"{{ 'OFF' if 'no error' in value else 'ON'}}\"," + nl;
}
else {
payload += "\"state_topic\": \"~/" + group + "/" + field + "\"," + nl;
}
}
else {
payload += "\"state_topic\": \"~/" + field + "\"," + nl;
}
if (unit != "") {
payload += "\"unit_of_meas\": \"" + unit + "\"," + nl;
}
if (deviceClass != "") {
payload += "\"device_class\": \"" + deviceClass + "\"," + nl;
}
if (stateClass != "") {
payload += "\"state_class\": \"" + stateClass + "\"," + nl;
}
if (entityCategory != "") {
payload += "\"entity_category\": \"" + entityCategory + "\"," + nl;
}
payload +=
"\"availability_topic\": \"~/" + std::string(LWT_TOPIC) + "\"," + nl +
"\"payload_available\": \"" + LWT_CONNECTED + "\"," + nl +
"\"payload_not_available\": \"" + LWT_DISCONNECTED + "\"," + nl;
payload +=
"\"device\": {" + nl +
"\"identifiers\": [\"" + maintopic + "\"]," + nl +
"\"name\": \"" + maintopic + "\"," + nl +
"\"model\": \"Meter Digitizer\"," + nl +
"\"manufacturer\": \"AI on the Edge Device\"," + nl +
"\"sw_version\": \"" + version + "\"," + nl +
"\"configuration_url\": \"http://" + *getIPAddress() + "\"" + nl +
"}" + nl +
"}" + nl;
MQTTPublish(topicFull, payload, true);
}
void MQTThomeassistantDiscovery() {
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
sendHomeAssistantDiscoveryTopic("", "uptime", "Uptime", "clock-time-eight-outline", "s", "", "", "diagnostic");
sendHomeAssistantDiscoveryTopic("", "MAC", "MAC Address", "network-outline", "", "", "", "diagnostic");
sendHomeAssistantDiscoveryTopic("", "hostname", "Hostname", "network-outline", "", "", "", "diagnostic");
sendHomeAssistantDiscoveryTopic("", "freeMem", "Free Memory", "memory", "B", "", "measurement", "diagnostic");
sendHomeAssistantDiscoveryTopic("", "wifiRSSI", "Wi-Fi RSSI", "wifi", "dBm", "signal_strength", "", "diagnostic");
sendHomeAssistantDiscoveryTopic("", "CPUtemp", "CPU Temperature", "thermometer", "°C", "temperature", "measurement", "diagnostic");
sendHomeAssistantDiscoveryTopic("", "interval", "Interval", "clock-time-eight-outline", "min", "" , "measurement", "diagnostic");
sendHomeAssistantDiscoveryTopic("", "IP", "IP", "network-outline", "", "", "", "diagnostic");
for (int i = 0; i < (*NUMBERS).size(); ++i) {
std::string group = (*NUMBERS)[i]->name;
// Group | Field | User Friendly Name | Icon | Unit | Device Class | State Class | Entity Category
sendHomeAssistantDiscoveryTopic(group, "value", "Value", "gauge", valueUnit, meterType, "total_increasing", "");
sendHomeAssistantDiscoveryTopic(group, "raw", "Raw Value", "raw", valueUnit, "", "total_increasing", "diagnostic");
sendHomeAssistantDiscoveryTopic(group, "error", "Error", "alert-circle-outline", "", "", "", "diagnostic");
/* Not announcing "rate" as it is better to use rate_per_time_unit resp. rate_per_digitalization_round */
// sendHomeAssistantDiscoveryTopic(group, "rate", "Rate (Unit/Minute)", "swap-vertical", "", "", "", ""); // Legacy, always Unit per Minute
sendHomeAssistantDiscoveryTopic(group, "rate_per_time_unit", "Rate (" + rateUnit + ")", "swap-vertical", rateUnit, "", "", "");
sendHomeAssistantDiscoveryTopic(group, "rate_per_digitalization_round", "Change since last digitalization round", "arrow-expand-vertical", valueUnit, "", "measurement", ""); // correctly the Unit is Uint/Interval!
/* The timestamp string misses the Timezone, see PREVALUE_TIME_FORMAT_OUTPUT!
We need to know the timezone and append it! Until we do this, we simply
do not set the device class to "timestamp" to avoid errors in Homeassistant! */
// sendHomeAssistantDiscoveryTopic(group, "timestamp", "Timestamp", "clock-time-eight-outline", "", "timestamp", "", "diagnostic");
sendHomeAssistantDiscoveryTopic(group, "timestamp", "Timestamp", "clock-time-eight-outline", "", "", "", "diagnostic");
sendHomeAssistantDiscoveryTopic(group, "json", "JSON", "code-json", "", "", "", "diagnostic");
sendHomeAssistantDiscoveryTopic(group, "problem", "Problem", "alert-outline", "", "", "", ""); // Special binary sensor which is based on error topic
}
}
void publishSystemData() {
char tmp_char[50];
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Publishing system MQTT topics...");
sprintf(tmp_char, "%ld", (long)getUpTime());
MQTTPublish(maintopic + "/" + "uptime", std::string(tmp_char), retainFlag);
sprintf(tmp_char, "%zu", esp_get_free_heap_size());
MQTTPublish(maintopic + "/" + "freeMem", std::string(tmp_char), retainFlag);
sprintf(tmp_char, "%d", get_WIFI_RSSI());
MQTTPublish(maintopic + "/" + "wifiRSSI", std::string(tmp_char), retainFlag);
sprintf(tmp_char, "%d", (int)temperatureRead());
MQTTPublish(maintopic + "/" + "CPUtemp", std::string(tmp_char), retainFlag);
}
void publishStaticData() {
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Publishing static MQTT topics...");
MQTTPublish(maintopic + "/" + "MAC", getMac(), retainFlag);
MQTTPublish(maintopic + "/" + "IP", *getIPAddress(), retainFlag);
MQTTPublish(maintopic + "/" + "hostname", hostname, retainFlag);
std::stringstream stream;
stream << std::fixed << std::setprecision(1) << roundInterval; // minutes
MQTTPublish(maintopic + "/" + "interval", stream.str(), retainFlag);
}
esp_err_t sendDiscovery_and_static_Topics(httpd_req_t *req) {
if (HomeassistantDiscovery) {
MQTThomeassistantDiscovery();
}
publishStaticData();
const char* resp_str = (const char*) req->user_ctx;
httpd_resp_send(req, resp_str, strlen(resp_str));
return ESP_OK;
}
void GotConnected(std::string maintopic, int retainFlag) {
if (HomeassistantDiscovery) {
MQTThomeassistantDiscovery();
}
publishStaticData();
publishSystemData();
}
void register_server_mqtt_uri(httpd_handle_t server) {
httpd_uri_t uri = { };
uri.method = HTTP_GET;
uri.uri = "/mqtt_publish_discovery";
uri.handler = sendDiscovery_and_static_Topics;
uri.user_ctx = (void*) "MQTT Discovery and Static Topics sent";
httpd_register_uri_handler(server, &uri);
}
std::string getTimeUnit(void) {
return timeUnit;
}
void SetHomeassistantDiscoveryEnabled(bool enabled) {
HomeassistantDiscovery = enabled;
}
void setMqtt_Server_Retain(int _retainFlag) {
retainFlag = _retainFlag;
}
void mqttServer_setMainTopic( std::string _maintopic) {
maintopic = _maintopic;
}

View File

@@ -0,0 +1,19 @@
#include "ClassFlowDefineTypes.h"
#define LWT_TOPIC "connection"
#define LWT_CONNECTED "connected"
#define LWT_DISCONNECTED "connection lost"
void SetHomeassistantDiscoveryEnabled(bool enabled);
void mqttServer_setParameter(std::vector<NumberPost*>* _NUMBERS, int interval, float roundInterval);
void mqttServer_setMeterType(std::string meterType, std::string valueUnit, std::string timeUnit,std::string rateUnit);
void setMqtt_Server_Retain(int SetRetainFlag);
void mqttServer_setMainTopic( std::string maintopic);
void register_server_mqtt_uri(httpd_handle_t server);
void publishSystemData();
std::string getTimeUnit(void);
void GotConnected(std::string maintopic, int SetRetainFlag);

View File

@@ -0,0 +1,7 @@
FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
idf_component_register(SRCS ${app_sources}
INCLUDE_DIRS "."
REQUIRES jomjol_image_proc jomjol_logfile esp_http_server esp32-camera jomjol_controlcamera jomjol_flowcontroll jomjol_helper)

View File

@@ -1,9 +1,15 @@
#include "CTfLiteClass.h"
#include "bitmap_image.hpp"
#include "ClassLogFile.h"
#include "Helper.h"
#include "esp_log.h"
#include <sys/stat.h>
// #define DEBUG_DETAIL_ON
static const char *TAG = "C TFLITE";
float CTfLiteClass::GetOutputValue(int nr)
{
TfLiteTensor* output2 = this->interpreter->output(0);
@@ -16,33 +22,46 @@ float CTfLiteClass::GetOutputValue(int nr)
}
int CTfLiteClass::GetClassFromImage(std::string _fn)
int CTfLiteClass::GetClassFromImageBasis(CImageBasis *rs)
{
// printf("Before Load image %s\n", _fn.c_str());
if (!LoadInputImage(_fn))
if (!LoadInputImageBasis(rs))
return -1000;
// printf("After Load image %s\n", _fn.c_str());
Invoke();
printf("After Invoke %s\n", _fn.c_str());
return GetOutClassification();
// return 0;
}
int CTfLiteClass::GetOutClassification()
int CTfLiteClass::GetOutClassification(int _von, int _bis)
{
TfLiteTensor* output2 = interpreter->output(0);
float zw_max = 0;
float zw_max;
float zw;
int zw_class = -1;
int zw_class;
if (output2 == NULL)
return -1;
int numeroutput = output2->dims->data[1];
for (int i = 0; i < numeroutput; ++i)
//ESP_LOGD(TAG, "number output neurons: %d", numeroutput);
if (_bis == -1)
_bis = numeroutput -1;
if (_von == -1)
_von = 0;
if (_bis >= numeroutput)
{
ESP_LOGD(TAG, "ANZAHL OUTPUT NEURONS passt nicht zu geforderter Classifizierung!");
return -1;
}
zw_max = output2->data.f[_von];
zw_class = _von;
for (int i = _von + 1; i <= _bis; ++i)
{
zw = output2->data.f[i];
if (zw > zw_max)
@@ -51,8 +70,7 @@ int CTfLiteClass::GetOutClassification()
zw_class = i;
}
}
// printf("Result Ziffer: %d\n", zw_class);
return zw_class;
return (zw_class - _von);
}
void CTfLiteClass::GetInputDimension(bool silent = false)
@@ -60,32 +78,45 @@ void CTfLiteClass::GetInputDimension(bool silent = false)
TfLiteTensor* input2 = this->interpreter->input(0);
int numdim = input2->dims->size;
if (!silent) printf("NumDimension: %d\n", numdim);
if (!silent) ESP_LOGD(TAG, "NumDimension: %d", numdim);
int sizeofdim;
for (int j = 0; j < numdim; ++j)
{
sizeofdim = input2->dims->data[j];
if (!silent) printf("SizeOfDimension %d: %d\n", j, sizeofdim);
if (!silent) ESP_LOGD(TAG, "SizeOfDimension %d: %d", j, sizeofdim);
if (j == 1) im_height = sizeofdim;
if (j == 2) im_width = sizeofdim;
if (j == 3) im_channel = sizeofdim;
}
}
int CTfLiteClass::ReadInputDimenstion(int _dim)
{
if (_dim == 0)
return im_width;
if (_dim == 1)
return im_height;
if (_dim == 2)
return im_channel;
void CTfLiteClass::GetOutPut()
return -1;
}
int CTfLiteClass::GetAnzOutPut(bool silent)
{
TfLiteTensor* output2 = this->interpreter->output(0);
int numdim = output2->dims->size;
printf("NumDimension: %d\n", numdim);
if (!silent) ESP_LOGD(TAG, "NumDimension: %d", numdim);
int sizeofdim;
for (int j = 0; j < numdim; ++j)
{
sizeofdim = output2->dims->data[j];
printf("SizeOfDimension %d: %d\n", j, sizeofdim);
if (!silent) ESP_LOGD(TAG, "SizeOfDimension %d: %d", j, sizeofdim);
}
@@ -96,25 +127,27 @@ void CTfLiteClass::GetOutPut()
for (int i = 0; i < numeroutput; ++i)
{
fo = output2->data.f[i];
printf("Result %d: %f\n", i, fo);
if (!silent) ESP_LOGD(TAG, "Result %d: %f", i, fo);
}
return numeroutput;
}
void CTfLiteClass::Invoke()
{
interpreter->Invoke();
// printf("Invoke Done.\n");
if (interpreter != nullptr)
interpreter->Invoke();
}
bool CTfLiteClass::LoadInputImage(std::string _fn)
{
bitmap_image image(_fn);
unsigned int w = image.width();
unsigned int h = image.height();
unsigned char red, green, blue;
// printf("Image: %s size: %d x %d\n", _fn.c_str(), w, h);
bool CTfLiteClass::LoadInputImageBasis(CImageBasis *rs)
{
std::string zw = "ClassFlowCNNGeneral::doNeuralNetwork after LoadInputResizeImage: ";
unsigned int w = rs->width;
unsigned int h = rs->height;
unsigned char red, green, blue;
// ESP_LOGD(TAG, "Image: %s size: %d x %d\n", _fn.c_str(), w, h);
input_i = 0;
float* input_data_ptr = (interpreter->input(0))->data.f;
@@ -122,44 +155,50 @@ bool CTfLiteClass::LoadInputImage(std::string _fn)
for (int y = 0; y < h; ++y)
for (int x = 0; x < w; ++x)
{
red = image.red_channel(x, y);
green = image.green_channel(x, y);
blue = image.blue_channel(x, y);
red = rs->GetPixelColor(x, y, 0);
green = rs->GetPixelColor(x, y, 1);
blue = rs->GetPixelColor(x, y, 2);
*(input_data_ptr) = (float) red;
input_data_ptr++;
*(input_data_ptr) = (float) green;
input_data_ptr++;
*(input_data_ptr) = (float) blue;
input_data_ptr++;
// printf("BMP: %f %f %f\n", (float) red, (float) green, (float) blue);
}
#ifdef DEBUG_DETAIL_ON
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Nach dem Laden in input");
#endif
return true;
}
void CTfLiteClass::MakeAllocate()
{
static tflite::ops::micro::AllOpsResolver resolver;
static tflite::AllOpsResolver resolver;
// ESP_LOGD(TAG, "%s", LogFile.getESPHeapInfo().c_str());
this->interpreter = new tflite::MicroInterpreter(this->model, resolver, this->tensor_arena, this->kTensorArenaSize, this->error_reporter);
// ESP_LOGD(TAG, "%s", LogFile.getESPHeapInfo().c_str());
TfLiteStatus allocate_status = this->interpreter->AllocateTensors();
if (allocate_status != kTfLiteOk) {
TF_LITE_REPORT_ERROR(error_reporter, "AllocateTensors() failed");
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "AllocateTensors() failed");
this->GetInputDimension();
return;
}
// printf("Allocate Done.\n");
// ESP_LOGD(TAG, "Allocate Done");
}
void CTfLiteClass::GetInputTensorSize(){
#ifdef DEBUG_DETAIL_ON
float *zw = this->input;
int test = sizeof(zw);
printf("Input Tensor Dimension: %d\n", test);
printf("Input Tensor Dimension: %d\n", test);
ESP_LOGD(TAG, "Input Tensor Dimension: %d", test);
#endif
}
long CTfLiteClass::GetFileSize(std::string filename)
@@ -174,31 +213,39 @@ unsigned char* CTfLiteClass::ReadFileToCharArray(std::string _fn)
{
long size;
size = this->GetFileSize(_fn);
size = GetFileSize(_fn);
if (size == -1)
{
printf("\nFile existiert nicht.\n");
return NULL;
ESP_LOGD(TAG, "File doesn't exist");
return NULL;
}
unsigned char *result = (unsigned char*) malloc(size);
int anz = 1;
while (!result && (anz < 6)) // maximal 5x versuchen (= 5s)
{
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "Speicher ist voll - Versuche es erneut: %d", anz);
#endif
result = (unsigned char*) malloc(size);
anz++;
}
if(result != NULL) {
// printf("\nSpeicher ist reserviert\n");
FILE* f = fopen(_fn.c_str(), "rb"); // vorher nur "r"
if(result != NULL) {
FILE* f = OpenFileAndWait(_fn.c_str(), "rb"); // vorher nur "r"
fread(result, 1, size, f);
fclose(f);
}else {
printf("\nKein freier Speicher vorhanden.\n");
}else {
ESP_LOGD(TAG, "No free memory available");
}
return result;
}
void CTfLiteClass::LoadModel(std::string _fn){
bool CTfLiteClass::LoadModel(std::string _fn){
#ifdef SUPRESS_TFLITE_ERRORS
this->error_reporter = new tflite::OwnMicroErrorReporter;
@@ -206,15 +253,16 @@ void CTfLiteClass::LoadModel(std::string _fn){
this->error_reporter = new tflite::MicroErrorReporter;
#endif
unsigned char *rd;
rd = this->ReadFileToCharArray(_fn.c_str());
// printf("loadedfile: %d", (int) rd);
modelload = ReadFileToCharArray(_fn.c_str());
this->model = tflite::GetModel(rd);
free(rd);
if (modelload == NULL)
return false;
model = tflite::GetModel(modelload);
// free(rd);
TFLITE_MINIMAL_CHECK(model != nullptr);
// printf("tfile Loaded.\n");
return true;
}
@@ -225,13 +273,17 @@ CTfLiteClass::CTfLiteClass()
this->interpreter = nullptr;
this->input = nullptr;
this->output = nullptr;
this->kTensorArenaSize = 600 * 1024;
this->kTensorArenaSize = 800 * 1024; /// laut testfile: 108000 - bisher 600;; 2021-09-11: 200 * 1024
this->tensor_arena = new uint8_t[kTensorArenaSize];
}
CTfLiteClass::~CTfLiteClass()
{
delete this->tensor_arena;
delete this->interpreter;
delete this->error_reporter;
if (modelload)
free(modelload);
}
@@ -241,6 +293,6 @@ namespace tflite {
return 0;
}
} // namespace tflite
}

View File

@@ -5,15 +5,16 @@
exit(1); \
}
#include "tensorflow/lite/micro/kernels/all_ops_resolver.h"
#include "tensorflow/lite/micro/all_ops_resolver.h"
#include "tensorflow/lite/micro/micro_error_reporter.h"
#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/version.h"
#include "tensorflow/lite/micro/kernels/micro_ops.h"
#include "esp_err.h"
#include "esp_log.h"
#include "CImageBasis.h"
#define SUPRESS_TFLITE_ERRORS // use, to avoid error messages from TFLITE
@@ -39,11 +40,14 @@ class CTfLiteClass
const tflite::Model* model;
tflite::MicroInterpreter* interpreter;
TfLiteTensor* output = nullptr;
static tflite::ops::micro::AllOpsResolver *resolver;
static tflite::AllOpsResolver resolver;
int kTensorArenaSize;
uint8_t *tensor_arena;
unsigned char *modelload = NULL;
float* input;
int input_i;
int im_height, im_width, im_channel;
@@ -54,16 +58,19 @@ class CTfLiteClass
public:
CTfLiteClass();
~CTfLiteClass();
void LoadModel(std::string _fn);
bool LoadModel(std::string _fn);
void MakeAllocate();
void GetInputTensorSize();
bool LoadInputImage(std::string _fn);
bool LoadInputImageBasis(CImageBasis *rs);
void Invoke();
void GetOutPut();
int GetOutClassification();
int GetClassFromImage(std::string _fn);
int GetAnzOutPut(bool silent = true);
int GetOutClassification(int _von = -1, int _bis = -1);
int GetClassFromImageBasis(CImageBasis *rs);
std::string GetStatusFlow();
float GetOutputValue(int nr);
void GetInputDimension(bool silent);
int ReadInputDimenstion(int _dim);
};

View File

@@ -0,0 +1,896 @@
#include "server_tflite.h"
#include <string>
#include <vector>
#include "string.h"
#include "esp_log.h"
#include <iomanip>
#include <sstream>
#include "defines.h"
#include "Helper.h"
#include "esp_camera.h"
#include "time_sntp.h"
#include "ClassControllCamera.h"
#include "ClassFlowControll.h"
#include "ClassLogFile.h"
#include "server_GPIO.h"
#include "server_file.h"
#include "connect_wlan.h"
#define DEBUG_DETAIL_ON
ClassFlowControll tfliteflow;
TaskHandle_t xHandleblink_task_doFlow = NULL;
TaskHandle_t xHandletask_autodoFlow = NULL;
bool flowisrunning = false;
long auto_intervall = 0;
bool auto_isrunning = false;
int countRounds = 0;
static const char *TAG = "TFLITE";
int getCountFlowRounds() {
return countRounds;
}
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;
}
void KillTFliteTasks()
{
#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, "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
}
}
void doInit(void)
{
#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
}
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
return true;
}
void blink_task_doFlow(void *pvParameter)
{
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "blink_task_doFlow");
#endif
if (!flowisrunning)
{
flowisrunning = true;
doflow();
flowisrunning = false;
}
vTaskDelete(NULL); //Delete this task if it exits from the loop above
xHandleblink_task_doFlow = NULL;
}
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
const char* resp_str = "Init started<br>";
httpd_resp_send(req, resp_str, strlen(resp_str));
doInit();
resp_str = "Init done<br>";
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);
#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
ESP_LOGD(TAG, "handler_doFlow uri: %s", req->uri);
if (flowisrunning)
{
const char* resp_str = "doFlow is already running and cannot be started again";
httpd_resp_send(req, resp_str, strlen(resp_str));
return 2;
}
else
{
xTaskCreate(&blink_task_doFlow, "blink_doFlow", configMINIMAL_STACK_SIZE * 64, NULL, tskIDLE_PRIORITY+1, &xHandleblink_task_doFlow);
}
const char* resp_str = "doFlow started - takes about 60 seconds";
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);
#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
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)
{
httpd_resp_send(req, zw.c_str(), zw.length());
}
else
{
httpd_resp_send(req, NULL, 0);
}
#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
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)
{
// 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;
}
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)
{
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];
}
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();
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);
#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
ESP_LOGD(TAG, "handler_editflow uri: %s", req->uri);
char _query[200];
char _valuechar[30];
string _task;
if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK)
{
if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK)
{
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "task is found: %s", _valuechar);
#endif
_task = string(_valuechar);
}
}
if (_task.compare("namenumbers") == 0)
{
ESP_LOGI(TAG, "Get NUMBER list");
return get_numbers_file_handler(req);
}
if (_task.compare("data") == 0)
{
ESP_LOGI(TAG, "Get data list");
return get_data_file_handler(req);
}
if (_task.compare("tflite") == 0)
{
ESP_LOGD(TAG, "Get tflite list");
return get_tflite_file_handler(req);
}
if (_task.compare("copy") == 0)
{
string in, out, zw;
httpd_query_key_value(_query, "in", _valuechar, 30);
in = string(_valuechar);
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
in = "/sdcard" + in;
out = "/sdcard" + out;
CopyFile(in, out);
zw = "Copy Done";
httpd_resp_sendstr_chunk(req, zw.c_str());
}
if (_task.compare("cutref") == 0)
{
string in, out, zw;
int x, y, dx, dy;
bool enhance = false;
httpd_query_key_value(_query, "in", _valuechar, 30);
in = string(_valuechar);
httpd_query_key_value(_query, "out", _valuechar, 30);
out = string(_valuechar);
httpd_query_key_value(_query, "x", _valuechar, 30);
zw = string(_valuechar);
x = stoi(zw);
httpd_query_key_value(_query, "y", _valuechar, 30);
zw = string(_valuechar);
y = stoi(zw);
httpd_query_key_value(_query, "dx", _valuechar, 30);
zw = string(_valuechar);
dx = stoi(zw);
httpd_query_key_value(_query, "dy", _valuechar, 30);
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
if (httpd_query_key_value(_query, "enhance", _valuechar, 10) == ESP_OK)
{
zw = string(_valuechar);
if (zw.compare("true") == 0)
{
enhance = true;
}
}
in = "/sdcard" + in;
out = "/sdcard" + out;
string out2 = out.substr(0, out.length() - 4) + "_org.jpg";
CAlignAndCutImage *caic = new CAlignAndCutImage(in);
caic->CutAndSave(out2, x, y, dx, dy);
delete caic;
CImageBasis *cim = new CImageBasis(out2);
if (enhance)
{
cim->Contrast(90);
}
cim->SaveToFile(out);
delete cim;
zw = "CutImage Done";
httpd_resp_sendstr_chunk(req, zw.c_str());
}
if (_task.compare("test_take") == 0)
{
std::string _host = "";
std::string _bri = "";
std::string _con = "";
std::string _sat = "";
std::string _int = "";
int bri = -100;
int sat = -100;
int con = -100;
int intens = -100;
if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK) {
_host = std::string(_valuechar);
}
if (httpd_query_key_value(_query, "int", _valuechar, 30) == ESP_OK) {
_int = std::string(_valuechar);
intens = stoi(_int);
}
if (httpd_query_key_value(_query, "bri", _valuechar, 30) == ESP_OK) {
_bri = std::string(_valuechar);
bri = stoi(_bri);
}
if (httpd_query_key_value(_query, "con", _valuechar, 30) == ESP_OK) {
_con = std::string(_valuechar);
con = stoi(_con);
}
if (httpd_query_key_value(_query, "sat", _valuechar, 30) == ESP_OK) {
_sat = std::string(_valuechar);
sat = stoi(_sat);
}
// ESP_LOGD(TAG, "Parameter host: %s", _host.c_str());
// string zwzw = "Do " + _task + " start\n"; ESP_LOGD(TAG, zwzw.c_str());
Camera.SetBrightnessContrastSaturation(bri, con, sat);
Camera.SetLEDIntensity(intens);
ESP_LOGD(TAG, "test_take - vor MakeImage");
std::string zw = tfliteflow.doSingleStep("[MakeImage]", _host);
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_sendstr_chunk(req, zw.c_str());
}
if (_task.compare("test_align") == 0)
{
std::string _host = "";
if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK) {
_host = std::string(_valuechar);
}
// ESP_LOGD(TAG, "Parameter host: %s", _host.c_str());
// string zwzw = "Do " + _task + " start\n"; ESP_LOGD(TAG, zwzw.c_str());
std::string zw = tfliteflow.doSingleStep("[Alignment]", _host);
httpd_resp_sendstr_chunk(req, zw.c_str());
}
/* 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
return ESP_OK;
};
esp_err_t handler_statusflow(httpd_req_t *req)
{
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_prevalue - Start");
#endif
const char* resp_str;
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "handler_prevalue: %s", req->uri);
#endif
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);
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_prevalue - Start");
#endif
return ESP_OK;
};
esp_err_t handler_cputemp(httpd_req_t *req)
{
#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());
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);
#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
const char* resp_str;
char rssi[20];
sprintf(rssi, "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);
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_rssi - End");
#endif
return ESP_OK;
};
esp_err_t handler_prevalue(httpd_req_t *req)
{
#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
char _query[100];
char _size[10] = "";
char _numbers[50] = "default";
if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
{
#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
}
httpd_query_key_value(_query, "numbers", _numbers, 50);
}
if (strlen(_size) == 0)
{
zw = tfliteflow.GetPrevalue(std::string(_numbers));
}
else
{
zw = "SetPrevalue to " + tfliteflow.UpdatePrevalue(_size, _numbers, true);
}
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);
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_prevalue - End");
#endif
return ESP_OK;
};
void task_autodoFlow(void *pvParameter)
{
int64_t fr_start, fr_delta_ms;
if (esp_reset_reason() == ESP_RST_PANIC) {
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);
vTaskDelay(60*5000 / portTICK_RATE_MS); // Wait 5 minutes to give time to do an OTA or fetch the log
}
ESP_LOGD(TAG, "task_autodoFlow: start");
doInit();
gpio_handler_init();
auto_isrunning = tfliteflow.isAutoStart(auto_intervall);
if (isSetupModusActive()) {
auto_isrunning = false;
std::string zw_time = gettimestring(LOGFILE_TIME_FORMAT);
tfliteflow.doFlowMakeImageOnly(zw_time);
}
while (auto_isrunning)
{
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "----------------------------------------------------------------"); // Clear separation between runs
std::string _zw = "task_autodoFlow - next round - Round #" + std::to_string(++countRounds);
LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw);
fr_start = esp_timer_get_time();
if (flowisrunning)
{
#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
flowisrunning = true;
doflow();
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "Remove older log files");
#endif
LogFile.RemoveOldLogFile();
LogFile.RemoveOldDataLog();
}
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "task_autodoFlow - round #" + std::to_string(countRounds) + " done");
//CPU Temp
float cputmp = temperatureRead();
std::stringstream stream;
stream << std::fixed << std::setprecision(1) << cputmp;
string zwtemp = "CPU Temperature: " + stream.str();
LogFile.WriteToFile(ESP_LOG_INFO, TAG, zwtemp);
fr_delta_ms = (esp_timer_get_time() - fr_start) / 1000;
if (auto_intervall > fr_delta_ms)
{
const TickType_t xDelay = (auto_intervall - fr_delta_ms) / portTICK_PERIOD_MS;
ESP_LOGD(TAG, "Autoflow: sleep for: %ldms", (long) xDelay);
vTaskDelay( xDelay );
}
}
vTaskDelete(NULL); //Delete this task if it exits from the loop above
xHandletask_autodoFlow = NULL;
ESP_LOGD(TAG, "task_autodoFlow: end");
}
void TFliteDoAutoStart()
{
BaseType_t xReturned;
int _i = configMINIMAL_STACK_SIZE;
ESP_LOGD(TAG, "task_autodoFlow configMINIMAL_STACK_SIZE: %d", _i);
ESP_LOGD(TAG, "getESPHeapInfo: %s", getESPHeapInfo().c_str());
xReturned = xTaskCreate(&task_autodoFlow, "task_autodoFlow", configMINIMAL_STACK_SIZE * 35, NULL, tskIDLE_PRIORITY+1, &xHandletask_autodoFlow);
if( xReturned != pdPASS )
{
//Memory: 64 --> 48 --> 35 --> 25
ESP_LOGD(TAG, "ERROR task_autodoFlow konnte nicht erzeugt werden!");
}
ESP_LOGD(TAG, "getESPHeapInfo: %s", getESPHeapInfo().c_str());
}
std::string GetMQTTMainTopic()
{
return tfliteflow.GetMQTTMainTopic();
}
void register_server_tflite_uri(httpd_handle_t server)
{
ESP_LOGI(TAG, "server_part_camera - Registering URI handlers");
httpd_uri_t camuri = { };
camuri.method = HTTP_GET;
camuri.uri = "/doinit";
camuri.handler = handler_init;
camuri.user_ctx = (void*) "Light On";
httpd_register_uri_handler(server, &camuri);
// Legacy API => New: "/setPreValue"
camuri.uri = "/setPreValue.html";
camuri.handler = handler_prevalue;
camuri.user_ctx = (void*) "Prevalue";
httpd_register_uri_handler(server, &camuri);
camuri.uri = "/setPreValue";
camuri.handler = handler_prevalue;
camuri.user_ctx = (void*) "Prevalue";
httpd_register_uri_handler(server, &camuri);
camuri.uri = "/doflow";
camuri.handler = handler_doflow;
camuri.user_ctx = (void*) "Light Off";
httpd_register_uri_handler(server, &camuri);
camuri.uri = "/statusflow.html";
camuri.handler = handler_statusflow;
camuri.user_ctx = (void*) "Light Off";
httpd_register_uri_handler(server, &camuri);
camuri.uri = "/statusflow";
camuri.handler = handler_statusflow;
camuri.user_ctx = (void*) "Light Off";
httpd_register_uri_handler(server, &camuri);
// Legacy API => New: "/cpu_temperature"
camuri.uri = "/cputemp.html";
camuri.handler = handler_cputemp;
camuri.user_ctx = (void*) "Light Off";
httpd_register_uri_handler(server, &camuri);
camuri.uri = "/cpu_temperature";
camuri.handler = handler_cputemp;
camuri.user_ctx = (void*) "Light Off";
httpd_register_uri_handler(server, &camuri);
// Legacy API => New: "/rssi"
camuri.uri = "/rssi.html";
camuri.handler = handler_rssi;
camuri.user_ctx = (void*) "Light Off";
httpd_register_uri_handler(server, &camuri);
camuri.uri = "/rssi";
camuri.handler = handler_rssi;
camuri.user_ctx = (void*) "Light Off";
httpd_register_uri_handler(server, &camuri);
camuri.uri = "/editflow";
camuri.handler = handler_editflow;
camuri.user_ctx = (void*) "EditFlow";
httpd_register_uri_handler(server, &camuri);
// Legacy API => New: "/value"
camuri.uri = "/value.html";
camuri.handler = handler_wasserzaehler;
camuri.user_ctx = (void*) "Value";
httpd_register_uri_handler(server, &camuri);
camuri.uri = "/value";
camuri.handler = handler_wasserzaehler;
camuri.user_ctx = (void*) "Value";
httpd_register_uri_handler(server, &camuri);
// Legacy API => New: "/value"
camuri.uri = "/wasserzaehler.html";
camuri.handler = handler_wasserzaehler;
camuri.user_ctx = (void*) "Wasserzaehler";
httpd_register_uri_handler(server, &camuri);
camuri.uri = "/json";
camuri.handler = handler_json;
camuri.user_ctx = (void*) "JSON";
httpd_register_uri_handler(server, &camuri);
}

View File

@@ -0,0 +1,26 @@
#include <esp_log.h>
#include <string>
#include <esp_http_server.h>
#include "CImageBasis.h"
#include "ClassFlowControll.h"
//#include "ClassControllCamera.h"
void register_server_tflite_uri(httpd_handle_t server);
void KillTFliteTasks();
void TFliteDoAutoStart();
bool isSetupModusActive();
std::string GetMQTTMainTopic();
int getCountFlowRounds();
esp_err_t GetJPG(std::string _filename, httpd_req_t *req);
esp_err_t GetRawJPG(httpd_req_t *req);
extern ClassFlowControll tfliteflow;

View File

@@ -0,0 +1,7 @@
FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
idf_component_register(SRCS ${app_sources}
INCLUDE_DIRS "."
REQUIRES tflite-lib jomjol_logfile)

View File

@@ -0,0 +1,204 @@
#include "time_sntp.h"
#include <string>
#include <time.h>
#include <sys/time.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_attr.h"
#include "esp_sleep.h"
#include "esp_sntp.h"
#include "ClassLogFile.h"
static const char *TAG = "SNTP";
time_t bootTime;
static bool obtain_time(void);
static void initialize_sntp(void);
static void logNtpStatus(sntp_sync_status_t status);
void time_sync_notification_cb(struct timeval *tv)
{
ESP_LOGI(TAG, "Notification of a time synchronization event");
}
std::string ConvertTimeToString(time_t _time, const char * frm)
{
struct tm timeinfo;
char strftime_buf[64];
localtime_r(&_time, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), frm, &timeinfo);
std::string result(strftime_buf);
return result;
}
std::string gettimestring(const char * frm)
{
time_t now;
struct tm timeinfo;
time(&now);
char strftime_buf[64];
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), frm, &timeinfo);
std::string result(strftime_buf);
return result;
}
bool setup_time()
{
time_t now;
struct tm timeinfo;
time(&now);
localtime_r(&now, &timeinfo);
char strftime_buf[64];
bool success = true;
// Is time set? If not, tm_year will be (1970 - 1900).
if (!getTimeIsSet()) {
ESP_LOGI(TAG, "Time is not set yet. Getting time over NTP.");
initialize_sntp();
if (!obtain_time()) {
success = false;
}
// update 'now' variable with current time
time(&now);
setTimeZone("CET-1CEST,M3.5.0,M10.5.0/3");
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%Y-%m-%d_%H:%M:%S", &timeinfo);
ESP_LOGI(TAG, "The current date/time in Berlin is: %s", strftime_buf);
}
else {
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%Y-%m-%d_%H:%M:%S", &timeinfo);
ESP_LOGI(TAG, "Time is already set (%s)", strftime_buf);
}
return success;
}
void setTimeZone(std::string _tzstring)
{
setenv("TZ", _tzstring.c_str(), 1);
tzset();
_tzstring = "Time zone set to " + _tzstring;
LogFile.WriteToFile(ESP_LOG_INFO, TAG, _tzstring);
}
static bool obtain_time(void)
{
time_t now = 0;
struct tm timeinfo = {};
int retry = 0;
const int retry_count = 10;
bool success = true;
time(&now);
localtime_r(&now, &timeinfo);
ESP_LOGI(TAG, "Waiting until we get a time from the NTP server...");
while (true) {
retry++;
if (retry == retry_count) {
ESP_LOGW(TAG, "NTP time fetching seems to take longer, will check again on next round!"); // The NTP client will automatically retry periodically!
success = false;
break;
}
sntp_sync_status_t status = sntp_get_sync_status();
logNtpStatus(status);
if (status == SNTP_SYNC_STATUS_COMPLETED) {
ESP_LOGI(TAG, "Time is synced with NTP Server");
break;
}
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
time(&now);
localtime_r(&now, &timeinfo);
return success;
}
void logNtpStatus(sntp_sync_status_t status) {
if (status == SNTP_SYNC_STATUS_COMPLETED) {
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "NTP Status OK");
}
else if (status == SNTP_SYNC_STATUS_IN_PROGRESS) {
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "NTP Status: In Progress");
}
else { // SNTP_SYNC_STATUS_RESET
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "NTP Status: Reset");
}
}
void reset_servername(std::string _servername)
{
ESP_LOGD(TAG, "Set SNTP-Server: %s", _servername.c_str());
sntp_stop();
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, _servername.c_str());
sntp_init();
obtain_time();
std::string zw = gettimestring("%Y%m%d-%H%M%S");
ESP_LOGD(TAG, "Time ist %s", zw.c_str());
}
static void initialize_sntp(void)
{
ESP_LOGI(TAG, "Initializing SNTP");
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, "pool.ntp.org");
// sntp_set_time_sync_notification_cb(time_sync_notification_cb);
sntp_init();
}
void setBootTime()
{
time(&bootTime);
}
time_t getUpTime()
{
time_t now;
time(&now);
return now - bootTime;
}
bool getTimeIsSet(void) {
time_t now;
struct tm timeinfo;
time(&now);
localtime_r(&now, &timeinfo);
char strftime_buf[64];
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%Y-%m-%d_%H:%M:%S", &timeinfo);
ESP_LOGD(TAG, "The current date/time in Berlin is: %s", strftime_buf);
// Is time set? If not, tm_year will be (1970 - 1900).
if ((timeinfo.tm_year < (2022 - 1900))) {
return false;
}
else {
return true;
}
}
void restartNtpClient(void) {
sntp_restart();
obtain_time();
}

Some files were not shown because too many files have changed in this diff Show More