Raspberry Pi Cheat Sheet for Dataplicity/Tmux/Nginx/Cloud Commander

Introduction   

This article is deliberately brief see the links below for more detail and a full understanding of Dataplicity/Nginx/Cloud Comander and Tmux.

The combination of these has allowed me to run a Python Script at a community centre that controls the heating and monitors tempreatures.  It has run 24/7 for many weeks.  I am able to connect from anywhere and minitor its operation, restart the script if there has been a power interuption and monify the script to try out changes or and fix bugs.

Procedures:

Get set for running Python Control Program:

At remote Location:

Connect with Dataplicity, Log in to “pi” user using “su pi” and change to the directory where the python code is stored.

Locally:

log in to”pi” in a terminal and change to directory where Python script is stored.

Locally or Remote:

If not running already (can check with “tmux ls”) initiate a tmux window with “tmux a -t ctrl”.

Execute script with e.g. python3 myprogram.py”

Leave running and exit session with “Ctrl b”, “d”.

To control web server and cloud commander:

You can only run either the web server or cloud commander.  So what I do is to use a tmux screen to control which is in use.

Set up a tmux session with “$ tmux new -s cloud” if its not running already.

To stop the web site and start Cloud Commander:

sudo service nginx stop  then   sudo cloudcmd

To stop Cloud Commander and start the website:

Ctrl c” “Enter” then  “sudo service nginx start”

Tmux Most Useful Commands

List Running Sessions: tmux ls

        Create A session for Python Prog.(and call it "ctrl") ,  tmux new -s ctrl,

        Create A session for Controlling if Cloud Comander or web  site is availavble through Port 80 (and call it "cloud"):   tmux new -s cloud,

To detach from session :                 “Ctrl-b” then “d”.

To reattach to python session (if is called "ctrl"):               tmux a -t ctrl, 

        To reattach to python session (if is called "cloud") :       tmux a -t cloud

Kill a session                       :        tmux kill-session -t session-name

Nginx Web Server:

Install using the instructions at: docs.dataplicity.com/docs/host-a-website-from-your-pi

(Make the directory at “/var/www/html” writable with sudo chown -R pi /var/www/html/

Control it with:

sudo service nginx start

sudo service nginx stop

sudo service nginx restart

$sudo service status nginx

Cloud Commander

Install Using the Instructions at: docs.dataplicity.com/docs/share-files-with-wormhole

Edit the Config File:  sudo nano /usr/lib/node_modules/cloudcmd/json/config.json

(Change:

User to “pi” (or your preference)

Change hashed password using hash.online-convert.com/sha512-generator to make a lower case Hex hash of your chosen password.. 

Change Port to 80.

Then no options needed with the start command below.

Run it:     sudo cloudcmd

Stop It:    “Ctrl-c” then “Enter”

Links for more Details:

Dataplicity See: docs.dataplicity A Facility for connection to an R Pi with minimal hassle from anywhere.

          Set up R Pi to host a website:  docs.dataplicity.com/docs/host-a-website-from-your-pi

          Wormhole and Cloud Commander:  docs.dataplicity.com/docs/share-files-with-wormhole

 Nginx: See nginx-restart-ubuntu-linux-command   and permissions-problems-with-var-www-html-and-my-own-home-directory-for-a-website An install that creates a web site on the R Pi.

Cloud Commander:  See cloudcmd.io and install to  R Pi l to provide a File Explorer. (Stop Nginx before use.)

Tmux:  See Tmux Tutorial A utility to set up terminals for continuously running scripts

Last Words:

As of Febuary 8th 2018 I had some suggestions for slight improvements in the Dataplicity Doicumentation.  These are writen up in this doc.

Any Comment query on attached please email rpi@torrens.xyz.