SMS writing tag and line breaking

Hi all,

As described in “writing tag in ewon with sms” written by krishnan on 24 August, I need to implement this solution on my flexy205. The difference is that I need to do this for two Tag instead of only one.
For example:
When I send a SMS with TIME=30 I need to set Tag Time@=30
When I send a SMS with PERIOD=90 I need to set Tag Period@=90

It is possible to do this or is possible only for a single Tag?

Other question is: is possible to insert a line breaking when I send a SMS? Just to format the text of the SMS.

Thank you in advance,

I found the solution to the second question.
Is in rg-0006-01-en-programming-reference-guide.pdf Pag.24.
CHR$ E1
Where E1 is, in my case, the number 13 (ASCII code for Carriage Return)

@Luca_Bartolomei

It is definitely possible to do what you are trying to do though you will need to use slightly more specific BASIC scripting to parse and extract the pertinent information.

Below are a few different ways you can do this. The options range from setting a single tag by name to setting multiple tags at once.


Setting a single tag with name and value:

In this example we are basically using what you had above. When you send a text message in the form of Tagname (delimiter) value, it will write that tags value. I have written this example to be dynamic in the sense that you can customize the delimiter being used to separate the values (you have an = sign but we can update that to be a -, : or other.


NOTE: This is a Flexy only script as it uses functions

FUNCTION writeTag($smsBody$)
    delimiter$ = "=" // Assign your delimiter Eg: Name=Value or Name:Value
    indexOfDelimiter% = INSTR 1, $smsBody$, delimiter$ // Find the index of your delimiter to split between name and value
    tagName$ = $smsBody$(1 TO (indexOfDelimiter% - 1)) // Get the tag name
    tagValue = VAL($smsBody$((indexOfDelimiter% + 1) TO LEN($smsBody$))) // Get the tag value
    SETIO tagName$, tagValue // Assign the new value to the tag. 
ENDFN


Usage with SMS:
INIT Section:
ONSMS "GOTO HSms"

HSms:
    a% = GETSYS PRG, "SmsRead"
    IF a% <> 0 THEN
        message$ = GETSYS PRG, "smsmsg"
        @writeTag(message$)
    ENDIF
END

Updating Multiple Tags (Single Message):

Now, let’s say instead of sending 4 text messages to update 4 tags, you’d prefer to simply send several tags at once. In this scenario we can basically send a bulk SMS with multiple tags and then have the eWON parse and assign the tag values.

FUNCTION smsTagAssign($smsBody$)
    $tagDelimiter$ = "," // Delimiter to specify separation of tag data
    $delimiter$ = "=" // Delimiter to specify tag name vs value
    $tagStr$ = "" // Placeholder tag
    $tagDelimiterIndex% = INSTR 1, $smsBody$, $tagDelimiter$ // Get the first index of the tag delimiter to extract tag
    
    // If the tag delimiter is not a zero, that means we have more than one tag remaining
    // As the delimiter was found. If so, extract the next tag.
    // If the value is a zero, we are at the last tag element.
    IF $tagDelimiterIndex% <> 0 THEN
        $tagStr$ = $smsBody$(1 TO ($tagDelimiterIndex% - 1))
    ELSE
        $tagStr$ = $smsBody$
    ENDIF
   
    $tagValDelimiter% = INSTR 2, $tagStr$, $delimiter$ // Index of the tag value and name separator
    $tagName$ = $tagStr$(1 TO ($tagValDelimiter% - 1)) // Extract the tag name
    $tagValue = VAL($tagStr$(($tagValDelimiter% + 1) TO LEN($tagStr$))) // Extract the tag value
    SETIO $tagName$, $tagValue // Assign the value to the tag
    
    // If the delimiter is anything other than a 0 it means we have more tags
    // to process so recursively call this function until the end. 
    IF $tagDelimiterIndex% <> 0 THEN
        @smsTagAssign($smsBody$(($tagDelimiterIndex% + 1) TO LEN($smsBody$)))
    ENDIF
ENDFN

Usage with SMS:

INIT Section:
ONSMS "GOTO HSms"

HSms:
    a% = GETSYS PRG, "SmsRead"
    IF a% <> 0 THEN
        message$ = GETSYS PRG, "smsmsg"
        @smsTagAssign(message$)
    ENDIF
END

Wow… Amazing reply… Thank you so much!
I tried to implement first solution but I’m stopped on IF because I already have some checks.
Please see below:

Hsms:
a%=Getsys Prg,"SmsRead"
If (a%<>0) Then
  h$=GETSYS PRG,"smsmsg"
  l$ = g$+",gsm,0"
  k$=""
   If (h$="START" Or h$="Start" Or h$="start") Then 
     COM_START@=1
     k$="Command:"+h$
   Endif
   If (h$="STOP" Or h$="Stop" Or h$="stop") Then 
     COM_STOP@=1
     k$="Command:"+h$
   Endif
   If (h$="RESET" Or h$="Reset" Or h$="reset") Then 
     COM_RESET@=1
     k$="Command:"+h$
   Endif
	PRINT k$
   IF (LEN k$)>1 THEN
      SENDSMS l$,k$
   ELSE
      SENDSMS l$,"Unknown Command"
   ENDIF
   a%=0
   Goto HSms
Endif
End

If I want to check if in h$ there is a delimiter, how can I do? Is present a “like” command?

@Luca_Bartolomei

You can easily check for a delimiter by using INSTR. INSTR basically checks in the string for a specific delimiter.

Example:

test$ = "HelloThere=Jordan"
d$ = "=" REM Here my delimiter is = sign. So if I want to check for it I would do: 
i% = INSTR 1,  test$, d$

IF i% > 0 THEN
    REM The delimiter exists because our index is greater than 0
ELSE
    REM The delimiter does NOT exist because the index of the delimiter is a 0
ENDIF