Skip to content

nashadroid/SCARLET-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SCARLET Python Webserver

A simple web server to transfer objects between machines in the lab

Server Side Instructions

This page details how to set up, update, and test the Scarlet Data Server. Note: This is not the instructions for the client side devices.

Prerequisites:

Python - I have tested with Python 3.6 - 3.8. The server uses only the standard library, so no additional packages need to be installed.

Git - Recommended, but not required.

 

 

Part 1: Downloading the Code

This part requires you to be connected to the internet.

 

a) Fresh Install (Skip to Part b if previously installed)

Option 1: Download with Git (recommended)

The easiest way to do this is by using Git. This will allow for easy updating and back ups in the future.

To do this, open a terminal and navigate to the folder where you want the server folder to be in (Git will create a new folder containing all the project files):

cd path/to/where/to/install
In the terminal, run the command:
git clone https://github.com/nashadroid/SCARLET-Server
 

Option 2: Direct download from Github.com

Using a browser, navigate to https://github.com/nashadroid/SCARLET-Server .

Click the green download code button

Move the downloaded zip file to where you want the server folder to be. Then, open a terminal and navigate to the zip file:

cd path/to/folder/containing/zip
Then unzip the folder:
unzip SCARLET-Server.zip
 

b) Update/Refresh Code (Skip this part if you just did Part a)

Open a terminal and navigate to the folder where you have ScarletServer:
cd path/to/SCARLET-Server/
Use git to update from the origin:
git pull origin master
This should be all you have to do. Only if the above does not work and it gives you conflicts:
git stash

git pull

 

 

Part 2: Configuring the Server

This part requires you to be connected to SCARLETNET (No www internet connection)

There are some options which can be toggled in the server. The main one that should be worried about is the ip address.

 

Setting Server IP

The IP address of the machine running the server must be saved in the file titled "ip.txt". This will be the local IP, not the public IP, so it will be different than the one displayed on whatismyip.com .

The local ip can be found in several different ways, an easy one being

hostname –I

If that doesn't work, try some of the other options described here. The local IP address can also be found in network settings/preferences. Note: This is not the router ip, which likely ends in .0 or .1

Other settings

Other settings which can be toggled are at the top of the file titled "ScarletServer.py". This includes:
  • overWriteFiles - Default is False, which means files cannot be overwritten from the client side. Set to True to enable overwriting of files.
  • sortFilesByDay - Default is False, set to True if you would like the server to force sorting files by day.
  • port - Default is 8080 , probably don't change this one.
 

Part 3: Running the Server

Navigate to within the Server folder:
cd SCARLET-Server/
Start Running the server. This may be different based on what your Python is aliased as:
python ScarletServer.py
And then you should receive a message similar to "Starting server at ip: 192.168.0.9:8080"

If no errors are thrown after that line and Python continues running, the server should be working.

 

Part 4: Check the server is running

Use a web browser and go to the ip address and port listed by the server. You should enter exactly where the server says it's running into the URL bar of your browser, something along the lines of: 192.168.0.9:8080

You should see a plain text webpage that looks similar to this:

The Placeholder text is just there for testing purposes. Any text values sent to the server will also end up here. Test this on other devices on the same network to ensure the ports are working properly. If using within the Scarlet-intranet, this means needing a wired connection to the local network (without access to internet).

Next set up the client on any device on the same network to send data to the server. Any device that can access the webpage at the server url should be able to send data through the clients.

 

Client Side Instructions

This page details how to set up, update, and test Clients for the Scarlet Data Server. Note: These are not the instructions for the Server side devices. This should be used for all devices which will be transmitting data to the Scarlet Server, but not the device which is hosting the Scarlet Server.

Prerequisites:

Python - I have tested with Python 3.6 - 3.8. The server uses only the standard library, so no additional packages need to be installed.

Git - Recommended, but not required.

 

 

Part 1: Downloading the Code

This part requires you to be connected to the internet.

 

a) Fresh Install (Skip to Part b if previously installed)

Option 1: Download with Git (recommended)

The easiest way to do this is by using Git. This will allow for easy updating and back ups in the future.

To do this, open a terminal and navigate to the folder where you want the server folder to be in (Git will create a new folder containing all the project files):

cd path/to/where/to/install

In the terminal, run the command:

git clone https://github.com/nashadroid/SCARLET-Server

 

Option 2: Direct download from Github.com

