Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions software/archive/backup nonworkign code/am1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import time
import gc
import machine
from machine import Pin, Timer

print("Running am1.py")

try:
networking
except NameError:
print("Trying to load networking from config.py")
from config import networking
if networking is None:
print("Error loading networking, reseting machine")
machine.reset()

peer_mac = b'\xff\xff\xff\xff\xff\xff' # Replace with actual MAC
lastPressed = 0
message = "Boop!"

networking.ping(peer_mac)

def boop(pin):
global lastPressed
if (time.ticks_ms() - lastPressed > 1000):
lastPressed = time.ticks_ms()
networking.ping(peer_mac)
# networking.echo(peer_mac, message)
# networking.send(peer_mac, time.ticks_ms())
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.rssi()}")

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

def heartbeat(timer):
print("")
boop(None)
print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Tool Heartbeat: {gc.mem_free()} bytes")
print("")
gc.collect()

# Periodic heartbeat timer (every 10 s)
timer = Timer(0)
timer.init(period=10000, mode=Timer.PERIODIC, callback=heartbeat)
1 change: 1 addition & 0 deletions software/archive/backup nonworkign code/boot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#empty
83 changes: 83 additions & 0 deletions software/archive/backup nonworkign code/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
config = {'name': 'Nick', 'ap_channel': 1, 'sta_mac': '64:e8:33:85:d3:bc', 'ap_mac': '64:e8:33:85:d3:bd', 'version': '2025-10-12-175607', 'id': '64e83385d3bc', 'configuration': 'AM1', 'sta_channel': 1, 'type': 'ESP32C3 module with ESP32C3'}
version = {
'adxl345.py': 3,
'am1.py': 1,
'hm1.py': 1,
'ssp_networking.py': 4,
'files.py': 2,
'icons.py': 2,
'prefs.py': 2,
'sensors.py': 4,
'servo.py': 2,
'ssd1306.py': 2,
'sm3.py': 1,
'sl1.py': 1,
'smartlight.py': 1,
'networking.py': 6,
'main.py': 2,
'boot.py': 0
}
mysecrets = {"SSID": "Tufts_Robot", "key": ""}
msg_codes = {"cmd": 0x01, "inf": 0x02, "ack": 0x03}
msg_subcodes = {
"cmd": {
"Reboot": 0x00,
"Firmware-Update": 0x01,
"File-Update": 0x02,
"File-Download": 0x03,
"File-Run": 0x05,
"Set-Admin": 0x06,
"Whitelist-Add": 0x07,
"Config-Change": 0x08,
"Name-Change": 0x09,
"Ping": 0x10,
"Pair": 0x11,
"Set-Pair": 0x12,
"RSSI/Status/Config-Boop": 0x13,
"Directory-Get": 0x14,
"Echo": 0x15,
"Resend": 0x16,
"Hive-Set": 0x17,
"Hive-Configure": 0x18,
"Web-Repl": 0x20,
"WiFi-Connect": 0x21,
"WiFi-Disconnect": 0x22,
"AP-Enable": 0x23,
"AP-Disable": 0x24,
"Pause": 0x25,
"Resume": 0x26,
},
"inf": {
"RSSI/Status/Config-Boop": 0x20,
"Data": 0x21,
"Message": 0x22,
"Directory": 0x23,
},
"ack": {
"Pong": 0x10,
"Success": 0x11,
"Fail": 0x12,
"Confirm": 0x13,
"Echo": 0x15,
},
}
networking_keys = {
"default_handshake_key": "handshake",
"handshake_key1": "handshake1",
"handshake_key2": "handshake2",
"handshake_key3": "handshake3",
"handshake_key4": "handshake4",
"default_ap_key": "password",
"default_wifi_key": "password"
}
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"]
sensor_dict = {"sensor": [0,4095], "potentiometer": [0,180], "select": [0,1], "up": [0,1], "down": [0,1], "button": [0,1], "sw1": [0,1], "sw2": [0,1], "sw3": [0,1], "sw4": [0,1]}
hive_config = {'hive': True, 'recipients': [], 'sender_sensor_list': [[b'd\xe83\x84\xd8\x18', 'None']], 'refreshrate': 200, 'mode': 'None'}

networking = None
91 changes: 91 additions & 0 deletions software/archive/backup nonworkign code/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import time


# Network
from ssp_networking import SSP_Networking

# Initialise
infmsg = True
dbgmsg = False
errmsg = True
networking = SSP_Networking(infmsg, dbgmsg, errmsg)

