I'm working with micropython, and learning from the documentation but I came across this error, it works running network.py, but it doesn't work running main.py running from thonny IDE network.py
import time
import network
import urequests
class netWireless:
def setUp(ssid,password):
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid,password)
max_wait = 10
while max_wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
max_wait -= 1
print("waiting for connection...")
time.sleep(1)
if wlan.status() != 3:
raise RuntimeError('network connection failed')
return 0;
else:
print('connected')
status = wlan.ifconfig()
print('ip = ' + status[0])
return 1;
def getJSON(url):
response = urequests.get(url)
json = response.json()
response.close()
return json;
#working
netWireless.setUp('ssid','password')
main.py
import config
import modules.network
import modules.dateTime
#not working
setUpStatus = netWireless.setUp('ssid','password')
Shell:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "modules/network.py", line 6
SyntaxError: invalid syntax
i already tried: pass the values to the function in variable form, assign the variable to have the return
You are importing network within network.py? If that import network refers to a different module, I would suggest you rename your network.py to something else. - @wokx
RENAME FILE
*the Import: