Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 880

HATs and other add-ons • Sporadic UART decoding errors with GSM hat on Pico

$
0
0
Hi all. I'm working on a weather station IOT project.

I'm using a Pico SIM7080G Cat-M/NB-IoT. on a Pico, and interacting with the project via Thonny.

I have a very basic script which currently connects too, and downloads information from an API.

However, a code module (supplied by the board maker) that sends ands receives 'AT' commands via UART has completely sparodic chances of getting unicode errors. I would say it has a 1 in 20 chance of making it all the way through the script, but it does happen.

Here is the code block for sending the AT command:

Code:

def send_at(cmd, back, timeout=1500):    rec_buff = b''    Pico_SIM7080G.read()    Pico_SIM7080G.write((cmd + '\r' + '\n').encode())    prvmills = utime.ticks_ms()    while (utime.ticks_ms() - prvmills) < timeout:        if Pico_SIM7080G.any():            rec_buff = b"".join([rec_buff, Pico_SIM7080G.read()])            #print('Initial rec buff', rec_buff)    if rec_buff != '':        Pico_SIM7080G.any()        if back not in rec_buff.decode():            if 'ERROR' in rec_buff.decode():                print(cmd + ' back:\t' + rec_buff.decode())                return 0            else:                # Resend cmd                rec_buff = b''                rec_buff = send_at_wait_resp(cmd, back, timeout)                if back not in rec_buff.decode():                    print(cmd + ' back:\t' + rec_buff.decode())                    return 0                else:                    return 1        else:            print(rec_buff.decode())            return 1    else:        print(cmd + ' no responce\n')        # Resend cmd        rec_buff = send_at_wait_resp(cmd, back, timeout)        if back not in rec_buff.decode():            print(cmd + ' back:\t' + rec_buff.decode())            return 0        else:            return 1
And here is an example of a command

Code:

send_at("AT", "OK")
The current script has probably 30 AT commands, and the following error can happen at any of them, seemingly completely at random, although usually during sending the first command

Code:

  File "<stdin>", line 44, in send_atUnicodeError: 
I apologize if it seems like I need a bit of handholding, I kinda do! This is by far and away the most electronics project I have ever undertaken, and it really seems like the data for this module is lacking.

Thanks!

Statistics: Posted by Bfreak — Fri Mar 22, 2024 11:23 pm



Viewing all articles
Browse latest Browse all 880

Trending Articles