mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-07 12:06:58 +03:00
Compare commits
69 Commits
v15.2.4
...
add-websoc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59ccd601fc | ||
|
|
becbfc463f | ||
|
|
a5d2086159 | ||
|
|
716dcb5a84 | ||
|
|
ba7d6b3621 | ||
|
|
d4a492463b | ||
|
|
46589288e7 | ||
|
|
17994494c9 | ||
|
|
c581d64a26 | ||
|
|
70c2b88f8a | ||
|
|
13d01a6c96 | ||
|
|
5a00bdd7f6 | ||
|
|
db7ffb30c4 | ||
|
|
9a07f271ff | ||
|
|
6a45ab7693 | ||
|
|
9fc876853b | ||
|
|
43aae5a3cd | ||
|
|
a5c66eb014 | ||
|
|
6c86317d52 | ||
|
|
fc719da0ae | ||
|
|
9b1a83c8b4 | ||
|
|
6defcf8d4c | ||
|
|
a636ce3679 | ||
|
|
a20fec1094 | ||
|
|
929796c87f | ||
|
|
e40ceb54ce | ||
|
|
eebdd7c6eb | ||
|
|
2a7f3b33a3 | ||
|
|
262d83ee6f | ||
|
|
de92c29245 | ||
|
|
19158c998f | ||
|
|
17ffd28c05 | ||
|
|
9ca02e0a7f | ||
|
|
7488d7bf23 | ||
|
|
e7bfba4b01 | ||
|
|
63ac38a52d | ||
|
|
e2cf8337d4 | ||
|
|
e995d6c498 | ||
|
|
0e3a50d0c1 | ||
|
|
df12deae00 | ||
|
|
b6bfeea936 | ||
|
|
f79e03faa2 | ||
|
|
de1dcc4d06 | ||
|
|
33bfef0af4 | ||
|
|
727b871fc5 | ||
|
|
db36fe2522 | ||
|
|
9ffaf6e3f8 | ||
|
|
fa09680711 | ||
|
|
e2b66aa73a | ||
|
|
c4b990ada0 | ||
|
|
267782d083 | ||
|
|
e4a6fd33fe | ||
|
|
5db20d3687 | ||
|
|
58185a0569 | ||
|
|
d93c5daf14 | ||
|
|
6ff83445ac | ||
|
|
d944e8676b | ||
|
|
a8d7b29507 | ||
|
|
ab0fc72257 | ||
|
|
933215c116 | ||
|
|
e81a7eebe8 | ||
|
|
863856ca5d | ||
|
|
eefc41d6ff | ||
|
|
d1807a1b3d | ||
|
|
dfc45772b7 | ||
|
|
4dd41c486f | ||
|
|
ff81fcbd7f | ||
|
|
5e5d2e2f72 | ||
|
|
512d7f95b4 |
@@ -1,8 +1,8 @@
|
|||||||
## [15.2.3] - 2023-05-01
|
## [15.2.4] - 2023-05-02
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
|
|
||||||
For a full list of changes see [Full list of changes](https://github.com/jomjol/AI-on-the-edge-device/compare/v15.2.1...v15.2.2)
|
For a full list of changes see [Full list of changes](https://github.com/jomjol/AI-on-the-edge-device/compare/v15.2.1...v15.2.4)
|
||||||
|
|
||||||
#### Changed
|
#### Changed
|
||||||
- Updated PlatformIO to `6.2.0`
|
- Updated PlatformIO to `6.2.0`
|
||||||
@@ -985,7 +985,7 @@ External Illumination
|
|||||||
- Initial Version
|
- Initial Version
|
||||||
|
|
||||||
|
|
||||||
[15.2.3]: https://github.com/jomjol/AI-on-the-edge-device/compare/v15.2.1...v15.2.3
|
[15.2.4]: https://github.com/jomjol/AI-on-the-edge-device/compare/v15.2.1...v15.2.4
|
||||||
[15.2.1]: https://github.com/jomjol/AI-on-the-edge-device/compare/v15.2.0...v15.2.1
|
[15.2.1]: https://github.com/jomjol/AI-on-the-edge-device/compare/v15.2.0...v15.2.1
|
||||||
[15.2.0]: https://github.com/jomjol/AI-on-the-edge-device/compare/v15.1.1...v15.2.0
|
[15.2.0]: https://github.com/jomjol/AI-on-the-edge-device/compare/v15.1.1...v15.2.0
|
||||||
[15.1.1]: https://github.com/jomjol/AI-on-the-edge-device/compare/v15.1.0...v15.1.1
|
[15.1.1]: https://github.com/jomjol/AI-on-the-edge-device/compare/v15.1.0...v15.1.1
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
|
|||||||
|
|
||||||
idf_component_register(SRCS ${app_sources}
|
idf_component_register(SRCS ${app_sources}
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
REQUIRES esp_timer esp_wifi jomjol_tfliteclass jomjol_helper jomjol_controlcamera jomjol_mqtt jomjol_influxdb jomjol_fileserver_ota jomjol_image_proc jomjol_wlan)
|
REQUIRES esp_timer esp_wifi jomjol_tfliteclass jomjol_helper jomjol_controlcamera jomjol_mqtt jomjol_influxdb jomjol_fileserver_ota jomjol_image_proc jomjol_wlan jomjol_helper)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,23 @@ ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNTy
|
|||||||
imagesRetention = 5;
|
imagesRetention = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, std::string _cnn_name) : ClassFlowImage(NULL, TAG)
|
||||||
|
{
|
||||||
|
string cnnmodelfile = "";
|
||||||
|
modelxsize = 1;
|
||||||
|
modelysize = 1;
|
||||||
|
CNNGoodThreshold = 0.0;
|
||||||
|
ListFlowControll = NULL;
|
||||||
|
previousElement = NULL;
|
||||||
|
SaveAllFiles = false;
|
||||||
|
disabled = false;
|
||||||
|
isLogImageSelect = false;
|
||||||
|
CNNType = AutoDetect;
|
||||||
|
flowpostalignment = _flowalign;
|
||||||
|
imagesRetention = 5;
|
||||||
|
cnn_name = _cnn_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution, int prev, float _before_narrow_Analog, float analogDigitalTransitionStart)
|
string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution, int prev, float _before_narrow_Analog, float analogDigitalTransitionStart)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ protected:
|
|||||||
t_CNNType CNNType;
|
t_CNNType CNNType;
|
||||||
std::vector<general*> GENERAL;
|
std::vector<general*> GENERAL;
|
||||||
float CNNGoodThreshold;
|
float CNNGoodThreshold;
|
||||||
|
std::string cnn_name = "ClassFlowCNNGeneral";
|
||||||
|
|
||||||
//moved to define.h
|
//moved to define.h
|
||||||
//float Analog_error = 3.0;
|
//float Analog_error = 3.0;
|
||||||
@@ -56,6 +57,7 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNType _cnntype = AutoDetect);
|
ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNType _cnntype = AutoDetect);
|
||||||
|
ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, std::string _cnn_name);
|
||||||
|
|
||||||
bool ReadParameter(FILE* pfile, string& aktparamgraph);
|
bool ReadParameter(FILE* pfile, string& aktparamgraph);
|
||||||
bool doFlow(string time);
|
bool doFlow(string time);
|
||||||
@@ -81,7 +83,7 @@ public:
|
|||||||
|
|
||||||
t_CNNType getCNNType(){return CNNType;};
|
t_CNNType getCNNType(){return CNNType;};
|
||||||
|
|
||||||
string name(){return "ClassFlowCNNGeneral";};
|
string name(){return "ClassFlowCNNGeneral " + cnn_name;};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ extern "C" {
|
|||||||
#include "server_mqtt.h"
|
#include "server_mqtt.h"
|
||||||
#endif //ENABLE_MQTT
|
#endif //ENABLE_MQTT
|
||||||
|
|
||||||
|
#include "websocket.h"
|
||||||
#include "server_help.h"
|
#include "server_help.h"
|
||||||
#include "MainFlowControl.h"
|
#include "MainFlowControl.h"
|
||||||
#include "../../include/defines.h"
|
#include "../../include/defines.h"
|
||||||
@@ -85,8 +86,10 @@ std::string ClassFlowControll::TranslateAktstatus(std::string _input)
|
|||||||
return ("Take Image");
|
return ("Take Image");
|
||||||
if (_input.compare("ClassFlowAlignment") == 0)
|
if (_input.compare("ClassFlowAlignment") == 0)
|
||||||
return ("Aligning");
|
return ("Aligning");
|
||||||
if (_input.compare("ClassFlowCNNGeneral") == 0)
|
if (_input.compare("ClassFlowCNNGeneral Digital") == 0)
|
||||||
return ("Digitalization of ROIs");
|
return ("Digitalization of Digital ROIs");
|
||||||
|
if (_input.compare("ClassFlowCNNGeneral Analog") == 0)
|
||||||
|
return ("Digitalization of Analog ROIs");
|
||||||
#ifdef ENABLE_MQTT
|
#ifdef ENABLE_MQTT
|
||||||
if (_input.compare("ClassFlowMQTT") == 0)
|
if (_input.compare("ClassFlowMQTT") == 0)
|
||||||
return ("Sending MQTT");
|
return ("Sending MQTT");
|
||||||
@@ -100,7 +103,7 @@ std::string ClassFlowControll::TranslateAktstatus(std::string _input)
|
|||||||
if (_input.compare("ClassFlowPostProcessing") == 0)
|
if (_input.compare("ClassFlowPostProcessing") == 0)
|
||||||
return ("Post-Processing");
|
return ("Post-Processing");
|
||||||
|
|
||||||
return "Unkown Status";
|
return "Unkown Status: " + _input +"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -187,6 +190,8 @@ void ClassFlowControll::SetInitialParameter(void)
|
|||||||
aktRunNr = 0;
|
aktRunNr = 0;
|
||||||
aktstatus = "Flow task not yet created";
|
aktstatus = "Flow task not yet created";
|
||||||
aktstatusWithTime = aktstatus;
|
aktstatusWithTime = aktstatus;
|
||||||
|
|
||||||
|
schedule_websocket_message("{\"state\": \"" + aktstatus + "\"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -220,12 +225,12 @@ ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
|
|||||||
}
|
}
|
||||||
if (toUpper(_type).compare("[ANALOG]") == 0)
|
if (toUpper(_type).compare("[ANALOG]") == 0)
|
||||||
{
|
{
|
||||||
cfc = new ClassFlowCNNGeneral(flowalignment);
|
cfc = new ClassFlowCNNGeneral(flowalignment, std::string("Analog"));
|
||||||
flowanalog = (ClassFlowCNNGeneral*) cfc;
|
flowanalog = (ClassFlowCNNGeneral*) cfc;
|
||||||
}
|
}
|
||||||
if (toUpper(_type).compare(0, 7, "[DIGITS") == 0)
|
if (toUpper(_type).compare(0, 7, "[DIGITS") == 0)
|
||||||
{
|
{
|
||||||
cfc = new ClassFlowCNNGeneral(flowalignment);
|
cfc = new ClassFlowCNNGeneral(flowalignment, std::string("Digit"));
|
||||||
flowdigit = (ClassFlowCNNGeneral*) cfc;
|
flowdigit = (ClassFlowCNNGeneral*) cfc;
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_MQTT
|
#ifdef ENABLE_MQTT
|
||||||
@@ -269,6 +274,8 @@ void ClassFlowControll::InitFlow(std::string config)
|
|||||||
aktstatus = "Initialization";
|
aktstatus = "Initialization";
|
||||||
aktstatusWithTime = aktstatus;
|
aktstatusWithTime = aktstatus;
|
||||||
|
|
||||||
|
schedule_websocket_message("{\"state\": \"" + aktstatus + "\"}");
|
||||||
|
|
||||||
//#ifdef ENABLE_MQTT
|
//#ifdef ENABLE_MQTT
|
||||||
//MQTTPublish(mqttServer_getMainTopic() + "/" + "status", "Initialization", 1, false); // Right now, not possible -> MQTT Service is going to be started later
|
//MQTTPublish(mqttServer_getMainTopic() + "/" + "status", "Initialization", 1, false); // Right now, not possible -> MQTT Service is going to be started later
|
||||||
//#endif //ENABLE_MQTT
|
//#endif //ENABLE_MQTT
|
||||||
@@ -331,6 +338,8 @@ void ClassFlowControll::setActStatus(std::string _aktstatus)
|
|||||||
{
|
{
|
||||||
aktstatus = _aktstatus;
|
aktstatus = _aktstatus;
|
||||||
aktstatusWithTime = aktstatus;
|
aktstatusWithTime = aktstatus;
|
||||||
|
|
||||||
|
schedule_websocket_message("{\"state\": \"" + aktstatus + "\"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -347,6 +356,8 @@ void ClassFlowControll::doFlowTakeImageOnly(string time)
|
|||||||
#ifdef ENABLE_MQTT
|
#ifdef ENABLE_MQTT
|
||||||
MQTTPublish(mqttServer_getMainTopic() + "/" + "status", aktstatus, 1, false);
|
MQTTPublish(mqttServer_getMainTopic() + "/" + "status", aktstatus, 1, false);
|
||||||
#endif //ENABLE_MQTT
|
#endif //ENABLE_MQTT
|
||||||
|
|
||||||
|
schedule_websocket_message("{\"state\": \"" + aktstatus + "\"}");
|
||||||
|
|
||||||
FlowControll[i]->doFlow(time);
|
FlowControll[i]->doFlow(time);
|
||||||
}
|
}
|
||||||
@@ -379,6 +390,7 @@ bool ClassFlowControll::doFlow(string time)
|
|||||||
aktstatus = TranslateAktstatus(FlowControll[i]->name());
|
aktstatus = TranslateAktstatus(FlowControll[i]->name());
|
||||||
aktstatusWithTime = aktstatus + " (" + zw_time + ")";
|
aktstatusWithTime = aktstatus + " (" + zw_time + ")";
|
||||||
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Status: " + aktstatusWithTime);
|
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Status: " + aktstatusWithTime);
|
||||||
|
schedule_websocket_message("{\"state\": \"" + aktstatus + "\"}");
|
||||||
#ifdef ENABLE_MQTT
|
#ifdef ENABLE_MQTT
|
||||||
MQTTPublish(mqttServer_getMainTopic() + "/" + "status", aktstatus, qos, false);
|
MQTTPublish(mqttServer_getMainTopic() + "/" + "status", aktstatus, qos, false);
|
||||||
#endif //ENABLE_MQTT
|
#endif //ENABLE_MQTT
|
||||||
@@ -413,6 +425,7 @@ bool ClassFlowControll::doFlow(string time)
|
|||||||
aktstatus = "Flow finished";
|
aktstatus = "Flow finished";
|
||||||
aktstatusWithTime = aktstatus + " (" + zw_time + ")";
|
aktstatusWithTime = aktstatus + " (" + zw_time + ")";
|
||||||
//LogFile.WriteToFile(ESP_LOG_INFO, TAG, aktstatusWithTime);
|
//LogFile.WriteToFile(ESP_LOG_INFO, TAG, aktstatusWithTime);
|
||||||
|
schedule_websocket_message("{\"state\": \"" + aktstatus + "\"}");
|
||||||
#ifdef ENABLE_MQTT
|
#ifdef ENABLE_MQTT
|
||||||
MQTTPublish(mqttServer_getMainTopic() + "/" + "status", aktstatus, qos, false);
|
MQTTPublish(mqttServer_getMainTopic() + "/" + "status", aktstatus, qos, false);
|
||||||
#endif //ENABLE_MQTT
|
#endif //ENABLE_MQTT
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "ClassLogFile.h"
|
#include "ClassLogFile.h"
|
||||||
|
|
||||||
#include "time_sntp.h"
|
#include "time_sntp.h"
|
||||||
|
#include "websocket.h"
|
||||||
#include "interface_mqtt.h"
|
#include "interface_mqtt.h"
|
||||||
#include "ClassFlowPostProcessing.h"
|
#include "ClassFlowPostProcessing.h"
|
||||||
#include "ClassFlowControll.h"
|
#include "ClassFlowControll.h"
|
||||||
@@ -249,11 +250,15 @@ bool ClassFlowMQTT::doFlow(string zwtime)
|
|||||||
namenumber = maintopic + "/" + namenumber + "/";
|
namenumber = maintopic + "/" + namenumber + "/";
|
||||||
|
|
||||||
|
|
||||||
if (result.length() > 0)
|
if (result.length() > 0) {
|
||||||
success |= MQTTPublish(namenumber + "value", result, qos, SetRetainFlag);
|
success |= MQTTPublish(namenumber + "value", result, qos, SetRetainFlag);
|
||||||
|
schedule_websocket_message("{\"value\": \"" + result + "\", \"number\": \"" + (*NUMBERS)[i]->name + "\"}");
|
||||||
|
}
|
||||||
|
|
||||||
if (resulterror.length() > 0)
|
if (resulterror.length() > 0) {
|
||||||
success |= MQTTPublish(namenumber + "error", resulterror, qos, SetRetainFlag);
|
success |= MQTTPublish(namenumber + "error", resulterror, qos, SetRetainFlag);
|
||||||
|
schedule_websocket_message("{\"error\": \"" + resulterror + "\", \"number\": \"" + (*NUMBERS)[i]->name + "\"}");
|
||||||
|
}
|
||||||
|
|
||||||
if (resultrate.length() > 0) {
|
if (resultrate.length() > 0) {
|
||||||
success |= MQTTPublish(namenumber + "rate", resultrate, qos, SetRetainFlag);
|
success |= MQTTPublish(namenumber + "rate", resultrate, qos, SetRetainFlag);
|
||||||
@@ -273,8 +278,10 @@ bool ClassFlowMQTT::doFlow(string zwtime)
|
|||||||
success |= MQTTPublish(namenumber + "rate_per_digitalization_round", resultchangabs, qos, SetRetainFlag);
|
success |= MQTTPublish(namenumber + "rate_per_digitalization_round", resultchangabs, qos, SetRetainFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultraw.length() > 0)
|
if (resultraw.length() > 0) {
|
||||||
success |= MQTTPublish(namenumber + "raw", resultraw, qos, SetRetainFlag);
|
success |= MQTTPublish(namenumber + "raw", resultraw, qos, SetRetainFlag);
|
||||||
|
schedule_websocket_message("{\"raw\": \"" + resultraw + "\", \"number\": \"" + (*NUMBERS)[i]->name + "\"}");
|
||||||
|
}
|
||||||
|
|
||||||
if (resulttimestamp.length() > 0)
|
if (resulttimestamp.length() > 0)
|
||||||
success |= MQTTPublish(namenumber + "timestamp", resulttimestamp, qos, SetRetainFlag);
|
success |= MQTTPublish(namenumber + "timestamp", resulttimestamp, qos, SetRetainFlag);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "websocket.h"
|
||||||
#include "time_sntp.h"
|
#include "time_sntp.h"
|
||||||
|
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
@@ -882,6 +883,8 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
|
|||||||
NUMBERS[j]->ReturnValue = "";
|
NUMBERS[j]->ReturnValue = "";
|
||||||
NUMBERS[j]->lastvalue = imagetime;
|
NUMBERS[j]->lastvalue = imagetime;
|
||||||
|
|
||||||
|
schedule_websocket_message("{\"status\": \"" + NUMBERS[j]->ErrorMessageText + "\", \"number\": \"" + NUMBERS[j]->name + "\"}");
|
||||||
|
|
||||||
string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
|
string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
|
||||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw);
|
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw);
|
||||||
WriteDataLog(j);
|
WriteDataLog(j);
|
||||||
@@ -915,6 +918,8 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
|
|||||||
NUMBERS[j]->ReturnRateValue = "";
|
NUMBERS[j]->ReturnRateValue = "";
|
||||||
NUMBERS[j]->lastvalue = imagetime;
|
NUMBERS[j]->lastvalue = imagetime;
|
||||||
|
|
||||||
|
schedule_websocket_message("{\"status\": \"" + NUMBERS[j]->ErrorMessageText + "\", \"number\": \"" + NUMBERS[j]->name + "\"}");
|
||||||
|
|
||||||
string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
|
string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
|
||||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw);
|
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw);
|
||||||
WriteDataLog(j);
|
WriteDataLog(j);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "Helper.h"
|
#include "Helper.h"
|
||||||
#include "statusled.h"
|
#include "statusled.h"
|
||||||
|
|
||||||
|
#include "websocket.h"
|
||||||
#include "esp_camera.h"
|
#include "esp_camera.h"
|
||||||
#include "time_sntp.h"
|
#include "time_sntp.h"
|
||||||
#include "ClassControllCamera.h"
|
#include "ClassControllCamera.h"
|
||||||
@@ -985,6 +986,10 @@ void task_autodoFlow(void *pvParameter)
|
|||||||
{
|
{
|
||||||
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "----------------------------------------------------------------"); // Clear separation between runs
|
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "----------------------------------------------------------------"); // Clear separation between runs
|
||||||
std::string _zw = "Round #" + std::to_string(++countRounds) + " started";
|
std::string _zw = "Round #" + std::to_string(++countRounds) + " started";
|
||||||
|
|
||||||
|
schedule_websocket_message("{\"round\": \"" + std::to_string(countRounds) + "\"}");
|
||||||
|
schedule_websocket_message("{\"uptime\": \"" + std::to_string(getUpTime()) + "\"}");
|
||||||
|
|
||||||
time_t roundStartTime = getUpTime();
|
time_t roundStartTime = getUpTime();
|
||||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw);
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw);
|
||||||
fr_start = esp_timer_get_time();
|
fr_start = esp_timer_get_time();
|
||||||
@@ -1012,12 +1017,15 @@ void task_autodoFlow(void *pvParameter)
|
|||||||
// Round finished -> Logfile
|
// Round finished -> Logfile
|
||||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Round #" + std::to_string(countRounds) +
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Round #" + std::to_string(countRounds) +
|
||||||
" completed (" + std::to_string(getUpTime() - roundStartTime) + " seconds)");
|
" completed (" + std::to_string(getUpTime() - roundStartTime) + " seconds)");
|
||||||
|
schedule_websocket_message("{\"round duration\": \"" + std::to_string(getUpTime() - roundStartTime) + "\"}");
|
||||||
|
|
||||||
// CPU Temp -> Logfile
|
// CPU Temp -> Logfile
|
||||||
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "CPU Temperature: " + std::to_string((int)temperatureRead()) + "°C");
|
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "CPU Temperature: " + std::to_string((int)temperatureRead()) + "°C");
|
||||||
|
schedule_websocket_message("{\"cpu temperature\": \"" + std::to_string(temperatureRead()) + "\"}");
|
||||||
|
|
||||||
// WIFI Signal Strength (RSSI) -> Logfile
|
// WIFI Signal Strength (RSSI) -> Logfile
|
||||||
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "WIFI Signal (RSSI): " + std::to_string(get_WIFI_RSSI()) + "dBm");
|
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "WIFI Signal (RSSI): " + std::to_string(get_WIFI_RSSI()) + "dBm");
|
||||||
|
schedule_websocket_message("{\"wifi rssi\": \"" + std::to_string(get_WIFI_RSSI()) + "\"}");
|
||||||
|
|
||||||
// Check if time is synchronized (if NTP is configured)
|
// Check if time is synchronized (if NTP is configured)
|
||||||
if (getUseNtp() && !getTimeIsSet()) {
|
if (getUseNtp() && !getTimeIsSet()) {
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
|
|||||||
|
|
||||||
idf_component_register(SRCS ${app_sources}
|
idf_component_register(SRCS ${app_sources}
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
REQUIRES esp_timer tflite-lib jomjol_logfile fatfs sdmmc)
|
REQUIRES esp_timer tflite-lib jomjol_logfile fatfs sdmmc esp_http_server)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -147,12 +147,6 @@ bool SDCardCheckFolderFilePresence()
|
|||||||
bRetval = false;
|
bRetval = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if file exists: gethost.js */
|
|
||||||
if (stat("/sdcard/html/gethost.js", &sb) != 0) {
|
|
||||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/gethost.js not found");
|
|
||||||
bRetval = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check if file exists: version.txt */
|
/* check if file exists: version.txt */
|
||||||
if (stat("/sdcard/html/version.txt", &sb) != 0) {
|
if (stat("/sdcard/html/version.txt", &sb) != 0) {
|
||||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/version.txt not found");
|
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/version.txt not found");
|
||||||
@@ -163,4 +157,4 @@ bool SDCardCheckFolderFilePresence()
|
|||||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Folder/file presence check successful");
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Folder/file presence check successful");
|
||||||
|
|
||||||
return bRetval;
|
return bRetval;
|
||||||
}
|
}
|
||||||
|
|||||||
129
code/components/jomjol_helper/websocket.cpp
Normal file
129
code/components/jomjol_helper/websocket.cpp
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
#include "esp_log.h"
|
||||||
|
#include <esp_http_server.h>
|
||||||
|
|
||||||
|
#include "../../include/defines.h"
|
||||||
|
|
||||||
|
#include "ClassLogFile.h"
|
||||||
|
#include "freertos/ringbuf.h"
|
||||||
|
#include "psram.h"
|
||||||
|
|
||||||
|
#include "websocket.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX_MESSAGE_LENGTH 100
|
||||||
|
|
||||||
|
static const char *TAG = "WEBSOCKET";
|
||||||
|
|
||||||
|
static httpd_handle_t server = NULL;
|
||||||
|
static httpd_handle_t websocket_handle = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Structure holding server handle and message
|
||||||
|
* in order to use out of request send */
|
||||||
|
struct async_resp_arg {
|
||||||
|
httpd_handle_t hd;
|
||||||
|
char message[MAX_MESSAGE_LENGTH];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* async send function, which we put into the httpd work queue
|
||||||
|
*/
|
||||||
|
static void websocket_send_pending_message(void *arg) {
|
||||||
|
esp_err_t ret;
|
||||||
|
struct async_resp_arg *resp_arg = (struct async_resp_arg *)arg;
|
||||||
|
|
||||||
|
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Sending Websocket message: '" + std::string(resp_arg->message) + "'");
|
||||||
|
|
||||||
|
httpd_ws_frame_t ws_pkt;
|
||||||
|
memset(&ws_pkt, 0, sizeof(httpd_ws_frame_t));
|
||||||
|
ws_pkt.payload = (uint8_t *)resp_arg->message;
|
||||||
|
ws_pkt.len = strlen(resp_arg->message);
|
||||||
|
ws_pkt.type = HTTPD_WS_TYPE_TEXT;
|
||||||
|
|
||||||
|
static size_t max_clients = CONFIG_LWIP_MAX_LISTENING_TCP;
|
||||||
|
size_t fds = max_clients;
|
||||||
|
int client_fds[max_clients];
|
||||||
|
|
||||||
|
ret = httpd_get_client_list(server, &fds, client_fds);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to get Websocket client ist: " + std::to_string(ret) + "!");
|
||||||
|
free_psram_heap("websocket msg", resp_arg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Send it to all websocket clients */
|
||||||
|
for (int i = 0; i < fds; i++) {
|
||||||
|
int client_info = httpd_ws_get_fd_info(server, client_fds[i]);
|
||||||
|
if (client_info == HTTPD_WS_CLIENT_WEBSOCKET) {
|
||||||
|
httpd_ws_send_frame_async(websocket_handle, client_fds[i], &ws_pkt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free_psram_heap("websocket msg", resp_arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
esp_err_t schedule_websocket_message(std::string message) {
|
||||||
|
// return 0;
|
||||||
|
esp_err_t ret;
|
||||||
|
|
||||||
|
if (websocket_handle == NULL) { // No websocket connecten open
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Scheduled websocket message: '" + message + "'");
|
||||||
|
|
||||||
|
struct async_resp_arg *resp_arg = (struct async_resp_arg *)malloc_psram_heap("websocket msg",
|
||||||
|
sizeof(struct async_resp_arg), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||||
|
if (resp_arg == NULL) {
|
||||||
|
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to malloc memory for scheduled websocket message!");
|
||||||
|
return ESP_ERR_NO_MEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
strncpy(resp_arg->message, message.c_str(), MAX_MESSAGE_LENGTH);
|
||||||
|
|
||||||
|
ret = httpd_queue_work(websocket_handle, websocket_send_pending_message, resp_arg);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Websocket Scheduling failed: " + std::to_string(ret) + "!");
|
||||||
|
free_psram_heap("websocket msg", resp_arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static esp_err_t ws_handler(httpd_req_t *req) {
|
||||||
|
if (req->method == HTTP_GET) {
|
||||||
|
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Handshake done, the new websocket connection was opened");
|
||||||
|
websocket_handle = req->handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static const httpd_uri_t ws_uri = {
|
||||||
|
.uri = "/ws",
|
||||||
|
.method = HTTP_GET,
|
||||||
|
.handler = ws_handler,
|
||||||
|
.user_ctx = NULL,
|
||||||
|
.is_websocket = true
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
esp_err_t start_websocket_server(httpd_handle_t _server) {
|
||||||
|
esp_err_t ret;
|
||||||
|
|
||||||
|
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Init Websocket Server");
|
||||||
|
|
||||||
|
server = _server;
|
||||||
|
|
||||||
|
// Registering the ws handler
|
||||||
|
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Registering URI handler");
|
||||||
|
ret = httpd_register_uri_handler(server, &ws_uri);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Registering Websocket URI handler failed: " + std::to_string(ret));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
10
code/components/jomjol_helper/websocket.h
Normal file
10
code/components/jomjol_helper/websocket.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef WEBSOCKET_H
|
||||||
|
#define WEBSOCKET_H
|
||||||
|
|
||||||
|
#include <esp_http_server.h>
|
||||||
|
|
||||||
|
esp_err_t start_websocket_server(httpd_handle_t server);
|
||||||
|
|
||||||
|
esp_err_t schedule_websocket_message(std::string message);
|
||||||
|
|
||||||
|
#endif // WEBSOCKET_H
|
||||||
@@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
|
|||||||
|
|
||||||
idf_component_register(SRCS ${app_sources}
|
idf_component_register(SRCS ${app_sources}
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
REQUIRES tflite-lib jomjol_logfile jomjol_configfile)
|
REQUIRES tflite-lib jomjol_logfile jomjol_configfile jomjol_helper)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "esp_sntp.h"
|
#include "esp_sntp.h"
|
||||||
#include "../../include/defines.h"
|
#include "../../include/defines.h"
|
||||||
|
|
||||||
|
#include "websocket.h"
|
||||||
#include "ClassLogFile.h"
|
#include "ClassLogFile.h"
|
||||||
|
|
||||||
#include "configFile.h"
|
#include "configFile.h"
|
||||||
@@ -68,6 +69,8 @@ void time_sync_notification_cb(struct timeval *tv)
|
|||||||
}
|
}
|
||||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Time is synced with NTP Server " +
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Time is synced with NTP Server " +
|
||||||
getServerName() + ": " + getCurrentTimeString("%Y-%m-%d %H:%M:%S"));
|
getServerName() + ": " + getCurrentTimeString("%Y-%m-%d %H:%M:%S"));
|
||||||
|
|
||||||
|
schedule_websocket_message("{\"ntp\": \"synchronized\"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#include "MainFlowControl.h"
|
#include "MainFlowControl.h"
|
||||||
#include "server_file.h"
|
#include "server_file.h"
|
||||||
#include "server_ota.h"
|
#include "server_ota.h"
|
||||||
|
#include "websocket.h"
|
||||||
#include "time_sntp.h"
|
#include "time_sntp.h"
|
||||||
#include "configFile.h"
|
#include "configFile.h"
|
||||||
//#include "ClassControllCamera.h"
|
//#include "ClassControllCamera.h"
|
||||||
@@ -491,7 +492,8 @@ extern "C" void app_main(void)
|
|||||||
// ********************************************
|
// ********************************************
|
||||||
ESP_LOGD(TAG, "starting servers");
|
ESP_LOGD(TAG, "starting servers");
|
||||||
|
|
||||||
server = start_webserver();
|
server = start_webserver();
|
||||||
|
start_websocket_server(server);
|
||||||
register_server_camera_uri(server);
|
register_server_camera_uri(server);
|
||||||
register_server_main_flow_task_uri(server);
|
register_server_main_flow_task_uri(server);
|
||||||
register_server_file_uri(server, "/sdcard");
|
register_server_file_uri(server, "/sdcard");
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ httpd_handle_t start_webserver(void)
|
|||||||
config.server_port = 80;
|
config.server_port = 80;
|
||||||
config.ctrl_port = 32768;
|
config.ctrl_port = 32768;
|
||||||
config.max_open_sockets = 5; //20210921 --> previously 7
|
config.max_open_sockets = 5; //20210921 --> previously 7
|
||||||
config.max_uri_handlers = 39; // previously 24, 20220511: 35, 20221220: 37, 2023-01-02:38
|
config.max_uri_handlers = 45; // previously 24, 20220511: 35, 20221220: 37, 2023-01-02:38, 20230430 (adding websocket): 45
|
||||||
config.max_resp_headers = 8;
|
config.max_resp_headers = 8;
|
||||||
config.backlog_conn = 5;
|
config.backlog_conn = 5;
|
||||||
config.lru_purge_enable = true; // this cuts old connections if new ones are needed.
|
config.lru_purge_enable = true; // this cuts old connections if new ones are needed.
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ CONFIG_ESP_INT_WDT_TIMEOUT_MS=300
|
|||||||
|
|
||||||
CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024
|
CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024
|
||||||
CONFIG_HTTPD_PURGE_BUF_LEN=16
|
CONFIG_HTTPD_PURGE_BUF_LEN=16
|
||||||
|
CONFIG_HTTPD_WS_SUPPORT=y
|
||||||
|
|
||||||
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=16
|
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=16
|
||||||
CONFIG_ESP32_WIFI_CACHE_TX_BUFFER_NUM=16
|
CONFIG_ESP32_WIFI_CACHE_TX_BUFFER_NUM=16
|
||||||
|
|||||||
90
sd-card/html/websocket.html
Normal file
90
sd-card/html/websocket.html
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
#rx {
|
||||||
|
font-family: 'Courier New', Courier, monospace;
|
||||||
|
font-size: small;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script type="text/javascript" src="common.js?v=$COMMIT_HASH"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="state">State: Please wait...</div>
|
||||||
|
<hr>
|
||||||
|
<div id="img">Image: Please wait...</div>
|
||||||
|
<hr>
|
||||||
|
<div id="rx">Events:<br></div>
|
||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var gateway = getDomainname().replace("http://", "ws://") + "/ws";
|
||||||
|
var websocket;
|
||||||
|
|
||||||
|
window.addEventListener('load', onLoad);
|
||||||
|
|
||||||
|
function initWebSocket() {
|
||||||
|
console.log('Trying to open a WebSocket connection...');
|
||||||
|
addToLog('Trying to open a WebSocket connection...');
|
||||||
|
|
||||||
|
websocket = new WebSocket(gateway);
|
||||||
|
websocket.onopen = onOpen;
|
||||||
|
websocket.onclose = onClose;
|
||||||
|
websocket.onmessage = onMessage; // <-- add this line
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function onOpen(event) {
|
||||||
|
console.log('Connection opened');
|
||||||
|
addToLog('Connection opened');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function onClose(event) {
|
||||||
|
console.log('Connection closed');
|
||||||
|
addToLog('Connection closed');
|
||||||
|
setTimeout(initWebSocket, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function onMessage(event) {
|
||||||
|
console.log(event);
|
||||||
|
addToLog(event.data);
|
||||||
|
|
||||||
|
data = JSON.parse(event.data)
|
||||||
|
|
||||||
|
// State
|
||||||
|
if (data.hasOwnProperty("state")) {
|
||||||
|
processStateChange(data.state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function onLoad(event) {
|
||||||
|
initWebSocket();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function addToLog(msg) {
|
||||||
|
document.getElementById('rx').innerHTML += "[" + new Date().toLocaleTimeString() + "] " + msg + "<br>\n";
|
||||||
|
window.scrollBy(0,document.body.scrollHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
function processStateChange(state) {
|
||||||
|
document.getElementById('state').innerHTML = "State: <b>" + data.state + "</b>";
|
||||||
|
|
||||||
|
// TODO only reload image for those steps where it changed...
|
||||||
|
var d = new Date();
|
||||||
|
var timestamp = d.getTime();
|
||||||
|
document.getElementById('img').innerHTML = 'Image: <br><img src=' + getDomainname() + '/img_tmp/alg_roi.jpg?timestamp='+ timestamp +'" height=200px;"></img>';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function updateImage() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user