Using a browser, navigate to https://github.com/nashadroid/SCARLET-Server .

Click the green download code button

Move the downloaded zip file to where you want the server folder to be. Then, open a terminal and navigate to the zip file:

cd path/to/folder/containing/zip

Then unzip the folder:

unzip SCARLET-Server.zip

 

b) Update/Refresh Code (Skip this part if you just did Part a)

Open a terminal and navigate to the folder where you have ScarletServer:
cd path/to/SCARLET-Server/
Use git to update from the origin:
git pull origin master
This should be all you have to do. Only if the above does not work and it gives you conflicts:
git stash
git pull
 

 

Part 2: Use the clients in your scripts

This part requires you to be connected to SCARLETNET (No www internet connection)

Two different modules have been made, one for Python and one for MATLAB. Both should work in just about the same way.

 

Initialize the client object (Different for Python and Matlab)

Matlab

The code for the Matlab Client is saved in the file "ScarletClient.m". Generally, you should never have to modify this file. First thing you will need to do is to make sure the client is in the path of where your script will be running from. You can do this in two ways: One is to simply copy the client file to wherever you will be running MATLAB scripts from. The second is to just add the client to your path with:
addpath('/path/to/SCARLET-Server/')
Next, you can instantiate an object using the following line, but change Server_IP to be the actual Server IP which the server prints out when starting the server. Note: the single quotes must remain.
client = ScarletClient('Server_IP')
If this returns no errors, then you have successfully initialized a client object! This client object will be reused over and over to communicate with the server, giving you easy access to the client methods without having to reinstantiate.

 

Python

The code for the Python Client is saved in the file "ScarletClient.py". Generally, you should never have to modify this file. First thing you will need to do is to make sure the client is in the path of where your script will be running from. You can do this in two ways: One is to simply copy the client file to wherever you will be running MATLAB scripts from. The second is to just add the client to your path with:
import sys

sys.path.append("/Path/to/SCARLET-Server")

Next, you need to import the class of client, which is ScarletClient:

from ScarletClient import ScarletClient

Next, you can instantiate an object using the following line, but change Server_IP to be the actual Server IP which the server prints out when starting the server.

client = ScarletClient('Server_IP')

If this returns no errors, then you have successfully initialized a client object! This client object will be reused over and over to communicate with the server, giving you easy access to the client methods without having to reinstantiate.

 

Using Client Methods (Same exact syntax for Python and Matlab)

Sending Text Data

Any data that is not an image or other singular file should be sent as text data. This should include readings from measurements taken every shot or even every second. If the size of memory for floating points is a concern, consider saving to a .mat file and then uploading the file (file upload outlined below).

Every value needs a label, which we will call the key. Use the sendTextData method as follows:

client.sendTextData(key, value)

For example, if we have a measurement for target thickness of 0.46 microns, we could do:

client.sendTextData('Target Thickness', '0.46 microns')

Note: Writing the same label will overwrite the previous value, but ALL values will be recorded in the log. Usage of double quotes will also mess up the script. Suggestion would be to label the shot, day, etc. in the key. The time of the value will also automatically be labeled on the server and saved as key + "_time"

 

Getting Text Data

Any text data that is sent with the above method can also be retrieved. This will be done with the getTextData method of the client which takes in only a key value.
client.getTextData(key)
For example, if we had previously sent a reading with the label 'Target Thickness' then we could retrieve it as:
thickness = client.getTextData('Target Thickness')
 

Uploading Files

Uploading files requires two parameters, the local path to the file, and the path you would like to save to on the server side. The server will automatically save all files within a directory called "files/". All organization within that folder is expected to be done from the client side. Any directories specified here will automatically be created on the server side. Usage of the uploadFile method is as follows:
client.uploadFile(localFilePath, serverFilePath)
Where both paths must include the file names. For example, if I have a file called AutoCorrelation.tiff and I want to label it with a shot number 21 and organize it into a folder called ACImages, then I can do:
client.uploadFile('AutoCorrelation.tiff', 'ACImages/AutoCorrelation21.tiff')
 

Downloading Files

Downloading Files requires one parameter, the path to the requested file. For example, if I want to download a file called AutoCorrelation21.tiff from a folder called ACImages, I can do:
data = client.getFile('ACImages/AutoCorrelation21.tiff'')
This file can then be saved however you choose.

 

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •