Setting connection time out if fails to connect. #11413
Closed
HookedonIOT
started this conversation in
General
Replies: 1 comment 1 reply
-
Maybe this helps: def connect():
count = 0
sta_if.active(True)
# seems more reliable to start with a fresh connect()
if sta_if.isconnected():
sta_if.disconnect()
print (f'started in the connected state, but now disconnected')
else:
print (f'started in the disconnected state')
utime.sleep(0.1)
if not sta_if.isconnected():
print (f'connecting to hotspot...')
utime.sleep(0.1)
try:
sta_if.ifconfig((config.WiFi_device, '255.255.255.0', config.gateway, '8.8.8.8'))
sta_if.connect(config.hotspot, config.password)
except OSError as error:
try:
with open('errors.txt', 'a') as outfile:
outfile.write(str(error) + '\n')
except OSError:
pass
while (count < 5):
count += 1
if (sta_if.isconnected()):
count = 0
print (f'network config: {sta_if.ifconfig()}')
break
print (f'. ')
utime.sleep(1)
if (count == 5):
try:
with open('errors.txt', 'a') as outfile:
outfile.write('failed to connect after 5 tries' + '\n')
except Exception as e:
pass
disconnect() # or you could get errors
print (f'machine reset')
utime.sleep(0.1)
machine.reset() # start from scratch and change the last line to And disconnect: def disconnect():
sta_if.disconnect()
sta_if.active(False) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, using sim7000g. I am trying to implement some code to send the module to deep sleep if it doesn’t connect within say 20 seconds.
Usage will be a remote sensor that is battery powered. Trying to simulate a scenario where telcos coverage is out. Don’t want the module to keep trying until battery goes flat.
Any pointers would be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions