This example application allows you to upload a compiled SNAPpy "SPY" file to a node using SNAPconnect.
Many networks use Portal to commission nodes, upload new SNAPpy scripts into them, etc.
Portal can upload either source (.py) or binary (.spy) files into embedded SNAP Nodes. Portal can also export ".py" files into ".spy" files.
SNAPconnect applications can also upload SPY files into SNAP Nodes, but doing so requires a handful of function calls. The SpyUploader class encapsulates some of the details, plus adds a high-level retry mechanism (it will attempt the entire script upload process up to three times).
In order to run this example, you will need to make sure that SNAPconnect is installed on your system:
pip install --extra-index-url https://update.synapse-wireless.com/pypi snapconnect
You will also need to make a few modifications to SpyUploader.py to configure your bridge address, serial type, and serial port. Some of the values that you can change include:
BRIDGE_NODE = "\x4B\x42\x34"
SERIAL_TYPE = snap.SERIAL_TYPE_RS232
SERIAL_PORT = 0 # COM1
Once you have configured the example, simply run:
$ python SpyUploader.py
2016-04-06 15:52:05 DEBUG: Querying for remote addr
2016-04-06 15:52:05 DEBUG: send: 0001.callback('7XombsadNuFWVJEP', 'getInfo', 3)
2016-04-06 15:52:05 DEBUG: Directing multi-cast to RS-232 Interface: 30
...
2016-04-06 15:52:08 DEBUG: send: 610dec.callback('su_recvd_reboot', 'reboot')
2016-04-06 15:52:08 DEBUG: rpc: 610dec.su_recvd_reboot(None,)
RF Script Upload: Successfully uploaded the script
errCode=3
You can use SpyUploader in your own SNAPconnect application by importing and setting up a SpyUploader instance:
-
Import SpyUploader into your application:
import SpyUploader
-
Create an instance of the SpyUploader object:
uploader = SpyUploader()
-
Tell the SpyUploader which SNAPconnect instance to use:
uploader.assign_SnapCom(xxx)
-
Tell the SpyUploader which callback function to invoke at the end of the upload process:
uploader.assign_Callback(yyy)
-
Initiate the actual script upload:
uploader.beginUpload(nodeAddress, filename)
Copyright © 2016 Synapse Wireless, licensed under the Apache License v2.0.