Skip to content

Commit

Permalink
Merge branch 'dev/nick' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
NicK4rT authored Nov 23, 2024
2 parents 05b218c + b7c19b6 commit cb954f0
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 28 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/tools.html
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ <h2>Useful Resources</h2>
<p style="margin: 5px 0;">Directly program and control your module from our online pyscript IDE</p>
</li>
<li style="margin-bottom: 20px;">
<a href="https://www.youtube.com/watch?v=GFq6wH5JR2A" style="font-weight: bold; font-size: 18px;">Cluster Management UI</a>
<a href="https://nickart.pyscriptapps.com/floral-firefly/latest/" style="font-weight: bold; font-size: 18px;">Cluster/Network Management UI</a>
<p style="margin: 5px 0;">Manage and control a cluster of modules from our pyscript Cluster Management UI</p>
</li>
<li style="margin-bottom: 20px;">
Expand Down
Binary file modified software/.DS_Store
Binary file not shown.
Binary file modified software/networking/.DS_Store
Binary file not shown.
3 changes: 1 addition & 2 deletions software/networking/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
config = "AdminModuleConfig"
whitelist = [b'd\xe83\x84\xd8\x18',b'd\xe83\x84\xd8\x19',b'd\xe83\x85\xd3\xbc', b'd\xe83\x85\xd3\xbd', b'd\xe83\x84\xd8\x18', b'd\xe83\x84\xd8\x19'] #each ESP32 has two MAC addresses
i2c_dict = {"0x3C": ["pca9685", 0, "screen"], "0x53" : ["ACCEL", 1, "accelerometer"]} #key is i2c address: ["device name", Output (0) or Input (1), "Description"]
version={"adxl345":3,"files":2, "icons":2, "main":4, "prefs":2, "sensors":4, "servo":2, "ssd1306":2}

version={"adxl345":3,"files":2, "icons":2, "motor":4, "main":0, "networking":0, "prefs":2, "sensors":4, "servo":2, "ssd1306":2} #motor used to be main
Binary file added software/networking/examples/.DS_Store
Binary file not shown.
23 changes: 13 additions & 10 deletions software/networking/examples/pyscript_main.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import os
from machine import Pin
import machine
import gc
gc.collect()

import time

print("Running pyscript networking tool")

from networking import Networking

#Network
networking = Networking(True, False, True)
peer_mac = b'\xff\xff\xff\xff\xff\xff'

print("Running pyscript networking tool")
print(f"Name: {networking.name}, ID: {networking.id}, config: {networking.config}, Sta mac: {networking.sta.mac()}, Ap mac: {networking.ap.mac()}, Version: {networking.version_n}")

print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Name: {networking.name}, ID: {networking.id}, config: {networking.config}, Sta mac: {networking.sta.mac()}, Ap mac: {networking.ap.mac()}, Version: {networking.version_n}")

lastPressed = 0
start_time = time.ticks_ms()

message="Boop!"

Expand All @@ -27,16 +26,20 @@ def boop(pin):
networking.aen.ping(peer_mac)
networking.aen.echo(peer_mac, message)
networking.aen.send(peer_mac, message)
print(f"Sent {message} to {peer_mac}")
print(networking.aen.rssi())
print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Tool: Sent {message} to {peer_mac}")
print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Tool: RSSI table: {networking.aen.rssi()}")

switch_select = Pin(9, Pin.IN, Pin.PULL_UP)

#Buttons
switch_select = Pin(9, Pin.IN, Pin.PULL_UP)
switch_select.irq(trigger=Pin.IRQ_FALLING, handler=boop)

while True:
print(f"{int(time.ticks_ms()-start_time)/1000}: {gc.mem_free()} bytes")
time.sleep(1)
def heartbeat(timer):
print("")
print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Tool Heartbeat: {gc.mem_free()} bytes")
print("")
gc.collect()

timer = machine.Timer(0)
timer.init(period=5000, mode=machine.Timer.PERIODIC, callback=heartbeat)
31 changes: 16 additions & 15 deletions software/networking/networking.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import network
import machine
from config import mysecrets, configname, config, whitelist, i2c_dict, version
#from version import version
import time
import ubinascii
import urequests
Expand All @@ -10,15 +9,15 @@
import asyncio
import struct
import json
import random
import sys
import uos
import os

