An archive of community.esquilo.io as of Saturday January 26, 2019.

Esquilo RPC, trying to understand a few things

JefferyS

Hi, I have created a web page and can turn a led on and off.

My question is, how does the RPC know what file to look in for the function that it is trying to run?

Does it go through all the files looking for that function and if so I would think that would mean you would have to have unique function names for the RPC.

Second Question, the javascript file for the RPC is supposed to be in /js/erpc.js but I've looked through all the files and can't find this. is this hidden or something? I have an SD card so I only see Flash and SD and under flash is only one file that I created. Didn't find anything in the library files I downloaded to the SD card.

Thanks,

Jeffery

patrick

Hi Jeffery,

Thanks for the questions. This is a confusing aspect of the system. We tried to explain in in the "Debugger" section of the IDE docs, here: http://www.esquilo.io/docs/#!esquilo-ide (in particular the 'execution model' and 'run').

To answer your first question: The files are not searched for a method that matches when an ERPC comes in. When you run a nut file, all the code, including the functions are complied to byte-code and stay resident in memory. They will stay there until: the board is reset, the VM is killed, or another nut file is run. When an ERPC request arrives, a function match is attempted on a table using the method name as the key. If you haven't run the nut containing the function, the ERPC request will fail.

Second question: /js/erpc.js comes directly from the internal flash. It is compiled as part of the EOS build (along with the web IDE). You can see the contents in your browser at: http:///js/erpc.js. You could also copy this to the SD and redirect the get from there, if you'd like to make changes, etc.

JefferyS

Thanks for the information. It makes more since now.

So I will need to build one all inclusive nut to handle both the web stuff and the hardware like a button.

Thanks,

Jeffery

Scott_Shumate

You can write different nuts and use dofile() to include them all together. However, you will need one top level nut that starts the execution, sort of like main() in C. An example of this is in the imu.nut demo where we include the code for the hardware at the top with dofile() calls. The dofile() calls can also be nested for more complex situations.

JefferyS

Thanks a lot, I will check out the imu.nut demo.

JefferyS

Hi, been looking at the demos and have been wondering if you can call the RPC with Ajax so as not to refresh the page all the time or does using the timeout() in JavaScript calling a RPC and using jQuery to change specific parts of the page make it appear like an Ajax page?

I hope that made since.

I would like to update the page on the fly without loading/refreshing it all the time.

Thanks,

Jeffery

Scott_Shumate

You can certainly do that. Calling ERPC with JavaScript is in essence the same as AJAX. An AJAX page uses JavaScript to call a web service on the server to return JSON data (XML is less common) which will cause the JavaScript to modify the web page in some way. That web service can be PHP accessing a SQL database as is in a typical usage or an Esquilo performing some hardware sensing function. Both will return JSON data to your JavaScript which can then be used to update the page using jQuery, the DOM, or some other JavaScript framework.

In the demos, we commonly use SetTimeout to call the ERPC function periodically. This does not refresh the page as the JavaScript reads the response back and dynamically updates the page. You don't have to use a timer and you can instead initiate the request based on user input or some other means.