User Guide for the PSLab Remote-Access Framework
The remote-lab framework of the pocket science lab has been designed to enable user to access their devices remotely via the internet. The pslab-remote repository includes an API server built with Python-Flask and a webapp that uses EmberJS. This post is a guide for users who wish to test the framework. A series of blog posts have been previously written which have explored and elaborated various aspect of the remote-lab such as designing the API server, remote execution of function strings, automatic deployment on various domains etc. In this post, we shall explore how to execute function strings, execute example scripts, and write a script ourselves.
A live demo is hosted at pslab-remote.surge.sh . The API server is hosted at pslab-stage.herokuapp.com, and an API reference which is being developed can be accessed at pslab-stage.herokuapp.com/apidocs . A screencast of the remote lab is also available
Create an account
Signing up at this point is very straightforward, and does not include any third party verification tools since the framework is under active development, and cannot be claimed to be ready for release yet.
Click on the sign-up button, and provide a username, email, and password. The e-mail will be used as the login-id, and needs to be unique.
Login to the remote lab
Use the email-id used for signing up, enter the password, and the app will redirect you to your new home-page, where you will be greeted with a similar screen.
On the home-page, you will find that the first section includes a text box for entering a function string, and an execute button. Here, you can enter any valid PSLab function such as `get_resistance()` , and click on the execute button in order to run the function on the PSLab device connected to the API server, and view the results. A detailed blog post on this process can be found here.
Since this is a new account, no saved scripts are present in the Your Scripts section. We will come to that shortly, but for now, there are some pre-written example scripts that will let you test them as well as view their source code in order to copy into your own collection, and modify them.
Click on the play icon next to `multimeter.py` in order to run the script. The eye icon to the right of the row enables you to view the source code, but this can also be done while the app is running. The multimeter app looks something like this, and you can click on the various buttons to try them out.
You may also click on the Source Code tab in order to view the source
Create and execute a small python script
We can now try to create a simple script of our own. Click on the `New Python Script` button in the top-bar to navigate to a page that will allow you to create and save your own scripts. We shall write a small 3-line code to print some sinusoidal coordinates, save it, and test it. Copy the following code for a sine wave with 30 points, and publish your script.
import numpy as np
print (x, np.sin(x))
Create a button widget and associate a callback to the get_voltage function
A small degree of object oriented capabilities have also been added, and the pslab-remote allows you to create button widgets and associate their targets with other widgets and labels.
The multimeter demo script uses this feature, and a single line of code suffices to demonstrate this feature.
button('Voltage on CH1 >',"get_voltage('CH1')","display_number")
You can copy the above line into a new script in order to try it out.
Associate a button’s callback to the capture routines, and set the target as a plot
The callback target for a button can be set to point to a plot. This is useful if the callback involves arrays such as those returned by the capture routines.
Example code to show a sine wave in a plot, and make button which will replace it with captured data from the oscilloscope:
import numpy as np x=np.linspace(0,2*np.pi,30) plt = plot(x, np.sin(x)) button('capture 1',"capture1('CH1',100,10)","update-plot",target=plt)
- Designing a remote access framework
- Creating an API server using Python-Flask
- Execute python function calls remotely
- Deploying the API server and Webapp
- Object Oriented apps from end user code
- Adding a graph component to the frontend
- A simple oscilloscope for PSLab remote