Industrielle styresystemer - Wiki
Industrielle styresystemer - Wiki
Input:
topic : STRING(255);
xTrigger : BOOL;
message : STRING;
Output:
Info |
---|
Type: FunctionBlock Responsible: André |
To set up a MQTT publisher in codesys the following libraries are necessary to use:
Before the PLC can publish to over MQTT, the WagoAppCloud settings needs to be changed to fit the system this is done by writing the PLC's IP into the searchbar of a web browser, then cloud connectivity → connection 1. The settings are set to:
Image Added
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
FUNCTION_BLOCK MQTTPublisher |
VAR_INPUT |
topic : STRING(255); |
xtrigger : BOOL; |
message : STRING; |
END_VAR |
VAR |
mqttPub : wagoappcloud.FbPublishMQTT_2(econnection := econnectionid.Connection1); |
dwSize : DWORD; |
aData : ARRAY[0..100] OF BYTE; |
xRetain : BOOL := FALSE; |
xError : BOOL := FALSE; |
xBusy : BOOL := FALSE; |
eQualityOfService : eQualityOfService := 1; |
END_VAR |
wagosysplainmem.MemCopy(pDest:=ADR(aData),pSource:=ADR(message),udiSize:=TO_WORD(len(message))); |
mqttPub(sTopic:=topic,eQualityOfService:=eQualityOfService,xRetain:=xRetain,dwSize:=TO_WORD(len(message)),aData:=aData,xTrigger:=xtrigger,xBusy=>xBusy,xError=>xError); |