boottime = time.ticks_ms()
inittime = time.ticks_ms()

class Networking:
def __init__(self, infmsg=False, dbgmsg=False, admin=False):
self.inittime = inittime
if infmsg:
print(f"{(time.ticks_ms() - inittime) / 1000:.3f} Initialising Networking")
self.master = self
self.infmsg = infmsg
self.dbgmsg = dbgmsg
Expand All @@ -38,6 +37,8 @@ def __init__(self, infmsg=False, dbgmsg=False, admin=False):
self.config = config
self.version = version
self.version_n = ''.join(str(value) for value in self.version.values())
if infmsg:
print(f"{(time.ticks_ms() - inittime) / 1000:.3f} seconds: Networking initialised and ready")

def _cleanup(self):
self._dprint("._cleanup")
Expand All @@ -49,17 +50,17 @@ def _cleanup(self):
def _iprint(self, message):
if self.infmsg:
try:
print(f"{int((time.ticks_ms()-boottime))//1/1000} networking Info: {message}")
print(f"{(time.ticks_ms() - inittime) / 1000:.3f} Networking Info: {message}")
except Exception as e:
print(f"Error printing networking Info: {2}")
print(f"Error printing networking Info: {e}")
return

def _dprint(self, message):
if self.dbgmsg:
try:
print(f"{int((time.ticks_ms()-boottime))//1/1000} networking Debug: {message}")
print(f"{(time.ticks_ms() - inittime) / 1000:.3f} Networking Debug: {message}")
except Exception as e:
print(f"Error printing networking Debug: {2}")
print(f"Error printing networking Debug: {e}")
return


Expand All @@ -69,7 +70,7 @@ def __init__(self, master, _staif):
self.master = master
self._sta = _staif
self._sta.active(True)
self.master._iprint("STA initialized and ready")
self.master._iprint("STA initialised and ready")

def scan(self):
self.master._dprint("sta.scan")
Expand Down Expand Up @@ -135,7 +136,7 @@ def __init__(self, master, _apif):
self.master = master
self._ap = _apif
self._ap.active(True)
self.master._iprint("AP initialized and ready")
self.master._iprint("AP initialised and ready")

def set_ap(self, name="", password="", max_clients=10):
self.master._dprint("ap.setap")
Expand Down Expand Up @@ -206,7 +207,7 @@ def __init__(self, master):

self._aen.irq(self._irq)

self.master._iprint("ESP-NOW initialized and ready")
self.master._iprint("ESP-NOW initialised and ready")

def update_peer(self, peer_mac, name=None, channel=None, ifidx=None):
self.master._dprint("aen.update_peer")
Expand Down Expand Up @@ -332,7 +333,7 @@ def _irq(self, espnow):
if self.master._admin:
try:
self._receive()
if self._irq_function and self.check_messages() and self._isrunning:
if self._irq_function and self.check_messages() and self._running:
self._irq_function()
gc.collect()
return
Expand All @@ -343,7 +344,7 @@ def _irq(self, espnow):
self._aen.active(False)
#self.master._cleanup()
raise SystemExit("Stopping networking execution. ctrl-c or ctrl-d again to stop main code") #in thonny stops library code but main code keeps running, same in terminal
#self._isrunning = False
#self._running = False
#raise KeyboardInterrupt #error in thonny but then stops running, just keeps running in terminal
#sys.exit(0) #breaks thonny, keeps running and recv (although ctl-d-able and keps running main loop in terminal
#machine.reset() #nogo keeps raising errors and running in terminal
Expand All @@ -354,7 +355,7 @@ def _irq(self, espnow):
#raise KeyboardInterrupt("User interrupt simulated.") #interrupts library code, but main code keeps running, recv just keeps running in terminal
else:
self._receive()
if self._irq_function and self.check_messages() and self._isrunning:
if self._irq_function and self.check_messages() and self._running:
self._irq_function()
gc.collect()
return
Expand Down

0 comments on commit cb954f0

Please sign in to comment.