Device-XBee-API
view release on metacpan or search on metacpan
once a command reply is received, however there are scenarios where
this can not be done (generally those that involve local or remote AT
commands, sleeping/offline nodes, etc).
Normally, when no frame IDs are available but one is needed, the module
will die with an error and the send attempt will be aborted. This
condition could be trapped by the caller (via eval) to retry later, or
could be treated as fatal.
With this flag set, instead of dieing, the oldest frame ID will be
reused. This will help work around any issues with frame ID's
"leaking", but could cause odd behavior in cases where all outstanding
frame IDs are still in use. This option should be used with caution.
[4malloc_frame_id_func[24m [4m=head3[24m [4mfree_frame_id_func[0m
Optional code references to functions used to allocate and free frame
IDs. If both are specified they will be called in place of the internal
frame ID tracking functions allowing the user more control over how
frame IDs are generated. The alloc_frame_id_func will be called when a
new frame ID is needed and will be passed as a parameter the reference
to the Device:XBee::API object and must return an integer between 1 and
255 inclusive. The free_frame_id_func will be called when the reply
frame is received and the frame ID is no longer needed and will be
passed as parameters a reference to the Device::XBee::API obect and the
frame ID to be freed.
See auto_reuse_frame_id for details on how this module uses frame IDs.
[4mapi_mode_escape[0m
Optional. If set to a true value, the module will automatically escape
outgoing data and un-escape incoming data for use with XBee API mode 2.
Defaults to false.
See the XBee datasheet for details on API mode 2 and escaped
characters.
[1mat[0m
Send an AT command to the module. Accepts two parameters, the first is
the AT command name (as two-character string), and the second is the
expected data for that command (if any). Data will be converted to a
string before it is sent, so integers must first be packed before
sending. See the XBee datasheet for a list of supported AT commands and
expected data for each.
Returns the frame ID sent for this packet. This method does not wait
for a reply from the XBee, as the expected reply is dependent on the AT
command sent. To retrieve the reply (if any), call one of the rx
methods.
If no reply is expected, the caller should immediately free the
returned frame ID via free_frame_id to prevent frame ID leaks.
[4mExample[0m
my $at_frame_id = $api->at( 'AO', pack( 'C', 1 ) );
[1mremote_at[0m
Send an AT command to a remote module. Accepts three parameters: a
hashref with endpoint addresses, command options, frame_id; the AT
command name (as two-character string); and the third as the expected
data for that command (if any) as a string. See the XBee datasheet for
a list of supported AT commands and expected data for each.
Endpoint addresses should be specified as a hashref containing the
following keys:
sh The high 32-bits of the destination address.
sl The low 32-bits of the destination address.
na The destination network address.
apply_changes
If set, changes are applied immediately. If not set, an AT AC
command must be sent separately before the changes will take
effect.
Note: The following command options are not supported on all XBee
devices.
disable_ack
If set, the remote node will not reply with an ack.
extended_xmit_timeout
If set, the exteded transmission timeout will be used.
Returns the frame ID sent for this packet. To retrieve the reply (if
any), call one of the rx methods. If no reply is expected, the caller
should immediately free the returned frame ID via free_frame_id to
prevent frame ID leaks.
[4mExample[0m
The following example disables the blinking association light on the
XBee with a constant on.
if (
!$api->remote_at(
{ sh => 1234567, sl => 1234567890, apply_changes => 1 },
'D5', "\x1"
)
) {
die "Transmit failed!";
}
my $rx = $api->rx();
warn Dumper( $rx );
[1mtx[0m
Sends a transmit request to the XBee. Accepts three parameters, the
first is the endpoint address, the second is a scalar containing the
data to be sent, and the third is an optional flag (known as the async
flag) specifying whether or not the method should wait for an
acknowledgement from the XBee.
Endpoint addresses should be specified as a hashref containing the
following keys:
sh The high 32-bits of the destination address.
sl The low 32-bits of the destination address.
na The destination network address. If this is not specified, it will
default to XBEE_API_BROADCAST_NA_UNKNOWN_ADDR.
If both sh and sl are missing or the parameter is undefined,, they will
default to XBEE_API_BROADCAST_ADDR_H and XBEE_API_BROADCAST_ADDR_L.
The meaning of these addresses can be found in the XBee datasheet.
Note: In the future, a Device::XBee::API::Node object will be an
acceptable parameter.
If the async flag is not set, the method will wait for an
acknowledgement packet from the XBee. Return values depend on calling
context. In scalar context, true or false will be returned representing
transmission acknowledgement by the remote XBee device. In array
context, the first return value is the delivery status (as set in the
transmit status packet and documented in the datasheet), and the second
is the actual transmit status packet (as a hashref) itself.
If the async flag is set, the method will not wait for an
acknowledgement packet and the tx frame ID will be returned. The caller
will need to then receive the transmit status packet (via one of the rx
methods) and free the frame ID (via free_frame_id) manually.
No retransmissions will be attempted by this module, but the XBee
device itself will likely attempt retransmissions as per its
configuration (and subject to whether or not the packet was a
"broadcast").
[1mrx[0m
Receives a packet from the XBee module. This packet may be a
transmission from a remote XBee node or a control packet from the local
XBee module.
If no packet is received before the timeout period expires, undef is
returned.
Returned packets will be as a hashref of the packet data, broken out by
key for easy access. Note, as this module is a work in progress, not
every XBee packet type is supported. Callers should check the
"api_type" key to determine the type of the received packet. When
possible, packed integers will be unpacked into the "data_as_int" key.
If no packed integer is found this key will not be present. If
unpacking is not possible (due to an unknown packet type, etc), the
value will be undef.
Accepts a single parameter, a flag indicating the received frame ID
should NOT be freed automatically. See rx_frame_id for why you might
want to use this flag (generally, cases when you expect multiple
packets to arrive with the same frame ID).
( run in 0.735 second using v1.01-cache-2.11-cpan-39bf76dae61 )