ESP32 remote firmware update options

Thread Starter

zazas321

Joined Nov 29, 2015
846
Hello. I am working with another ESP32 project. It will be used as a ultra low power tracking device. It will have GPS and GSM.
The device will be used in a different region than I am at hence I am concerned about remote firmware update. At some point in the future, I may need to release an update and flash all the required devices. There may not be wifi available.

Can someone share their knowledge or suggest me any ideas what are other options to perform a remote firmware update for the device? Is it possible to do over GPS?
 

Yaakov

Joined Jan 27, 2019
2,381
Hello. I am working with another ESP32 project. It will be used as a ultra low power tracking device. It will have GPS and GSM.
The device will be used in a different region than I am at hence I am concerned about remote firmware update. At some point in the future, I may need to release an update and flash all the required devices. There may not be wifi available.

Can someone share their knowledge or suggest me any ideas what are other options to perform a remote firmware update for the device? Is it possible to do over GPS?
You meant GSM not GPS, right?
 
Hello. I am working with another ESP32 project. It will be used as a ultra low power tracking device. It will have GPS and GSM.
The device will be used in a different region than I am at hence I am concerned about remote firmware update. At some point in the future, I may need to release an update and flash all the required devices. There may not be wifi available.

Can someone share their knowledge or suggest me any ideas what are other options to perform a remote firmware update for the device? Is it possible to do over GPS?
Well in principle the firmware in the device already exposes the ability to self-update from the web but this is unreliable, I mean few people if any have seen this work.

Why do you say there may not be WiFi available? the ESP32 is a WiFi device, did you mean you want the ability to update the firmware even if WiFi is not working?
 

Thread Starter

zazas321

Joined Nov 29, 2015
846
Well in principle the firmware in the device already exposes the ability to self-update from the web but this is unreliable, I mean few people if any have seen this work.

Why do you say there may not be WiFi available? the ESP32 is a WiFi device, did you mean you want the ability to update the firmware even if WiFi is not working?
Because this device might be used in such places where wifi networks may not be available. I mean there will be simply no internet available
 
Because this device might be used in such places where wifi networks may not be available. I mean there will be simply no internet available
OK I see, so your choice to use ESP32 has nothing to do with the device's WiFi capabilities, you're just using it as an MCU (or perhaps Bluetooth)?

I'm not clear why you'd select an MCU with WiFi features for a non-WiFi application.
 

Thread Starter

zazas321

Joined Nov 29, 2015
846
Yes I have selected the ESP32 despite the fact that we are not planning to use its Wi-Fi capabilities. The reason for that is because I have had prior experience with ESP32 device, we can get these modules for cheap, and they have deep sleep mode which is the most important for us.
 

Thread Starter

zazas321

Joined Nov 29, 2015
846
The closest thing what I have managed to find:
https://github.com/vshymanskyy/TinyGSM/issues/133

In the link above, you will find the example code should work for ESP32 to perform GSM OTA to download the firmware from the server, however I am now not able to get this code to fully work because I am not very experienced with the servers. The example code requires you to fill some information:
Code:
const char server[] = "here the server like sample.com.ar";
const int port = 80;

const char resource[] = "/updates/v1_0.bin"; //here de bin file
As you can see, I am required to put in link to the server as well as the binary file destination.

For this to work, do I must somehow host a server and put my binary file there? If I just want to test this, what is the easiest way to do this?
 

Yaakov

Joined Jan 27, 2019
2,381
Yes, you need an httpd to make it work but you could simply use an ESP32 for that if you really want to. Personally, I would just set up a cheap VPS (I use Linode, and you can get a perfectly good VPS for your purposes for $5/mo, no contract, cancel whenever). Then, you can simply host an update server for test or even production.

Otherwise, just set up an ESP32 as an update server and use port mapping on your router to point some port (something other than 80 to avoid script kiddies) to the ESP’s port.
 

Thread Starter

zazas321

Joined Nov 29, 2015
846
Yes, you need an httpd to make it work but you could simply use an ESP32 for that if you really want to. Personally, I would just set up a cheap VPS (I use Linode, and you can get a perfectly good VPS for your purposes for $5/mo, no contract, cancel whenever). Then, you can simply host an update server for test or even production.

