Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

To set up a MQTT publisher in codesys the following libraries are necessary to use:

  • WagoSysPlainMem
  • WagoAppCloud

The functionblock MQTT_Publisher was then created , with the following code:


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);

Input: (NEEDS TO BE UPDATED WHEN I HAVE THE FUNCTION IN FRONT OF ME)
v : ARRAY [0..2] OF LREAL;

Output:

norm : LREAL;
Info

Type: Functionblock

Responsible: Andre

The first implementation of MQTT on the Wago-PLC. This enables external visualization, such as CDP-Studio. The intention of this implementation was to make a 24_7 CDP-Studio Dashboard, that shows near realtime updates of the actual and the target motorspeed and position in CDP-Studio. Since it publishes the information is also used in 24_7 3D-Visualization in Blender.

Implementation: