Closed meijer3 closed 1 year ago
I see that prettier, made the markdown scripts, prettier.... It changes some of the formatting
I see I need to fix a small thing.
Dimmer was not dimmable in the first version. Now it is. In the meanwhile, I also added a meta tag. So in MQTT you can see some extra info if you want. Location/id or something. Is a bit faster than spinning up a VM/éCOCKPIT
And please notice that I changed FB_OUTPUT_DIMMER_MQTT.InitMqtt
to straighten sub/pub topic buildup.
Thanks for your work! I'll give this a thorough check but I see that the ecp is not yet updated. Could you encoperate your changes in the ecp as well?
The ecp is what is used by new adopters for their own project. It's also what is used to update the exports (Codesys V3 and PLC open). The exports can then be used by people that aleady adopted the project to update their FB to the latest version.
So you see, we need both unfortunattely. I know it's a bit cumbersom, it's a pitty that these PLC projects always are binary files.
Well yes I ll update the ecp tonight. I don't change the hardware tho? Nearly impossible to check then? Do you know there is subversion for éCockpit (30 day trial...)? It shows all the changes.
I created a new doc for merge/pull request. It is inside this PR
Done, I updated the .ecp
and docs. The discovery is only for the dimmers available for now.
I'm missing docs on the FB_MQTT_LOG function block
I added the docs. Maybe you want to straighten it all to your own style? If you think the rest is okay there is still work to do
MqttVariables
, maybe you don't want that, since you dont work so much with globals.
- startup
I'll indeed finetune the docs a bit more in a follow up PR. Seems like I forgot to finish my review yesterday, could you have a look at the remaining open points.
Almost there :)
Closes #128
Hmm It looks like mqtt is not working as an input sub, maybe I did something wrong here. I need to fix that. Copied something old or something
// THIS^.OUT_Internal:=STRING_TO_BYTE(Data.PayloadString^);
THIS^.OUT_Target:=STRING_TO_BYTE(Data.PayloadString^);
THIS^.SoftDimToValue:=TRUE
Hmm It looks like mqtt is not working as an input sub, maybe I did something wrong here. I need to fix that. Copied something old or something
// THIS^.OUT_Internal:=STRING_TO_BYTE(Data.PayloadString^); THIS^.OUT_Target:=STRING_TO_BYTE(Data.PayloadString^); THIS^.SoftDimToValue:=TRUE
perhaps consider reverting that change for another PR where you can also introduce more dimming curves? This is what's in master:
ELSIF OSCAT_BASIC.IS_CC(str:= Data.PayloadString^,cmp:='0123456789.') AND THIS^.PRIO_HIGH = FALSE THEN
THIS^.OUT:=STRING_TO_BYTE(Data.PayloadString^);
END_IF
I copied the old code from few weeks ago, but now it hangs on this. I dont know how to debug this. Never understood where the error message was.
I added discovery for switches already, I can push that tomorrow or day after
To add HADiscovery and update InitMqtt
for other FB (docs for future us)
InitMqtt
to this base.
THIS^.pMqttPublishQueue := pMqttPublishQueue;
THIS^.InstanceNamePt := CommonTypesAndFunctions.FindLastDot(ADR(THIS^.InstanceName)) + 1;
// Publish (Out); THIS^.MqttPublishTopicSuffix := THIS^.InstanceNamePt^; THIS^.MQTTPublishTopic := CONCAT(MQTTPublishPrefix^, THIS^.MqttPublishTopicSuffix);
// Subscribe (In) THIS^.MQTTSubscribeTopicSuffix := THIS^.InstanceNamePt^; THIS^.MQTTSubscribeTopic := CONCAT(MQTTSubscribePrefix^ ,THIS^.MQTTSubscribeTopicSuffix);
// register the FB agains the collector so mqtt events can be received pMqttCallbackCollector^.put(instance:= THIS^);
InitMqttDone := TRUE;
2. Remove `InstanceNamePt: POINTER TO STRING` from VAR in InitMqtt and move it to the main FB
3. Add this at the main FB VARs
MqttPublishTopicPrefix: POINTER TO STRING; MqttPublishTopicSuffix: STRING(50); MQTTPublishTopic: STRING(50); MqttSubscribeTopicPrefix: POINTER TO STRING; MqttSubscribeTopicSuffix: STRING(50); MQTTSubscribeTopic: STRING(50);
4. Replace all topics from:
`Topic := CONCAT(MqttPublishTopicPrefix^, MqttPublishTopicSuffix),`
to
`Topic := MQTTSubscribeTopic,`
However, if every mqtt FB has this, maybe we can extend a base mqtt FB
I think now its done and know that I added libraries. Like
SM0
(system/project details, dont know if they work for codesys)pro_json 15
Otherwise the application needs to be called Application
You should test thoroughly, with the extra libraries and such.I am glad that you can review my work. At work nobody checked my code for like 5 year at two clients... Thanks for your time!
yes that's a good idea. Yet not all MQTT function blocks needs subscriptions but that could be -perhaps- solved by making the method on the base private and call it 'baseInitMqtt' and call that one from a public method 'InitMqtt' on the extended FB. On the latter we can then only request what we need and pass empty values to the base for subscription values in some cases. (Thoughts for a latter PR).
I had another look at your code and I'm under the impression that the objectId and UniqueId is not prefixed with the projectName, is that correct? It's up to you if you want to add that in this PR or I'll do it in a follow up PR as I have multiple projects for multiple devices in my home automation setup (there's a barn with a separate device). Without the prefix I wouldn't have unique Id's in Home Assistant.
I think now its done and know that I added libraries. Like
* SM3_Shared for `SM0` (system/project details, dont know if they work for codesys) * `pro_json 15` Otherwise the application needs to be called `Application` You should test thoroughly, with the extra libraries and such.
I am glad that you can review my work. At work nobody checked my code for like 5 year at two clients... Thanks for your time!
I'm glad your time and effort on this. I gave it my best review now but will do some extensive testing later on a device.
I continued a bit. Added a general MQTT_FB and added some more auto-discoveries. Let me know if you want to add it in this PR (not done yet, but I get the hang of it)
I had another look at your code and I'm under the impression that the objectId and UniqueId is not prefixed with the projectName, is that correct? It's up to you if you want to add that in this PR or I'll do it in a follow up PR as I have multiple projects for multiple devices in my home automation setup (there's a barn with a separate device). Without the prefix I wouldn't have unique Id's in Home Assistant.
Now I do, but is it not a problem inside the rest of the code?
Shouldn't we implement the device name inside the mqttprefix?
Devices/PLC/House/availability
Shouldnt all URLs not be in the global MQTTVariables
?
The example ecp shows:
PLC_GROUP_MAIN
=> MqttSubDimmerPrefix :STRING(100) := 'Devices/PLC/House/In/Dimmers/';
MQTT_SUBSCRIBE
=> Topic:= ADR('Devices/PLC/House/In/Dimmers/#'), ';
Maybe just be a bit less flexible and add something like
<prefix>/<device>/In/<entity>
Where
prefix
, global fixed stringdevices
comes directly from the settings in device (e.g. 'PLC_Home'),entity
a variable is people can name them selfs? e.g. 'Dimmers'So you have only 2 globals, and one for every entity So that the urls are more autogenerated and fixed.
go ahead and push all you want, on Tuesday I can do a final review and let's focus then on merging it. I've got some stuff I need to merge as well and the binary files are troublesome for parallel branches.
Concerning your MQTT questions; YES, things are to spread out for sure. I was also planning on grouping everything in MQTTvariables.
While I understand your thoughts on the auto generated topics, I wouldn't take away this configuration possibility from the end user. I think the topic structure used now is great but for sure it will not suit everyone. No?
I think I am done with coding for this PR. Done:
FB_MQTT_BASE
MqttVariables
Still on my list in an other PR
Didnt you had any troubles with JSON_PRO 15 vs 12? MQTT needs 12.
If MQTT is lacking 12 but 15 is a main lib does work, but trhows an error...
12 => Application needs to be called Application
Didnt you had any troubles with JSON_PRO 15 vs 12? MQTT needs 12. If MQTT is lacking 12 but 15 is a main lib does work, but trhows an error... 12 => Application needs to be called
Application
I had to install the PRO_JSON library you added in the 'libraries' folder, after that everything compiles fine. Unfortunnately I don't have a device ready to perfom in depth tests with it.
Pull Request Checklist
Check if the tasks below are relevant for your PR, to mark an item as completed use [X].
Proposed Changes
This adds (for now only dimmers) a auto discovery to Home Assistant DMX artnet is also added to dimmers. A simple MQTT logger is also included
Related issues