Skip to content

Commit 772b904

Browse files
v0.1
Added connection to the mesh and the CLI is now actually operational and functional albeit with simple commands. - Added the cliconfig.json file to the .gitignore - Added the fyrmesh.png banner image. - Updated the LICENSE and MANIFEST - Moved the server.py file into the main package directory - Moved the cli.py file into the main package directory - Eliminated sub packages to keep it simple. - Replaced the cli.py and server.py with fully functional code that connects to an actual control node and sends commands and receives logs. The RPC server can also be connected to from a remote machine.
1 parent 20466af commit 772b904

12 files changed

+326
-142
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,7 @@ dmypy.json
129129
.pyre/
130130

131131
# VSCode Related
132-
**/.vscode/
132+
**/.vscode/
133+
134+
# Config files
135+
**/cliconfig.json

LICENSE

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
**********************************************
2-
32
Copyright (C) 2020 Manish Meganathan, Mariyam A.Ghani. All Rights Reserved.
43

54
All and not limited to - folders, documents, source codes, programs, algorithms, sequences
@@ -11,5 +10,4 @@ No part of the mentioned properties by any means be distributed, copied, downloa
1110
transformed to any other form using electronic or mechanical methods without the prior and
1211
written approval from the Publishers. All resources are protected and any unauthorised usage
1312
will lead to severe action permissible by law.
14-
1513
**********************************************

MANIFEST.in

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
include LICENSE
1+
include LICENSE
2+
include setup.py
3+
include README.md

README.md

+38-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,44 @@
1-
# fyrmesh
2-
## A python package for mesh orchestration and control.
1+
# FyrMesh
2+
![FyrMesh Banner](fyrmesh.png)
3+
## A Python package for mesh orchestration and control with a built-in CLI and RPC-based mesh handling server.
34

4-
### Contributors
5-
- Manish Meganathan
6-
- Mariyam A. Ghani
5+
**Version: 0.1.0**
6+
**Platform: Raspberry Pi (Linux)**
7+
**Language: Python 3.7**
8+
9+
### **Contributors**
10+
- **Manish Meganathan**
11+
- **Mariyam A. Ghani**
712

813
This repository is a python package that includes:
9-
- **A Local Server Script**
10-
A script that runs the orchestartion interface between the mesh and the Raspberry Pi while exposing a REST based server built on Bottle on the localhost.
14+
- **An RPC Server Program**
15+
An RPC Service that runs the orchestartion interface between the mesh and the Raspberry Pi while exposing the methods of the service as an RPC object that is hosted on Raspberry Pi and can be connected through the localnet.
1116
- **A Command Line Interface library**
12-
An interface library that allows interacting with the mesh on the command line.
17+
An interface library that exposes commands as a CLI built using the Click framework. It connects to the RPC server and can be spun on up on machine on the local network and configured.
1318
- **A Firbase Cloud Interface library**
1419
An interface library that communicates with the Firebase backend and other cloud services.
15-
- **A Mesh Orchestration library**
16-
A library of custom thread runtimes, data classes, mesh messaging protocol runtimes, etc. that play a role in the orchestation of the mesh.
20+
- **A Mesh Orchestration library**
21+
A library of custom thread runtimes, data classes, mesh messaging protocol runtimes, etc. that play a role in the orchestation of the mesh.
22+
23+
24+
### **Installation**
25+
The ``fyrmesh`` package and CLI can be installed by first ``cd`` into the repository and running the command:
26+
```
27+
pip3 install -e .
28+
```
29+
The ``-e`` flag sets the installation to *editable*. This is reserved just for development use. Similarly the use between ``pip3`` and ``pip`` is dependant on the configuration of the machine.
30+
31+
The fyrmesh CLI is now installed. Run ``fyrmesh`` on the terminal to see the help document. If an 'entry point not found' error is thrown, do the following:
32+
- Run the following to open the ``.bash_profile`` file.
33+
```
34+
nano ~/.bash_profile
35+
```
36+
- Add the following line to the file.
37+
```
38+
export PATH=~/.local/bin:$PATH
39+
```
40+
- Run the following on a terminal
41+
```
42+
source ~/.bash_profile
43+
```
44+
The last command might have to be run for each new terminal window depending on the machine configuration.