Otherwise, just set up an ESP32 as an update server and use port mapping on your router to point some port (something other than 80 to avoid script kiddies) to the ESP’s port.
Hello. This post was meant to go on my other thread, by mistake i put it here. Please check there as I want to confirm something :)
ESP32 remote firmware update options

Mod:Moved to remote firmware.E
 
Last edited by a moderator:

Thread Starter

zazas321

Joined Nov 29, 2015
846
The closest thing what I have managed to find:
https://github.com/vshymanskyy/TinyGSM/issues/133

In the link above, you will find the example code should work for ESP32 to perform GSM OTA to download the firmware from the server, however I am now not able to get this code to fully work because I am not very experienced with the servers. The example code requires you to fill some information:
Code:
const char server[] = "here the server like sample.com.ar";
const int port = 80;

const char resource[] = "/updates/v1_0.bin"; //here de bin file
As you can see, I am required to put in link to the server as well as the binary file destination.

For this to work, do I must somehow host a server and put my binary file there? If I just want to test this, what is the easiest way to do this?
 

Yaakov

Joined Jan 27, 2019
2,381
I
I have downloaded XAMPP. Would that work?
View attachment 234822
It's overkill but it will work as long as it is reachable from outside your network. Be sure it is up to date and all security patches are in place. Make sure the your firewall is operating. Otherwise, Apache is fine. As I said, if you are hosting inside a network with NAT, port map a random outside port to 80 on the httpd machine to avoid scripts attempting to compromise it.
 

Thread Starter

zazas321

Joined Nov 29, 2015
846
For now, I just want to confirm whether this code ( downloading binary using GSM) is working. This server solution will not be final for the product that we develop. This is just for testing to see if the code is working as expected. I am not yet familiar with what you are suggesting but I will look into more.


***UPDATE***

I am now attempting to make a connection between ESP32 and the apache server on my computer:

Code:
const char server[] = "192.168.1.247";
const int port = 80;
The example code returns OK, which probably means the connection is sucessfull. However, it is not yet fully clear to me where should I store my binary file so that the ESP32 can access it. I would assume that it would have to be stored in one of those folders right?:

1617873257785.png
 

Thread Starter

zazas321

Joined Nov 29, 2015
846
Thanks for the help. My current code:
Code:
const char server[] = "192.168.1.247";
const int port = 80;
const char resource[] = "esp.bin"; //here de bin file

And the arduino code snippet:

Code:
Serial.print("Waiting for network...");
    if (!modem.waitForNetwork())
    {
        Serial.println(" fail");
        delay(10000);
        return;
    }
    Serial.println(" OK");

    Serial.print("Connecting to ");
    Serial.print(apn);
    if (!modem.gprsConnect(apn, user, pass))
    {
        Serial.println(" fail");
        delay(10000);
        return;
    }
    Serial.println(" OK");

    Serial.print("Connecting to ");
    Serial.print(server);

    // if you get a connection, report back via serial:
    if (!client.connect(server, port))
    {
        Serial.println(" fail");
        delay(10000);
        return;
    }
    Serial.println(" OK");
    // Make a HTTP request:
    client.print(String("GET ") + resource + " HTTP/1.0\r\n");
    client.print(String("Host: ") + server + "\r\n");
    client.print("Connection: close\r\n\r\n");

    long timeout = millis();
    while (client.available() == 0)
    {
        if (millis() - timeout > 5000L)
        {
            Serial.println(">>> Client Timeout !");
            client.stop();
            delay(10000L);
            return;
        }
    }
In particular , the most important part of the code:

Code:
 // Make a HTTP request:
    client.print(String("GET ") + resource + " HTTP/1.0\r\n");
    client.print(String("Host: ") + server + "\r\n");
    client.print("Connection: close\r\n\r\n");

    long timeout = millis();
    while (client.available() == 0)
    {
        if (millis() - timeout > 5000L)
        {
            Serial.println(">>> Client Timeout !");
            client.stop();
            delay(10000L);
            return;
        }
    }

This suppose to make the get request to the server with the resource ( my binary file). I have copied my binary to htdocs as you have suggested:
1617875750956.png

However, I am getting a client timeout error;
1617875794721.png

Which probably means that there is something wrong with the get request or the resource.

Can you clarify to me how does get request with the resource works? How does it know that it must refer to htdocs folder or I have to give the full path as following:
Code:
const char resource[] = "D:\Program Files (x86)\XAMPP\htdocs\esp.bin"
 
Top