mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-14 07:26:53 +03:00
add websocket support
This commit is contained in:
@@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
|
||||
|
||||
idf_component_register(SRCS ${app_sources}
|
||||
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)
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ extern "C" {
|
||||
#include "server_mqtt.h"
|
||||
#endif //ENABLE_MQTT
|
||||
|
||||
#include "websocket.h"
|
||||
#include "server_help.h"
|
||||
#include "MainFlowControl.h"
|
||||
#include "../../include/defines.h"
|
||||
@@ -187,6 +188,8 @@ void ClassFlowControll::SetInitialParameter(void)
|
||||
aktRunNr = 0;
|
||||
aktstatus = "Flow task not yet created";
|
||||
aktstatusWithTime = aktstatus;
|
||||
|
||||
schedule_websocket_message("{\"state\": \"" + aktstatus + "\"}");
|
||||
}
|
||||
|
||||
|
||||
@@ -264,6 +267,8 @@ void ClassFlowControll::InitFlow(std::string config)
|
||||
aktstatus = "Initialization";
|
||||
aktstatusWithTime = aktstatus;
|
||||
|
||||
schedule_websocket_message("{\"state\": \"" + aktstatus + "\"}");
|
||||
|
||||
//#ifdef ENABLE_MQTT
|
||||
//MQTTPublish(mqttServer_getMainTopic() + "/" + "status", "Initialization", 1, false); // Right now, not possible -> MQTT Service is going to be started later
|
||||
//#endif //ENABLE_MQTT
|
||||
@@ -326,6 +331,8 @@ void ClassFlowControll::setActStatus(std::string _aktstatus)
|
||||
{
|
||||
aktstatus = _aktstatus;
|
||||
aktstatusWithTime = aktstatus;
|
||||
|
||||
schedule_websocket_message("{\"state\": \"" + aktstatus + "\"}");
|
||||
}
|
||||
|
||||
|
||||
@@ -342,6 +349,8 @@ void ClassFlowControll::doFlowTakeImageOnly(string time)
|
||||
#ifdef ENABLE_MQTT
|
||||
MQTTPublish(mqttServer_getMainTopic() + "/" + "status", aktstatus, 1, false);
|
||||
#endif //ENABLE_MQTT
|
||||
|
||||
schedule_websocket_message("{\"state\": \"" + aktstatus + "\"}");
|
||||
|
||||
FlowControll[i]->doFlow(time);
|
||||
}
|
||||
@@ -374,6 +383,7 @@ bool ClassFlowControll::doFlow(string time)
|
||||
aktstatus = TranslateAktstatus(FlowControll[i]->name());
|
||||
aktstatusWithTime = aktstatus + " (" + zw_time + ")";
|
||||
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Status: " + aktstatusWithTime);
|
||||
schedule_websocket_message("{\"state\": \"" + aktstatus + "\"}");
|
||||
#ifdef ENABLE_MQTT
|
||||
MQTTPublish(mqttServer_getMainTopic() + "/" + "status", aktstatus, qos, false);
|
||||
#endif //ENABLE_MQTT
|
||||
@@ -408,6 +418,7 @@ bool ClassFlowControll::doFlow(string time)
|
||||
aktstatus = "Flow finished";
|
||||
aktstatusWithTime = aktstatus + " (" + zw_time + ")";
|
||||
//LogFile.WriteToFile(ESP_LOG_INFO, TAG, aktstatusWithTime);
|
||||
schedule_websocket_message("{\"state\": \"" + aktstatus + "\"}");
|
||||
#ifdef ENABLE_MQTT
|
||||
MQTTPublish(mqttServer_getMainTopic() + "/" + "status", aktstatus, qos, false);
|
||||
#endif //ENABLE_MQTT
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "ClassLogFile.h"
|
||||
|
||||
#include "time_sntp.h"
|
||||
#include "websocket.h"
|
||||
#include "interface_mqtt.h"
|
||||
#include "ClassFlowPostProcessing.h"
|
||||
#include "ClassFlowControll.h"
|
||||
@@ -249,11 +250,15 @@ bool ClassFlowMQTT::doFlow(string zwtime)
|
||||
namenumber = maintopic + "/" + namenumber + "/";
|
||||
|
||||
|
||||
if (result.length() > 0)
|
||||
if (result.length() > 0) {
|
||||
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);
|
||||
schedule_websocket_message("{\"error\": \"" + resulterror + "\", \"number\": \"" + (*NUMBERS)[i]->name + "\"}");
|
||||
}
|
||||
|
||||
if (resultrate.length() > 0) {
|
||||
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);
|
||||
}
|
||||
|
||||
if (resultraw.length() > 0)
|
||||
if (resultraw.length() > 0) {
|
||||
success |= MQTTPublish(namenumber + "raw", resultraw, qos, SetRetainFlag);
|
||||
schedule_websocket_message("{\"raw\": \"" + resultraw + "\", \"number\": \"" + (*NUMBERS)[i]->name + "\"}");
|
||||
}
|
||||
|
||||
if (resulttimestamp.length() > 0)
|
||||
success |= MQTTPublish(namenumber + "timestamp", resulttimestamp, qos, SetRetainFlag);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "websocket.h"
|
||||
#include "time_sntp.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
@@ -882,6 +883,8 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
|
||||
NUMBERS[j]->ReturnValue = "";
|
||||
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;
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw);
|
||||
WriteDataLog(j);
|
||||
@@ -915,6 +918,8 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
|
||||
NUMBERS[j]->ReturnRateValue = "";
|
||||
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;
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw);
|
||||
WriteDataLog(j);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "Helper.h"
|
||||
#include "statusled.h"
|
||||
|
||||
#include "websocket.h"
|
||||
#include "esp_camera.h"
|
||||
#include "time_sntp.h"
|
||||
#include "ClassControllCamera.h"
|
||||
@@ -968,6 +969,10 @@ void task_autodoFlow(void *pvParameter)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "----------------------------------------------------------------"); // Clear separation between runs
|
||||
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();
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw);
|
||||
fr_start = esp_timer_get_time();
|
||||
@@ -995,12 +1000,15 @@ void task_autodoFlow(void *pvParameter)
|
||||
// Round finished -> Logfile
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Round #" + std::to_string(countRounds) +
|
||||
" completed (" + std::to_string(getUpTime() - roundStartTime) + " seconds)");
|
||||
schedule_websocket_message("{\"round duration\": \"" + std::to_string(getUpTime() - roundStartTime) + "\"}");
|
||||
|
||||
// CPU Temp -> Logfile
|
||||
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
|
||||
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)
|
||||
if (getUseNtp() && !getTimeIsSet()) {
|
||||
|
||||
Reference in New Issue
Block a user