User guide

BB2-7040 User Guide – Rev. 1.2 Page 42
A program code snippet that will send the IS command to a remote device and print its reply is as follows:
$api = "Remote,C9,00:13:A2:00:40:2D:37:7A,Y,IS"
print #1, $api
timeout 10
line input #1, $r
print $r, "\n"
The format for the API string is as follows:
"Local,FF,CC,hhhhhh..hh"
"Remote,FF,Vnn,Y,CC,hhhhhh..hh"
"Remote,FF,00:00:00:00:00:00:00:00,Y,CC,hhhhhh..hh"
"Raw,hhhhhh..hh"
The first comma separated field must be one of Local, Remote, or Raw. The FF must be a frame number, in
hexadecimal, in the range of 201-255. Frame numbers outside this range will not be routed back to Basic. The next field,
for Remote API only, is a device designation, either a 64-bit device address formatted as illustrated, or a device number
Vnn to look up on the ZigBee Client Devices page where nn is 1 to 50. Following the device, again in Remote API only,
is a field which must be either Y or N. If 'Y', then the AC immediate bit is sent (accept changes). For Local or Remote
API, the CC field is the 2-character AT command to be sent. In all cases, the last field(s) represent the data payload
(which can be omitted for API commands with no parameters).
The hhhhhh.hhh may actually be one or more fields. For each comma separated field following CC, the value will be
interpreted as one or more bytes of data in ASCII hexadecimal form, or be interpreted as multiple bytes of an ASCII
string with one byte per character. If the first character of the string is not a hexadecimal digit, it will be taken as an
ASCII string. If the first character in the comma separated field is a hexadecimal digit, the string will be parsed as
hexadecimal data with one packet byte per two ASCII characters. Note that this interpretation differs from the API web
page behavior.
An example of a string that will set the Network Interface name of a remote device is as follows:
$api = "Remote,c9,00:13:a0:00:4d:45:fa:af,Y,NI,Temp Sensor 1
For a complete discussion of the API command set, refer to the Digi International/Maxstream XBee PRO documentation.
The following program example sends an on-demand sample command to a Digi SmartPlug and parses a data value from
the reply.
FUNCTION stuff(a)
if (a > 255) then
$h = "FF"
else
$k = hex(a)
if len($k) = 1 then
$h = "0" & $k
else
$h = $k
end if
end if
stuff = $h
END FUNCTION
FUNCTION unstuff($v)
e = 0
for i = 1 to 4
c = asc(mid($v,i,1))
if c > 57 then c = c - 7