Skip to content

Commit b0c391a

Browse files
Add files via upload
1 parent f3b080c commit b0c391a

19 files changed

+620
-319
lines changed

mpython/ESP32/mpython_wifi.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,34 @@ def http_get(url):
2020

2121
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
2222

23-
# Get wifi details and more from a secrets.py file
23+
# Read config
24+
config = {}
25+
envfound = True
2426
try:
25-
from secrets import secrets
26-
except ImportError:
27-
print("WiFi secrets are kept in secrets.py, please add them there!")
28-
raise
29-
30-
# Check secrets.py has updated credentials
31-
if secrets['ssid'] == 'your-ssid-here':
32-
assert False, ("WiFi secrets are kept in secrets.py, please add them there!")
27+
envfile = open('/.env')
28+
except:
29+
envfound = False
30+
31+
if envfound:
32+
for line in envfile:
33+
try:
34+
config[line.split('=')[0].strip()] = line.split('=')[1].strip()
35+
except:
36+
pass
37+
envfile.close()
38+
39+
# Check .env has updated credentials
40+
if not envfound or config.get('CIRCUITPY_WIFI_SSID','') == '':
41+
assert False, ("/.env has not been updated with your unique keys and data")
3342

3443
# Create WiFi connection and turn it on
3544
wlan = network.WLAN(network.STA_IF)
3645
if not wlan.active():
3746
wlan.active(True)
3847

3948
# Connect to WiFi router
40-
print ("Connecting to WiFi: {}".format( secrets['ssid'] ) )
41-
wlan.connect( secrets['ssid'], secrets['password'])
49+
print ("Connecting to WiFi: {}".format( config['CIRCUITPY_WIFI_SSID'] ) )
50+
wlan.connect( config['CIRCUITPY_WIFI_SSID'], config['CIRCUITPY_WIFI_PASSWORD'])
4251

4352
# Wait until wifi is connected
4453
while not wlan.isconnected():

mpython/ESP32/wifi_financeMP.py

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,35 @@
77
import ussl as ssl
88
except:
99
import ssl
10+
import time
1011

11-
# Get wifi details and more from a secrets.py file
12+
config = {}
13+
envfound = True
1214
try:
13-
from secrets import secrets
14-
except ImportError:
15-
print("WiFi secrets are kept in secrets.py, please add them there!")
16-
raise
15+
envfile = open('/.env')
16+
except:
17+
envfound = False
18+
19+
if envfound:
20+
for line in envfile:
21+
try:
22+
config[line.split('=')[0].strip()] = line.split('=')[1].strip()
23+
except:
24+
pass
25+
envfile.close()
26+
27+
# Check .env has updated credentials
28+
if not envfound or config.get('CIRCUITPY_WIFI_SSID','') == '':
29+
assert False, ("/.env has not been updated with your unique keys and data")
1730

1831
# AP info
19-
SSID=secrets['ssid'] # Network SSID
20-
KEY=secrets['password'] # Network key
32+
SSID=config['CIRCUITPY_WIFI_SSID'] # Network SSID
33+
KEY=config['CIRCUITPY_WIFI_PASSWORD'] # Network key
2134

2235
PORT = 443
23-
HOST = "money.cnn.com"
36+
#HOST = "money.cnn.com"
2437
#HOST2 = "www.money.cnn.com/data/markets"
38+
HOST = "finance.yahoo.com"
2539

2640
wlan = network.WLAN(network.STA_IF)
2741
if not wlan.active():
@@ -55,8 +69,9 @@
5569
#client.settimeout(3.0)
5670

5771
# Send HTTP request and recv response
58-
print("Fetching text from %s/data/markets" % HOST)
59-
client.write("GET /data/markets HTTP/1.1\r\nHost: %s\r\n\r\n"%(HOST))
72+
print("Fetching text from %s/quote/%%5EIXIC" % HOST)
73+
#client.write("GET /data/markets HTTP/1.1\r\nHost: %s\r\n\r\n"%(HOST))
74+
client.write("GET /quote/%%5EIXIC HTTP/1.1\r\nHost: %s\r\n\r\n"%(HOST))
6075

6176
print("-" * 40)
6277
response = client.read(800).decode('utf-8')
@@ -65,16 +80,43 @@
6580
print()
6681

