Skip to content

Commit c18f44a

Browse files
massive maintenance update
* new modularization for native components * node module loading (`require`) added * browser/node-like console instead of print function * custom events can be added to eventloop implementation * ssl server and client sockets realized (w/o ssl validation) * basic `fetch` implementation * basic `promise` implementation * `global` variable access * basic stringbuffer implementation
1 parent 6e4dc22 commit c18f44a

File tree

137 files changed

+18653
-11345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+18653
-11345
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
build
2-
*.hex
32
main/esp32.js
43
sdkconfig.old*

.vscode/c_cpp_properties.json

Lines changed: 16 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -3,111 +3,26 @@
33
{
44
"name": "ESP32",
55
"includePath": [
6-
"../esp-idf/components/wear_levelling/include",
7-
"../esp-idf/components/vfs/include",
8-
"../esp-idf/components/ulp/include",
9-
"../esp-idf/components/mbedtls/include",
10-
"../esp-idf/components/mbedtls/port/include",
11-
"../esp-idf/components/coap/libcoap/include",
12-
"../esp-idf/components/coap/port/include",
13-
"../esp-idf/components/driver/include",
14-
"../esp-idf/components/mdns/include",
15-
"../esp-idf/components/app_update/include",
16-
"../esp-idf/components/nghttp/nghttp2/third-party/mruby/include",
17-
"../esp-idf/components/nghttp/port/include",
18-
"../esp-idf/components/spi_flash/include",
19-
"../esp-idf/components/bootloader_support/include",
20-
"../esp-idf/components/tcpip_adapter/include",
21-
"../esp-idf/components/ethernet/include",
22-
"../esp-idf/components/json/include",
23-
"../esp-idf/components/json/port/include",
24-
"../esp-idf/components/spiffs/include",
25-
"../esp-idf/components/xtensa-debug-module/include",
26-
"../esp-idf/components/sdmmc/include",
27-
"../esp-idf/components/newlib/include",
28-
"../esp-idf/components/bt/include",
29-
"../esp-idf/components/bt/bluedroid/osi/include",
30-
"../esp-idf/components/bt/bluedroid/btcore/include",
31-
"../esp-idf/components/bt/bluedroid/external/sbc/decoder/include",
32-
"../esp-idf/components/bt/bluedroid/external/sbc/encoder/include",
33-
"../esp-idf/components/bt/bluedroid/btc/include",
34-
"../esp-idf/components/bt/bluedroid/btc/profile/esp/blufi/include",
35-
"../esp-idf/components/bt/bluedroid/btc/profile/esp/include",
36-
"../esp-idf/components/bt/bluedroid/btc/profile/std/battery/include",
37-
"../esp-idf/components/bt/bluedroid/btc/profile/std/include",
38-
"../esp-idf/components/bt/bluedroid/btc/profile/std/smp/include",
39-
"../esp-idf/components/bt/bluedroid/btc/profile/std/hid/include",
40-
"../esp-idf/components/bt/bluedroid/btc/profile/std/a2dp/include",
41-
"../esp-idf/components/bt/bluedroid/btc/profile/std/dis/include",
42-
"../esp-idf/components/bt/bluedroid/include",
43-
"../esp-idf/components/bt/bluedroid/api/include",
44-
"../esp-idf/components/bt/bluedroid/device/include",
45-
"../esp-idf/components/bt/bluedroid/hci/include",
46-
"../esp-idf/components/bt/bluedroid/bta/sys/include",
47-
"../esp-idf/components/bt/bluedroid/bta/include",
48-
"../esp-idf/components/bt/bluedroid/stack/sdp/include",
49-
"../esp-idf/components/bt/bluedroid/stack/include",
50-
"../esp-idf/components/bt/bluedroid/stack/smp/include",
51-
"../esp-idf/components/bt/bluedroid/stack/avct/include",
52-
"../esp-idf/components/bt/bluedroid/stack/gatt/include",
53-
"../esp-idf/components/bt/bluedroid/stack/avrc/include",
54-
"../esp-idf/components/bt/bluedroid/stack/l2cap/include",
55-
"../esp-idf/components/bt/bluedroid/stack/rfcomm/include",
56-
"../esp-idf/components/bt/bluedroid/stack/avdt/include",
57-
"../esp-idf/components/bt/bluedroid/stack/gap/include",
58-
"../esp-idf/components/bt/bluedroid/stack/a2dp/include",
59-
"../esp-idf/components/soc/include",
60-
"../esp-idf/components/soc/esp32/include",
61-
"../esp-idf/components/nvs_flash/include",
62-
"../esp-idf/components/jsmn/include",
63-
"../esp-idf/components/freertos/include",
64-
"../esp-idf/components/openssl/include",
65-
"../esp-idf/components/app_trace/include",
66-
"../esp-idf/components/esp_adc_cal/include",
67-
"../esp-idf/components/wpa_supplicant/include",
68-
"../esp-idf/components/wpa_supplicant/port/include",
69-
"../esp-idf/components/esp32/include",
70-
"../esp-idf/components/log/include",
71-
"../esp-idf/components/lwip/include/lwip",
72-
"../esp-idf/components/lwip/include/lwip/port",
73-
"../esp-idf/components/aws_iot/include",
74-
"../esp-idf/components/aws_iot/aws-iot-device-sdk-embedded-C/tests/integration/include",
75-
"../esp-idf/components/aws_iot/aws-iot-device-sdk-embedded-C/tests/unit/include",
76-
"../esp-idf/components/aws_iot/aws-iot-device-sdk-embedded-C/include",
77-
"../esp-idf/components/heap/include",
78-
"../esp-idf/components/expat/include",
79-
"../esp-idf/components/expat/port/include",
80-
"../esp-idf/components/idf_test/include",
81-
"../esp-idf/components/libsodium/libsodium/src/libsodium/include",
82-
"../xtensa-esp32-elf/lib/gcc/xtensa-esp32-elf/5.2.0/plugin/include",
83-
"../xtensa-esp32-elf/lib/gcc/xtensa-esp32-elf/5.2.0/include",
84-
"../xtensa-esp32-elf/lib/gcc/xtensa-esp32-elf/5.2.0/install-tools/include",
85-
"../xtensa-esp32-elf/include",
86-
"../xtensa-esp32-elf/xtensa-esp32-elf/include",
87-
"../xtensa-esp32-elf/xtensa-esp32-elf/include/include",
88-
"../xtensa-esp32-elf/xtensa-esp32-elf/sysroot/usr/include",
89-
"./components/arduino-spi/include",
90-
"./components/arduino-wire/include",
91-
"./components/ws2812/include",
92-
"./components/lmic/include",
93-
"./components/u8g2/include",
94-
"./components/arduino-esp32/include",
95-
"./components/duktape/include",
96-
"./build/include/",
97-
".",
98-
"/home/marric/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0",
99-
"/home/marric/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/xtensa-esp32-elf"
6+
"${workspaceRoot}/**",
7+
"${workspaceRoot}/components/**",
8+
"${workspaceRoot}/build/**",
9+
"${workspaceRoot}/build/include/**",
10+
"${env:IDF_PATH}/components/**"
10011
],
101-
"defines": [],
10212
"intelliSenseMode": "clang-x64",
10313
"browse": {
10414
"path": [
105-
".."
106-
],
107-
"limitSymbolsToIncludedHeaders": true,
108-
"databaseFilename": ""
109-
}
15+
"${workspaceRoot}/**",
16+
"${workspaceRoot}/components/**",
17+
"${workspaceRoot}/build/**",
18+
"${workspaceRoot}/build/include/**",
19+
"${env:IDF_PATH}/components/**"
20+
],
21+
"limitSymbolsToIncludedHeaders": true
22+
},
23+
"cStandard": "c11",
24+
"cppStandard": "c++17"
11025
}
11126
],
11227
"version": 4
113-
}
28+
}

