This code is to send data to an API.
The help I’m looking for when creating a route
@ Var_int3 (“packaging-units”, Good_Units_BB @, “3”, Presentation_BB @)
I have to declare two variables Good_Units_BB and Presentation_BB these variables have values that will change the idea is that every time they change a trigger, send this change, normally it has been working with the ONCHANGE function that works well when there is only one variable that presents instead but when there are two or more variables that can change in the error path
the part of code in which I do this is
// ---------------------------------- UNITS FULL ------------ ------
@ Var_int3 (“packaging-units”, Good_Units_BB @, “3”, Presentation_BB @)
// ------------ CHANGES UNITS FULL ------------------------------
ONCHANGE “TRIGGER”, ‘Var_int3 (“packaging-units”, Good_Units_BB @, “3”, Presentation_BB @)’
In the ONCHANGE function there is the TRIGGER that works detecting the changes in the variable (Good_Units_BB and Presentation_BB) but this route has two variables and the ONCHANGE only works for me to detect the change in a single variable as I do the detection of the change in two variables.
NOTE WHEN I REFER TO THE TRIGGER, IT IS THE VARIABLE THAT WHEN IT SHOWS A CHANGE, THE SHIPPING IS MADE
HANDBOOK
ONCHANGE
Syntax
ONCHANGE S1, S2
S1 the tag reference (tag name, ID or index).
S2 the command line to execute in case the tag value or configuration changes.
Description
This command executes the S2 command line when the tag S1 changes. The change can be
its value or configuration. The EVTINFO parameter is set to the tag ID when command is called.
ONALARM will execute the command when the alarm status gets the value “2” (or above)
which means that ONALARM does not detect the “pre trigger” status (value = 1).
I PUBLISH THE CODE
// ---------------------------------- UNITS FULL ------------ ------
@ Var_int3 (“packaging-units”, Good_Units_BB @, “3”, Presentation_BB @)
// ------------ CHANGES UNITS FULL ------------------------------
ONCHANGE “TRIGGER”, ‘Var_int3 (“packaging-units”, Good_Units_BB @, “3”, Presentation_BB @)’
Function SendInfo ($ Info $, $ api $)
URL $ = “https://dataplc.smartessi.com/api/” + $ api $ + “?”
T $ = Time $
year $ = T $ (7 To 10)
mon $ = T $ (4 To 5)
date $ = T $ (1 To 2)
hour $ = T $ (12 To 13)
min $ = T $ (15 To 16)
sec $ = T $ (18 To 19)
fff $ = year $ + “-” + mon $ + “-” + date $
hour $ = hour $ + “:” + min $ + “:” + sec $
// --------------- PRINTING THE PATH URL + DATA -------------------------
endpoint $ = URL $ + $ Info $
PRINT endpoint $
REQUESTHTTPX endpoint $, “POST”, “Content-Type: application / json; charset = utf-8”
ENDFN
// -------------------------------- UNITS FULL -------------- --------
Function Var_int3 ($ api_int $, @ $ Val_Var_int, $ head_id $, @ $ Val_Var_int2)
AR_I3 $ = SFMT $ Val_Var_int, 30, 0, “% d”
AR_I32 $ = SFMT $ Val_Var_int2, 30, 0, “% d”
DataR_I3 $ = “value =” + AR_I3 $ + “& id_head =” + $ id_head $ + “& presentation =” + AR_I32 $ + “& date =” + fff $ + “& time =” + time $
@SendInfo (DataR_I3 $, $ api_int $)
ENDFN