Publish a text string to Azure EWON Flexy 205

Hi Tech support

I am currently publishing a group of tags to azure.
I want to add a text string to Group A tags to be publish to Azure.
Then I stop/start the script on ewon to gather which tags to be published.
I get the following error when the ewon tries to publish.
Syntax error (0) 104 : IF GroupC$ = “1” And GROUPC%= 1 THEN json$ = json$ + ‘"’ + i$+ ‘":’+STR$ GETIO i$ + ‘,’: counter% = counter% +1 ENDIF
I think the script converts the values in Group A to String.
May be the error is related to the specific tag is not a value.
I can put all the strings in Group C.
Can you please change the script that Group C has tags with strings.
I sent you an email to hms.how as well.
Not sure the email has gone thru.
Thanks

Where is the value of “i” coming from? can you send me the rest of the code? the STR$ will convert the value called after it into a string, so the issue may be that you’re trying to convert a string into a string.

Hi Tim

Thanks for your reply.

I am pretty much using the script on the tech support forum to publish tags to mqqt.

Can you please change the script so Group C tags are Strings.

So don’t need to change Group C tags value to string.

Here’s the script I am using,

Rem — eWON start section: Cyclic Section

eWON_cyclic_section:

Rem — eWON user (start)

Rem — eWON user (end)

End

Rem — eWON end section: Cyclic Section

Rem — eWON start section: Init Section

eWON_init_section:

Rem — eWON user (start)

FirstScan% = 1

TSET 4, 10

ONtimer 4, “goto Totalkwh”

CLS

ONDATE 8, “59 23 * * *”,“Goto MidNight”

//Publish every 5 mins

ONDATE 9,"*/5 * * * *",“GOTO GasUsage5Mins”

//Publish every 1 mins

ONDATE 10,"*/1 * * * *",“GOTO MqttPublishAllValue”

//################" CONFIGURATION #################

DeviceId$=“ThomastownEwon”

IotHubName$ =“IoTHub-PGH”

Fullpushtime% = 2// Timer to push all values in mins

//Select the Tag Group to publish -> 0 or 1

//Tag must be created and at least set in one of the groups.

GROUPA% = 1

GROUPB% = 1

GROUPC% = 1

GROUPD% = 0

// /usr directory operations to do :

// 1. Generate a Self-Signed certificate using

// openssl req -x509 -sha256 -nodes -days 3650 -newkey rsa:2048 -keyout ReplaceByDeviceID.key -out ReplaceByDeviceID.crt -config openssl.cnf

// 2. Rename the cert and the key with the DeviceID (.crt and .key)

// 3. Upload the self-signed cert + the key + the baltimoreCA certificate to the /usr

// 4. Start the script -> You should see some “PUBLISH…” logs in the console.

// 5. Do not forget to select Run > Autorun in order to have the script running at boot

//################"END CONFIGURATION ##############

//Read number of Tags

NB%= GETSYS PRG,“NBTAGS”

DIM a(NB%,2)

//Start “Try to Connect” timer

Goto “MqttCONNECT”

MqttCONNECT:

MQTT “Open”,DeviceId$,IotHubName$ + “.azure-devices.net”

Mqtt “SetParam”,“Port”,“8883”

MQTT “setparam”, “log”, “1”

MQTT “setparam”, “keepalive”, “20”

MQTT “setparam”, “TLSVERSION”, “tlsv1.2”

MQTT “setparam”, “PROTOCOLVERSION”, “3.1.1”

MQTT “setparam”, “cafile”,"/usr/BaltimoreCyberTrustRoot.pem"

MQTT “setparam”, “CertFile”,"/usr/"+DeviceId$+".crt"

MQTT “setparam”, “KeyFile”,"/usr/"+DeviceId$+".key"

Mqtt “SetParam”,“Username”,IotHubName$+ “.azure-devices.net/”+DeviceId$+"/api-version=2016-11-14"

