GithubHelp home page GithubHelp logo

scottchiefbaker / esp-webota Goto Github PK

View Code? Open in Web Editor NEW
282.0 14.0 38.0 57 KB

Simple web based Over-the-Air (OTA) updates for ESP based projects

License: MIT License

C++ 100.00%
esp32 esp32-arduino ota arduino-library esp esp8266 esp8266-arduino

esp-webota's Introduction

ESP WebOTA

Easily add web based OTA updates to your ESP32/ESP8266 projects.

Installation

Clone this repo to your Arduino libraries directory. On Linux this is ~/Arduino/libraries/

Usage

Include the WebOTA library

#include <WebOTA.h>

Optionally initialize the WebOTA library if you want to change the defaults. This is done at the end of your setup() function:

void setup() {
    // Other init code here (WiFi, etc)

    // To use a specific port and path uncomment this line
    // Defaults are 8080 and "/webota"
    // webota.init(8888, "/update");

    // If you call useAuth() in your setup function WebOTA will use
    // HTTP digest authentication to request credentials from the user
    // before allowing uploads
    // webota.useAuth("username", "password");
}

Listen for update requests at the end of your loop() function:

void loop() {
    // Other loop code here

    webota.handle();
}

Note: If you have long delay() commands in your loop() WebOTA may not be responsive. We have provided webota.delay() as a drop-in replacement, which is more WebOTA friendly.

Upload a sketch

You will need to create a binary sketch image to upload. This is done in the Arduino IDE by going to the Sketch menu and selecting Export compiled Binary.

Navigate to your ESP in a web browser to upload your binary image. Typical URLs are: http://esp-ota.local:8080/webota.

You can also use Curl if you want to script your uploads from the CLI

curl -F "[email protected]" http://esp-ota.local:8080/webota

Based on

Borrowed from randomnerdtutorials.com and improved upon.

esp-webota's People

Contributors

albrechtl avatar jamesfowkes avatar leojz avatar scottchiefbaker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp-webota's Issues

Crash when request "GET /webota"

Hi,

Thanks for your great project!

I integrated your source code into my project https://github.com/AlbrechtL/BTT_TF_Cloud_AFW and I ran into the issue that the ESP8266 is crashing when the Web browser is requesting the page GET /webota HTTP/1.1\r\n.

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (3):
epc1=0x4000bf64 epc2=0x00000000 epc3=0x00000000 excvaddr=0x4024d985 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffce0 end: 3fffffc0 offset: 0190
3ffffe70:  00000001 00000001 3ffffea0 40212a1c  
3ffffe80:  4024d985 3ffffea0 3ffe942c 40212572  
3ffffe90:  3ffffef0 00000001 3fff1e2c 4020717b  
3ffffea0:  3fff1fac 001e001f 00fffed0 40212355  
3ffffeb0:  3ffffef0 3fff08c4 3fff1dec 401000e1  
3ffffec0:  3fff1dec 3fff08c4 3fff1dec 40204cb0  
3ffffed0:  62657700 0061746f 800069be 80ff0b7c  
3ffffee0:  3fff1dec 3fff08c4 3fff0884 40206d86  
3ffffef0:  6265772f 0061746f 87ff2400 0000005f  
3fffff00:  8000746f 4bc6a7f0 000069be 3fff0b7c  
3fffff10:  3fff08c4 00000000 4bc6a7f0 00000001  
3fffff20:  00000001 3fff1dec 40100462 1810624d  
3fffff30:  00000000 3fff08a8 3fff0884 3fff0b7c  
3fffff40:  00000001 3fff08a8 3fff0884 40206edf  
3fffff50:  3fffdad0 00000000 3fff0990 4020df31  
3fffff60:  007a1200 8548d0a7 3fff0500 4020c446  
3fffff70:  3fffdad0 00000000 3fff0530 40206f8b  
3fffff80:  3fffdad0 00000000 3fff0530 402012bc  
3fffff90:  3fffdad0 00000000 3fff0b3c 40100395  
3fffffa0:  3fffdad0 00000000 3fff0b3c 40213620  
3fffffb0:  feefeffe feefeffe 3ffe8584 401002d9  
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Do you have any idea what can be the problem?

A couple of warnings

These are the ones I'm getting while compiling the sketch.