fyrmesh.png

13.2 KB
Loading

fyrmesh/cli.py

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import os
2+
import sys
3+
import rpyc
4+
import json
5+
import click
6+
7+
mesh = None
8+
MESH_CONNECTED = False
9+
serverhost = None
10+
serverport = None
11+
12+
def connectserver(host: str, port: int) -> bool:
13+
"""A function that attempts to connect to the server and returns
14+
whether the attempt was successful"""
15+
16+
global mesh
17+
18+
try:
19+
conn = rpyc.connect(host, port)
20+
mesh = conn.root
21+
return True
22+
except Exception:
23+
return False
24+
25+
def loadserver():
26+
"""A function that loads the server values from the configuration file and connects to it.
27+
If the configuration file is not found, it is created.
28+
"""
29+
30+
global MESH_CONNECTED
31+
32+
if not os.path.isfile(configfile):
33+
with open(configfile, "w") as fp:
34+
serverdata = {"host": "localhost", "port": 18000}
35+
json.dump(serverdata, fp)
36+
37+
else:
38+
with open(configfile) as fp:
39+
serverdata = json.load(fp)
40+
41+
serverhost = serverdata['host']
42+
serverport = serverdata['port']
43+
MESH_CONNECTED = connectserver(serverhost, serverport)
44+
45+
directory = os.path.dirname(os.path.realpath(__file__))
46+
serverscript = os.path.join(directory, '..', 'server','server.py')
47+
configfile = os.path.join(directory, 'cliconfig.json')
48+
49+
loadserver()
50+
51+
def checkconnection():
52+
"""A function that checks if the connection is already established"""
53+
if not MESH_CONNECTED:
54+
bootmessage = ("""The FyrMesh server is not connected.Run 'fyrmesh boot' to start the server on this
55+
machine or set the host and port for a remote machine with 'fyrmesh setconfig' command""")
56+
click.echo(bootmessage)
57+
sys.exit()
58+
59+
@click.group()
60+
def cli():
61+
"""FyrMesh CLI to interact with the mesh of sensor nodes"""
62+
pass
63+
64+
@cli.command()
65+
def boot():
66+
"""boots up the FyrMesh server"""
67+
if MESH_CONNECTED:
68+
click.echo("The FyrMesh server is already running.")
69+
sys.exit()
70+
71+
os.system(f"lxterminal -e 'python3 {serverscript}' &")
72+
73+
@cli.command()
74+
def connect():
75+
"""connects the server to the mesh"""
76+
checkconnection()
77+
response = mesh.connectmesh()
78+
click.echo(response)
79+
80+
@cli.command()
81+
def disconnect():
82+
"""disconnects the server from the mesh"""
83+
checkconnection()
84+
response = mesh.disconnectmesh()
85+
click.echo(response)
86+
87+
@cli.command()
88+
def status():
89+
"""returns the current status of the mesh"""
90+
checkconnection()
91+
response = mesh.status()
92+
click.echo(response)
93+
94+
@cli.command()
95+
def poll():
96+
"""polls the sensors on all nodes on the mesh"""
97+
checkconnection()
98+
mesh.pollmeshsensors()
99+
100+
@cli.command()
101+
def reloadconfig():
102+
"""reloads the FyrMesh connection by realoading the configuration values"""
103+
loadserver()
104+
105+
@cli.command()
106+
@click.option('--host', default="localhost", help='IP address of the host')
107+
@click.option('--port', default=18000, help='port of the host')
108+
def setconfig(host, port):
109+
"""set the FyrMesh server host and port values to a configuration file"""
110+
with open(configfile, "w") as fp:
111+
serverdata = {"host": host, "port": port}
112+
json.dump(serverdata, fp)

fyrmesh/cli/__init__.py

Whitespace-only changes.

fyrmesh/cli/cli.py

-55
This file was deleted.

0 commit comments

Comments
 (0)