App Inventor 2 and Particle Communications
Probably the most important thing is to go over how you call a Particle Function via POST, and how you GET a Particle Variable. The blocks for these are strewn throughout the programs. Using a part of the precipiSTATION app, the POST and the reply looks like this:
Probably the most important thing is to go over how you call a Particle Function via POST, and how you GET a Particle Variable. The blocks for these are strewn throughout the programs. Using a part of the precipiSTATION app, the POST and the reply looks like this:
The upper blocks are a "Procedure" block that uses a "Web" block to make a POST, by assembling a string with coreID and access_token, and, in this case, appending the letter P as the parameter to be passed (see "Message Data Definitions" page for more examples of passed parameters).
The function in this example is used in the precipiSTATION and is received by the Particle Function fetchData(String x) which understands it as a command to assemble all currently stored program names into a CSV variable called pgmList[]. The lower block decodes the JSON information in the reply from the Particle Photon (note the index values of 5 and 2 for a POST - if you just use this you don't necessarily have to learn about JSON), which in this case is simply "80", or the ASCII value of P. The value 80 (arbitrarily picked BTW) is returned by the Particle Function fetchData() firmware on the Particle Photon to verify proper communication by the app. The lower blocks then call procedure "getProgramData" which is partially seen below:
The function in this example is used in the precipiSTATION and is received by the Particle Function fetchData(String x) which understands it as a command to assemble all currently stored program names into a CSV variable called pgmList[]. The lower block decodes the JSON information in the reply from the Particle Photon (note the index values of 5 and 2 for a POST - if you just use this you don't necessarily have to learn about JSON), which in this case is simply "80", or the ASCII value of P. The value 80 (arbitrarily picked BTW) is returned by the Particle Function fetchData() firmware on the Particle Photon to verify proper communication by the app. The lower blocks then call procedure "getProgramData" which is partially seen below:
The "getProgramData" procedure block assembles the GET request, asking for Particle Variable "pgmList". The lower block decodes the JSON reply information from the Particle Photon, which in this case will be a CSV String containing all the currently stored program names (note the index values of 4 and 2 for a GET). That data can then be processed by the precipiSTATION app.
A large amount of each of the apps I have created is just these types of POSTs and GETs.
A large amount of each of the apps I have created is just these types of POSTs and GETs.