print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Example: Running example.py")
print()


###Example code###

recipient_mac = b'\xff\xff\xff\xff\xff\xff' # This mac sends to all
message = b'Boop'

# Print device networking configuration
print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Example: Config: {networking.config}")
print()


#Command Types:
# Ping, calculates the time until you receive a response from the peer and adds their infor to the networking address book
networking.ping(recipient_mac)
print()

# Echo, sends a message that will be repeated back by the recipient
networking.echo(recipient_mac, message)
print()

# There are a bunch of more command types, the complete list can be found in the config.py or ssp_networking.py


#Message Type
# Message, sends the specified message to the recipient, supported formats are bytearrays, bytes, int, float, string, bool, list and dict, if above 241 bytes, it will send in multiple packages: max 60928 bytes
networking.send(recipient_mac, message)
print()

# Check if there are any messages in the message buffer, returns True or False
print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Example: {networking.check_messages()}")
print()

# Get Last Received Message
print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Example: {networking.return_message()}") # Returns none, none, none if there are no messages
print()


#Other
# Get the RSSI table
print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Example: {networking.rssi()}")
print()


#IRQ
# Set up an interrupt which runs a function as soon as possible after receiving a new message
def receive():
for mac, message, rtime in networking.return_messages(): # You can directly iterate over the function
print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Example: Received {message} from {peer_mac} at {rtime}")

networking.irq(receive) # interrupt handler


#Send trigger
#You could set up a function that sends a message to all and is called when the select button on the dahal board is pressed
from machine import Pin
import machine

lastPressed = 0

def boop(pin):
global lastPressed
if (time.ticks_ms() - lastPressed > 1000): #prevents button to be called multiple times within 1 second
lastPressed = time.ticks_ms()
networking.send(peer_mac, "Hewwo!")
print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Example: Sent {message} to {peer_mac}")

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


#print something on the screen

#set up servo

#set up sensor

109 changes: 109 additions & 0 deletions software/archive/backup nonworkign code/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import config
import utime as time
from machine import Pin, Timer
import machine

print("Running main.py")

try:
time.sleep(3)
except Exception as e:
print(f"Error {e}")

module_name = config.config["configuration"].lower()

import gc

gc.collect()

import network

# just to be safe
sta = network.WLAN(network.STA_IF)
ap = network.WLAN(network.AP_IF)
sta.active(True)
ap.active(True)
sta.active(False)
ap.active(False)

from ssp_networking import SSP_Networking
import ssp_networking

# Network
infmsg = True
dbgmsg = False
errmsg = True
configuration = config.config["configuration"]

config.networking = SSP_Networking(infmsg, dbgmsg, errmsg)
networking = config.networking

peer_mac = b'\xff\xff\xff\xff\xff\xff'

print("{:.3f} Name: {}, ID: {}, Configuration: {}, Type: {}, Sta mac: {}, Sta channel: {}, Ap mac: {}, Ap channel: {}, Version: {}".format(
(time.ticks_ms() - networking.inittime) / 1000,
networking.config["name"],
networking.config["id"],
networking.config["configuration"],
networking.config["type"],
networking.config["sta_mac"],
networking.config["sta_channel"],
networking.config["ap_mac"],
networking.config["ap_channel"],
networking.config["version"]
))

def am1():
print("Running am1")

peer_mac = b'\xff\xff\xff\xff\xff\xff' # Replace with actual MAC
lastPressed = 0
message = "Boop!"

networking.ping(peer_mac)

def boop(pin):
global lastPressed
if (time.ticks_ms() - lastPressed > 1000):
lastPressed = time.ticks_ms()
networking.ping(peer_mac)
# networking.echo(peer_mac, message)
# networking.send(peer_mac, time.ticks_ms())
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.rssi()}")

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

def heartbeat(timer):
print("")
boop(None)
print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Tool Heartbeat: {gc.mem_free()} bytes")
print("")
gc.collect()

# Periodic heartbeat timer (every 10 s)
timer = Timer(0)
timer.init(period=1000, mode=Timer.PERIODIC, callback=heartbeat)


def deinit():
networking.cleanup()
try:
timer.deinit()
except Exception as e:
print(e)
machine.reset()


try:
if configuration == "AM1":
am1()
else:
with open(module_name + ".py") as f:
code = f.read()
exec(code, {"networking": networking, "configuration": configuration, "__name__": "__main__"})
except Exception as e:
print(f"Error running {module_name}: {e}")

Loading