6782
nasdaq = -1
68-
while nasdaq == -1:
83+
strtime = time.ticks_ms()
84+
timer = 0
85+
while nasdaq == -1 and timer < 60000:
6986
gc.collect()
70-
response = client.read(4096).decode('utf-8')
71-
72-
nasdaq = response.find('data-ticker-name="Nasdaq"')
73-
pct = response[nasdaq:].find('%')
74-
pctst = response[nasdaq+35:].find('>')
75-
pctend = response[nasdaq+35:].find('<')-1
76-
77-
print("Nasdaq: ",response[nasdaq+36+pctst:nasdaq+36+pctend])
87+
#response = client.read(4096).decode('utf-8')
88+
encresponse = client.read(4096)
89+
decerror = False
90+
try:
91+
response = encresponse.decode()
92+
except:
93+
decerror = True
94+
95+
if decerror:
96+
response = ""
97+
for chresp in encresponse:
98+
try:
99+
response += chr(chresp)
100+
except:
101+
pass
102+
103+
#nasdaq = response.find('data-ticker-name="Nasdaq"')
104+
nasdaq = response.find('data-symbol="^IXIC" data-field="regularMarketChangePercent"')
105+
pct = response[nasdaq:].find('%)')
106+
pctst = response[nasdaq+pct-15:].find('>')
107+
pctend = response[nasdaq+pct:].find('<')
108+
109+
timedelta = time.ticks_ms() - strtime
110+
if timedelta > 0:
111+
timer += timedelta
112+
strtime += timedelta
113+
else:
114+
strtime = time.ticks_ms()
115+
116+
if nasdaq == -1:
117+
print("Timeout fetching Web data")
118+
else:
119+
print("Nasdaq: ",response[nasdaq+pct-14+pctst:nasdaq+pct+pctend])
78120

79121
# Close socket
80122
#sslclient.close()

mpython/NanoConnect/connect_wifiMP.py

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
import network, socket
22

3-
# Get wifi details and more from a secrets.py file
3+
config = {}
4+
envfound = True
45
try:
5-
from secrets import secrets
6-
except ImportError:
7-
print("WiFi secrets are kept in secrets.py, please add them there!")
8-
raise
6+
envfile = open('/.env')
7+
except:
8+
envfound = False
9+
10+
if envfound:
11+
for line in envfile:
12+
try:
13+
config[line.split('=')[0].strip()] = line.split('=')[1].strip()
14+
except:
15+
pass
16+
envfile.close()
17+
18+
# Check .env has updated credentials
19+
if not envfound or config.get('CIRCUITPY_WIFI_SSID','') == '':
20+
assert False, ("/.env has not been updated with your unique keys and data")
921

1022
# AP info
11-
SSID=secrets['ssid'] # Network SSID
12-
KEY=secrets['password'] # Network key
23+
SSID=config['CIRCUITPY_WIFI_SSID'] # Network SSID
24+
KEY=config['CIRCUITPY_WIFI_PASSWORD'] # Network key
1325

1426
PORT = 80
1527
HOST = "www.google.com"
@@ -37,7 +49,29 @@
3749

3850
# Send HTTP request and recv response
3951
client.send("GET / HTTP/1.1\r\nHost: %s\r\n\r\n"%(HOST))
40-
print(client.recv(1024))
52+
print((client.recv(1024)).decode())
53+
# Close socket
54+
client.close()
55+
56+
57+
HOST = 'wifitest.adafruit.com'
58+
# Get addr info via DNS
59+
addr = socket.getaddrinfo(HOST, PORT)[0][4]
60+
print(addr)
61+
62+
# Create a new socket and connect to addr
63+
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
64+
client.connect(addr)
65+
66+
# Set timeout
67+
client.settimeout(3.0)
68+
69+
# Send HTTP request and recv response
70+
client.send("GET /testwifi/index.html HTTP/1.1\r\nHost: %s\r\n\r\n"%(HOST))
71+
print("-" * 40)
72+
print((client.recv(1024)).decode())
73+
print("-" * 40)
74+
4175

4276
# Close socket
4377
client.close()

mpython/badblink.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33
from machine import Pin
44
from os import uname
5+
from pydos_hw import Pydos_hw
56

67
import _thread
78
global threadLock
@@ -15,8 +16,12 @@
1516