lib\ESP-WebOTA\src\WebOTA.cpp: In member function 'int WebOTA::handle()':
lib\ESP-WebOTA\src\WebOTA.cpp:61:14: warning: unused variable 'init_run' [-Wunused-variable]
  static bool init_run = false;
              ^
lib\ESP-WebOTA\src\WebOTA.cpp:72:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
lib\ESP-WebOTA\src\WebOTA.cpp: In member function 'int WebOTA::add_http_routes(WebServer*, const char*)':
lib\ESP-WebOTA\src\WebOTA.cpp:198:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
lib\ESP-WebOTA\src\WebOTA.cpp: In function 'int init_wifi(const char*, const char*, const char*)':
lib\ESP-WebOTA\src\WebOTA.cpp:256:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^

Suggestion : Check the right firmware

Hi,

You project is very good and I really liked it.
There is one flaw, that is your code doesn't do any check's for the correct firmware. If will update whichever firmware we provide.

Thanks
Venkat

Is there a way to auto-reset?

Is there a way to make the ESP32 automatically reset after uploading a file via the OTA webpage?

The uploading is working great, but the ESP32 doesn't automatically reboot for the new binary to take effect, which kind of defeats the purpose of OTA uploads for me as I hoped I could make changes to the firmware once I placed the ESP32 somewhere out of reach...

question about updating via curl - terminal

I am using the lib 'ESP-Web OTA' in my project, and when I go to do the firmware update via curl through the linux terminal, I find the following error.

I add the following lines to init_wifi()

IPAddress local_ip(192,168,1,46);
IPAddress getway(168,168,1,1);
IPAddress subnet(255,255,0,0);
IPAddress primaryDNS(8,8,8,8);
IPAddress secondaryDNS(8,8,4,4);
if (!WiFi.config(local_ip, getway, subnet, primaryDNS, secondaryDNS)) ESP.restart();

to be able to get it by changing the ip of eps32.

using code in main

#include <WebOTA.h>
#include <Arduino.h>

void setup() {
Serial.begin(115200);
init_wifi("LAb", "test123", "esp-ota");
}

void loop() {
webota.handle();
}

image

I did several tests and found that it only works if the ip of the esp32 is 192.168.1.* , when changing the ip of the esp32 does not work with the error 'Timeout for connection'.

I would like to know how to fix this in my code, if I'm doing something wrong.

Cannot easily distinguish between WebOTA installations

With several ESP32s running WebOTA on the same network, the only way to distinguish them is by IP address.

It would be useful to have a way to customise the HTML, such that the ESP32 can be identified uniquely by name.

There's lots of ways to do this, I wondered what your thoughts were about the idea, and the best way to implement it, if you think it would be useful.

ethernet

Hi Scott! I am really impressed with this library and use it in all my projects. Your library only uses wifi connections. is it possible to add ethernet as well?

ESP-01 ?

Hi!
I'm using a ESP-01 board with a slightly modified usb-serial adapter like
https://www.amazon.de/AZDelivery-ESP8266-ESP-01-USB-Adapter-Arduino/dp/B078J7LDLY
to upload sketches.

So usually I upload a new firmware by serial connection to a ESP-01 board. After I had some really good experiences with WebOTA on Wemos D1 boards, I also wanted to give it a try on a ESP-01 board. So I made this basic sketch:

`
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <WebOTA.h>

void setup() {
delay(2000);
pinMode(LED_BUILTIN, OUTPUT);
WiFi.mode(WIFI_STA);
WiFi.begin("", ""); //insert your wifi credentials
while (WiFi.status() != WL_CONNECTED) {
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
}
webota.init(8888, "/update");
}

void loop() {
digitalWrite(LED_BUILTIN, HIGH);
webota.handle();
delay(500);
digitalWrite(LED_BUILTIN, LOW);
webota.handle();
delay(500);
}
`

Now I can access the webOTA interface on :8888/update and upload a new "firmware.bin" . Right after reaching 100% nothing happens anymore. I have to update by the serial interface to make the ESP-01 work again.

I watched the build output for the serial interface saying it's uploading a compressed file:

`Looking for upload port...
Auto-detected: COM7
Uploading .pioenvs\esp01_1m\firmware.bin
esptool.py v2.6
Serial port COM7
Connecting....
Chip is ESP8266EX

Features: WiFi
MAC: b4:e6:2d:29:46:eb
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 1MB
Compressed 318688 bytes to 226708...
Wrote 318688 bytes (226708 compressed) at 0x00000000 in 28.0 seconds (effective 91.0 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
[SUCCESS] Took 33.90 seconds`

