Short Explanations for weavedapi Public Methods - siddhesh-singh/JavaIOPi GitHub Wiki
weavedapi objects are meant to encapsulate all data relevant to the GPIO, Pi, WebIOPi and Weaved and all methods should be called through a weavedapi object. Here are some of the important public methods that you will need to know. There are many other more self explanatory ones in the class (such as the getter and setter methods), be sure to look at the source code.
-
weavedapi() The constructor takes no arguments and creates a new weavedapi with an empty token and a null Pi list. Pis are saved in an ArrayList in the object so every Pi is uniquely identified by an index.
-
login(String usr, String psw) This methods accepts a username (usr) and a password (psw) for a weaved account and gets a token from weaved. A valid token is necessary to make further calls. The token is saved in the object.
-
setup(boolean saved) Retrieve all the devices associated with the current weaved account. NOTE: will only work if login has been called previously with a valid token returned. Also, Pis will not have their pin information until they are connected to and updated individually.
-
setPiCreds(int index, String usr, String psw) Set credentials for the pi at the specific index of the device list. This is the username and password used to log into WebIOPi (not weaved). This method must be called after setup otherwise there will be no Pi information available.
-
genPiProxy(int index) Get a proxy for a Pi from weaved. The proxy will be stored in the rasppi object. This method can be called before or after setCreds but must be called after setup.
-
setupPi(int index, boolean saved, String param) Updates the pi on the specific index to its latest GPIO state (number of pins, hi/lo, function) retrieved from WebIOPi. This method can only be called after setPiCreds and genPiProxy have been called for the same index. Specifying saved = true will simply call the setup_saved method of the rasppi object which has not yet been implemented (so keep saved = false). The param string will be passed to the setup_saved function.
NOTE: persistent pins have their current states pushed to the WebIOPi before their attributes are updated so that they may not be overwritten by external sources.
- updatePi(int index) Update the GPIO state of the pi at index. Only call this method after setupPi has been called for the same index.
NOTE: the following are REST API methods for WebIOPI. All these methods have a boolean field 'update'. if update = true, then the method will update the Pi's state right after making the call.
-
GetPiGPIOState(int piIndex, boolean update) Get the complete GPIO state of pi stored at piIndex in JSON format.
-
GetPiGPIOPinFunction(int piIndex, int pinNumber, boolean update) Get the function of the the specific pin (pinNumber) from the Pi at index piIndex. The function is represented as a boolean value. true = input false = output. Instead of making direct comparisons like this, you can use functions such as getPinInBool() to return the boolean values which represent certain functions or values
-
GetPiGPIOPinValue(int piIndex, int pinNumber, boolean update) Get the value of the the specific pin (pinNumber) from the Pi at index piIndex. true = high false = low
-
SetPiGPIOPinFunction(int piIndex, int pinNumber, boolean fun, boolean update) Set the function of the the specific pin (pinNumber) from the Pi at index piIndex.
-
SetPiGPIOPinValue(int piIndex, int pinNumber, boolean val, boolean update) Set the value of the the specific pin (pinNumber) from the Pi at index piIndex.
The following methods provide a way to easily get all relevant information about a Pi or its GPIO without having to make multiple get calls.
-
exportPiPinJSON(int index, int pin) Exports the state of a specific pin from a specific Pi into a JSON string
-
exportPiJSON(int index) Exports the state of the specified Pi into a JSON string (not identical to the format obtained from GetPiGPIOState).
-
getPiPinInfoArray(int piIndex) Returns an ArrayList containing PinInfoObj objects. These objects contain information about the pins from the Pi at index piIndex and have methods for extracting that information (see class source code).
-
getPiInfoArray() Returns an ArrayList containing PiInfoObj objects. These objects contain information about the Pi at index piIndex and have methods for extracting that information (see class source code). This can be used to determine a specific Pi's index in the weavedapi object.