1617
if uname().machine == 'Adafruit Feather RP2040 with RP2040':
1718
led = Pin(13, Pin.OUT)
19+
elif uname().machine == 'Adafruit ItsyBitsy RP2040 with RP2040':
20+
led = Pin(11, Pin.OUT)
1821
elif uname().machine == 'Arduino Nano RP2040 Connect with RP2040':
1922
led = Pin(6, Pin.OUT)
23+
elif Pydos_hw.led:
24+
led = Pin(Pydos_hw.led, Pin.OUT)
2025
else:
2126
led = Pin(25, Pin.OUT)
2227

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# PyDOS Board Configuration for 'Adafruit Feather RP2040 with RP2040'
2+
3+
Pydos_pins = {
4+
'sndPin' : (12,"D12 GPIO12"),
5+
'neoPixel' : (16,None),
6+
'I2C_NUM' : (1,None),
7+
'SCL' : (3,"SCL GPIO3"),
8+
'SDA' : (2,"SDA GPIO2"),
9+
'SPI_NUM' : (0,None),
10+
'SCK' : (18,"SCK GPIO18"),
11+
'MOSI' : (19,"MO GPIO19"),
12+
'MISO' : (20,"MI GPIO20"),
13+
'CS' : (7,"D5 GPIO7")
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# PyDOS Board Configuration for 'Adafruit ItsyBitsy RP2040 with RP2040'
2+
3+
Pydos_pins = {
4+
'sndPin' : (10,"GPIO10 D12"),
5+
'led' : (11,None),
6+
'neoPixel' : (17,None),
7+
'neoPixel_Pow' : (16,None),
8+
'I2C_NUM' : (1,None),
9+
'SCL' : (3,"GPIO3 SCL"),
10+
'SDA' : (2,"GPIO2 SDA"),
11+
'SPI_NUM' : (0,None),
12+
'SCK' : (18,"GPI18 SCK"),
13+
'MOSI' : (19,"GPI19 MO"),
14+
'MISO' : (20,"GPI20 MI"),
15+
'CS' : (7,"GPIO7 D9")
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# PyDOS Board Configuration for 'Adafruit QT Py RP2040 with RP2040'
2+
3+
Pydos_pins = {
4+
'sndPin' : (29,"A0"),
5+
'neoPixel' : (12,None),
6+
'neoPixel_Pow' : (11,None),
7+
'I2C_NUM' : (1,None),
8+
'SCL' : (23,"SCL"),
9+
'SDA' : (22,"SDA"),
10+
'SCK' : (6,"SCK"),
11+
'MOSI' : (3,"MO"),
12+
'MISO' : (4,"MI"),
13+
'CS' : (26,"A3")
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# PyDOS Board Configuration for 'Arduino Nano RP2040 Connect with RP2040'
2+
3+
Pydos_pins = {
4+
'sndPin' : (29,"GPIO29 A3"),
5+
'led' : (6,"GPIO6 D13"),
6+
'I2C_NUM' : (0,None),
7+
'SCL' : (13,"GPIO13 A5"),
8+
'SDA' : (12,"GPIO12 A4"),
9+
'SCK' : (6,"GPIO6 D13"),
10+
'MOSI' : (7,"GPIO7 D11"),
11+
'MISO' : (4,"GPIO4 D12"),
12+
'CS' : (5,"GPIO5 D10")
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# PyDOS Board Configuration for 'Raspberry Pi Pico with RP2040 with Cytron Maker Pi Pico'
2+
3+
Pydos_pins = {
4+
'sndPin' : (18,"GP18 Onboard Buzzer"),
5+
'neoPixel' : (28,None),
6+
'I2C_NUM' : (0,None),
7+
'SCL' : (3,"GP3 GROVE#2"),
8+
'SDA' : (2,"GP2 GROVE#2"),
9+
'SD_SPI_NUM' : (1,None),
10+
'SCK' : (10,"GP10 Onboard SD"),
11+
'MOSI' : (11,"GP11 Onboard SD"),
12+
'MISO' : (12,"GP12 Onboard SD"),
13+
'CS' : (15,"GP15 Onboard SD")
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# PyDOS Board Configuration for 'ESP32C3 module with ESP32C3' (adafruit_qtpy_esp32c3)
2+
3+
Pydos_pins = {
4+
'sndPin' : (4,"A0"),
5+
'neoPixel' : (2,None),
6+
'I2C_NUM' : (0,None),
7+
'SCL' : (6,"SCL"),
8+
'SDA' : (5,"SDA"),
9+
'SCK' : (10,"SCK"),
10+
'MOSI' : (7,"MO"),
11+
'MISO' : (8,"MI"),
12+
'CS' : (0,"A3")
13+
}

0 commit comments

Comments
 (0)