Could it be I have to upload a compressed firmware.bin ? I'm really sorry for beeing such a noob :(
Do you have a hint for me?

Kind regards MM82

Use with WiFiManager.h

@scottchiefbaker Can your library somehow be used with WiFiManager.h? On an unattached ESP32 it would be good to update and setup Wifi without tethering to a PC.

Please advise.

P.S. Nice work. Worked on the first try!

Interrupt block update?

Do interrupts block the update? It looks like they do

Could you add noInterrupts and interrupts to your code or provide some form of callback like the ArduinoOTA.onStart ?

OTA update is aborting

Hi,
thx for this easy to use functionality.

Before, I tried https://lastminuteengineers.com/esp32-ota-web-updater-arduino-ide/ and this was more complex as the web server code needed to be in my ino file. Only to mention, that the issue is the same...

The web page displays the OTA dialog and I can choose a file to 'Update'. The Percentage is nearly immediately 37% and then it stops.

The Serial output of my C3-32S-Kit (board: ESP32C3 Dev Module with 2 MB flash) is:
Firmware update initiated: PostGPS.ino.bin

abort() was called at PC 0x40381639 on core 0
Core 0 register dump:
MEPC : 0x403823de RA : 0x40386ad2 SP : 0x3fc9de30 GP : 0x3fc8de00
TP : 0x3fc7a58c T0 : 0x37363534 T1 : 0x7271706f T2 : 0x33323130
S0/FP : 0x3fc9de5c S1 : 0x3fc9de5c A0 : 0x3fc9de68 A1 : 0x3fc9de4a
A2 : 0x00000000 A3 : 0x3fc9de95 A4 : 0x00000001 A5 : 0x3fc97000
A6 : 0x7a797877 A7 : 0x76757473 S2 : 0x00010000 S3 : 0x00010000
S4 : 0x00000b38 S5 : 0x00001000 S6 : 0x3fcad3d0 S7 : 0x000004c8
S8 : 0x00000073 S9 : 0x3c0dd000 S10 : 0x3fc9e000 S11 : 0x00000000
T3 : 0x6e6d6c6b T4 : 0x6a696867 T5 : 0x66656463 T6 : 0x62613938
MSTATUS : 0x00001801 MTVEC : 0x40380001 MCAUSE : 0x00000007 MTVAL : 0x00000000
MHARTID : 0x00000000

Stack memory:
3fc9de30: 0x00000000 0x00000000 0x3fc9de48 0x4038bf56 0x00000000 0x00000000 0x3fca0030 0x3fc90718
3fc9de50: 0x3fc9de5c 0x3fc90734 0x3fc9de48 0x38333034 0x39333631 0x3fcaa800 0x726f6261 0x20292874
3fc9de70: 0x20736177 0x6c6c6163 0x61206465 0x43502074 0x34783020 0x31383330 0x20393336 0x63206e6f
...

Rebooting...
ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0x3 (RTC_SW_SYS_RST),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x40381fb6
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5810,len:0x438
load:0x403cc710,len:0x90c
load:0x403ce710,len:0x2624
entry 0x403cc710
Build date: 240508 18:45
Connecting
.
Connected to WiFi network with IP Address: 192.168.8.149
WebOTA url : http://.local:8080/webota

I have no idea, who is when calling abort(). After Rebooting... the old scetch is executed (seen by my output line: Build date: 240508 18:45 which should be at 19:00.

Did you see this issue before and can help? How is the update process done; e.g. is the file first loaded into (which) memory, before getting flashed - then, it could be a lack of space problem?
Best Regards
mkMunich

Identifier on web page

Not really and issue but an enhancement request:

Would it be possible to add some sort of identifier on the web page, so when the WebOTA web page is up, and about to load code to an ESP board, you could identify the particular ESP board you are about to update ?? I have several ESP processors running in a system, and it would be very helpful, in the Arduino IDE, to pass an identifying name to that particular instance of WebOTA. In this way, you would know you are about to update the correct board. TIA !!

Error updating thru webota (2 different boards tested)

Firmware update initiated: ESP8266_RF433_HUB.ino.nodemcu.bin

Exception (0):
epc1=0x40202798 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

stack>>>

ctx: cont
sp: 3ffff950 end: 3fffffc0 offset: 01a0
3ffffaf0: 3ffee644 3ffee640 3ffee63c 00000100

BUT ESP8266 > Examples > WebUpdate Works

Use WebOTA in FreeRTOS ?

That's not an issue but a question.
I've used your code in several projects and would like to use it also on a new one I've borrowed around ( an energy monitor for the house ).
Difference this time is that the project use FreeRTOS and works with tasks and not the usual loop.
I was wondering if you or someone has never thougth to use this code in a FreeRTOS environment.

Thanks for your code and thanks for your time :)

