Compare commits
	
		
			No commits in common. "46997b1f9548e6dd2753cfa20ad1e3e53c663a0d" and "46a9cc3ee98c8f4e989dd277590d192bfbe0c718" have entirely different histories.
		
	
	
		
			46997b1f95
			...
			46a9cc3ee9
		
	
		|  | @ -266,17 +266,17 @@ PierMesh has two main events loops to learn about: the TUI and the service. | ||||||
| 
 | 
 | ||||||
| ## TUI | ## TUI | ||||||
| 
 | 
 | ||||||
| [🔗 Docs](https://git.utopic.work/PierMesh/piermesh/src/branch/main/docs/tlog.md) | [🔗 Docs](https://git.utopic.work/PierMesh/piermesh/src/branch/main/docs/ui.md) | ||||||
| 
 | 
 | ||||||
| [🔗 Source](https://git.utopic.work/PierMesh/piermesh/src/branch/main/src/tlog.py) | [🔗 Source](https://git.utopic.work/PierMesh/piermesh/src/branch/main/src/ui.py) | ||||||
| 
 | 
 | ||||||
| The TUI is provided via [curses](https://docs.python.org/3/howto/curses.html) library. It's a relatively simple application that gives us a quick overview of system statistics in the way of memory and cpu usage as well as logs you can scroll with the directional keys | The TUI is provided via [Textual's](https://textual.textualize.io/) library. It's a relatively simple application that gives us a quick overview of system statistics in the way of memory and cpu usage as well as scrollable logs. You can toggle full screen logs with f and close the TUI and service with q. | ||||||
| 
 | 
 | ||||||
| ## The Service | ## The Service | ||||||
| 
 | 
 | ||||||
| PierMesh runs a number of loops under the hood. These are primarily initialized in the main loop of run with a special logging loop outside of that. | PierMesh runs a number of loops under the hood. These are primarily initialized in the main loop of run with a special logging loop outside of that. | ||||||
| 
 | 
 | ||||||
| Note that we make use of [Meshtastic's Python API](https://github.com/meshtastic/python). | Note that we make heavy use of [Meshtastic's Python API](https://github.com/meshtastic/python). | ||||||
| 
 | 
 | ||||||
| ### run | ### run | ||||||
| 
 | 
 | ||||||
|  | @ -288,18 +288,18 @@ Note that we make use of [Meshtastic's Python API](https://github.com/meshtastic | ||||||
| 
 | 
 | ||||||
| In run.main we (in order) | In run.main we (in order) | ||||||
| 1. Initialize the `Node` class to a global `nodeOb`. | 1. Initialize the `Node` class to a global `nodeOb`. | ||||||
| 2. Wait for x seconds determined by command line arguments (see the falin script in scripts) | 2. Wait for x seconds determined by command line arguments (see the falin and marcille scripts in scripts) | ||||||
| 3. Initialize our `Transceiver` class (and the corresponding hardware) | 3. Initialize our `Transceiver` class (and the corresponding hardware) | ||||||
| 4. Initialize our `Server` class | 4. Initialize our `Server` class | ||||||
| 5. Create an async task running the `Node.spongeListen` method which looks for updates from the filter system | 5. Create an async task running the `Node.spongeListen` method which looks for updates from the filter system | ||||||
| 6. Kick the loop on with `await asyncio.sleep(1)` (we do this to kick on all async loops so I will omit this step going forward) | 6. Kick the loop on with `await asyncio.sleep(1)` (we do this to kick on all async loops so I will omit this step going forward) | ||||||
| 7. Create an async task running the `Transceiver.checkProgress` method which checks for packet reception progress and resends packets if necessary (currently not in use) | 7. Create an async task running the `Transceiver.checkProgress` method which checks for packet reception progress and resends packets if necessary | ||||||
| 8. Create an async task running `Node.monitor` which checks and reports system usage | 8. Create an async task running `Node.monitor` which checks and reports system usage | ||||||
| 9. Create an async task running the `Transceiver.announce` method which broadcasts a `Packets.Message` containing network mapping information | 9. Create an async task running the `Transceiver.announce` method which broadcasts a `Packets.Message` containing network mapping information | ||||||
| 10. Last we start the `Microdot` server loop | 10. Last we start the `Microdot` server loop | ||||||
| 
 | 
 | ||||||
| ### .. | ### .. | ||||||
| Travelling out of the run.main thread to the primary ____main____ code we see the other thread running the TUI loop which has it's own system we just kick on by running .runLogUI | Travelling out of the run.main thread to the primary ____main____ code we see the other two threads: one running the `logPassLoop` loop which is created in the same way as the main thread: `lplThread = threading.Thread(target=asyncio.run, args=(logPassLoop(),))` and one running the TUI loop which has it's own system we just kick on by instantiating the TUI class and calling .run() on. | ||||||
| 
 | 
 | ||||||
| ## Packet lifecycle | ## Packet lifecycle | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										28
									
								
								readme.md
								
								
								
								
							
							
						
						
									
										28
									
								
								readme.md
								
								
								
								
							|  | @ -2,6 +2,8 @@ | ||||||
| # PierMesh | # PierMesh | ||||||
| ## A new internet, a fresh start | ## A new internet, a fresh start | ||||||
| 
 | 
 | ||||||
|  | This is the monorepo for PierMesh. | ||||||
|  | 
 | ||||||
| # Docs | # Docs | ||||||
| 
 | 
 | ||||||
| You can find the full docs here: [docs/](https://git.utopic.work/PierMesh/piermesh/src/branch/main/docs) | You can find the full docs here: [docs/](https://git.utopic.work/PierMesh/piermesh/src/branch/main/docs) | ||||||
|  | @ -13,43 +15,25 @@ Note: these instructions will probably only work on Linux at the moment | ||||||
| Note: check the scripts to make sure they'll work with your system, and in general I recommend checking scripts before you run them | Note: check the scripts to make sure they'll work with your system, and in general I recommend checking scripts before you run them | ||||||
| 
 | 
 | ||||||
| Follow Meshtastic's guide on setting up your device: [https://meshtastic.org/docs/getting-started/](https://meshtastic.org/docs/getting-started/) | Follow Meshtastic's guide on setting up your device: [https://meshtastic.org/docs/getting-started/](https://meshtastic.org/docs/getting-started/) | ||||||
| 
 |  | ||||||
| Make sure you have the latest Python installed | Make sure you have the latest Python installed | ||||||
| 
 | 
 | ||||||
| Make sure you have pip and venv installed |  | ||||||
| 
 |  | ||||||
| ``` | ``` | ||||||
| git clone https://git.utopic.work/PierMesh/piermesh | git clone https://git.utopic.work/PierMesh/piermesh | ||||||
| 
 | 
 | ||||||
| cd piermesh | cd piermesh | ||||||
| 
 | 
 | ||||||
| python -m venv .venv | python -m venv . | ||||||
| 
 | 
 | ||||||
| source .venv/bin/activate | source bin/activate | ||||||
| 
 | 
 | ||||||
| pip install -r requirements.txt | pip install -r requirements.txt | ||||||
| 
 | 
 | ||||||
| cd src | cd src | ||||||
| 
 | 
 | ||||||
| cp .piermesh.example .piermesh | chmod a+x ./scripts/falin | ||||||
| 
 | 
 | ||||||
| Set the TransceiverPort (you should have this from setting up your Meshtastic device) | ./scripts/falin | ||||||
| 
 |  | ||||||
| Set the PSK, this should match the PSK of node's you want to connect with |  | ||||||
| 
 |  | ||||||
| python run.py |  | ||||||
| ``` | ``` | ||||||
| You should now be able to access the web interface at port 5000 of the machine you set up on (likely localhost:5000) |  | ||||||
| 
 |  | ||||||
| Make sure to click connect at the top of the page to initialize your websocket connection, after this you can use the utilities provided |  | ||||||
| 
 |  | ||||||
| Hopper: proxy requests to the main internet |  | ||||||
| 
 |  | ||||||
| Catch: browse for a Catch/website on PierMesh |  | ||||||
| 
 |  | ||||||
| Catch Editor: create and publish a Catch onto PierMesh |  | ||||||
| 
 |  | ||||||
| Bubble: send peer to peer messages (and art using the pixel art tool) to other nodes |  | ||||||
| 
 | 
 | ||||||
| # License text | # License text | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ | ||||||
| Nickname = node1 | Nickname = node1 | ||||||
| StartupDelay = 0 | StartupDelay = 0 | ||||||
| WebUIPort = 5000 | WebUIPort = 5000 | ||||||
| ShowTUI = True | ShowTUI = False | ||||||
| 
 | 
 | ||||||
| [OPERATOR_REQUIRED] | [OPERATOR_REQUIRED] | ||||||
| TransceiverPort = /dev/ttyACM0 | TransceiverPort = /dev/ttyACM0 | ||||||
|  |  | ||||||
|  | @ -4,17 +4,17 @@ PierMesh has two main events loops to learn about: the TUI and the service. | ||||||
| 
 | 
 | ||||||
| ## TUI | ## TUI | ||||||
| 
 | 
 | ||||||
| [🔗 Docs](https://git.utopic.work/PierMesh/piermesh/src/branch/main/docs/tlog.md) | [🔗 Docs](https://git.utopic.work/PierMesh/piermesh/src/branch/main/docs/ui.md) | ||||||
| 
 | 
 | ||||||
| [🔗 Source](https://git.utopic.work/PierMesh/piermesh/src/branch/main/src/tlog.py) | [🔗 Source](https://git.utopic.work/PierMesh/piermesh/src/branch/main/src/ui.py) | ||||||
| 
 | 
 | ||||||
| The TUI is provided via [curses](https://docs.python.org/3/howto/curses.html) library. It's a relatively simple application that gives us a quick overview of system statistics in the way of memory and cpu usage as well as logs you can scroll with the directional keys | The TUI is provided via [Textual's](https://textual.textualize.io/) library. It's a relatively simple application that gives us a quick overview of system statistics in the way of memory and cpu usage as well as scrollable logs. You can toggle full screen logs with f and close the TUI and service with q. | ||||||
| 
 | 
 | ||||||
| ## The Service | ## The Service | ||||||
| 
 | 
 | ||||||
| PierMesh runs a number of loops under the hood. These are primarily initialized in the main loop of run with a special logging loop outside of that. | PierMesh runs a number of loops under the hood. These are primarily initialized in the main loop of run with a special logging loop outside of that. | ||||||
| 
 | 
 | ||||||
| Note that we make use of [Meshtastic's Python API](https://github.com/meshtastic/python). | Note that we make heavy use of [Meshtastic's Python API](https://github.com/meshtastic/python). | ||||||
| 
 | 
 | ||||||
| ### run | ### run | ||||||
| 
 | 
 | ||||||
|  | @ -26,18 +26,18 @@ Note that we make use of [Meshtastic's Python API](https://github.com/meshtastic | ||||||
| 
 | 
 | ||||||
| In run.main we (in order) | In run.main we (in order) | ||||||
| 1. Initialize the `Node` class to a global `nodeOb`. | 1. Initialize the `Node` class to a global `nodeOb`. | ||||||
| 2. Wait for x seconds determined by command line arguments (see the falin script in scripts) | 2. Wait for x seconds determined by command line arguments (see the falin and marcille scripts in scripts) | ||||||
| 3. Initialize our `Transceiver` class (and the corresponding hardware) | 3. Initialize our `Transceiver` class (and the corresponding hardware) | ||||||
| 4. Initialize our `Server` class | 4. Initialize our `Server` class | ||||||
| 5. Create an async task running the `Node.spongeListen` method which looks for updates from the filter system | 5. Create an async task running the `Node.spongeListen` method which looks for updates from the filter system | ||||||
| 6. Kick the loop on with `await asyncio.sleep(1)` (we do this to kick on all async loops so I will omit this step going forward) | 6. Kick the loop on with `await asyncio.sleep(1)` (we do this to kick on all async loops so I will omit this step going forward) | ||||||
| 7. Create an async task running the `Transceiver.checkProgress` method which checks for packet reception progress and resends packets if necessary (currently not in use) | 7. Create an async task running the `Transceiver.checkProgress` method which checks for packet reception progress and resends packets if necessary | ||||||
| 8. Create an async task running `Node.monitor` which checks and reports system usage | 8. Create an async task running `Node.monitor` which checks and reports system usage | ||||||
| 9. Create an async task running the `Transceiver.announce` method which broadcasts a `Packets.Message` containing network mapping information | 9. Create an async task running the `Transceiver.announce` method which broadcasts a `Packets.Message` containing network mapping information | ||||||
| 10. Last we start the `Microdot` server loop | 10. Last we start the `Microdot` server loop | ||||||
| 
 | 
 | ||||||
| ### .. | ### .. | ||||||
| Travelling out of the run.main thread to the primary ____main____ code we see the other thread running the TUI loop which has it's own system we just kick on by running .runLogUI | Travelling out of the run.main thread to the primary ____main____ code we see the other two threads: one running the `logPassLoop` loop which is created in the same way as the main thread: `lplThread = threading.Thread(target=asyncio.run, args=(logPassLoop(),))` and one running the TUI loop which has it's own system we just kick on by instantiating the TUI class and calling .run() on. | ||||||
| 
 | 
 | ||||||
| ## Packet lifecycle | ## Packet lifecycle | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										41
									
								
								src/run.py
								
								
								
								
							
							
						
						
									
										41
									
								
								src/run.py
								
								
								
								
							|  | @ -129,7 +129,7 @@ if __name__ == "__main__": | ||||||
|     else: |     else: | ||||||
|         if "ShowTUI" in config["OPERATOR_OVERRIDES"]: |         if "ShowTUI" in config["OPERATOR_OVERRIDES"]: | ||||||
|             showTUI = config["OPERATOR_OVERRIDES"]["ShowTUI"] |             showTUI = config["OPERATOR_OVERRIDES"]["ShowTUI"] | ||||||
|     showTUI = showTUI == "True" |     showTUI = bool(showTUI) | ||||||
|     psk = False |     psk = False | ||||||
|     if argConfig.override: |     if argConfig.override: | ||||||
|         if not argConfig.PSK: |         if not argConfig.PSK: | ||||||
|  | @ -274,14 +274,15 @@ class Node: | ||||||
|         """ |         """ | ||||||
|         Monitor and log ram and cpu usage |         Monitor and log ram and cpu usage | ||||||
|         """ |         """ | ||||||
|         global tuiOb, logger |         global tuiOb | ||||||
|         while True: |         while True: | ||||||
|             if tuiOb is not None and showTUI: |             if tuiOb != None: | ||||||
|                 await asyncio.sleep(10) |                 await asyncio.sleep(10) | ||||||
|                 memmb = self.proc.memory_info().rss / (1024 * 1024) |                 memmb = self.proc.memory_info().rss / (1024 * 1024) | ||||||
|                 memmb = round(memmb, 2) |                 memmb = round(memmb, 2) | ||||||
|                 cpup = self.proc.cpu_percent(interval=1) |                 cpup = self.proc.cpu_percent(interval=1) | ||||||
|                 logger.info( |                 logger.log( | ||||||
|  |                     10, | ||||||
|                     " MEM: {0} mB | CPU: {1} %".format( |                     " MEM: {0} mB | CPU: {1} %".format( | ||||||
|                         memmb, |                         memmb, | ||||||
|                         cpup, |                         cpup, | ||||||
|  | @ -289,17 +290,6 @@ class Node: | ||||||
|                 ) |                 ) | ||||||
|                 tuiOb.do_set_cpu_percent(float(cpup)) |                 tuiOb.do_set_cpu_percent(float(cpup)) | ||||||
|                 tuiOb.do_set_mem(memmb) |                 tuiOb.do_set_mem(memmb) | ||||||
|             elif not showTUI: |  | ||||||
|                 await asyncio.sleep(10) |  | ||||||
|                 memmb = self.proc.memory_info().rss / (1024 * 1024) |  | ||||||
|                 memmb = round(memmb, 2) |  | ||||||
|                 cpup = self.proc.cpu_percent(interval=1) |  | ||||||
|                 logger.info( |  | ||||||
|                     " MEM: {0} mB | CPU: {1} %".format( |  | ||||||
|                         memmb, |  | ||||||
|                         cpup, |  | ||||||
|                     ), |  | ||||||
|                 ) |  | ||||||
|             else: |             else: | ||||||
|                 logger.log(20, "No TUI object, waiting 5 seconds...") |                 logger.log(20, "No TUI object, waiting 5 seconds...") | ||||||
|                 await asyncio.sleep(5) |                 await asyncio.sleep(5) | ||||||
|  | @ -316,7 +306,6 @@ class Node: | ||||||
|         ----- |         ----- | ||||||
|         We use a common technique here that calls the function from our preloaded actions via dictionary entry |         We use a common technique here that calls the function from our preloaded actions via dictionary entry | ||||||
|         """ |         """ | ||||||
|         global logger |  | ||||||
|         while True: |         while True: | ||||||
|             while (len(self.todo) >= 1): |             while (len(self.todo) >= 1): | ||||||
|                 try: |                 try: | ||||||
|  | @ -495,23 +484,17 @@ def initLogger(nodeName, tolog, tui=True): | ||||||
|     """ |     """ | ||||||
|     global logger |     global logger | ||||||
|     logger = logging.getLogger(__name__) |     logger = logging.getLogger(__name__) | ||||||
|     logger.propagate = False |     logger.propagate = not tui | ||||||
|     logger.setLevel(logging.DEBUG) |     logger.setLevel(logging.DEBUG) | ||||||
| 
 | 
 | ||||||
|  |     vh = VHandler(logging.DEBUG, tolog) | ||||||
|  | 
 | ||||||
|     formatter = logging.Formatter( |     formatter = logging.Formatter( | ||||||
|         '%(asctime)s - %(name)s - %(levelname)s - %(message)s') |         '%(asctime)s - %(name)s - %(levelname)s - %(message)s') | ||||||
| 
 | 
 | ||||||
|     if tui: |  | ||||||
|         vh = VHandler(logging.DEBUG, tolog) |  | ||||||
| 
 |  | ||||||
|     vh.setFormatter(formatter) |     vh.setFormatter(formatter) | ||||||
| 
 | 
 | ||||||
|     logger.addHandler(vh) |     logger.addHandler(vh) | ||||||
|     else: |  | ||||||
|         sh = logging.StreamHandler() |  | ||||||
|         sh.setLevel(logging.DEBUG) |  | ||||||
|         sh.setFormatter(formatter) |  | ||||||
|         logger.addHandler(sh) |  | ||||||
| 
 | 
 | ||||||
|     dt = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") |     dt = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") | ||||||
| 
 | 
 | ||||||
|  | @ -524,14 +507,14 @@ def initLogger(nodeName, tolog, tui=True): | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
|     try: |     try: | ||||||
|         tolog = queue.Queue() |         tolog = queue.Queue() | ||||||
|         initLogger(nodeNickname, tolog, tui=showTUI) |         initLogger(nodeNickname, tolog) | ||||||
|         mainThread = threading.Thread(target=uvloop.run, args=(main(),)) |         mainThread = threading.Thread(target=uvloop.run, args=(main(),)) | ||||||
|         mainThread.start() |         mainThread.start() | ||||||
|  |         # TODO: Waiting for this to finish when no tui | ||||||
|  |         # TODO: Logging to screen when no tui | ||||||
|         if showTUI: |         if showTUI: | ||||||
|             tlog.runLogUI(tolog, nodeNickname) |             tlog.runLogUI(tolog, nodeNickname) | ||||||
|         else: |         # else: | ||||||
|             # TODO: Resource logging |  | ||||||
|             print("No TUI") |  | ||||||
|     except Exception: |     except Exception: | ||||||
|         print(traceback.format_exc()) |         print(traceback.format_exc()) | ||||||
|         os._exit(1) |         os._exit(1) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue