45
5 CHECKING OPERATIONS
5.3 Checking the Operation of Publish (Sending of MQTT Data)
5.3 Checking the Operation of Publish (Sending of
MQTT Data)
Create a JSON string with M+StrProcessing_JSONSerialize_F, and use M+FX5ENET_MQTT_PublishSend (Sending of
MQTT data) to send messages to the server (MQTT broker).
FB library registration
Register the FB library. For the operating procedures, refer to the following.
Page 53 FB Library
Program
■Send data creation
• Settings for data to be sent
M50 (Execution command) turns on for setting the data to be sent.
• JSON string creation
When M50 (Execution command) turns on, the function block creates a JSON string in accordance with the information of
uType (Value type), s32Key (Key name), s64Value (value of Value), and uDepth (depth of layer) in the set member list
(pb_st30Member) and it outputs the string to the file register at the address specified with the start address of the JSON string
storage destination.
(1) FX5U CPU module
(2) FX5-ENET
(1) (2)
FB
Publish
FB
AWS
M+StrProcessing_JSONSerialize_F M+FX5ENET_MQTT_PublishSend
M50
1
2
3
4
5
K1000 D41DMOV
M_StrProcessing_JSONSerialize_F_00A_1.pb_st30Member[0].uType := K3; //Set the Value type to K3 (character string).
M_StrProcessing_JSONSerialize_F_00A_1.pb_st30Member[0].s32Key := 'Sample'; //Set the Key name to "Sample".
M_StrProcessing_JSONSerialize_F_00A_1.pb_st30Member[0].s64Value := 'MQTT_TEST'; //Set Value to "MQTT_TEST".
M_StrProcessing_JSONSerialize_F_00A_1.pb_st30Member[0].uDepth := K1; //Set the depth of layer to K1.
M_StrProcessing_JSONSerialize_F_00A_1.pb_st30Member[1].uType := K0; //Set the Value type to K0 (end of the member structure array).
Set JSON start address to K1000.
o_bErr :B
o_bOK :B
o_bENO :B
UD: i_udJSONAddr
B: i_bEN
o_uErrId :UW
o_uJSONLength :UW
M51
M50
M52
M53
M_StrProcessing_JSONSerialize_F_00A_1
(M+StrProcessing_JSONSerialize_F_00A)
D41
D42
D43
StrProcessing_JSONSerialize_FB
pb_st30Member
JSON start address: K1000