Examples won't compile properly with Arduino IDE 2.1.1

Get the following error when compiling examples or my own code (which compiled fine last year):

/Users/darylrm/Documents/Arduino/sketch_jul18b/sketch_jul18b.ino: In function 'void loop()':
/Users/darylrm/Documents/Arduino/sketch_jul18b/sketch_jul18b.ino:36:5: error: 'webota' was not declared in this scope
     webota.handle();
     ^~~~~~

exit status 1

Compilation error: 'webota' was not declared in this scope

Error in math using millis & delay

See this post someone put on reddit about using math to compare millis():
https://old.reddit.com/r/esp32/comments/g0jqux/being_stupid/fnbznvj/

This function incorrectly uses a signed number for 'last':

void WebOTA::delay(int ms) {
int last = millis();

while ((millis() - last) < ms) {
	OTAServer.handleClient();
	::delay(5);
}

}

The math involving wraparound as millis() increments to its largest possible value and goes back to zero only works if you do math using the exact same size and type of variables as the type and size returned by the function millis();

This can be challenging because you have to know the type and size of the millis(); function and hope it doesn't change between ESP8266 and ESP32 or whatever future platform you reuse this code on.

The best way to do it is to use the C built in method:

decltype(millis()) last = millis();

This ensures 'last' is the same size and type as the return value of millis, and that ensures this comparison always works, even if millis() rolls over to zero and starts counting up again during the interval:
(millis() - last) < ms)

https://en.cppreference.com/w/cpp/language/decltype

[[ Also, while not a bug, it's better to used 'unsigned int' for things that can't be negative. The argument to your delay function is better off as just an 'unsigned int'. ]]

Thanks.

Flash config wrong real: 1048576 IDE: 4194304

I have worked on this problem all day today. I have tried different IDE configurations, clearing flash, loading via different methods and non of them solved this issue. It was working fine and now it won't work on any of my devices. The only way I can get code to modify is to use esptool. If you have any suggestions, I am open to anything.

UPDATE

After working on this for another day, I finally found a workaround for it. I compiled and uploaded your basic OTA sketch on one of my RPI. Once that completed successfully I opened a browser and used the OTA and uploaded the bin file that would not load. This worked and now all of my devices are able to perform OTA's. I had two that wouldn't work and the rest where fine. I thought it might be helpful to post this in case someone in the future has the same issue.

TIA
Menu
Chip
Errors

Having trouble compiling this

Compiling with Arduino application on OSX. Error is obscure so I'm unsure what might be wrong. I'm trying to compile the Primes.ino example.

Users/cms/Documents/Arduino/libraries/ESP-WebOTA-master/src/WebOTA.cpp: In member function 'int WebOTA::init(unsigned int, const char*)':
/Users/cms/Documents/Arduino/libraries/ESP-WebOTA-master/src/WebOTA.cpp:40:22: error: no matching function for call to 'ESP8266WebServer::begin(const unsigned int&)'
  OTAServer.begin(port);
                      ^
/Users/cms/Documents/Arduino/libraries/ESP-WebOTA-master/src/WebOTA.cpp:40:22: note: candidate is:
In file included from /Users/cms/Documents/Arduino/libraries/ESP-WebOTA-master/src/WebOTA.h:4:0,
                 from /Users/cms/Documents/Arduino/libraries/ESP-WebOTA-master/src/WebOTA.cpp:5:
/Users/cms/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WebServer/src/ESP8266WebServer.h:69:8: note: void ESP8266WebServer::begin()
   void begin();
        ^
/Users/cms/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WebServer/src/ESP8266WebServer.h:69:8: note:   candidate expects 0 arguments, 1 provided
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

Connection reset by peer

Hello, I was getting a "connection reset by peer" error when uploading the .bin file using curl. I was able to remove it by using --limit-rate 100k.

I am adding this comment in case others experience the same error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.