From cfa0656fdea74d124435668c907e3f54cde79051 Mon Sep 17 00:00:00 2001 From: Nick Art Date: Thu, 21 Nov 2024 14:51:30 -0500 Subject: [PATCH 1/3] Added features fixed bugs in networking, added main.py for pyscript page reworked config --- software/.DS_Store | Bin 8196 -> 8196 bytes software/networking/.DS_Store | Bin 6148 -> 6148 bytes software/networking/config.py | 3 +- software/networking/examples/.DS_Store | Bin 0 -> 6148 bytes software/networking/examples/pyscript_main.py | 23 ++++++------- software/networking/networking.py | 31 +++++++++--------- 6 files changed, 29 insertions(+), 28 deletions(-) create mode 100644 software/networking/examples/.DS_Store diff --git a/software/.DS_Store b/software/.DS_Store index 9365f422f91f55794d6504961e2c433a875319ee..6d29c9c21830e9f91bfe2917bf9d630beefe5fc1 100644 GIT binary patch delta 318 zcmZp1XmOa}&nUk!U^hRb{A52tnavskiENy#3?&TtK$tUGO+c|8&SNOfNjD5m&d)7i z0E3USffSN#ZoZ34QcivnP?RJ1pcSKW*fB?R6)6N%6l5UTz!(73KC$HLW_F3DLFcMV E0L6MsyZ`_I delta 36 qcmZp1XmOa}&nUGqU^hRb)MP(FnavskiEJCo>KHe(OEdu))rB!ku~2NI-d)DUADEdYb2F9KCzTf$B<18MF)%RfNGiz5EG{uHxW>rD z%)-jX&cV*X%@G@%kzXEMl2}q&?37p(4dR95=jSBB*ojGDnW^RR0wT`&c_oRNd8tKU z4VfvaKqWEZnRzMsB)qu~2NI-d)DY+$`mjqgdOu*coye5*acX@)-0O3K%LqbMljua`KZH z7#IW?7?{$5wBCO(VAy<@Rf}n3!z!lD>>T_YK%+Jba(ri=%rD}|0aV4n$iTp|IYML& FGXQlG9a8`R diff --git a/software/networking/config.py b/software/networking/config.py index d62620a..26b6133 100644 --- a/software/networking/config.py +++ b/software/networking/config.py @@ -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 \ No newline at end of file diff --git a/software/networking/examples/.DS_Store b/software/networking/examples/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..52480c493ce34ffea9e216efd4eb4ea4e4a0605d GIT binary patch literal 6148 zcmeHKOHRW;41F$L6j;z5Y>;w-O57k+Wx<*QKtCy}loA9~f?f6;h9knW$5b?F#SS5` zEBnn%Y^U=kiemsWT+PmaK7bxov9nLJMfAFAOFF*NC5q)(p~MrevBbFL9Sgsa0X@4T z%ury?Gy8ge3*2FVd%Rqh)pSx;6MFJ7kyGN}-NZI@z}RQTF6moxyd?(bjhJJ4R?L5E z&q{$u{>GdYoPVF~t&y#-|B@M|c))_=&nIx#4qhAawv8~sKrj#t{38ZfvsHSB3Bv{h z!9XyuW8o5 zI$;Wjc=I8CXYme2?C#8;nL8v;7&aIP1~wVkOVhsA|BK!I|7K9kf`MS*Pcb0f(bZ_k zEqQHiZBA=#M!lh`s9&9M9m0W?V)|++KB1a$J<|a(cdQd~g%TeEMnjlj;71ww03n=C AApigX literal 0 HcmV?d00001 diff --git a/software/networking/examples/pyscript_main.py b/software/networking/examples/pyscript_main.py index a9aac2f..5148c41 100644 --- a/software/networking/examples/pyscript_main.py +++ b/software/networking/examples/pyscript_main.py @@ -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!" @@ -27,8 +26,8 @@ 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) @@ -36,9 +35,11 @@ def boop(pin): 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: {gc.mem_free()} bytes") + print("") gc.collect() - +timer = machine.Timer(0) +timer.init(period=5000, mode=machine.Timer.PERIODIC, callback=heartbeat) \ No newline at end of file diff --git a/software/networking/networking.py b/software/networking/networking.py index 7cb2926..3d7e15e 100644 --- a/software/networking/networking.py +++ b/software/networking/networking.py @@ -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 @@ -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 @@ -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") @@ -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 @@ -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") @@ -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") @@ -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") @@ -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 @@ -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 @@ -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 From e20f267541d34b74b7024f60d3c817a07f9475e4 Mon Sep 17 00:00:00 2001 From: Nick Art Date: Thu, 21 Nov 2024 23:18:14 -0500 Subject: [PATCH 2/3] SMall additions added pyscript link to webpage updated main.py --- .DS_Store | Bin 12292 -> 12292 bytes docs/tools.html | 2 +- software/networking/examples/pyscript_main.py | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.DS_Store b/.DS_Store index 38ed7729b99ef207b08b5690061d729bdda89efb..9720e53693e55910db9e6ab8b2da07d7d25842ad 100644 GIT binary patch delta 25 gcmZokXi3;$p~zukV4|a7Vre$HK+t}3y<#gL0A>XTng9R* delta 32 ncmZokXi3;$p~!D;VydHHW@22cqfl*WWHh-^)M9hJVk;j2pHT^t diff --git a/docs/tools.html b/docs/tools.html index f43d693..be89216 100644 --- a/docs/tools.html +++ b/docs/tools.html @@ -212,7 +212,7 @@

Useful Resources

Directly program and control your module from our online pyscript IDE

  • - Cluster Management UI + Cluster/Network Management UI

    Manage and control a cluster of modules from our pyscript Cluster Management UI

  • diff --git a/software/networking/examples/pyscript_main.py b/software/networking/examples/pyscript_main.py index 5148c41..dbab0b7 100644 --- a/software/networking/examples/pyscript_main.py +++ b/software/networking/examples/pyscript_main.py @@ -37,7 +37,7 @@ def boop(pin): def heartbeat(timer): print("") - print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Tool: {gc.mem_free()} bytes") + print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Tool Heartbeat: {gc.mem_free()} bytes") print("") gc.collect() From b7c19b632e805739802a11d59709c15f8f5e92c8 Mon Sep 17 00:00:00 2001 From: Nick Art <100365428+NicK4rT@users.noreply.github.com> Date: Fri, 22 Nov 2024 15:27:44 -0500 Subject: [PATCH 3/3] Delete .READMEdescription.md --- .READMEdescription.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .READMEdescription.md diff --git a/.READMEdescription.md b/.READMEdescription.md deleted file mode 100644 index 8c8cf9d..0000000 --- a/.READMEdescription.md +++ /dev/null @@ -1 +0,0 @@ -This is the main directory. \ No newline at end of file