.vscode/settings.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"esp_system.h": "c",
1313
"ws2812.h": "c",
1414
"esp32-hal-gpio.h": "c",
15-
"*.hex": "c",
1615
"socket.h": "c",
1716
"array": "cpp",
1817
"string_view": "cpp",
@@ -22,6 +21,22 @@
2221
"unordered_set": "cpp",
2322
"vector": "cpp",
2423
"initializer_list": "cpp",
25-
"*.ipp": "cpp"
24+
"*.ipp": "cpp",
25+
"system_error": "cpp",
26+
"opt.h": "c",
27+
"esp_spiram.h": "c",
28+
"*.tcc": "cpp",
29+
"streambuf": "cpp",
30+
"task.h": "c",
31+
"ssl.h": "c",
32+
"ssl_lib.h": "c",
33+
"ssl_types.h": "c",
34+
"ssl_dbg.h": "c",
35+
"cstddef": "cpp",
36+
"stdlib.h": "c",
37+
"time.h": "c",
38+
"reent.h": "c",
39+
"thread": "cpp",
40+
"cmath": "cpp"
2641
}
2742
}

Makefile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
##
22
# MIT License
33
#
4-
# Copyright (c) 2017 Marcel Kottmann
4+
# Copyright (c) 2019 Marcel Kottmann
55
#
66
# Permission is hereby granted, free of charge, to any person obtaining a copy
77
# of this software and associated documentation files (the "Software"), to deal
@@ -28,7 +28,20 @@ PROJECT_NAME := "esp32-javascript"
2828
ESP32_JS_FLAGS :=
2929

