diff --git a/code/components/jomjol_controlGPIO/Color.cpp b/code/components/jomjol_controlGPIO/Color.cpp index b2beb9acf..631abd44e 100644 --- a/code/components/jomjol_controlGPIO/Color.cpp +++ b/code/components/jomjol_controlGPIO/Color.cpp @@ -89,15 +89,6 @@ Rgb& Rgb::blend( Rgb in ) { 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 ) ); diff --git a/code/components/jomjol_controlGPIO/Color.h b/code/components/jomjol_controlGPIO/Color.h index 1923cf0b2..24ce3828c 100644 --- a/code/components/jomjol_controlGPIO/Color.h +++ b/code/components/jomjol_controlGPIO/Color.h @@ -19,13 +19,21 @@ union Rgb { bool operator==( Rgb in ) const { return in.value == value; } Rgb& blend( Rgb in ); void swap( Rgb& o ) { value = o.value; } + constexpr Rgb(const Rgb& other) : r(other.r), g(other.g), b(other.b), a(other.a) { } void linearize() { r = channelGamma(r); g = channelGamma(g); b = channelGamma(b); } - uint8_t IRAM_ATTR getGrb( int idx ); + uint8_t IRAM_ATTR getGrb( int idx ) { + switch ( idx ) { + case 0: return g; + case 1: return r; + case 2: return b; + } + __builtin_unreachable(); + } void stretchChannels( uint8_t maxR, uint8_t maxG, uint8_t maxB ) { r = stretch( r, maxR ); @@ -54,6 +62,7 @@ union Rgb { } }; + union Hsv { struct __attribute__ ((packed)) { uint8_t h, s, v, a; @@ -66,4 +75,5 @@ union Hsv { Hsv& operator=( Rgb rgb ); bool operator==( Hsv in ) const { return in.value == value; } void swap( Hsv& o ) { value = o.value; } + constexpr Hsv(const Hsv& other) : h(other.h), s(other.s), v(other.v), a(other.a) { } }; diff --git a/code/components/jomjol_controlGPIO/SmartLeds.cpp b/code/components/jomjol_controlGPIO/SmartLeds.cpp index a2ba7b292..bcfbd72b1 100644 --- a/code/components/jomjol_controlGPIO/SmartLeds.cpp +++ b/code/components/jomjol_controlGPIO/SmartLeds.cpp @@ -16,16 +16,16 @@ void IRAM_ATTR SmartLed::interruptHandler(void*) { if ( RMT.int_st.val & (1 << (24 + channel ) ) ) { // tx_thr_event if ( self ) self->copyRmtHalfBlock(); - RMT.int_clr.val |= 1 << ( 24 + channel ); + RMT.int_clr.val = 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 ); + RMT.int_clr.val = RMT.int_clr.val | 1 << ( 3 * channel ); } } } -void IRAM_ATTR SmartLed::copyRmtHalfBlock() { +void SmartLed::copyRmtHalfBlock() { int offset = detail::MAX_PULSES * _halfIdx; _halfIdx = !_halfIdx; int len = 3 - _componentPosition + 3 * ( _count - 1 ); diff --git a/code/components/jomjol_controlGPIO/SmartLeds.h b/code/components/jomjol_controlGPIO/SmartLeds.h index 4c46fec76..ffd2fad39 100644 --- a/code/components/jomjol_controlGPIO/SmartLeds.h +++ b/code/components/jomjol_controlGPIO/SmartLeds.h @@ -56,10 +56,14 @@ #include #include #include + #include + #include #include #include + #include } #include + extern rmt_mem_t RMTMEM; #endif #include "Color.h" @@ -131,8 +135,7 @@ class SmartLed { 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 ); + RMT.int_ena.val = RMT.int_ena.val | (1 << ( 24 + _channel )) | (1 << ( 3 * _channel )); _bitToRmt[ 0 ].level0 = 1; _bitToRmt[ 0 ].level1 = 0; diff --git a/code/components/jomjol_controlGPIO/server_GPIO.cpp b/code/components/jomjol_controlGPIO/server_GPIO.cpp index c21adde52..0a1ae5c23 100644 --- a/code/components/jomjol_controlGPIO/server_GPIO.cpp +++ b/code/components/jomjol_controlGPIO/server_GPIO.cpp @@ -108,7 +108,7 @@ void GpioPin::init() 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)) { + if ((_interruptType != GPIO_INTR_DISABLE) && (_mode != GPIO_PIN_MODE_EXTERNAL_FLASH_WS281X)) { //hook isr handler for specific gpio pin ESP_LOGD(TAG_SERVERGPIO, "GpioPin::init add isr handler for GPIO %d", _gpio); gpio_isr_handler_add(_gpio, gpio_isr_handler, (void*)&_gpio); diff --git a/code/components/jomjol_controlGPIO/server_GPIO.h b/code/components/jomjol_controlGPIO/server_GPIO.h index 074b08af1..642fe3e9a 100644 --- a/code/components/jomjol_controlGPIO/server_GPIO.h +++ b/code/components/jomjol_controlGPIO/server_GPIO.h @@ -5,6 +5,8 @@ #include #include +#include "hal/gpio_ll.h" +#include "rom/gpio.h" #include "driver/gpio.h" #include "SmartLeds.h" @@ -109,4 +111,4 @@ GpioHandler* gpio_handler_get(); -#endif //SERVER_GPIO_H \ No newline at end of file +#endif //SERVER_GPIO_H diff --git a/code/components/jomjol_controlcamera/CMakeLists.txt b/code/components/jomjol_controlcamera/CMakeLists.txt index 9f1a39272..ca0ffdfb2 100644 --- a/code/components/jomjol_controlcamera/CMakeLists.txt +++ b/code/components/jomjol_controlcamera/CMakeLists.txt @@ -4,6 +4,6 @@ list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/proto 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) + REQUIRES esp32-camera esp_timer esp_http_server jomjol_logfile jomjol_image_proc nvs_flash jomjol_fileserver_ota jomjol_controlGPIO) diff --git a/code/components/jomjol_controlcamera/ClassControllCamera.cpp b/code/components/jomjol_controlcamera/ClassControllCamera.cpp index 208dcefb4..e8ffa13ba 100644 --- a/code/components/jomjol_controlcamera/ClassControllCamera.cpp +++ b/code/components/jomjol_controlcamera/ClassControllCamera.cpp @@ -70,41 +70,7 @@ static const char *TAGCAMERACLASS = "server_part_camera"; -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 - -}; +static camera_config_t camera_config; #include "driver/ledc.h" @@ -112,6 +78,9 @@ static camera_config_t camera_config = { CCamera Camera; #define FLASH_GPIO GPIO_NUM_4 +#ifdef BLINK_GPIO +#undef BLINK_GPIO +#endif #define BLINK_GPIO GPIO_NUM_33 typedef struct { @@ -533,7 +502,11 @@ esp_err_t CCamera::CaptureToHTTP(httpd_req_t *req, int delay) esp_camera_fb_return(fb); int64_t fr_end = esp_timer_get_time(); +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) + ESP_LOGI(TAGCAMERACLASS, "JPG: %luKB %lums", (uint32_t)(fb_len/1024), (uint32_t)((fr_end - fr_start)/1000)); +#else ESP_LOGI(TAGCAMERACLASS, "JPG: %uKB %ums", (uint32_t)(fb_len/1024), (uint32_t)((fr_end - fr_start)/1000)); +#endif if (delay > 0) { @@ -672,6 +645,40 @@ CCamera::CCamera() esp_err_t CCamera::InitCam() { ESP_LOGD(TAGCAMERACLASS, "Init Camera"); + + camera_config.pin_pwdn = CAM_PIN_PWDN; + camera_config.pin_reset = CAM_PIN_RESET; + camera_config.pin_xclk = CAM_PIN_XCLK; + camera_config.pin_sccb_sda = CAM_PIN_SIOD; + camera_config.pin_sccb_scl = CAM_PIN_SIOC; + + camera_config.pin_d7 = CAM_PIN_D7; + camera_config.pin_d6 = CAM_PIN_D6; + camera_config.pin_d5 = CAM_PIN_D5; + camera_config.pin_d4 = CAM_PIN_D4; + camera_config.pin_d3 = CAM_PIN_D3; + camera_config.pin_d2 = CAM_PIN_D2; + camera_config.pin_d1 = CAM_PIN_D1; + camera_config.pin_d0 = CAM_PIN_D0; + camera_config.pin_vsync = CAM_PIN_VSYNC; + camera_config.pin_href = CAM_PIN_HREF; + camera_config.pin_pclk = CAM_PIN_PCLK; + + //XCLK 20MHz or 10MHz for OV2640 double FPS (Experimental) + camera_config.xclk_freq_hz = 20000000; // Orginalwert +// camera_config.xclk_freq_hz = 5000000; // Test, um die Bildfehler los zu werden !!!! Hängt in Version 9.2 !!!! + camera_config.ledc_timer = LEDC_TIMER_0; + camera_config.ledc_channel = LEDC_CHANNEL_0; + + camera_config.pixel_format = PIXFORMAT_JPEG; //YUV422,GRAYSCALE,RGB565,JPEG + camera_config.frame_size = FRAMESIZE_VGA; //QQVGA-UXGA Do not use sizes above QVGA when not JPEG +// camera_config.frame_size = FRAMESIZE_UXGA; //QQVGA-UXGA Do not use sizes above QVGA when not JPEG + camera_config.jpeg_quality = 12; //0-63 lower number means higher quality + camera_config.fb_count = 1; //if more than one, i2s runs in continuous mode. Use only with JPEG + camera_config.fb_location = CAMERA_FB_IN_PSRAM; /*!< The location where the frame buffer will be allocated */ +// camera_config.grab_mode = CAMERA_GRAB_WHEN_EMPTY; + camera_config.grab_mode = CAMERA_GRAB_LATEST; // erst ab neuer esp32cam-version + ActualQuality = camera_config.jpeg_quality; ActualResolution = camera_config.frame_size; //initialize the camera diff --git a/code/components/jomjol_fileserver_ota/CMakeLists.txt b/code/components/jomjol_fileserver_ota/CMakeLists.txt index c3f99abe7..37d42532a 100644 --- a/code/components/jomjol_fileserver_ota/CMakeLists.txt +++ b/code/components/jomjol_fileserver_ota/CMakeLists.txt @@ -2,6 +2,6 @@ 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) + REQUIRES tflite-lib esp_http_server bootloader_support app_update esp_http_client vfs nvs_flash jomjol_tfliteclass jomjol_flowcontroll spiffs jomjol_helper jomjol_controlGPIO) diff --git a/code/components/jomjol_fileserver_ota/miniz.c b/code/components/jomjol_fileserver_ota/miniz.c index 9ded4c75a..00318fea0 100644 --- a/code/components/jomjol_fileserver_ota/miniz.c +++ b/code/components/jomjol_fileserver_ota/miniz.c @@ -3076,7 +3076,9 @@ static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream) #define MZ_DELETE_FILE remove #else +#if 0 #pragma message("Using fopen, ftello, fseeko, stat() etc. path for file I/O - this path may not support large files.") +#endif #ifndef MINIZ_NO_TIME #include #endif diff --git a/code/components/jomjol_fileserver_ota/server_ota.cpp b/code/components/jomjol_fileserver_ota/server_ota.cpp index 7df5e72c4..95c70aa73 100644 --- a/code/components/jomjol_fileserver_ota/server_ota.cpp +++ b/code/components/jomjol_fileserver_ota/server_ota.cpp @@ -3,7 +3,6 @@ #include #include "string.h" -#include #include @@ -17,7 +16,9 @@ #include #include "esp_http_client.h" #include "esp_flash_partitions.h" +#include "esp_vfs.h" #include "esp_partition.h" +#include "esp_app_format.h" #include #include "nvs_flash.h" #include "driver/gpio.h" @@ -78,16 +79,28 @@ static bool ota_update_task(std::string fn) const esp_partition_t *running = esp_ota_get_running_partition(); if (configured != running) { +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) + ESP_LOGW(TAGPARTOTA, "Configured OTA boot partition at offset 0x%08lx, but running from offset 0x%08lx", +#else ESP_LOGW(TAGPARTOTA, "Configured OTA boot partition at offset 0x%08x, but running from offset 0x%08x", +#endif configured->address, running->address); ESP_LOGW(TAGPARTOTA, "(This can happen if either the OTA boot data or preferred boot image become somehow corrupted.)"); } +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) + ESP_LOGI(TAGPARTOTA, "Running partition type %d subtype %d (offset 0x%08lx)", +#else ESP_LOGI(TAGPARTOTA, "Running partition type %d subtype %d (offset 0x%08x)", +#endif running->type, running->subtype, running->address); update_partition = esp_ota_get_next_update_partition(NULL); +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) + ESP_LOGI(TAGPARTOTA, "Writing to partition subtype %d at offset 0x%lx", +#else ESP_LOGI(TAGPARTOTA, "Writing to partition subtype %d at offset 0x%x", +#endif update_partition->subtype, update_partition->address); // assert(update_partition != NULL); @@ -474,7 +487,17 @@ esp_err_t handler_ota_update(httpd_req_t *req) }; void hard_restart() { + +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) + esp_task_wdt_config_t wd_config; + wd_config.timeout_ms = 1000; + wd_config.idle_core_mask = (1 << portNUM_PROCESSORS) - 1; // Bitmask of all cores + wd_config.trigger_panic = true; + + esp_task_wdt_init(&wd_config); +#else esp_task_wdt_init(1,true); +#endif esp_task_wdt_add(NULL); while(true); } diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp index 64d257c2f..bc1469af4 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp @@ -13,7 +13,7 @@ #define __HIDE_PASSWORD -static const char *TAG = "class_flow_MQTT"; +//static const char *TAG = "class_flow_MQTT"; #define LWT_TOPIC "connection" #define LWT_CONNECTED "connected" @@ -143,7 +143,11 @@ void publishRuntimeData(std::string maintopic, int SetRetainFlag) { sprintf(tmp_char, "%ld", (long)getUpTime()); MQTTPublish(maintopic + "/" + "uptime", std::string(tmp_char), SetRetainFlag); +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) + sprintf(tmp_char, "%lu", esp_get_free_heap_size()); +#else sprintf(tmp_char, "%zu", esp_get_free_heap_size()); +#endif MQTTPublish(maintopic + "/" + "freeMem", std::string(tmp_char), SetRetainFlag); sprintf(tmp_char, "%d", get_WIFI_RSSI()); diff --git a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.h b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.h index 4150cf7f7..441d86571 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.h +++ b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.h @@ -4,7 +4,9 @@ #include +#ifndef BLINK_GPIO #define BLINK_GPIO GPIO_NUM_4 +#endif #define CAMERA_MODEL_AI_THINKER diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index 44ad50b03..b9e40c510 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -25,6 +25,7 @@ extern "C" { #include "ClassLogFile.h" #include "esp_vfs_fat.h" +#include "esp_mac.h" static const char* TAG = "helper"; @@ -116,7 +117,11 @@ string getSDCardPartitionAllocationSize(){ f_getfree("0:", (DWORD *)&fre_clust, &fs); allocation_size = fs->ssize; - printf("SD Card Partition Allocation Size (bytes): %d)\n", allocation_size); +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) + printf("SD Card Partition Allocation Size (bytes): %lu)\n", allocation_size); +#else + printf("SD Card Partition Allocation Size (bytes): %zu)\n", allocation_size); +#endif return std::to_string(allocation_size); } diff --git a/code/components/jomjol_influxdb/interface_influxdb.cpp b/code/components/jomjol_influxdb/interface_influxdb.cpp index 2089d98e9..a434b6072 100644 --- a/code/components/jomjol_influxdb/interface_influxdb.cpp +++ b/code/components/jomjol_influxdb/interface_influxdb.cpp @@ -41,19 +41,24 @@ static esp_err_t http_event_handler(esp_http_client_event_t *evt) case HTTP_EVENT_DISCONNECTED: ESP_LOGI(TAG_INTERFACEINFLUXDB, "HTTP Client Disconnected"); break; +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) + case HTTP_EVENT_REDIRECT: + ESP_LOGI(TAG_INTERFACEINFLUXDB, "HTTP Client Redirect"); + break; +#endif } 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 - }; + esp_http_client_config_t http_config; + + http_config.user_agent = "ESP32 Meter reader"; + http_config.method = HTTP_METHOD_POST; + http_config.event_handler = http_event_handler; + http_config.buffer_size = MAX_HTTP_OUTPUT_BUFFER; + http_config.user_data = response_buffer; if (_influxDBUser.length() && _influxDBPassword.length()){ http_config.username = _influxDBUser.c_str(); diff --git a/code/components/jomjol_mqtt/interface_mqtt.cpp b/code/components/jomjol_mqtt/interface_mqtt.cpp index 1f30d525a..6f5daa288 100644 --- a/code/components/jomjol_mqtt/interface_mqtt.cpp +++ b/code/components/jomjol_mqtt/interface_mqtt.cpp @@ -116,7 +116,11 @@ static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event) } static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) { +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) + ESP_LOGD(TAG_INTERFACEMQTT, "Event dispatched from event loop base=%s, event_id=%ld", base, event_id); +#else ESP_LOGD(TAG_INTERFACEMQTT, "Event dispatched from event loop base=%s, event_id=%d", base, event_id); +#endif mqtt_event_handler_cb((esp_mqtt_event_handle_t) event_data); } @@ -149,6 +153,7 @@ void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _us } bool MQTT_Init() { + esp_mqtt_client_config_t mqtt_cfg; esp_err_t ret; LogFile.WriteToFile(ESP_LOG_INFO, "MQTT - Init"); @@ -156,19 +161,33 @@ bool MQTT_Init() { 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 (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) + mqtt_cfg.broker.address.uri = uri.c_str(); + mqtt_cfg.credentials.client_id = client_id.c_str(); + mqtt_cfg.session.last_will.topic = lwt_topic.c_str(); + mqtt_cfg.session.last_will.msg = lw.c_str(); + mqtt_cfg.session.last_will.msg_len = (int)(lw.length()); + mqtt_cfg.session.last_will.retain = 1; + mqtt_cfg.session.keepalive = keepalive; +#else + mqtt_cfg.uri = uri.c_str(); + mqtt_cfg.client_id = client_id.c_str(); + mqtt_cfg.lwt_topic = lwt_topic.c_str(); + mqtt_cfg.lwt_msg = lw.c_str(); + mqtt_cfg.lwt_retain = 1; + mqtt_cfg.lwt_msg_len = (int)(lw.length()); + mqtt_cfg.keepalive = keepalive; +#endif if (user.length() && password.length()){ +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) + mqtt_cfg.credentials.username = user.c_str(); + mqtt_cfg.credentials.authentication.password = password.c_str(); + mqtt_cfg.credentials.authentication.key_password_len = password.length(); +#else mqtt_cfg.username = user.c_str(); mqtt_cfg.password = password.c_str(); +#endif }; client = esp_mqtt_client_init(&mqtt_cfg); diff --git a/code/components/jomjol_tfliteclass/server_tflite.cpp b/code/components/jomjol_tfliteclass/server_tflite.cpp index 5298b39b6..52c1fb3d7 100644 --- a/code/components/jomjol_tfliteclass/server_tflite.cpp +++ b/code/components/jomjol_tfliteclass/server_tflite.cpp @@ -12,6 +12,7 @@ #include "Helper.h" #include "esp_camera.h" +#include "esp_timer.h" #include "time_sntp.h" #include "ClassControllCamera.h" diff --git a/code/components/jomjol_time_sntp/time_sntp.cpp b/code/components/jomjol_time_sntp/time_sntp.cpp index d1eea362c..ccdff5b8b 100644 --- a/code/components/jomjol_time_sntp/time_sntp.cpp +++ b/code/components/jomjol_time_sntp/time_sntp.cpp @@ -7,7 +7,6 @@ #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" @@ -138,4 +137,4 @@ time_t getUpTime() time(&now); return now - bootTime; -} \ No newline at end of file +} diff --git a/code/components/jomjol_time_sntp/time_sntp.h b/code/components/jomjol_time_sntp/time_sntp.h index c56e6c919..3673101f5 100644 --- a/code/components/jomjol_time_sntp/time_sntp.h +++ b/code/components/jomjol_time_sntp/time_sntp.h @@ -5,7 +5,6 @@ #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" diff --git a/code/components/jomjol_wlan/CMakeLists.txt b/code/components/jomjol_wlan/CMakeLists.txt index 2887f8ca7..8f86028eb 100644 --- a/code/components/jomjol_wlan/CMakeLists.txt +++ b/code/components/jomjol_wlan/CMakeLists.txt @@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*) idf_component_register(SRCS ${app_sources} INCLUDE_DIRS "." - REQUIRES nvs_flash jomjol_helper) + REQUIRES esp_wifi nvs_flash jomjol_helper) diff --git a/code/components/jomjol_wlan/connect_wlan.cpp b/code/components/jomjol_wlan/connect_wlan.cpp index 2f81e7014..b949524ff 100644 --- a/code/components/jomjol_wlan/connect_wlan.cpp +++ b/code/components/jomjol_wlan/connect_wlan.cpp @@ -13,6 +13,8 @@ #include "lwip/err.h" #include "lwip/sys.h" +#include "lwip/ip_addr.h" +#include "lwip/inet.h" #include #include @@ -36,10 +38,14 @@ static EventGroupHandle_t s_wifi_event_group; #define WIFI_FAIL_BIT BIT1 static const char *TAG = "wifi station"; +static esp_netif_t *my_sta; static int s_retry_num = 0; /////////////////////////////////////////////////////////// +#ifdef BLINK_GPIO +#undef BLINK_GPIO +#endif #define BLINK_GPIO GPIO_NUM_33 int BlinkDauer; @@ -75,7 +81,11 @@ void task_doBlink(void *pvParameter) BlinkIsRunning = true; // Init the GPIO +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) + esp_rom_gpio_pad_select_gpio(BLINK_GPIO); +#else gpio_pad_select_gpio(BLINK_GPIO); +#endif /* Set the GPIO as a push/pull output */ gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT); @@ -127,7 +137,9 @@ static void event_handler(void* arg, esp_event_base_t event_base, } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip)); - ipadress = std::string(ip4addr_ntoa((const ip4_addr*) &event->ip_info.ip)); + char ip_addr[16]; + inet_ntoa_r(event->ip_info.ip.addr, ip_addr, 16); + ipadress = std::string(ip_addr); s_retry_num = 0; xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); LEDBlinkTask(1000, 5, true); @@ -149,7 +161,7 @@ void wifi_init_sta(const char *_ssid, const char *_password, const char *_hostna ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_event_loop_create_default()); - esp_netif_t *my_sta = esp_netif_create_default_wifi_sta(); + my_sta = esp_netif_create_default_wifi_sta(); if ((_ipadr != NULL) && (_gw != NULL) && (_netmask != NULL)) { @@ -225,7 +237,7 @@ void wifi_init_sta(const char *_ssid, const char *_password, const char *_hostna if (_hostname != NULL) { - esp_err_t ret = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA , _hostname); + esp_err_t ret = esp_netif_set_hostname(my_sta, _hostname); hostname = std::string(_hostname); if(ret != ESP_OK ){ ESP_LOGE(TAG,"failed to set hostname:%d",ret); diff --git a/code/main/main.cpp b/code/main/main.cpp index 5f1da209a..1f0cfaa7e 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -46,6 +46,9 @@ extern const char* BUILD_TIME; #include "server_GPIO.h" +#ifdef BLINK_GPIO +#undef BLINK_GPIO +#endif #define BLINK_GPIO GPIO_NUM_33 static const char *TAGMAIN = "main"; @@ -88,11 +91,10 @@ bool Init_NVS_SDCard() // Options for mounting the filesystem. // If format_if_mount_failed is set to true, SD card will be partitioned and // formatted in case when mounting fails. - esp_vfs_fat_sdmmc_mount_config_t mount_config = { - .format_if_mount_failed = false, - .max_files = 7, // anstatt 5 (2022-09-21) - .allocation_unit_size = 16 * 1024 - }; + esp_vfs_fat_sdmmc_mount_config_t mount_config; + mount_config.format_if_mount_failed = false; + mount_config.max_files = 7; // anstatt 5 (2022-09-21) + mount_config.allocation_unit_size = 16 * 1024; // Use settings defined above to initialize SD card and mount FAT filesystem. // Note: esp_vfs_fat_sdmmc_mount is an all-in-one convenience function. diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index 719bdd7ab..1b14251b3 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -12,6 +12,7 @@ #include "version.h" #include "esp_wifi.h" +#include "lwip/inet.h" #include "server_tflite.h" #include "esp_log.h" @@ -359,12 +360,25 @@ esp_err_t sysinfo_handler(httpd_req_t *req) std::string gitrevision = libfive_git_revision(); std::string htmlversion = getHTMLversion(); char freeheapmem[11]; +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) + sprintf(freeheapmem, "%lu", esp_get_free_heap_size()); +#else sprintf(freeheapmem, "%zu", esp_get_free_heap_size()); +#endif - tcpip_adapter_ip_info_t ip_info; - ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info)); + char ipstr[INET_ADDRSTRLEN]; const char *hostname; - ESP_ERROR_CHECK(tcpip_adapter_get_hostname(TCPIP_ADAPTER_IF_STA, &hostname)); + esp_netif_t *esp_netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"); + if (esp_netif != NULL) { + esp_netif_ip_info_t ip_info; + ESP_ERROR_CHECK(esp_netif_get_ip_info(esp_netif, &ip_info)); + esp_ip4addr_ntoa(&ip_info.ip, ipstr, INET_ADDRSTRLEN); + + ESP_ERROR_CHECK(esp_netif_get_hostname(esp_netif, &hostname)); + } else { + ipstr[0] = '\0'; + hostname = "n/a"; + } zw = "[\ {\ @@ -376,7 +390,7 @@ esp_err_t sysinfo_handler(httpd_req_t *req) \"html\" : \"" + htmlversion + "\",\ \"cputemp\" : \"" + cputemp + "\",\ \"hostname\" : \"" + hostname + "\",\ - \"IPv4\" : \"" + ip4addr_ntoa(&ip_info.ip) + "\",\ + \"IPv4\" : \"" + ipstr + "\",\ \"freeHeapMem\" : \"" + freeheapmem + "\"\ }\ ]"; diff --git a/code/main/server_main.h b/code/main/server_main.h index ccf4c7cba..4d7298f28 100644 --- a/code/main/server_main.h +++ b/code/main/server_main.h @@ -9,7 +9,6 @@ #include #include "nvs_flash.h" #include "esp_netif.h" -#include "esp_eth.h" #include "server_GPIO.h" #include diff --git a/code/sdkconfig.defaults b/code/sdkconfig.defaults index 4fff3341c..b7f0a9d91 100644 --- a/code/sdkconfig.defaults +++ b/code/sdkconfig.defaults @@ -22,8 +22,9 @@ CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" CONFIG_PARTITION_TABLE_OFFSET=0x8000 CONFIG_PARTITION_TABLE_MD5=y -CONFIG_ESP32_SPIRAM_SUPPORT=y +CONFIG_VFS_SUPPORT_IO=y +CONFIG_SPIRAM=y CONFIG_SPIRAM_SIZE=-1 CONFIG_SPIRAM_SPEED_40M=y CONFIG_SPIRAM=y @@ -63,4 +64,6 @@ CONFIG_OV5640_SUPPORT=n CONFIG_GC2145_SUPPORT=n CONFIG_GC032A_SUPPORT=n CONFIG_GC0308_SUPPORT=n -CONFIG_BF3005_SUPPORT=n \ No newline at end of file +CONFIG_BF3005_SUPPORT=n + +CONFIG_RMT_SUPPRESS_DEPRECATE_WARN=y