br-automation-com / paho.mqtt.c-ar

MQTT Client for Automation Runtime based on eclipse/paho.mqtt.c
21 stars 7 forks source link

Buffersize & others #25

Open stefanlk opened 1 year ago

stefanlk commented 1 year ago

we just found out, when publishing data and subscribed on other system, there is one byte less received than in buffer size.

also there has to toggel the Read and Send flags. There is nothing in Readme?

Stefan

JobFranken commented 1 year ago

Could you post more info what you sending and what you are using to receive the data. Maybe a small sample / screenshots of your findings.

Depending of the function block you need to create a rising edge on to process the data. This information is already at the function block interface in the .fun file.

stefanlk commented 1 year ago

Type of Struct: MQTTcmdsLcu2Master_typ CmdStartMovement USINT CmdCabin2Sledge_block USINT CmdCabin2Sledge_unblock USINT fbkReadyForInspection USINT Spare1 USINT Init: IotMqttSubscribe_CmdsFromLcu.IotMqttLink = IotMqttClient_0.IotMqttLink; IotMqttSubscribe_CmdsFromLcu.Buffer = &CmdsFromLcu; IotMqttSubscribe_CmdsFromLcu.BufferSize = sizeof(CmdsFromLcu); IotMqttSubscribe_CmdsFromLcu.QueueSize = 10; IotMqttSubscribe_CmdsFromLcu.RecievedTopic = strCmdsFromLcu_RecvdTopic; IotMqttSubscribe_CmdsFromLcu.RecievedTopicSize = sizeof(strCmdsFromLcu_RecvdTopic); strncpy(strCmdsFromLcu_Topic, ConfigInternal_Var.MqttId, sizeof(IotMqttParameters.ClientID)); strcat(strCmdsFromLcu_Topic, "/data/LCU/+/Cmds2Mst"); // Todo: check of too big data IotMqttSubscribe_CmdsFromLcu.Topic = &strCmdsFromLcu_Topic; IotMqttSubscribe_CmdsFromLcu.Enable = true; usiCmdsFromLcuTopic_pos = strchr(strCmdsFromLcu_Topic, '+') - strCmdsFromLcu_Topic; Cyclic: IotMqttSubscribe_CmdsFromLcu.Read = !IotMqttSubscribe_CmdsFromLcu.Read; IotMqttSubscribe(&IotMqttSubscribe_CmdsFromLcu); if ( IotMqttSubscribe_CmdsFromLcu.NewDataValid ) { Init: IotMqttPublish_CmdsToMaster.IotMqttLink = IotMqttClient_0.IotMqttLink; strncpy(strCmdsToMaster_Topic, ConfigInternal_Var.MqttId, sizeof(strCmdsToMaster_Topic)); strcat(strCmdsToMaster_Topic, "/data/LCU/"); // Todo: check of too big data strcat(strCmdsToMaster_Topic, SubSysID_str); strcat(strCmdsToMaster_Topic, "/Cmds2Mst"); // Todo: check of too big data IotMqttPublish_CmdsToMaster.Topic = strCmdsToMaster_Topic; IotMqttPublish_CmdsToMaster.Buffer = &cmdsLcu2Master; IotMqttPublish_CmdsToMaster.BufferLength = sizeof(cmdsLcu2Master); IotMqttPublish_CmdsToMaster.Enable = true; Cyclic: if ((IotMqttPublish_CmdsToMaster.Done == false)) IotMqttPublish_CmdsToMaster.Send = true; else IotMqttPublish_CmdsToMaster.Send = false; IotMqttPublish(&IotMqttPublish_CmdsToMaster); //IotMqttPublish_CmdsToMaster(); I just counted Spare1 up on publisher side, but on receiver side, it is not received.

stefanlk commented 1 year ago

Also, in the example is used .NewDataValid. But we use now MessageRetrieved. It seems NewDataValid do not work correct.

stefanlk commented 1 year ago

Also can you send me a working example code with RegPar functions. I do not get it working.

priesf commented 1 year ago

Hi, you can find a sample project within the repo. Samples/IotMqttSamples/SampleProject

I have no issues with the test project from the repo. Please check the samples and see what you can take from there. Your source code is not providing the needed information. E.g how do you convert your struct datatype to a string which is then provided at the buffer input of the publisher?

Hope you find the necessary information within the demo. BR

stefanlk commented 1 year ago

Thanks for the response. What I read in you answer: The normal Publish/Subscribe Functions are only sending textual strings? So the last character must be 0 and is reflected as 0? The Samples do not use NewDataValid. I am very dissatisfied about documentation and answers about the module. Thanks for supporting

priesf commented 1 year ago

Hello @stefanlk, sorry for your inconvenience. MQTT per definition is only working with textual strings. Using the "normal" publish/subscribe functionblock gives you the possibility to freely define your payload. The payload has to be a string. Using the "RegPar" publish/subscribe functionblock gives you the possibility to define a variable from your task as your payload. The variable will be converted to a string internally before sending.

I don't really understand your comment about

So the last character must be 0 and is reflected as 0?

Each string has to be \0 (zero terminated) at the end no matter where you use it.

The output "NewDataValid" is used to signal, that for the subscribed topic a message can be read from the buffer. When this signal is TRUE, you can retrieve a message using the "Read" input. After the message is copied to the provided buffer, the signal "MessageRetrieved" is set to TRUE. Resetting the "Read" input will reset the signal "MessageRetrieved". image

Please let me know if there is anything else we can help with. BR