pythings / Drivers

Some drivers for MicroPython
Apache License 2.0
63 stars 22 forks source link

Modem.connect(apn='') issue #9

Open Martijn21c opened 3 years ago

Martijn21c commented 3 years ago

Hi,

When I try this code the error popping up on the step modem.connect(apn='iew.be') Traceback (most recent call last): File "", line 16, in File "SIM800L.py", line 293, in connect File "SIM800L.py", line 276, in get_ip_addr File "SIM800L.py", line 183, in execute_at_command GenericATError: Got generic AT error

I use a LILYGO ESP32 with SIM800L.

sarusso commented 3 years ago

Hi @Martijn21c ,

the problem with generic AT errors is that they are.. well, generic errors :) Usually, the modem does not provide much more information in these cases, and debugging is hard.

However, you can try running with the logger on and set to the DEBUG level in order to get some more context.

varna9000 commented 3 years ago

If your APN uses username and password, the module won't connect with the current code. I modified sim800L.py and added the following

'setuser':     {'string':'AT+SAPBR=3,1,"USER","{}"'.format(data), 'timeout':3, 'end': 'OK'},
'setpwd':     {'string':'AT+SAPBR=3,1,"PWD","{}"'.format(data), 'timeout':3, 'end': 'OK'},                    

then add username and pass parameters to the connect() function

def connect(self, apn, user, pwd)

and call the two AT commands above, right after set APN command

self.execute_at_command('setapn', apn)
self.execute_at_command('setuser', user)
self.execute_at_command('setpwd', pwd)

In the actual code you can call the connect function as follows

    modem.connect(apn='yourAPN,',user='xxxx',pwd='xxxxxx')

After the above changes, my module connects ok.

sarusso commented 3 years ago

Thanks for the feedback @varna9000! Why don't you create a pull request with these few lines of code to get the credit you deserve for adding this functionality?

varna9000 commented 3 years ago

@sarusso Thanks, will do.