Home > front end >  Firmware over the air algorithm
Firmware over the air algorithm

Time:09-22

I'm doing firmware over the air update, but I don't know how long will it take to download the firmware and upgrade the device. So what I have tried is to go into infinite loop while(1) and check if the firmware is finished upgrading. That fcked up the devices on the street... The other option is to do timeout but for how long? It's unpredictable. The question is, how to ensure realiability and do it correctly?

Here is what I have tried:

signed char wait_commands(vu32 timeout, char*command, const char *result_command, int valueToCheck)
{
    char *result = NULL;
        
    timer_1sec = 0;

        while(timer_1sec < timeout)
        {
            if( GSMGetString(tempdata, 5) == OK)
            {
            result = strstr(tempdata, command);
            if ( result != NULL)
            {
                int value;
                if ( result_command != NULL)
                {
                    if( valueToCheck != -1)
                    {
                        if (sscanf(result, result_command, &value) > 0)
                        {
                            
                            if (value != valueToCheck)
                            {
                                return FEHLER; 
                            }
                            else
                            {
                                return OK;
                            }
                        }
                }
                }
                else
                {
                    return OK;
                }
            }
        }
    }
    return FEHLER;
}

u8 isUpdated(void)
{
        
    char *currentFirmwareVersion = "BG96MAR02A07M1G_01.019.01.019";

    while (GSMCommand(" QGMR", tempdata, 20) != AT_OK)
        ;
    
    if (strncmp(tempdata, currentFirmwareVersion, strlen(currentFirmwareVersion))==0)
    {
        isBG96Updated = 1;
    }
    else
    {
        isBG96Updated = 0;
        
    }
    
    return isBG96Updated;
}

signed char updateBG96FirmwareVersion(vu32 timeout)
{
    char *url = "\"http://10.10.169.1/dfota/upgrade.bin\"";
    char command[150] = {0};
    signed char res = FEHLER;
    
    if(isUpdated())
        return OK;
    
    sprintf(command, "AT QFOTADL=%s", url);
    PutStringUART(UART_GSM, command);
    PutCharUART(UART_GSM, '\r');
    res = wait_commands(timeout, "\"FOTA\",\"HTTPSTART\"", NULL, -1);
    res = wait_commands(timeout, "\"FOTA\",\"END\"",  "\"FOTA\",\"END\",%d", 0);
    
    return res;
}

CodePudding user response:

I have no experience with the Quectel BG96 chip, specifically, but it appears to support DFOTA, and there is also an official guide that you can view/download here.

This guide contains the AT commands necessary to upgrade the firmware over-the-air. Plus, I think it may clarify your doubts about the upgrade procedure.

  • Related