open62541-arduino icon indicating copy to clipboard operation
open62541-arduino copied to clipboard

Subscription stops with decreasing stack

Open sammer-h opened this issue 6 years ago • 5 comments

First of all. Thanks for your great work at the open62541 project. I did some experiments with the stack on RPI, Ubuntu and although Windows. The stack always worked fine for me.

Then I tried to get it running on the ESP32 platform with esp-idf - with less success. But with the help of this repo everything seemed to work perfect. The only necessary change was #include "task.h" -> #include "freertos/task.h" I use the amalgamation files open65421.c/h in my project. For testing UAExpert is great.

The server starts fine, browsing, read requests and even method calls work as expected. Subscribing to e.g. the Servers current time node works although fine. But after some seconds the time doesn't get refreshed any more even UAExpert states "Good". There is nothing special in the console output (level 100). The only abnormal is that the stack seems to be fine but the heap is decreasing approx. 1-2kb per minute.

Are there any known issues or restrictions with the freertoslwip architecture?

sammer-h avatar Feb 10 '19 21:02 sammer-h

We are using the stack on an ESP32 and there we do not have memory issues.

Maybe there's a free missing in your code? We are testing the full stack for memory leaks which means there shouldn't be any in the core.

Can you post your code example/main which you are using.

Pro avatar Feb 25 '19 05:02 Pro

It's nothing special at all - I basically took your code for Arduino. But there seems to be the same or at least a similar problem with other freertos-lwip platforms. After writing this post I found the following issue: https://github.com/open62541/open62541/issues/2227 Near the end of the issue (Jan 28) FishEatingCat describes the problem.

...
xTaskCreate(&opcua_task, "opcua_task", 1024 * 8, NULL, 1, NULL);
...
void opcua_task(void *pvParameter) {
   	ESP_LOGI(TAG, "Fire up OPC UA Server.");

	config = UA_ServerConfig_new_customBuffer(4840, NULL, 8192, 8192);
	UA_ServerConfig_set_customHostname(config, UA_STRING("espressif"));
	server = UA_Server_new(config);
	UA_StatusCode retVal = UA_Server_run_startup(server);

	while (1) 	{
		UA_Server_run_iterate(server, true);

		struct timeval tv;
		time_t nowtime;

		gettimeofday(&tv, NULL);
		nowtime = tv.tv_sec;

		vTaskDelay(20 / portTICK_PERIOD_MS);
		if (nowtime - lastMemOutput > 5) {
			memUsage();
			lastMemOutput = nowtime;
		}
	}

    ESP_LOGI(TAG, "RAM left %d", esp_get_free_heap_size());

    ESP_LOGI(TAG, "Now going to stop the server.");
    UA_Server_delete(server);
    UA_ServerConfig_delete(config);

    ESP_LOGI("OPC_TASK", "opcua_task going to return");
    vTaskDelete(NULL);
}

sammer-h avatar Feb 26 '19 19:02 sammer-h

image <- console output of ESP32 when everything is working fine

image <- console output of ESP32 if subscription stopps

image <- corresponding log of UA Expert

sammer-h avatar Feb 26 '19 21:02 sammer-h

hi @sammer-h, can you tell me how to build this repo? I never succeed to build this repo.

Always have this error:

[ 98%] Linking CXX executable arduino_opcua.elf Generating EEP image usage: gen_esp32part.py [-h] [--flash-size [{1MB,2MB,4MB,8MB,16MB}]] [--disable-md5sum] [--no-verify] [--verify] [--quiet] [--offset OFFSET] [--secure] input [output] gen_esp32part.py: error: argument input: can't open '{build.path}/partitions.csv': [Errno 2] No such file or directory: '{build.path}/partitions.csv' CMakeFiles/arduino_opcua.dir/build.make:201: recipe for target 'arduino_opcua.elf' failed make[2]: *** [arduino_opcua.elf] Error 2 make[2]: *** Deleting file 'arduino_opcua.elf' CMakeFiles/Makefile2:279: recipe for target 'CMakeFiles/arduino_opcua.dir/all' failed make[1]: *** [CMakeFiles/arduino_opcua.dir/all] Error 2 Makefile:151: recipe for target 'all' failed make: *** [all] Error 2

kusumy avatar Oct 25 '19 10:10 kusumy

@kusumy Please see this #16 to be able to build successfully @sammer-h hello, did you resolve your issue? do you use wifi or eth on your project?

dj-fiorex avatar Feb 10 '21 00:02 dj-fiorex