Clock Pulse Pin: {outpin}
Power Analysis Pin: {adcpin}
Frequency: {frequency}Hz (Duty Cycle: {dutyy}%)
Samples Per Pulse: {samples_per_pulse}
Delay Between Samples: {us_sample}us
LFGGGGGGGG FRONG
{footer}
"""
return str(template)
print("Board Started or Reset\n===========\n\n")
toggle_power = machine.Pin(power_on_pin, machine.Pin.OUT)
toggle_power.value(0)
# I like to have the LED on :3
led = machine.Pin('LED', machine.Pin.OUT)
led.value(1)
# do da thingggggssssss
def reset_init(t):
print("==Looping==")
toggle_power.value(1)
utime.sleep(1)
toggle_power(0)
# Connect to WLAN
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
# Wait for Wi-Fi connection
connection_timeout = 10
while connection_timeout > 0:
if wlan.status() >= 3:
break
connection_timeout -= 1
print('Waiting for Wi-Fi connection...')
utime.sleep(1)
# Check if connection is successful
if wlan.status() != 3:
raise RuntimeError('Failed to establish a network connection')
else:
print('Connection successful!')
network_info = wlan.ifconfig()
print(f"\n\nOpen web browser and navigate to http://{network_info[0]}\n\n")
# Set up socket and start listening
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(addr)
s.listen()
while True:
try:
conn, addr = s.accept()
request = conn.recv(1024)
request = str(request)
try:
fullreq = request.split()
request = fullreq[1]
except IndexError:
pass
# Process the action page!
if request.startswith('/action?', 0):
# parse the request path to extract da GET vars
req_string = request.split('?')[1]
req_vars = req_string.split('&')
for f in req_vars:
req_split = f.split('=')
# Type strict whitelist for safety and compatibility
if req_split[0] == 'duty_cycle':
duty_cycle_in = float(req_split[1])
elif req_split[0] == 'freq':
freq_in = int(req_split[1])
elif req_split[0] == 'samples_per_pulse':
samples_per_pulse_in = int(req_split[1])
loop_time = 1000*(seconds_awake-1)
print(f"power_analysis_pin: {power_analysis_pin}\nduty_cycle_in: {duty_cycle_in}\nfreq_in: {freq_in}\nsamples_per_pulse_in: {samples_per_pulse_in}\nloop_time (ms): {loop_time}\npower_on_pin: {power_on_pin}")
# run the clock pulse (PWM) task
do_pwm(clock_pulse_pin, duty_cycle_in, freq_in)
# fork the voltage measuring ADC reading to the second core
adc_thread = _thread.start_new_thread(do_adc, (power_analysis_pin, duty_cycle_in, freq_in, samples_per_pulse_in))
Timer(mode=Timer.PERIODIC, period=loop_time, callback=reset_init)
response = running_webpage()
else:
response = default_webpage()
# Send the HTTP response and close the conn
conn.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
conn.send(response)
conn.close()
except OSError as e:
conn.close()
print('Connection closed')