PWM To analog
CODESYS Forge
talk
(Thread)
PWM To analog
Last updated: 2024-01-12
POU - Access to runtime
CODESYS Forge
talk
(Thread)
POU - Access to runtime
Last updated: 2024-03-02
How to change bHiresMode
CODESYS Forge
talk
(Thread)
How to change bHiresMode
Last updated: 2024-03-12
CODESYSControl_User.cfg - link to documentation?
CODESYS Forge
talk
(Thread)
CODESYSControl_User.cfg - link to documentation?
Last updated: 2024-06-11
GVL to SHMem
CODESYS Forge
talk
(Thread)
GVL to SHMem
Last updated: 2024-07-09
Array to String
CODESYS Forge
talk
(Thread)
Array to String
Last updated: 2024-07-18
Array to String
CODESYS Forge
talk
(Thread)
Array to String
Last updated: 2024-07-24
Send data to USB
CODESYS Forge
talk
(Thread)
Send data to USB
Last updated: 2024-08-05
Password to POU
CODESYS Forge
talk
(Thread)
Password to POU
Last updated: 2024-08-14
Post by gustavocsw on MQTT memory leak problem
CODESYS Forge
talk
(Post)
Hello everyone, I'm using the IoT Library to implement the MQTT communication with my local broker server in order to publish and subscribe at specifics topics to share and consume information about my application. But, it seems that are occurring some memory leak problem in a "high" frequency (more than 10 Hz) subscribe process. I follow the same method as in IoT Lib exemples, and at first looks perfect but my PLC was rebooting frequently and when I check its memory usage that was increasing as fast as the subscribe massage was sent. I'm using a WEG PLC410 and a WEG PLC500, and this error occurred in both of them (including in CODESYS Control Win x64). The application sends to the system a message JSON with the float payload Ex. {"data" : 0.8500}, but this happens with a INT, or BOL as well. I use the follow code in my application to find the value: //FindFirstValueByKey VARs PROGRAM JSON_VELO VAR //------Setting the JSON Subscriber to Set the Relay Value jsonDataVelo : JSON.JSONData; jsonByteArrayReaderVelo : JSON.JSONByteArrayReader; xST1okVelo : BOOL; FindFirstValueByKeyVelo : JSON.FindFirstValueByKey; jsonElementVelo : JSON.JSONElement; xDoneReaderVelo : BOOL; xDoneFindVelo : BOOL; //STRING and WSTRING for Subscribe the massage sPayloadJsonVelo : STRING := 'opa'; psPayloadJsonVelo : POINTER TO BYTE := ADR(sPayloadJsonVelo); //wsPayloadJsonRelaySet : WSTRING := "opa"; wsPayloadJsonVelo : WSTRING := STRING_TO_WSTRING('opa'); pwsPayloadJsonVelo : POINTER TO WORD := ADR(wsPayloadJsonVelo); lrVelo : LREAL; xKeepAliveVelo : BOOL; xSetVelo : BOOL; RSSet : RS; LIMPAR : STRING; //Find the msg end sFindVelo : STRING := '}'; psFindVelo : POINTER TO STRING := ADR(sFindVelo); iLenVelo : INT; iSizeVelo : INT := 12; udiContMsg : UDINT; END_VAR // FindFirstValueByKey CODE // Relay Set configuration xSetVelo := MQTT_SUBSCRIBER.RSVelo.Q1; IF xSetVelo THEN xKeepAliveVelo := TRUE; END_IF IF xKeepAliveVelo THEN udiContMsg := udiContMsg + 1; iLenVelo := TO_INT(StrLenA(psPayloadJsonVelo)); iSizeVelo := iLenVelo - TO_INT(MQTT_SUBSCRIBER.udiPayloadSizeVelo); StrDeleteA(psPayloadJsonVelo,iSizeVelo,iLenVelo); wsPayloadJsonVelo := STRING_TO_WSTRING(sPayloadJsonVelo); pwsPayloadJsonVelo := ADR(wsPayloadJsonVelo); //MQTT.ConvertUTF8toUTF16(sourceStart:= ADR(sPayloadJsonVelo), targetStart:= ADR(wsPayloadJsonVelo), dwTargetBufferSize:= TAM, bStrictConversion:= 1); //Reset jsonByteArrayReader jsonByteArrayReaderVelo ( xExecute := TRUE, pwData := pwsPayloadJsonVelo, jsonData := jsonDataVelo, xDone => xDoneReaderVelo ); FindFirstValueByKeyVelo( xExecute := xDoneReaderVelo, wsKey := "data", diStartIndex:= 0, jsonData := jsonDataVelo, jsonElement => jsonElementVelo, xDone => xDoneFindVelo ); IF xDoneFindVelo THEN lrVelo := jsonElementVelo.value.lrValue; //Reset jsonByteArrayReader jsonByteArrayReaderVelo ( xExecute := FALSE, pwData := pwsPayloadJsonVelo, jsonData := jsonDataVelo, xDone => xDoneReaderVelo ); FindFirstValueByKeyVelo( xExecute := FALSE, wsKey := "data", diStartIndex:= 1, jsonData := jsonDataVelo, jsonElement => jsonElementVelo, xDone => xDoneFindVelo ); xKeepAliveVelo := FALSE; GVL.xSetVeloRead := TRUE; END_IF END_IF And this to subscribe at the topic: //SUBSCRIBE VAR: //----------------- Subscribe Velocity ----------------------- MQTTSubscribeVelo : MQTT.MQTTSubscribe;//Variable MQTTSubscriber block -X - function-X wsTopicSubscribeVelo : WSTRING(1024) := "CORE/odometry/GET/data/simp"; // Topic to publish a message sSubscribeMassageVelo : STRING; udiPayloadSizeVelo : UDINT; xSDoneVelo : BOOL; xSErrorVelo : BOOL; xReceiveVelo : BOOL; eSTypeVelo : MQTT.MQTT_ERROR; eSMQTTErrorVelo : MQTT.MQTT_ERROR; RSVelo : RS; udiCont : UDINT; //SUBSCRIBE CODE: MQTTSubscribeVelo( xEnable:= MQTT_CLIENT.xConnection_Broker AND NOT xSErrorVelo AND NOT JSON_VELO.xKeepAliveVelo, pbPayload:= JSON_VELO.psPayloadJsonVelo, udiMaxPayloadSize:= SIZEOF(JSON_VELO.sPayloadJsonVelo), udiPayloadSize => udiPayloadSizeVelo, mqttClient:= MQTT_CLIENT.ClientMQTT, wsTopicFilter:=wsTopicSubscribeVelo, xDone => xSDoneVelo, xError=> xSErrorVelo, xReceived => xReceiveVelo, eMQTTError=> eSMQTTErrorVelo ); RSVelo(SET := xReceiveVelo, RESET1 := JSON_VELO.xKeepAliveVelo);
Last updated: 2024-09-09
How to configure CODESYSControl_User.cfg in order to use a specific network card for OPCUA Server
CODESYS Forge
talk
(Thread)
How to configure CODESYSControl_User.cfg in order to use a specific network card for OPCUA Server
Last updated: 2023-08-28
how to transfer raspberrypi runtime license from sdcard to dongle without the original raspi?
CODESYS Forge
talk
(Thread)
how to transfer raspberrypi runtime license from sdcard to dongle without the original raspi?
Last updated: 2021-04-13
What is the best way to upgrade a project to a new version of Codesys?
CODESYS Forge
talk
(Thread)
What is the best way to upgrade a project to a new version of Codesys?
Last updated: 2022-03-01
I want to use the function of PVT to realize move
CODESYS Forge
talk
(Thread)
I want to use the function of PVT to realize move
Last updated: 2013-05-14
How to intercept a variation in the RetainPerstist variables (for saving to file)
CODESYS Forge
talk
(Thread)
How to intercept a variation in the RetainPerstist variables (for saving to file)
Last updated: 2018-08-03
How to set "Always updatevariables" to "enable 2" by default in DeviceDescription.
CODESYS Forge
talk
(Thread)
How to set "Always updatevariables" to "enable 2" by default in DeviceDescription.
Last updated: 2020-12-10
Specify Input Configuration "OnDialogClosed" Action to only react to certain Dialogs
CODESYS Forge
talk
(Thread)
Specify Input Configuration "OnDialogClosed" Action to only react to certain Dialogs
Last updated: 2023-10-02
Can't connect to my raspberry pi 3 after I tried to adjust CODESYScontrol.cfg
CODESYS Forge
talk
(Thread)
Can't connect to my raspberry pi 3 after I tried to adjust CODESYScontrol.cfg
Last updated: 2021-06-17
How to connect Codesys Control win v3 to an ethercat device
CODESYS Forge
talk
(Thread)
How to connect Codesys Control win v3 to an ethercat device
Last updated: 2021-04-26
How to generate PDO explicit request with RTR flag to TRUE
CODESYS Forge
talk
(Thread)
How to generate PDO explicit request with RTR flag to TRUE
Last updated: 2018-06-13
Codesys closes instantly after I try to download to PLC
CODESYS Forge
talk
(Thread)
Codesys closes instantly after I try to download to PLC
Last updated: 2022-12-21
Unable to get retain variables to work in a specific Raspberry Pi project
CODESYS Forge
talk
(Thread)
Unable to get retain variables to work in a specific Raspberry Pi project
Last updated: 2019-12-03
Cannot convert type 'Unknown type: 'ADR(tabOrderIdArray)" to type 'POINTER TO ARRAY [0..0]OF INT'
CODESYS Forge
talk
(Thread)
Cannot convert type 'Unknown type: 'ADR(tabOrderIdArray)" to type 'POINTER TO ARRAY [0..0]OF INT'
Last updated: 2021-04-26
what to do in case of a writing error to eeprom
CODESYS Forge
talk
(Thread)
what to do in case of a writing error to eeprom
Last updated: 2020-11-26
Beaglebone Black - only one Ethernet port - how to connect to LAN, and EtherCAT?
CODESYS Forge
talk
(Thread)
Beaglebone Black - only one Ethernet port - how to connect to LAN, and EtherCAT?
Last updated: 2022-01-16
To search for an exact phrase, put it in quotes. Example: "getting started docs"
To exclude a word or phrase, put a dash in front of it. Example: docs -help
To search on specific fields, use these field names instead of a general text search. You can group with AND
or OR
.