This is a detailed guide to the functions available when configuring action flows in ASTERIA’s Gravio (Node Computing Platform). These functions can be used in the right-hand expressions of Pre Mappings and Post Mappings, as well as in trigger expressions.
| Function Name | Arguments | Description | Example |
|---|---|---|---|
| Len | Len(s) | Returns the length (in bytes) of a string. For arrays or Objects, returns the number of elements. | Len(“abc012漢字”) -> 11 |
| Contains | Contains(s, substr) | Returns a Bool indicating whether substr is within s | Contains(“abc012漢字”, “漢字”) -> true |
| RuneCount | RuneCount(s) | Returns the number of characters in string s | RuneCount(“abc012漢字”) -> 8 |
| HasPrefix | HasPrefix(s, prefix) | Returns a Bool indicating whether s begins with prefix | HasPrefix(“https://www.asteria.com/”, “https://”) -> true |
| HasSuffix | HasSuffix(s, suffix) | Returns a Bool indicating whether s ends with suffix | |
| FirstIndex | FirstIndex(s, substr) | Returns the position of the first occurrence of substr in s. Returns -1 if not found | FirstIndex(“abc012漢字”, “漢字”) -> 6 |
| Join | Join(a, sep) | Joins array elements with sep between them into a single string | Join([“abc”,”def”], “-“) -> “abc-def” |
| LastIndex | LastIndex(s, substr) | Returns the position of the last occurrence of substr in s. Returns -1 if not found | |
| Repeat | Repeat(s, count) | Returns a string with s repeated count times | Repeat(“abc012漢字”, 3) -> “abc012漢字abc012漢字abc012漢字” |
| Replace | Replace(s, old, new[, n]) | Replaces occurrences of old with new in s up to n times. When n is less than 0, replaces all occurrences (default is -1) | |
| Split | Split(s, sep[, n]) | Splits s into an array of at most n elements using sep. When n is less than 0, splits all occurrences (default is -1) | Split(“a,b,c”, “,”) -> [“a”, “b”, “c”] |
| ToLower | ToLower(s) | Converts s to lowercase | |
| ToUpper | ToUpper(s) | Converts s to uppercase | |
| Trim | Trim(s[, cutset]) | Returns s with characters in cutset removed from start and end. Default cutset is whitespace | Trim(“ abc “) -> “abc” |
| TrimLeft | TrimLeft(s[, cutset]) | Returns s with characters in cutset removed from start. Default cutset is whitespace | |
| TrimRight | TrimRight(s[, cutset]) | Returns s with characters in cutset removed from end. Default cutset is whitespace | |
| TrimPrefix | TrimPrefix(s, prefix) | Returns s without the prefix if it begins with prefix, otherwise returns s unchanged | TrimPrefix(“https://www.asteria.com”, “https://”) -> “www.asteria.com” |
| TrimSuffix | TrimSuffix(s, suffix) | Returns s without the suffix if it ends with suffix, otherwise returns s unchanged | |
| JSONPath | JSONPath(path, s) | Returns a value as a string from s specified by path | JSONPath(“$.store.book[*].author”, cv.Payload) |
| Sprintf | Sprintf(format, s) | Returns a formatted string. Format can include conversion specifiers with optional flags, width, and precision following % | Sprintf(“Message count: %d”, ToInt(cv.Payload)) |
| IFS | IFS(condition1, value1[, condition2, value2, …]) | Evaluates conditions in order and returns the value of the first matching condition. Using true as a condition ensures a match, so specifying true as the last condition can serve as a default case | IFS(ToFloat(cv.Payload) >= 10, “10 or greater”, true, “less than 10”) |
| Left | Left(s, len) | Returns len characters from the start of s. len counts multibyte characters as single characters | |
| Right | Right(s, len) | Returns len characters from the end of s. len counts multibyte characters as single characters | |
| Mid | Mid(s, start, len) | Returns len characters from position start in s. start begins at 1, and both start and len count multibyte characters as single characters | |
| Substring | Substring(s, start[, end]) | Returns characters from start to end position in s. start/end begin at 0 and count multibyte characters as single characters | |
| Slice | Slice(s[, start[, end]]) | Returns characters from start to end position in s. start/end begin at 0 and count multibyte characters as single characters. Negative values for start/end count from the end |
The JSONPath() function can be used to reference values in JSON-formatted sensor data (@cv.Payload@) or action arguments in trigger conditions (@tv.Data@).
For example, to reference store -> bicycle -> color, you can write:
cv.Payload.store.bicycle.color
Or using JSONPath():
JSONPath("$.store.bicycle.color", cv.Payload)
Syntax Elements for path in JSONPath First Argument:
| Path | Description |
|---|---|
| $ | Root object/element |
| @ | Current object/element |
| . or [] | Child operator |
| .. | Recursive descent |
| * | Wildcard |
| [] | Subscript operator (native array operator) |
| [,] | Union operator (can use alternative names or array indices as a set) |
| [start:end:step] | Array slice operator |
| ?() | Filter (script) expression |
| () | Script expression using underlying script engine |
Examples of path in JSONPath First Argument:
| Example | Description |
|---|---|
| $.store.book[*].author | All authors in book array within store |
| $..author | All authors |
| $.store.* | Book array and bicycle within store |
| $.store..price | All prices within store |
| $..book[2] | Third book |
| $..book[-1:] or $..book[(@.length-1)] | Last book |
| $..book[0,1] or $..book[:2] | First two books |
| $..book[?(@.isbn)] | All books with isbn |
| $..book[?(@.price<10)] | All books with price less than 10 |
| $..* | All nodes/elements |
Returns a formatted string. Format can include conversion specifiers with optional flags, width, and precision.
Conversion Specifiers:
| Specifier | Description |
|---|---|
| %b | Integer in binary |
| %d | Integer in decimal |
| %x %X | Hexadecimal |
| %e %E | Floating-point, scientific notation |
| %f %F | Floating-point, decimal notation |
| %g %G | %e for large exponents, %f otherwise |
| %s | String |
| %% | Literal % |
Flags:
| Flag | Description |
|---|---|
| + | Always show sign |
| - | Left-align |
| 0 | Pad with zeros instead of spaces |
Width and Precision:
| Format | Description |
|---|---|
| %f | Default width and precision |
| %9f | Width 9 |
| %.2f | Precision 2 |
| %9.2f | Width 9, precision 2 |
Examples:
Sprintf("Message count: %d", ToInt(cv.Payload))
Sprintf("Float to 2 decimal places: %.2f", cv.Payload)
The following functions are available:
| Function Name | Arguments | Description |
|---|---|---|
| ToBool | ToBool(a) | Convert to Bool type |
| ToInt | ToInt(a) | Convert to integer type |
| ToFloat | ToFloat(a) | Convert to floating-point type |
| ToString | ToString(a) | Convert to string type |
| ToDate | ToDate(a) | Convert to date type |
| ToBinary | ToBinary(a) | Convert to byte sequence |
| ToJSON | ToJSON(a) | Convert to JSON array or JSON Object type |
The following functions are available:
| Function Name | Arguments | Description | Example |
|---|---|---|---|
| URLPathEscape | URLPathEscape(s) | Escapes s for safe placement in URL path segments | URLPathEscape(“test 1?test2 test3”) -> “test1%3Ftest2%20test3” |
| URLPathUnescape | URLPathUnescape(s) | Unescapes string escaped by URLPathEscape | |
| URLQueryEscape | URLQueryEscape(s) | Escapes s for safe placement in URL query | URLQueryEscape(“test 1?test2 test3”) -> “test1%3Ftest2+test3” |
| URLQueryUnescape | URLQueryUnescape(s) | Unescapes string escaped by URLQueryEscape | |
| MD5 | MD5(b) | Returns MD5 of byte sequence b | |
| SHA1 | SHA1(b) | Returns SHA1 of byte sequence b | |
| SHA256 | SHA256(b) | Returns SHA256 of byte sequence b | |
| BASE64 | BASE64(b[, pad]) | Returns BASE64 of byte sequence b. If pad is true, = padding is added (default is true) | |
| DecodeBASE64 | DecodeBASE64(s[, pad]) | Decodes BASE64 s. If pad is true, interprets as BASE64 with = padding (default is true) | |
| BASE64URL | BASE64URL(b[, pad]) | Returns URL/filename-safe BASE64 of byte sequence b. If pad is true, = padding is added (default is true) | |
| DecodeBASE64URL | DecodeBASE64URL(s[, pad]) | Decodes URL/filename-safe BASE64 s. If pad is true, interprets as BASE64 with = padding (default is true) |
The following functions are available:
| Function Name | Arguments | Description | Example |
|---|---|---|---|
| Now | Now([timezone]) | Returns current date/time | |
| Year | Year(t[, timezone]) | Returns year from date t. If timezone specified, interprets in that timezone | |
| Month | Month(t[, timezone]) | Returns month from date t. If timezone specified, interprets in that timezone | |
| Day | Day(t[, timezone]) | Returns day from date t. If timezone specified, interprets in that timezone | |
| Hour | Hour(t[, timezone]) | Returns hour from date t. If timezone specified, interprets in that timezone | |
| Minute | Minute(t[, timezone]) | Returns minute from date t. If timezone specified, interprets in that timezone | |
| Second | Second(t[, timezone]) | Returns second from date t. If timezone specified, interprets in that timezone | |
| Weekday | Weekday(t[, timezone]) | Returns weekday from date t. If timezone specified, interprets in that timezone (0 is Sunday) | |
| ToLocal | ToLocal(t) | Converts date t to system timezone | |
| ToUTC | ToUTC(t) | Converts date t to UTC | |
| ToTimezone | ToTimezone(t, timezone) | Converts date t to specified timezone | ToTimezone(Now(), “America/New_York”) |
| DateFormat | DateFormat(t, layout) | Converts date t to string using specified layout | DateFormat(Now(), “02 Jan 06 15:04 JST”) |
| DateParse | DateParse(layout, s[, timezone]) | Parses s according to layout and returns date | |
| AddDuration | AddDuration(t, s) | Adds duration s to date t. If s is integer, treats as milliseconds; if string, can specify unit (h=hours, m=minutes, s=seconds, ms=milliseconds, us=microseconds, ns=nanoseconds) | AddDuration(Now(), 100) AddDuration(Now(), “1h”) |
| AddDate | AddDate(t, y, m, d) | Adds specified years y, months m, days d to date t | AddDate(Now(), 0, 0, 7) |
Layout Examples for DateFormat and DateParse:
| Format | Layout |
|---|---|
| Layout | “01/02 03:04:05PM ‘06 +0900” |
| ANSIC | “Mon Jan _2 15:04:05 2006” |
| UnixDate | “Mon Jan _2 15:04:05 JST 2006” |
| RubyDate | “Mon Jan 02 15:04:05 +0900 2006” |
| RFC822 | “02 Jan 06 15:04 JST” |
| RFC822Z | “02 Jan 06 15:04 +0900” |
| RFC850 | “Monday, 02-Jan-06 15:04:05 JST” |
| RFC1123 | “Mon, 02 Jan 2006 15:04:05 JST” |
| RFC1123Z | “Mon, 02 Jan 2006 15:04:05 +0900” |
| RFC3339 | “2006-01-02T15:04:05Z07:00” |
| RFC3339Nano | “2006-01-02T15:04:05.999999999Z07:00” |
| Generic | “20060102” |
Example:
Creating a filename with the date from 7 days ago:
DateFormat(AddDate(Now("Asia/Tokyo"),0,0,-7),"20060102")+".CSV"
The following functions are available:
| Function Name | Arguments | Description |
|---|---|---|
| Env | Env(s) | Returns environment variable |
The following functions are available:
| Function Name | Arguments | Description | Example |
|---|---|---|---|
| RegexMatch | RegexMatch(re, s) | Returns Bool indicating whether regular expression re matches s | RegexMatch(“G.*o”, “Gravio Hub Kit”) -> true |
| RegexFind | RegexFind(re, s) | Returns first substring matching regular expression re | RegexFind(“i.”, “Gravio HubKit”) -> “io” |
| RegexFindSubmatch | RegexFindSubmatch(re, s) | Returns array of first match and any subexpressions in parentheses | RegexFindSubmatch(“(G.o)(H.t)”, “Gravio HubKit”) -> [“Gravio HubKit”, “Gravio”, “HubKit”] |
| RegexFindAll | RegexFindAll(re, s[, n]) | Returns array of all substrings matching regular expression re | RegexFindAll(“i.”, “Gravio Hub Kit”) -> [“io”, “it”] |
| RegexReplace | RegexReplace(re, s, repl) | Returns s with matches of re replaced by repl. Can use $1 etc. in repl for subexpressions | |
| UUID | UUID([sep]) | Returns UUID string. sep is separator (default is empty string) |
The following functions are available:
| Function Name | Arguments | Description |
|---|---|---|
| Abs | Abs(v) | Returns absolute value |
| Acos | Acos(v) | Returns arc cosine |
| Acosh | Acosh(v) | Returns inverse hyperbolic cosine |
| Asin | Asin(v) | Returns arc sine |
| Asinh | Asinh(v) | Returns inverse hyperbolic sine |
| Atan | Atan(v) | Returns arc tangent |
| Atan2 | Atan2(y, x) | Returns arc tangent of y/x |
| Atanh | Atanh(v) | Returns inverse hyperbolic tangent |
| Cbrt | Cbrt(v) | Returns cube root |
| Ceil | Ceil(v) | Returns ceiling (smallest integer >= v) |
| Copysign | Copysign(x, y) | Returns value with magnitude of x and sign of y |
| Cos | Cos(v) | Returns cosine |
| Cosh | Cosh(v) | Returns hyperbolic cosine |
| Erf | Erf(v) | Returns error function |
| Erfc | Erfc(v) | Returns complementary error function |
| Exp | Exp(x) | Returns e^x |
| Exp2 | Exp2(x) | Returns 2^x |
| Expm1 | Expm1(x) | Returns e^x - 1 |
| Floor | Floor(v) | Returns floor (largest integer <= v) |
| Hypot | Hypot(x, y) | Returns Sqrt(xx + yy) |
| Inf | Inf(sign) | Returns positive infinity if sign>=0, negative infinity if sign<0 |
| IsInf | IsInf(v, sign) | Returns whether v is infinity (considering sign) |
| IsNaN | IsNaN(v) | Returns whether v is Not a Number |
| Log | Log(v) | Returns natural logarithm |
| Log10 | Log10(v) | Returns base-10 logarithm |
| Log1p | Log1p(v) | Returns natural logarithm of 1 plus argument |
| Log2 | Log2(v) | Returns base-2 logarithm |
| Max | Max(v1[, v2, v3, …]) | Returns maximum value |
| Min | Min(v1[, v2, v3, …]) | Returns minimum value |
| NaN | NaN() | Returns Not a Number |
| PI | PI() | Returns π |
| Pow | Pow(x, y) | Returns x^y |
| Round | Round(v[, n]) | Returns v rounded to nearest integer. If n specified, rounds to n decimal places |
| Signbit | Signbit(v) | Returns whether v is negative |
| Sin | Sin(v) | Returns sine |
| Sinh | Sinh(v) | Returns hyperbolic sine |
| Sqrt | Sqrt(v) | Returns square root |
| Random | Random([max]) | Returns random number. Without arguments, returns float >= 0 and < 1. With max, returns integer >= 0 and < max |
| Tan | Tan(v) | Returns tangent |
| Tanh | Tanh(v) | Returns hyperbolic tangent |
| Trunc | Trunc(v[, n]) | Returns integer part of v. If n specified, truncates to n decimal places |
| Degrees | Degrees(v) | Converts radians to degrees |
| Radians | Radians(v) | Converts degrees to radians |
| FtoC | FtoC(v) | Converts Fahrenheit to Celsius |
| CtoF | CtoF(v) | Converts Celsius to Fahrenheit |
| GtoLBM | GtoLBM(v) | Converts grams to pounds |
| LBMtoG | LBMtoG(v) | Converts pounds to grams |
| GtoOZM | GtoOZM(v) | Converts grams to ounces |
| OZMtoG | OZMtoG(v) | Converts ounces to grams |
| MtoIN | MtoIN(v) | Converts meters to inches |
| INtoM | INtoM(v) | Converts inches to meters |
| MtoFT | MtoFT(v) | Converts meters to feet |
| FTtoM | FTtoM(v) | Converts feet to meters |