Skip to content

Native OTA #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Sep 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Marcel Kottmann
Copyright (c) 2021 Marcel Kottmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
45 changes: 40 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Because of the limited memory on ESP32-WROOM modules, the full functionality is

### Prerequisites

Install [esp-idf 4.2](https://docs.espressif.com/projects/esp-idf/en/release-v4.2/esp32/get-started/index.html) on your system.
Install [esp-idf 4.2.2](https://docs.espressif.com/projects/esp-idf/en/release-v4.2/esp32/get-started/index.html) on your system.

### First install

Expand Down Expand Up @@ -63,13 +63,21 @@ If this is your first install, your onboard LED should blink now. Blinking signa

On the Setup page you can configure your WLAN settings and an URL to download your JS main script from.

Please note that the script, does not need to have a main function, because its evaluated entirely.
![Setup page screenshot](setup.png)
### Examples

Please note that the Javascript OTA script, does not need to have a main function, because its evaluated entirely.
That means, to print out "Hello World", you only have to include one line in your script on the webserver:

```js
console.log("Hello world!");
```

You can test this example by configuring this URL as "Javascript OTA":
https://raw.githubusercontent.com/marcelkottmann/esp32-javascript/master/examples/example.js

Please see also the other example in [./examples](./examples)

### C/C++bindings

If you need to create your own C/C++ bindings for your JS code, this are the steps to perform:
Expand All @@ -92,6 +100,13 @@ If you need more than this, you can create your own esp-idf component below `./c
Additionally you have to set your component name in the top level `./CMakeLists.txt`. Refer to the documentation next to the setting `ESP32_JS_PROJECT_NAME`.
See [ESP Build System](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html) for information on how to create a component with the esp-idf build system.

### Native OTA

You can perform a native firmware OTA upgrade by calling the URL /setup . There is a section called "Native OTA" where you can provide two urls to the new images: One for the actual firmware image (normally named esp32-javascript.bin in your build directory) and the other for the JS modules image (normally named modules.bin in your build directory).

The upgrade is performed in the background. You can check the upgrade status either by staying on the upgrade page, which is reloaded automatically every ~20 seconds or click on "Upgrade status" in the setup page.

After upgrade has finished you have to restart the device to load the new firmware.
### Clean

You can clean the project by executing
Expand Down Expand Up @@ -120,12 +135,32 @@ You can erase the persistent flash memory, which will be equivalent to a factory

| Version | Compatible |
| ----------------------------------------------------------------- | :--------------------: |
| [4.2](https://github.com/espressif/esp-idf/releases/tag/v4.2) | :heavy_check_mark:[^1] |
| [4.2.1](https://github.com/espressif/esp-idf/releases/tag/v4.2.1) | :heavy_check_mark:[^1] |
| [4.2](https://github.com/espressif/esp-idf/releases/tag/v4.2) | ☑️<sup>1</sup> |
| [4.2.1](https://github.com/espressif/esp-idf/releases/tag/v4.2.1) | ☑️<sup>1</sup> |
| [4.2.2](https://github.com/espressif/esp-idf/releases/tag/v4.2.2) | ✅ Recommended |

[^1]: SSL client connections currently not working properly for ESP32-S2 devices due to esp-idf bug in 4.2.x:
<sup>1</sup> SSL client connections currently not working properly for ESP32-S2 devices due to esp-idf bug in 4.2.x:
https://github.com/espressif/esp-idf/pull/6998 , but can be fixed manually (see changes in PR).

## REPL

The [examples](examples/) directory contains a [repl](examples/repl.js) that can be used as JS OTA Url:
https://raw.githubusercontent.com/marcelkottmann/esp32-javascript/http-streaming/examples/repl.js

The repl can be used with netcat directly or with a combination of rlwrap and netcat to have a history-support:
`rlwrap netcat [IP-ADDRESS] 1234`

Enter username and password separated with colon(`:`) to authenticate, e.g. `esp32:esp32` + Enter

```bash
~/esp/esp32-javascript> rlwrap netcat 192.168.188.24 1234
> esp32:esp32
====> authorized.
> console.log('Hello world.')
LOG|Hello world.
====> undefined
>
```
## API

[API documentation](docs/README.md)
Expand Down
9 changes: 8 additions & 1 deletion babel.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"presets": ["minify"],
"presets": [
[
"minify",
{
"builtIns": false
}
]
],
"comments": false
}
23 changes: 23 additions & 0 deletions components/duk-module-node/duk_module_load_bindings.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/*
MIT License

Copyright (c) 2021 Marcel Kottmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "duktape.h"
#include "duk_module_node.h"
#include "esp32-javascript.h"
Expand Down
Loading