Mqtt “SetParam”,“Password”,“HostName=”+IotHubName$+";DeviceID="+DeviceId$+";x509=true"

Mqtt “Connect”

//IF No error --> Connected --> Disable Retry timer

ONMQTTSTATUS “GOTO IsConnected”

END

IsConnected:

//Record the Tag ONCHANGE events into an array.

//Allows to post only values that have changed

MQTTstatus@ = MQTT(“STATUS”)

FOR i% = 0 TO NB%-1

k%=i%+1

SETSYS Tag, “load”,-i%

a(k%,1)=-i%

a(k%,2) = 0

GroupA$= GETSYS TAG,“IVGROUPA”

GroupB$= GETSYS TAG,“IVGROUPB”

GroupC$= GETSYS TAG,“IVGROUPC”

GroupD$= GETSYS TAG,“IVGROUPD”

IF GroupA$ = “1” And GROUPA%= 1 THEN Onchange -i%, “a(”+ STR$ k%+",2)= 1" ENDIF

IF GroupB$ = “1” And GROUPB%= 1 THEN Onchange -i%, “a(”+ STR$ k%+",2)= 1" ENDIF

IF GroupC$ = “1” And GROUPC%= 1 THEN Onchange -i%, “a(”+ STR$ k%+",2)= 1" ENDIF

IF GroupD$ = “1” And GROUPD%= 1 THEN Onchange -i%, “a(”+ STR$ k%+",2)= 1" ENDIF

NEXT i%

//ONTIMER 1,“goto MqttPublishAllValue”

TSET 1,Fullpushtime%

FirstScan% = 0

Print “first scan 0”

END

GasUsage5Mins:

//Kiln gas usage

TTP4_KIL_GasUsage5Mins@ = TTP4_KIL_GasTotalM3@-TTP4_KIL_GasUsageTotalLast@

TTP4_KIL_GasUsageTotalLast@ = TTP4_KIL_GasTotalM3@

TTP5_KIL_GasUsage5Mins@ = TTP5_KIL_GasTotalM3@-TTP5_KIL_GasUsageTotalLast@

TTP5_KIL_GasUsageTotalLast@ = TTP5_KIL_GasTotalM3@

END

//publish all tags

MqttPublishAllValue:

Print “publish”

counter%=0

json$ = ‘{’

FOR i% = 0 TO NB% -1

SETSYS Tag, “load”,-i%

i$= GETSYS TAG,“Name”

GroupA$= GETSYS TAG,“IVGROUPA”

GroupB$= GETSYS TAG,“IVGROUPB”

GroupC$= GETSYS TAG,“IVGROUPC”

GroupD$= GETSYS TAG,“IVGROUPD”

IF GroupA$ = “1” And GROUPA%= 1 THEN json$ = json$ + ‘"’ + i$+ ‘":’+STR$ GETIO i$ + ‘,’: counter% = counter% +1 ENDIF

IF GroupB$ = “1” And GROUPB%= 1 THEN json$ = json$ + ‘"’ + i$+ ‘":’+STR$ GETIO i$ + ‘,’: counter% = counter% +1 ENDIF

IF GroupC$ = “1” And GROUPC%= 1 THEN json$ = json$ + ‘"’ + i$+ ‘":’+STR$ GETIO i$ + ‘,’: counter% = counter% +1 ENDIF

IF GroupD$ = “1” And GROUPD%= 1 THEN json$ = json$ + ‘"’ + i$+ ‘":’+STR$ GETIO i$ + ‘,’: counter% = counter% +1 ENDIF

NEXT i%

json$ = json$ + ‘“time”: "’+ @GetTime$() +’"’

json$ = json$ + ‘}’

STATUS% = MQTT(“STATUS”)

//Is Connected

If (STATUS% = 5) Then

Print STR$ counter% + " tags selected and published"

LOGEVENT STR$ counter% + " tags selected and published"

MQTT “PUBLISH”,“devices/”+DeviceID$+"/messages/events/",json$, 0, 0

GOTO “Label1”

Else

Print “Not connected (” + STR$ STATUS% + “)”

Logevent “Not connected (” + STR$ STATUS% + “)”, 50

Goto “MqttCONNECT”

//Endif

Label1:

//Reset Total after published at 2355hrs

If(TTP4_KIL_ResetGasTotal@ = 1) Then

GoTo “GasUsageTotalReset”

Else

TTP4_KIL_ResetGasTotal@ = 0

Endif

IF TTP4_KIL_GasUsageTotalLast@ > TTP4_KIL_GasTotalM3@ THEN

TTP4_KIL_GasUsageTotalLast@ = 0

ENDIF

IF TTP5_KIL_GasUsageTotalLast@ > TTP5_KIL_GasTotalM3@ THEN

TTP5_KIL_GasUsageTotalLast@ = 0

ENDIF

End

CheckMQTT:

MQTTstatus@ = MQTT(“STATUS”)

//PRINT “CheckMQTT (” + STR$ MQTTstatus@")"

IF MQTTstatus@ = 4 THEN

Print “Status = 4”

Goto “MqttCONNECT”

ENDIF

END

Totalkwh:

TTP4_EXT_ExtTotalkwh@ = TTP4_EXT_Extkwh@ + TTP4_EXT_ExtMwh@*1000

TTP4_EXT_MixerTotalkwh@ = TTP4_EXT_Mixerkwh@ + TTP4_EXT_MixerMwh@*1000

GOTO “CheckMQTT”

End

MidNight:

TSET 3,40

//Reset VSD’s kwh/mwh

TTP4_EXT_MixerEnergyMeterReset@=1

TTP4_EXT_ExtEnergyMeterReset@=1

TTP4_DEH_DataReset@=1

TTP4_EXT_LoadCellsReset@=1

TTP5_EXT_LoadCellsReset@=1

TTP4_KIL_ResetGasTotal@ = 1

LOGEVENT “Reset done VSD’s kwh”

Label22:

If Not TGET 3 Then

GoTo Label22

Else

TTP4_EXT_MixerEnergyMeterReset@=0

TTP4_EXT_ExtEnergyMeterReset@=0

TTP4_DEH_DataReset@=0

TTP4_EXT_LoadCellsReset@=0

TTP5_EXT_LoadCellsReset@=0

End

GasUsageTotalReset:

TTP4_KIL_GasUsageTotalLast@ = 0

TTP4_KIL_GasTotalM3@ = 0

TTP4_KIL_ResetGasTotal@ = 0

TTP5_KIL_GasUsageTotalLast@ = 0

TTP5_KIL_GasTotalM3@ = 0

TTP5_KIL_ResetGasTotal@ = 0

Print “Gas Usage Total Reset done”

LOGEVENT “Gas Usage Total Reset done”

End

End

ReadTime:

Function GetTime$()

$a$ = Time$

$GetTime$ = $a$(7 To 10) + “-” + $a$(4 To 5) + “-” + $a$(1 To 2) + " " +$a$(12 To 13) + “:” +$a$(15 To 16)+":"+$a$(18 To 19)

//

H% = Val($a$(12 To 13))

M% = Val($a$(15 To 16))

D% = Val($a$(1 To 2))

Z% = Val($a$(4 To 5))

Y% = Val($a$(7 To 10))

Print “Hour:”;H%

Print “Min:”;M%

Print “Date:”;D%

Print “Month:”;Z%

Print “Year:”;Y%

TTP5_EXT_Set_Hour@=H%

TTP5_EXT_Set_Mins@=M%

EndFn

End

Rem — eWON user (end)

End

Rem — eWON end section: Init Section

Regards

image001.png

image002.jpg

Hello,

I can help you modify the script but unfortunately we can only create custom scripts as part of a paid service. If you want to have the values from tags in group C behave as strings, you can call these values the following way

new_string_value$ = STR$ yourtagname@