- API Reference Guide
- Functions
- __init__
- accept_sniffer
- accept_tcp
- add_rpc_func
- allow_serial_sharing
- cancel_upgrade
- close_all_serial
- close_serial
- connect_tcp
- data_mode
- directed_mcast_rpc
- disconnect_tcp
- dmcast_rpc
- get_info
- load_nv_param
- local_addr
- loop
- mcast_data_mode
- mcast_rpc
- open_serial
- poll
- poll_internals
- replace_rpc_func
- rpc
- rpc_alternate_key_used
- rpc_source_addr
- rpc_source_interface
- rpc_use_alternate_key
- save_nv_param
- set_hook
- start_sniffer
- stop_accepting_sniffer
- stop_accepting_tcp
- stop_sniffer
- traceroute
- upgrade_firmware
- Constants and Enumerations
- NV Parameters
- Authentication Realms
- Hooks
- Exceptions
- Sniffer Descriptors
- Functions
- Release Notes
Functions¶
__init__¶
-
class
Snap
(license_file=None, nvparams_file=None, funcs=None, scheduler=None, addr=None, rpc_handler=None)¶ Initializes a SNAPconnect instance.
Parameters: - license_file – The full path to a SNAPconnect license file. The default value of None indicates that the license file is named License.dat and is located in the present working directory, which will typically be the same directory that holds your Python code files. For the free evaluation license, no License.dat is needed. If SNAPconnect cannot find License.dat in the current directory, it will fall back to the free evaluation license.
- nvparams_file – The full path to a SNAPconnect NV parameters file. The default value of None indicates that the file is named nvparams.dat and is located in the present working directory, which will typically be the same directory that holds your Python code files.
- funcs – The callable functions for this instance to expose to the SNAP network. If you do not want to
expose any callable functions to the SNAP network, set funcs to an empty dictionary
{}
. Any given function dictionary should only be passed to a single instance of SNAPconnect. - scheduler – Internally used by SNAPconnect
- addr – The SNAP address to use from the license file. If nothing is specified, SNAPconnect uses the first address in the license file. The format of this parameter is a three-byte string, e.g., x76 xa2 x5c represents SNAP address 76.A2.5C.
- rpc_handler – Internally used by SNAPconnect
Raises: - RuntimeError(“Non-licensed address provided”) – For example, the License.dat file is for address 11.22.33 but you have asked to “be” address 22.44.66.
- RuntimeError(“Invalid license found”) – The license file specified is invalid. If you don’t specify a license file name, the default of “License.dat” is assumed.
- IOError(“Unable to load NV params file – <filename>”) : The expected NV parameters file could not be loaded. If you specify a file, it is required to be present and valid. If you do not specify a file, then the default of “nvparams.dat” is assumed, and an empty file with default values will be generated if the file is not found
- RuntimeError(“Unable to determine callable functions”) – You must provide a dictionary of callable functions, even if it is an empty one, or None to indicate that all functions in your application are callable.
- ImportError(“Unable to find PyCrypto library required for AES support”) – You have enabled AES-128 encryption, but you have not provided the required PyCrypto library.
- ValueError(“Unknown encryption type specified – <encryption type>”) : Valid choices are NONE (0), AES128 (1), and BASIC (2).
accept_sniffer¶
-
Snap.
accept_sniffer
()¶ Start allowing remote sniffer connections over TCP.
Returns: None Raises: RuntimeError(“You must be accepting TCP connections to call accept_sniffer()”) – You must make a call to accept_tcp()
prior to accepting remote sniffer connections over TCP.Note
Incoming remote sniffer connections will be using a different realm for the authentication function than regular TCP connections. See the Authentication Realms section for more details.
accept_tcp¶
-
Snap.
accept_tcp
(auth_info=<function server_auth>, ip='', port=48625, tcp_keepalives=False, forward_groups=None)¶ Start listening for and accepting remote IP connections.
Parameters: - auth_info – The function to call when authenticating remote credentials (defaults to public credentials). If providing a custom function to call, it should have the signature “server_auth(realm, username)” where the two string arguments are supplied by the connecting instance and the function returns the appropriate password. See the Authentication Realms section for more details on the realm parameter.
- ip – The IPv4 address to listen on for remote connections (default all addresses)
- port – The IP port number to listen on for remote connections (default 48625)
- tcp_keepalives – Enable or disable TCP keepalives (default False)
- forward_groups – Multi-cast groups to forward onward through this interface; the default value of None
indicates that the interface will use the value specified in NV6 - Multicast Forward Groups. The
forward_groups
parameter can be important if you have a radio network that uses multicast traffic, but you do not want those packets to propagate over the Internet.
Returns: None
Raises: ValueError(“auth_info is not callable”) – Parameter
auth_info
can be unspecified (in which case the defaultserver_auth()
routine is used), but if you provide a value for this parameter it must be a function that SNAPconnect can invoke.Note
Establishment of an actual connection can trigger a
hooks.HOOK_SNAPCOM_OPENED
event. If the connection later goes down it can trigger ahooks.HOOK_SNAPCOM_CLOSED
event.
add_rpc_func¶
-
Snap.
add_rpc_func
(rpc_func_name, rpc_func, allow_alternate_key=False)¶ Adds a function to the existing “RPC dictionary”.
Parameters: - rpc_func_name – This is the name the new function will be callable by via RPC. It does not have to match the actual function’s name.
- rpc_func – This must be a Python callable and represents the actual function to be invoked.
- allow_alternate_key – Defaults to False if unspecified, but if True adds the specified rpc_func_name to a
“whitelist” of functions that can also be remotely invoked with alternate encryption (an alternate
encryption key). See also function
rpc_alternate_key_used()
, which is how you can detect that this has actually taken place.
Returns: This function returns True if the function was successfully added to the RPC dictionary. It returns False if the function could not be added because one with the same name already exists in the dictionary. (You can use this function to add a new function but you cannot use it to replace an existing function.)
Note
When the SNAPconnect instance is first instantiated by your application code, you pass it a Python dictionary containing all of the function names that you want to be able to invoke from other SNAP nodes. This function lets you add additional functions to that dictionary after-the-fact.
allow_serial_sharing¶
-
static
Snap.
allow_serial_sharing
(enabled=True)¶ Enable or disable sharing of serial connections between SNAPconnect instances.
If serial connection sharing is enabled, all open serial connections will be shared when a new SNAPconnect instance is constructed. Serial connections opened after a SNAPconnect instance is constructed will not be shared. Shared serial connections will be able to receive broadcast messages and route for all connected SNAPconnect instances.
Example
This is a static function on the Snap class and should be invoked like this:
snap.Snap.allow_serial_sharing(True)
Parameters: enabled – True if serial connection sharing should be enabled or False if it should be disabled. This parameter is shared across all SNAPconnect instances. This defaults to True. Returns: None Note
SNAPconnect instances must be running in the same Python interpreter session in order to share serial connections. SNAPconnect instances running in different Python interpreter sessions will not be able to share serial connections.
See also
cancel_upgrade¶
-
Snap.
cancel_upgrade
(addr)¶ Cancel an over-the-air firmware upgrade.
Parameters: addr – The three-byte network address of the remote node for which the firmware upgrade is to be cancelled (Ex. “x12x34x56”) Returns: This function returns True if the upgrade was canceled. This function returns False if no upgrade is currently running for the given address or the upgrade has already completed. Note
This function can result in a
hooks.HOOK_OTA_UPGRADE_COMPLETE
event if an upgrade was successfully canceled.See also
close_all_serial¶
-
static
Snap.
close_all_serial
()¶ Close all opened serial connections for all SNAPconnect instances.
Warning
This is a static function on the Snap class. If multiple instances of SNAPconnect are running in the same application, they will all have their serial connections closed.
This is equivalent to calling the
close_serial()
function for every serial connection created withopen_serial()
.Returns: None Note
This function can trigger one or more
hooks.HOOK_SERIAL_CLOSE
events.See also
close_serial¶
-
Snap.
close_serial
(serial_type, port)¶ Close the specified serial port if open.
Parameters: - serial_type – The type of serial interface to close
- port – The port of that particular type to close, as appropriate for your operating system. On Windows,
port is a zero-based list. (Specify 0 for COM1 for example.). On Linux, port will typically be a string,
for example
/dev/ttys1
.
Returns: None
Note
This function can trigger a
hooks.HOOK_SERIAL_CLOSE
event.See also
open_serial()
- Serial port operations for serial_type constants
connect_tcp¶
-
Snap.
connect_tcp
(host, auth_info=<function client_auth>, port=None, retry_timeout=60, secure=False, forward_groups=None, tcp_keepalives=False, cache_dns_lookup=False, sniffer_callback=None)¶ Connect to another SNAP node over TCP/IP.
Warning
SNAPconnect only supports connecting to IPv4 addresses. If a hostname is provided it must be able to be resolved to an IPv4 address.
Parameters: - host – The IPv4 address or hostname of the other SNAP node as a dotted string (e.g., “192.168.1.1”)
- auth_info – The function to call when requesting the client’s credentials (defaults to public credentials).
If providing a custom function to call, it should have the signature “client_auth(realm)” where
the
realm
argument is supplied by the remote server and the function returns a tuple that contains the client’s username and password. See the Authentication Realms section for more details on the realm parameter. - port – The IP port number to connect to
- retry_timeout – A timeout, in seconds, to wait before retrying to connect (default 60)
- secure – A boolean value specifying whether SSL encryption is enabled for this connection (default False) SNAPconnect can initiate an SSL connection but cannot accept an SSL connection. Some type of proxy is necessary to decrypt and reroute received traffic in order to form an encrypted connection between SNAPconnect instances. For example, stunnel (www.stunnel.org) could be used to receive encrypted data on a port, decrypt the data, and forward it to the port SNAPconnect is using to accept_tcp. When secure is set to True, the port will default to 443.
- forward_groups – Multi-cast groups to forward onward through this interface; defaults to using the value specified in NV6 - Multicast Forward Groups. The forward_groups parameter can be important if you have a radio network that uses multicast traffic but you do not want those packets to propagate over the Internet.
- tcp_keepalives – Enable TCP layer keepalives (default False). If enabled, you may experience conflicts with certain firewall configurations, which may close the connection. The keepalives can also increase the amount of TCP/IP traffic your SNAP network generates, which might be an issue if you are using a cellular modem for your network connectivity.
- cache_dns_lookup – Only perform a DNS lookup once for the host being connected to (default False). This option was added because some DNS servers are extremely slow.
- sniffer_callback – Callback used for making remote sniffer connections to SNAPconnect instances that have
called both
accept_tcp()
andaccept_sniffer()
. When this callback is used, regular traffic will not pass across this TCP connection, and the accepting end of the connection will forward all received and transmitted packets to this interface. This function should have the signature “sniffer(descriptor)”. See the Sniffer Descriptors section for more detailson the descriptor objects that are passed to local and remote sniffers. The sniffer is NOT sniffing over-the-air packets. This callback is only passed packets which are received and transmitted over SNAPconnect serial and TCP connections.
Returns: None
Note
Establishment of the actual connection can trigger a
hooks.HOOK_SNAPCOM_OPENED
event. If the connection later goes down it can trigger ahooks.HOOK_SNAPCOM_CLOSED
event.
data_mode¶
-
Snap.
data_mode
(dst_addr, data)¶ Sends a transparent (aka data) mode packet to the specified SNAP network address.
Parameters: - dst_addr – The three-byte network address of the remote node (Ex. ‘x12x34x56’)
- data – The data to send
Returns: A packet identifier which can be used in the
hooks.HOOK_RPC_SENT
handler.Note
This function can result in a
hooks.HOOK_STDIN
event at the node specified bydst_addr
.See also
directed_mcast_rpc¶
-
Snap.
directed_mcast_rpc
(conn, port, group, ttl, func_name, *args)¶ Makes a Remote Procedure Call, or RPC, using multicast messaging. This means the message could be acted upon by multiple nodes. The multicast message will only be directed out one interface instead of broadcast across all open TCP and serial connections.
Despite the similarity of the names, the result of this function is very different from that of the
dmcast_rpc()
function. This function restricts which interface will be used to send a standard multicast message, while thedmcast_rpc()
function sends a message across all interfaces (subject to their Multicast Forwarded Groups settings in :ref:`sc_nv6’).Parameters: - conn – For serial connections, this is the serial type passed to
open_serial()
. For TCP interfaces, this value should be a string for the IP address of the interface. - port – The TCP or serial port number of the interface that should transmit the message.
- group – Specifies which nodes should respond to the request, based on the receiving node’s Multicast Process Groups setting in NV5 - Multicast Process Groups.
- ttl – Specifies the Time To Live (TTL) for the request.
- func_name – The function name to be invoked.
- args – Any arguments for the function specified by func_name. See
mcast_rpc()
for more details.
Returns: A packet identifier which can be used in the
hooks.HOOK_RPC_SENT
handler. This function will return False if the specified interface does not exist.Note
This function can trigger a
hooks.HOOK_RPC_SENT
event.See also
- conn – For serial connections, this is the serial type passed to
disconnect_tcp¶
-
Snap.
disconnect_tcp
(host, port=48625, all=False, retry=False)¶ Disconnect from the specified instance.
Parameters: - host – The IP address or hostname of the instance from which to disconnect
- port – The IP port number (default 48625)
- all – Disconnect all connections matching the criteria (default False)
- retry – Disconnect, but then retry connecting to the same host and port (default False)
Returns: This function returns True if the specified connection was found and closed, otherwise False.
Note
This function can result in one or more
hooks.HOOK_SNAPCOM_CLOSED
events being generated.
dmcast_rpc¶
-
Snap.
dmcast_rpc
(dst_addrs, groups, ttl, delay_factor, func_name, *args)¶ Makes a Directed Remote Procedure Call, or RPC, using multicast messaging. This means the message could be acted upon by multiple nodes. Unlike a standard multicast, however, the message will only be acted upon by nodes explicitly listed in
dst_addrs
. Unlike an addressed RPC call, this directed multicast does not make use of routing or packet acknowledgement. Other nodes in the mesh network will forward the message (subject to their Multicast Forwarded Groups settings in NV6 - Multicast Forward Groups) when there is sufficient TTL to do so. There is no route discovery performed, and there are no retries.Note that though they have similar names,
dmcast_rpc()
functions very differently fromdirected_mcast_rpc()
. Thedirected_mcast_rpc()
function allows you to restrict the interface used to transmit your message, but the message sent is a “standard” multicast. This function forwards through all interfaces that would normally forward the message (subject to the multicast group forwarding settings specified when the interface connection is opened), but will only be acted on by the node(s) specified, and then only if the multicast group specified for the call matches the node’s Multicast Process Groups setting in NV5 - Multicast Process Groups.Parameters: - dst_addrs –
A string containing concatenated three-byte addresses for any nodes you wish to act on the directed multicast. For example, if you have nodes with addresses 01.02.03, 04.05.06, 07.08.09, and 0A.0B.0C, the parameter should contain:
\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c
If you provide a string that is not a multiple of three characters in length, the
dmcast_rpc()
call will fail and no message will be sent to any node. If you provide an empty string (""
) for this parameter, all nodes that receive the message that would otherwise act on the message (subject to the groups parameter and the existence of the function in the node’s script) will act on the request as though the call were a regularmcast_rpc()
call. However in this case, added features available only for directed multicast (such as information available through severalget_info()
calls) are also available. - group – Specifies which nodes should respond to the request, based on the receiving node’s Multicast Process Groups setting in NV5 - Multicast Process Groups.
- ttl – Specifies the Time To Live (TTL) for the request.
- delay_factor –
Provides a mechanism to allow receiving nodes to stagger their responses to the request. The parameter should be a one-byte integer specifying the amount of time, in milliseconds, that should pass between node responses among the nodes targeted by the request. For example, if the dst_addrs parameter contains:
\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c
and the
delay_factor
parameter contains 40, any radio traffic generated in response by node 01.02.03 would be released immediately, radio traffic generated by 04.05.06 would be queued and held for 40 ms, radio traffic generated by 07.08.09 would be delayed for 80 ms, and radio traffic generated by 0A.0B.0C would be held for 120 ms before release. Note that the function on the target node is executed without delay. The delay only applies to radio communications directly invoked by the called function. No delay is applied to serial communications from the receiving node. Thus, an instance of SNAPconnect, which has only serial interfaces, is not affected by this parameter. Setting this parameter to zero allows all receiving nodes with radio interfaces to respond immediately, which may cause packet loss due to interference. A check ofget_info(25)
in the called function on the receiving node returns thedelay_factor
value specified, but also tells the receiving node to ignore the transmission delay that would normally be enforced. - func_name – The function name to be invoked.
- args – Any arguments for the function specified by func_name. See
mcast_rpc()
for more details.
Returns: A packet identifier which can be used in the
hooks.HOOK_RPC_SENT
handler. This function will return False if the specified interface does not exist.Note
This function can trigger a
hooks.HOOK_RPC_SENT
event.See also
- dst_addrs –
New in version 3.4.
get_info¶
-
Snap.
get_info
(which_info)¶ Get the specified system information.
Parameters: which_info – Specifies the type of information to be retrieved (0-28 but with some gaps – not all of the “info” types from the original [embedded] SNAP nodes apply to a PC-based application like SNAPconnect). This function returns the requested information or None if the which_info
parameter is invalid.The possible values for
which_info
and their meanings/return values are:which_info Meaning Return Value 0 Vendor Always returns 0 indicating “Synapse” 1 Type of radio Always returns 1 indicating “no radio” 2 Type of CPU Always returns 8 indicating “unknown” 3 Hardware platform Always returns 7 indicating “SNAPconnect” 4 Build Type (debug or release) Returns 0 if running under a debugger, Returns 1 if running standalone 5 Software MAJOR version Example: if version is 3.2.1 get_info(5)
returns 36 Software MINOR version Example: if version is 3.2.1 get_info(6)
returns 27 Software BUILD version Example: if version is 3.2.1 get_info(7)
returns 18 Encryption capability Returns 1 if AES-128 is available, (not necessarily enabled, just available for use), Otherwise returns 2, indicating that only “SNAP Basic” encryption is available 9 SNAP Sequence Number For SNAPconnect applications you should use the value returned by the rpc()
,mcast_rpc()
, anddmcast_rpc()
functions. This enumeration is only implemented to loosely match the embedded nodes10 Multicast flag Returns 1 if the RPC currently being processed came in via multicast; returns 0 if the packet came in via unicast 11 TTL Remaining Returns the TTL (the “hops remaining”) field of the packet currently being processed. For this to be of any use, you would have to know how many hops were originally specified 15 Routes stored in Route Table Returns the number of active routes 24 Is Directed Multicast Returns a 1 if the function running was invoked by a directed multicast using dmcast_rpc()
. Returns a 0 if the function running was invoked by a hook or scheduled event, by an addressed RPC, or by a “normal” multicast (i.e.,directed_mcast_rpc()
ormcast_rpc()
).25 Read Delay Factor Returns the delay factor specified for a message sent using dmcast_rpc()
. This delay factor has no effect on a SNAPconnect-based node, because the SNAPconnect instance has only serial interfaces.26 Address Index Directed multicast messages sent using dmcast_rpc()
can target multiple nodes by concatenating multiple SNAP addresses in thedst_addrs
parameter. This option indicates where the address of the contextual node appears in that list, as a zero-based index.27 Multicast Groups Returns an integer indicating the multicast group mask specified for the packet when it was originally sent, if it was sent as a directed multicast using dmcast_rpc()
.28 Original TTL Returns the TTL (the “hops”) field specified for the packet when it was originally sent, if it was sent as a directed multicast using dmcast_rpc()
. Combined withget_info(11)
, you can determine how many hops it took for the message to reach your node.Note
The string
snap.VERSION
is equivalent to retrieving the major, minor and build revisions (getinfo 5, 6, and 7 respectively). For example:>>> from snapconnect import snap >>> snap.VERSION ‘3.4.0’
load_nv_param¶
-
Snap.
load_nv_param
(nv_param_id)¶ This function returns the requested NV Parameter. Note that on some platforms the MAC Address parameter is set by the hardware (for example, on a SNAPconnect E12). In such cases, a request for that parameter will return the “hardware” value rather than any artificially stored value.
Parameters: nv_param_id – Specifies which “key” to retrieve from storage. Some NV parameters may have no effect on the SNAPconnect instance. Returns: The indexed parameter from storage. See also
save_nv_param()
- NV Parameters section for more details about the individual NV Parameters
local_addr¶
-
Snap.
local_addr
()¶ Returns the local network address of this instance.
Returns: The three-byte network address of the SNAPconnect instance (Ex. “x12x34x56”).
loop¶
-
Snap.
loop
()¶ Calling the loop function is essentially equivalent to using this in your code:
from time import sleep while True: poll() sleep(0.001)
Returns: This function does not return. You should only call it if your SNAPconnect application is “purely reactive” – for example, an application that only responds to RPC calls from other nodes. Example
The 1 ms sleep between polls prevents SNAPconnect from completely monopolizing your CPU. You can adjust this sleep duration by setting the
snap.SLEEP_TIME
global in your code to a value, in seconds. Longer sleep periods between checks consume less of your CPU, but also reduce the responsiveness of your network as it takes longer to get packets between SNAPconnect and your bridge node (or other interface):snap.SLEEP_TIME = 0.1 loop()
Note
If your application needs to take action on its own behalf (for example, if it needs to be polling other nodes but needs to perform its own independent processing between received messages), then you probably should be using the
poll()
function instead.See also
mcast_data_mode¶
-
Snap.
mcast_data_mode
(group, ttl, data)¶ Sends a multicast transparent (aka data) mode packet to the nodes specified by the group.
Parameters: - group – Specifies which nodes should respond to the request, based on the receiving node’s Multicast Process Groups setting in NV5 - Multicast Process Groups
- ttl – Specifies the Time To Live (TTL) for the request
- data – The data to send
Returns: A packet identifier which can be used in the
hooks.HOOK_RPC_SENT
handler.Note
This function can result in a
hooks.HOOK_STDIN
event in one or more other nodes.See also
mcast_rpc¶
-
Snap.
mcast_rpc
(group, ttl, func_name, *args)¶ Call a Remote Procedure (make a Remote Procedure Call, or RPC), using multicast messaging. This means the message could be acted upon by multiple nodes.
Parameters: - group – Specifies which nodes should respond to the request, based on the receiving node’s Multicast Process Groups setting in NV5 - Multicast Process Groups
- ttl – Specifies the Time To Live (TTL) for the request
- func_name – The function name to be invoked
- args –
Any arguments for the function specified by func_name
Note
Arguments should be given individually (separated by commas), not bundled into a tuple. For example, if
foo()
is a function taking two parameters, use something like:mcast_rpc(1, 2, 'foo', 1, 2) # <- correct!
instead of using something like:
mcast_rpc(1, 2, 'foo', (1,2)) # <- wrong!
Returns: A packet identifier which can be used in the
hooks.HOOK_RPC_SENT
handler.Note
This function can trigger a
hooks.HOOK_RPC_SENT
event.See also
open_serial¶
-
Snap.
open_serial
(serial_type, port, reconnect=False, dll_path=MODULE_PATH, forward_groups=None, baudrate=None, io_loop=None)¶ Open the specified serial port for sending and receiving SNAP packets.
Parameters: - serial_type – The type of serial interface to open
- port – The port of that particular type to open, as appropriate for your operating system. On Windows, port
is a zero-based list. (Specify 0 for COM1 for example). On Linux, port will typically be a string, for
example
/dev/ttys1
. - reconnect – Close the connection and re-open (default False)
- forward_groups – Multi-cast groups to forward through; defaults to using NV param
- baudrate – The baudrate for the serial connection
- io_loop – A Tornado IOLoop instance
See also
- Serial port operations for serial_type constants
replace_rpc_func¶
-
Snap.
replace_rpc_func
(rpc_func_name, rpc_func)¶ Replace an existing function to be called remotely via RPC.
Parameters: - rpc_func_name – An existing public RPC function name
- rpc_func – The callable to be executed via RPC
Returns: The original function that was replaced None if the function name had not been previously added
rpc¶
-
Snap.
rpc
(dst_addr, func_name, *args)¶ Sends a unicast RPC.
Call a Remote Procedure (make a Remote Procedure Call, or RPC), using unicast messaging. A packet will be sent to the node specified by the dst_addr parameter, asking the remote node to execute the function specified by the func_name parameter. The specified function will be invoked with the parameters specified by the args parameter, if any arguments are present.
Parameters: - dst_addr – The three-byte network address of the remote node (Ex. “x12x34x56”)
- func_name – The function name to be invoked on the remote node
- args – Any arguments for the function specified by func_name
rpc_alternate_key_used¶
-
Snap.
rpc_alternate_key_used
()¶ Returns: True if the packet came in with the alternate encryption key and the function was on the whitelist.
rpc_source_addr¶
-
Snap.
rpc_source_addr
()¶ Originating address of the current RPC context (None if called outside RPC).
Returns: The three-byte network address of the remote node which initiated the RPC call (Ex. “x12x34x56”).
rpc_source_interface¶
-
Snap.
rpc_source_interface
()¶ Originating interface of the current RPC context (None if called outside RPC).
Returns: The interface of the remote node which initiated the RPC call.
rpc_use_alternate_key¶
-
Snap.
rpc_use_alternate_key
(enable_flag)¶ Enable and disable use of the alternate key. When enabled, this setting persists until you disable it, and it affects ALL multicast RPC calls you send.
Parameters: enable_flag – If True, use the alternate key. If False, revert to the normal key.
save_nv_param¶
-
Snap.
save_nv_param
(nv_param_id, obj, optional_bitmask=None)¶ Store individual objects for later access by id.
Parameters: - nv_param_id – Specifies which “key” to store the obj parameter under. 0-127 are pre-assigned system IDs.
- obj – The object you would like to store for later use.
- optional_bitmask – For integers only, you can specify a bitmask of “bits of obj to be applied”. Any bits not set in optional_bitmask remain intact.
See also
load_nv_param()
- NV Parameters section for more details about the individual NV Parameters
set_hook¶
-
Snap.
set_hook
(hook, callback=None)¶ Set the specified SNAP hook to call the provided function.
Parameters: - hook – The SNAP event hook identifier
- callback – The function to invoke when the specified event occurs
start_sniffer¶
-
Snap.
start_sniffer
(callback)¶ Start a local sniffer that passes descriptors to the given callback.
Parameters: callback – Called when packets are sent or received by this SNAPconnect instance. Returns: True if a sniffer could be started. False if one was already running.
stop_accepting_sniffer¶
-
Snap.
stop_accepting_sniffer
(close_existing=False)¶ Stop accepting remote sniffer connections over TCP.
Parameters: close_existing – If True, close all existing sniffer connections
stop_accepting_tcp¶
-
Snap.
stop_accepting_tcp
(close_existing=False)¶ Stop listening for and accepting remote IP connections.
Parameters: close_existing – If True, close all existing TCP connections
stop_sniffer¶
-
Snap.
stop_sniffer
()¶ Stop a running local sniffer.
Returns: True if the sniffer could be stopped. False if one was not already running.
traceroute¶
-
Snap.
traceroute
(dst_addr)¶ Sends a traceroute request.
Parameters: dst_addr – The three-byte network address of the remote node (Ex. “x12x34x56”)
upgrade_firmware¶
-
Snap.
upgrade_firmware
(addr, file)¶ Start an over the air firmware upgrade.
Programming may take up to 2 minutes after the transfer completes. Do not remove power to the device during this time.
Parameters: - addr – The three-byte network address of the node to upgrade (Ex. “x12x34x56”)
- file – The path to the firmware image
Returns: Returns True if an upgrade can be started or False if the upgrade can’t be started for some reason. Will result in a call to the OTA upgrade complete hook.
Note
This function will trigger a
hooks.HOOK_OTA_UPGRADE_COMPLETE
event when an upgrade completes successfully or an error occurs that halts the upgrade process. Ahooks.HOOK_OTA_UPGRAGE_STATUS
event will be triggered every time progress is made in an over the air upgrade.