3030
##### Board config #####
31-
# Specify your board here. Identifier can be any of the directory names in ./components/arduino-esp32/include/variants/
32-
export BOARD_VARIANT := "heltec_wifi_lora_32"
31+
# Specify your board here. Identifier can be any of the directory names in
32+
# ./components/arduino-esp32/include/variants/
33+
# or you can create your own variant in ./components/esp32-javascript/include/variants
34+
export BOARD_VARIANT := "my"
3335

3436
include $(IDF_PATH)/make/project.mk
37+
38+
clean:
39+
rm -rf build/modules
40+
41+
cp_modules:
42+
./scripts/copy-modules.sh
43+
44+
SPIFFS_IMAGE_FLASH_IN_PROJECT := 1
45+
SPIFFS_IMAGE_DEPENDS += cp_modules
46+
$(eval $(call spiffs_create_partition_image,storage,build/modules))
47+

README.md

Lines changed: 10 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# esp32-javascript
22

33
"Lightweight" JS interpreter for ESP32. Provides JS-based eventloop implementation
4-
and native asynchronous network and timer functions.
4+
and native asynchronous network and timer functions.
5+
Because of the limited memory on ESP32-WROOM modules, the full functionality is currently only realizable on ESP32-WROVER modules, that include additional 4MB of SPIRAM memory.
56

67
## Content
78
[Getting started](#getting-started)
@@ -35,94 +36,24 @@ Use the keyboard shortcut `AltGr + ]` to leave serial monitor.
3536

3637
Now you have installed the pre-configured boot script.
3738

38-
If this is your first install, your onboard LED should now blink. Blinking signals that
39-
your Board has started a soft ap with the ssid "esp32". With your mobile or desktop connect
40-
to the WLAN SSID "esp32" and open http://192.168.4.1/setup
39+
If this is your first install, your onboard LED should blink now. Blinking signals that
40+
your board has started a soft ap with the ssid "esp32". With your mobile or desktop connect
41+
to the WLAN SSID "esp32" and open http://192.168.4.1/setup (if you have not changed the default
42+
credentials your username / password is esp32 / esp32 ).
4143

42-
On the Setup page you can configure your WLAN settings and an URL to download your JS script from.
43-
44-
Please note that currently only http (and NO https) is possible.
44+
On the Setup page you can configure your WLAN settings and an URL to download your JS main script from.
4545

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

49-
print('Hello world!');
49+
console.log('Hello world!');
5050

5151
## Compatibility
5252

53-
Tested with 129d32772e5e5eafe88be5b9eb34687e84a6f8b8 of esp-idf and xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.
53+
Tested with release/v4.0 (ba0f4f17ed91c3372149beacdfbee6af58e4f634) of esp-idf.
5454

5555
## API
56-
57-
### Timer API
58-
59-
#### setTimeout
60-
61-
function setTimeout(cb, timeout)
62-
63-
Creates a timer and calls the function cb **once** after the configured timeout. Returns a handle.
64-
65-
#### clearTimeout
66-
67-
function clearTimeout(handle)
68-
69-
Clears and removes the timeout timer by specifing the corresponding handle.
70-
71-
#### setInterval
72-
73-
function setInterval(cb, interval)
74-
75-
Creates a interval timer and call the function cb endlessly in the configured interval time. Returns a handle.
76-
77-
#### clearInterval
78-
79-
function clearInterval(handle)
80-
81-
Clears and removes an interval timer by specifing the corresponding handle.
82-
83-
### Socket API
84-
85-
#### sockConnect
86-
87-
function sockConnect(host, port, onConnect, onData, onError, onClose)
88-
89-
Creates a non-blocking sockets and connects it to host and port. Provides some callback functions:
90-
91-
* onConnect: ()=>void called once upon successful connect.
92-
* onData: (data:string)=>void called several times providing a data string, on each call.
93-
* onError: ()=>void called once upon error.
94-
* onClose: function() called once upon socket close.
95-
96-
#### sockListen
97-
98-
function sockListen(port, onAccept, onError, onClose)
99-
100-
Creates a non-blocking listening socket, which automatically accepts incoming connections. Upon connection the onAccept call back is called with the connected
101-
socket as argument.
102-
103-
* port: number The listening port.
104-
* onAccept: (socket: Socket)=>void Called once for every incoming connection.
105-
* onError: ()=>void called once upon error with the listening socket.
106-
* onClose: ()=>void called once upon socket close.
107-
108-
#### Socket
109-
110-
type Socket =
111-
{
112-
sockfd: number;
113-
onData?: onData(data: string, sockfd: number)=>void;
114-
onError?: onError()=>void;
115-
onClose?: onClose()=>void;
116-
isConnected: boolean;
117-
isError: boolean;
118-
isListening: boolean;
119-
120-
//only for listening sockets
121-
onAccept?: onAccept(socket: Socket)=>void;
122-
123-
//only for non-listening sockets
124-
onConnect?: onConnect()=>void;
125-
}
56+
[API documentation](api.md)
12657

12758
## License
12859
See source files.

0 commit comments

Comments
 (0)