Following the integration of all the subsystems, one very stark problem came to light.
Firstly, let me recap the server-client relationship:
Server: connected to the Robotic Arm, LBS hand and IR sensors
Client: connected to the Leap Motion and the vibrational motors
Previously, for usability purposes, the client was accessed through a web browser, and only required a web browser and the Leap Motion to be connected. However, it quickly became clear that there was no way that you could control the Arduino through the browser. All browsers are sandboxed by default, and for good reason! If you were able to affect the local computer through a browser, there would be a massive vulnerability with Javascript.
(Pedantic note: there are ways to unlock the sandboxing in Chrome, but that is unsafe and if you forget to lock it up after yourself, it leaves you, your machine and your network vulnerable to attack)
Thus, we decided that a server-client relationship that was instead two servers talking to each other would be much easier, but less user-friendly. It will probably not feature in our demo, but it is an option for others to improve on in the future if they wish to.
In this post, I'll be outlining the general way to get the server and client working. There are multitudes of tutorials on this set-up, but for documentation's sake it's good to have this recorded.
Step 1: Install NodeJS - the easiest step. The setup is quite simple, and will help install the Node Package Manager (npm) for you.
Step 2: Create your new project directory - for our sakes let's call C:\SecretPlans\WorldDomination.
Step 3: Open Command prompt and navigate to that directory. (use "cd [insert path here]") In our example, it will be cd C:\SecretPlans\WorldDomination.
Step 4: Install package dependencies through npm. In our case here, we haven't done it the best way - you will have to use "npm install johnny-five socket.io socket.io-client leapjs" which installs all the latest versions of those packages.
The best way is to instead wrap it up in a JSON file that includes all the dependencies - usually called package.json. In that case, you can merely write "npm install" and it will read the package.json and download all it's dependencies. The package.json file is used mainly when one is writing a script or package that may be used in the npm directories (ie downloadable by others). There's a lot of information you can put in the package.json so that it can be read by others. Read more about it here!
Step 5: Write the script in the editor of your choice (our choices have been Notepad++ (for Windows) and Sublime Text 2 (for Mac)). In our case for Airgrip, we have files called FINALclient.js or FINALserver.js. Each of these need to certain lines modified in the code as to what port the Arduino boards are attached to. In our fictional case, lets call the files NukeWorld.js and CommandCenter.js.
Step 6: Back to Command prompt - set the program running by using 'node filename.js'. So in our fictional case, we would run 'node CommandCenter.js' (assuming that's the server). On the other computer, we would run 'node NukeWorld.js' (assuming that's the client).
Step 7: ??? World Domination...?
Next up - more magical blogposts :)
No comments:
Post a Comment