bonescript RPC

I see the start.html file that ships on the BBB can run bonescript right the from browser. It really slick the way you can take bonescript code from the browser and have it run remotely on the Bone.

My question is: Is there a tutorial on how to use this remote procedure call? I have a demo[1] that pulls audio from a web cam on the Bone and displays the waveform on a web page. I have another demo that reads various sensors on the Bone and plots the results on a web page.

I’d like to switch these two examples to use the same RPC server the bonescript demo uses. Any pointers one where to start?

–Mark

[1] https://github.com/MarkAYoder/BeagleBoard-exercises/tree/master/node.js/realtime

I see the start.html file that ships on the BBB can run bonescript right the from browser. It really slick the way you can take bonescript code from the browser and have it run remotely on the Bone.

My question is: Is there a tutorial on how to use this remote procedure call? I have a demo[1] that pulls audio from a web cam on the Bone and displays the waveform on a web page. I have another demo that reads various sensors on the Bone and plots the results on a web page.

I’d like to switch these two examples to use the same RPC server the bonescript demo uses. Any pointers one where to start?

Copy-and-paste to start. :slight_smile:

Let’s start with BeagleBoard.org - getPlatform.

Note how it brings in http://beagleboard.org/static/bonescript-demo.js, which is where much of the magic happens. It sets up to read some other interesting JavaScript files including:

What was meant to work was that the static bonescript.js would provide this setTargetAddress() function that the UI could use to load the dynamic bonescript.js off of your board. The dynamic bonescript.js on your board, often located at http://192.168.7.2/bonescript.js, includes script injection to load the socket.io communications library. This dynamic board-served bonescript.js defines some global variables and creates a require() function that can be used in your browser scripts just like it is used in your board-hosted node.js scripts to read in the BoneScript library functions. In this case, it would be loading versions that pass the arguments to the web server running on the board using socket.io, run the functions and use registered callbacks to complete the remote-procedure call (RPC). You can follow how the _bonescript global variable is used to pass the relevant information, including callbacks to notify your client-side JavaScript application of various socket.io events and initialization of these variables such that you could start usage of the RPC-based BoneScript library. Kinda slick if I do say myself, so please do let me know if I’ve lost you at this point.

What happened with the initial implementation of the BoneScript server was that the proper address for making the socket.io connection wasn’t properly communicated and if you were using a page served up by http://beagleboard.org, it wouldn’t make a connection unless you updated the BoneScript server. This made beagle-ui.js a bit uglier than I’d planned by introducing the need for a work-around, _onSocketIOLoaded_workaround() to be precise. This isn’t needed if you have the latest BoneScript server, but is being carried by beagle-ui.js nevertheless. I also introduced a couple more work-arounds here to provide interfaces to send messages that aren’t RPCs to the socket.io connection for running shell commands, since I never properly introduced a BoneScript library shell() function.

You’ll also see that beagle-ui.js provides that nifty “Your board is connected!” message. It seems pretty self-explanatory to me, but I wrote it, so it would. Perhaps a few more well-phrased questions would help result in some better documentation here.

Looking back at bonescript-demo.js, you’ll see a handful of functions I use within the BeagleBoard.org - BoneScript pages to provide you with live editors and ‘run’ buttons, namely initClient() will run demoEdit() on any blocks where it sees the “use-editor” class and demoRun() will extract code from the identified block for execution, respectively. I’ve simply created a ‘run’ button on the BeagleBoard.org - getPlatform page to call demoRun() on the block containing the example code. Pages like BeagleBoard.org - dogtag simply execute the provided script (in that case using shellRun()) upon establishing a connection.

Assuming an up-to-date BoneScript server/library and using the http://beagleboard.org/static/bonescript.js with the setTargetAddress function to point to the target board could result in a rather clean implementation of your application on your website. Simply provide a solution for providing the target ‘address’ of your board and set ‘handlers’ appropriately for the socket.io notifications for which you’d like to add UI elements and you are good to go!

Hope this helps. Patches welcome!

http://gitorious.org/beagleboard-org

Jason:
Thanks for the detailed response. I’m still digesting it and will follow up with questions.

In the mean time it might be helpful for others to point out where the server is. To discover this I did:

bone$ ps aux | grep node
root 123 6.7 5.1 52332 12896 ? Ss 15:29 0:06 /usr/bin/node4 /usr/share/cloud9/bin/cloud9.js -l 0.0.0.0 -w /var/lib/cloud9 -p 3000
root 124 2.0 3.7 38996 9316 ? Ssl 15:29 0:01 /usr/bin/node autorun.js
root 366 8.9 8.6 42092 21404 ? Ssl 15:30 0:05 /usr/bin/node server.js
root 374 0.0 0.2 1960 668 pts/0 S+ 15:31 0:00 grep --color=auto node

Now just find the file named server.js. Unfortunately find / -name server.js returns 43 files, so I tried

bone$ cd /proc/366
bone$ ls
attr coredump_filter limits ns sched syscall
autogroup cwd maps oom_adj schedstat task
auxv environ mem oom_score smaps wchan
cgroup exe mountinfo oom_score_adj stack
clear_refs fd mounts pagemap stat
cmdline fdinfo mountstats personality statm
comm io net root status
bone$ ls -ls cwd
0 lrwxrwxrwx 1 root root 0 Jul 16 15:31 cwd → /usr/lib/node_modules/bonescript

There it is! One mystery was solved when I saw the string INSERT_HOST is replaced with the host name. That’s why when bonescript.js is served it always has the right URL.

My next task is to construct a minimal HTML page the uses the bonescript RPC. If I can’t make it fit on half a page it’s too complex to use in class.

–Mark

Where does the winston package put it’s log files? I think they’s give some insight in how things work.

–Mark

Where does the winston package put it’s log files? I think they’s give some insight in how things work.

It is configurable in bonescript/index.js, but normal output goes to the systemd journal. Use ‘journalctl -u bonescript’.

So, Mark, did you get it to fit on half a page?

If so, it would be great to see that half page.

Simon.

Simon:
Sorry, I haven’t gotten to it. It was easier to build my own server[1] than to dig into the RPC.

Some day…

–Mark

[1] https://github.com/MarkAYoder/BeagleBoard-exercises/blob/master/realtime/boneServer.js