Adding HTTPClient, fix esp32 build board, deprecate old spi flash.

This commit is contained in:
Brad Nelson
2024-10-26 09:59:55 -07:00
parent c5ac9b0df0
commit eeaad939a2
10 changed files with 135 additions and 14 deletions

View File

@ -34,8 +34,9 @@ ESP32_OPTIONAL.append(
'$dst/esp32/ESP32forth/ESP32forth.ino')) '$dst/esp32/ESP32forth/ESP32forth.ino'))
def Esp32Optional(main_name, main_source, parts): def Esp32Optional(main_name, main_source, parts, very_optional=False):
global ESP32_OPTIONAL global ESP32_OPTIONAL
if not very_optional:
ESP32_OPTIONAL.append( ESP32_OPTIONAL.append(
Copy('$dst/esp32/with_optional/ESP32forth/' + main_name + '.h', Copy('$dst/esp32/with_optional/ESP32forth/' + main_name + '.h',
'$dst/esp32/ESP32forth/optional/' + main_name + '.h')) '$dst/esp32/ESP32forth/optional/' + main_name + '.h'))
@ -65,10 +66,12 @@ ESP32_ZIP_FILES += [
[('interrupts', '$src/esp32/optional/interrupts/timers.fs')]), [('interrupts', '$src/esp32/optional/interrupts/timers.fs')]),
Esp32Optional('oled', '$src/esp32/optional/oled/oled.h', Esp32Optional('oled', '$src/esp32/optional/oled/oled.h',
[('oled', '$src/esp32/optional/oled/oled.fs')]), [('oled', '$src/esp32/optional/oled/oled.fs')]),
Esp32Optional('spi-flash', '$src/esp32/optional/spi-flash/spi-flash.h',
[('spi-flash', '$src/esp32/optional/spi-flash/spi-flash.fs')]),
Esp32Optional('serial-bluetooth', '$src/esp32/optional/serial-bluetooth/serial-bluetooth.h', Esp32Optional('serial-bluetooth', '$src/esp32/optional/serial-bluetooth/serial-bluetooth.h',
[('serial-bluetooth', '$src/esp32/optional/serial-bluetooth/serial-bluetooth.fs')]), [('serial-bluetooth', '$src/esp32/optional/serial-bluetooth/serial-bluetooth.fs')],
very_optional=True),
Esp32Optional('http-client', '$src/esp32/optional/http-client/http-client.h', []),
Esp32Optional('spi-flash', '$src/esp32/optional/spi-flash/spi-flash.h',
[('spi-flash', '$src/esp32/optional/spi-flash/spi-flash.fs')], very_optional=True),
] ]
# Zip it. # Zip it.
@ -110,14 +113,17 @@ BOARDS = {
'tdongles3': '--fqbn=esp32:esp32:esp32s3:CDCOnBoot=cdc,FlashSize=16M,PartitionScheme=huge_app', 'tdongles3': '--fqbn=esp32:esp32:esp32s3:CDCOnBoot=cdc,FlashSize=16M,PartitionScheme=huge_app',
} }
for board_base in BOARDS: for board_base in BOARDS:
options = BOARDS[board_base] for optional, optional_dir, deps in (('', '', ESP32_FILES),
for opt, optdir, deps in (('', '', ESP32_FILES),
('opt', 'with_optional/', ESP32_OPTIONAL)): ('opt', 'with_optional/', ESP32_OPTIONAL)):
board = board_base + opt options = BOARDS[board_base]
if optional:
options = options.replace('PartitionScheme=default', 'PartitionScheme=huge_app')
options = options.replace('PartitionScheme=no_ota', 'PartitionScheme=huge_app')
board = board_base + optional
clobber = f'rm -rf {WINTMP}/ueforth_esp32/{board}_dir/ && ' clobber = f'rm -rf {WINTMP}/ueforth_esp32/{board}_dir/ && '
setup = (f'mkdir -p {WINTMP}/ueforth_esp32/{board}_dir/build && ' setup = (f'mkdir -p {WINTMP}/ueforth_esp32/{board}_dir/build && '
f'mkdir -p {WINTMP}/ueforth_esp32/{board}_dir/cache && ' f'mkdir -p {WINTMP}/ueforth_esp32/{board}_dir/cache && '
f'cp -r $dst/esp32/ESP32forth {WINTMP}/ueforth_esp32/{board}_dir/ && ' f'cp -r $dst/esp32/' + optional_dir + f'ESP32forth/ {WINTMP}/ueforth_esp32/{board}_dir/ && '
f'cd {WINTMP} && ') f'cd {WINTMP} && ')
cmd = f' {ARDUINO_CLI} compile ' cmd = f' {ARDUINO_CLI} compile '
upload = '--port $${PORT:-com3} --upload ' upload = '--port $${PORT:-com3} --upload '

View File

@ -84,6 +84,14 @@
# define OPTIONAL_SPI_FLASH_SUPPORT # define OPTIONAL_SPI_FLASH_SUPPORT
# endif # endif
// Hook to pull in optional HTTPClient support.
# if __has_include("http-client.h")
# include "http-client.h"
# else
# define OPTIONAL_HTTP_CLIENT_VOCABULARY
# define OPTIONAL_HTTP_CLIENT_SUPPORT
# endif
static cell_t ResizeFile(cell_t fd, cell_t size); static cell_t ResizeFile(cell_t fd, cell_t size);
#endif #endif
@ -120,7 +128,8 @@ static cell_t ResizeFile(cell_t fd, cell_t size);
OPTIONAL_OLED_SUPPORT \ OPTIONAL_OLED_SUPPORT \
OPTIONAL_RMT_SUPPORT \ OPTIONAL_RMT_SUPPORT \
OPTIONAL_SERIAL_BLUETOOTH_SUPPORT \ OPTIONAL_SERIAL_BLUETOOTH_SUPPORT \
OPTIONAL_SPI_FLASH_SUPPORT OPTIONAL_SPI_FLASH_SUPPORT \
OPTIONAL_HTTP_CLIENT_SUPPORT
#define REQUIRED_MEMORY_SUPPORT \ #define REQUIRED_MEMORY_SUPPORT \
YV(internals, MALLOC, SET malloc(n0)) \ YV(internals, MALLOC, SET malloc(n0)) \

View File

@ -16,6 +16,7 @@ These are the current optional modules:
* serial-bluetooth.h - Support for Bluetooth serial and * serial-bluetooth.h - Support for Bluetooth serial and
bterm a Bluetooth serial redirector for the terminal bterm a Bluetooth serial redirector for the terminal
* spi-flash.h - Support for low level SPI Flash partition access * spi-flash.h - Support for low level SPI Flash partition access
* http-client.h - Support for HTTP/HTTPS
Initially ESP32forth focused on a minimal C kernel, with most functionality Initially ESP32forth focused on a minimal C kernel, with most functionality
built in Forth code loaded at boot. Eventually, as support for more capabilities built in Forth code loaded at boot. Eventually, as support for more capabilities

View File

@ -0,0 +1,52 @@
// Copyright 2024 Bradley D. Nelson
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* ESP32forth RMT v{{VERSION}}
* Revision: {{REVISION}}
*/
#include "HTTPClient.h"
#define OPTIONAL_HTTP_CLIENT_VOCABULARY V(HTTPClient)
#define OPTIONAL_HTTP_CLIENT_SUPPORT \
XV(HTTPClient, "NetworkClientSecure.new", NetworkClientSecure_new, PUSH new NetworkClientSecure()) \
XV(HTTPClient, "NetworkClientSecure.delete", NetworkClientSecure_delete, delete ((NetworkClientSecure *) a0); DROP) \
XV(HTTPClient, "NetworkClientSecure.setCACert", NetworkClientSecure_setCACert, \
((NetworkClientSecure *) a0)->setCACert(c1); DROPn(2)) \
XV(HTTPClient, "HTTPClient.new", HTTPClient_new, PUSH new HTTPClient()) \
XV(HTTPClient, "HTTPClient.delete", HTTPClient_delete, delete (HTTPClient *) a0; DROP) \
XV(HTTPClient, "HTTPClient.begin", HTTPClient_begin, n0 = ((HTTPClient *) a0)->begin(c1); NIP) \
XV(HTTPClient, "HTTPClient.beginNC", HTTPClient_beginNC, \
n0 = ((HTTPClient *) a0)->begin(*(NetworkClient *)a1, c2); NIPn(2)) \
XV(HTTPClient, "HTTPClient.end", HTTPClient_end, ((HTTPClient *) a0)->end(); DROP) \
XV(HTTPClient, "HTTPClient.connected", HTTPClient_connected, n0 = ((HTTPClient *) a0)->connected()) \
XV(HTTPClient, "HTTPClient.setReuse", HTTPClient_setReuse, ((HTTPClient *) a0)->setReuse(n1); DROPn(2)) \
XV(HTTPClient, "HTTPClient.setUserAgent", HTTPClient_setUserAgent, ((HTTPClient *) a0)->setUserAgent(c1); DROPn(2)) \
XV(HTTPClient, "HTTPClient.setAuthorization", HTTPClient_setAuthorization, \
((HTTPClient *) a0)->setAuthorization(c2, cc1); DROPn(3)) \
XV(HTTPClient, "HTTPClient.setFollowRedirects", HTTPClient_setFollowRedirects, \
((HTTPClient *) a0)->setFollowRedirects((followRedirects_t) n1); DROPn(2)) \
XV(HTTPClient, "HTTPClient.setRedirectLimit", HTTPClient_setRedirectLimit, \
((HTTPClient *) a0)->setRedirectLimit(n1); DROPn(2)) \
XV(HTTPClient, "HTTPClient.GET", HTTPClient_GET, n0 = ((HTTPClient *) a0)->GET()) \
XV(HTTPClient, "HTTPClient.POST", HTTPClient_POST, n0 = ((HTTPClient *) a0)->POST(b2, n1); NIPn(2)) \
XV(HTTPClient, "HTTPClient.addHeader", HTTPClient_addHeader, ((HTTPClient *) a0)->addHeader(c2, c1); DROPn(3)) \
XV(HTTPClient, "HTTPClient.sendRequest", HTTPClient_sendRequest, n0 = ((HTTPClient *) a0)->sendRequest(c3, b2, n1); NIPn(3)) \
XV(HTTPClient, "HTTPClient.getSize", HTTPClient_getSize, n0 = ((HTTPClient *) a0)->getSize()) \
XV(HTTPClient, "HTTPClient.getString", HTTPClient_getString, ((HTTPClient *) a0)->getString().getBytes(b2, n1); DROPn(3)) \
XV(HTTPClient, "HTTPClient.getStreamPtr", HTTPClient_getStreamPtr, \
NetworkClient *s = ((HTTPClient *) a0)->getStreamPtr(); n0 = (cell_t) s) \
XV(HTTPClient, "NetworkClient.available", NetworkClient_available, n0 = ((NetworkClient *) a0)->available()) \
XV(HTTPClient, "NetworkClient.readBytes", NetworkClient_readBytes, n0 = ((NetworkClient *) a0)->readBytes(b2, n1); NIPn(2))

View File

@ -21,6 +21,11 @@
#include "BluetoothSerial.h" #include "BluetoothSerial.h"
#define bt0 ((BluetoothSerial *) a0) #define bt0 ((BluetoothSerial *) a0)
#if defined(CONFIG_IDF_TARGET_ESP32S3)
# define BT0_ENABLE_SSP
#else
# define BT0_ENABLE_SSP bt0->enableSSP()
#endif
#define OPTIONAL_BLUETOOTH_VOCABULARY V(bluetooth) #define OPTIONAL_BLUETOOTH_VOCABULARY V(bluetooth)
#define OPTIONAL_SERIAL_BLUETOOTH_SUPPORT \ #define OPTIONAL_SERIAL_BLUETOOTH_SUPPORT \
@ -35,7 +40,7 @@
XV(bluetooth, "SerialBT.write", SERIALBT_WRITE, n0 = bt0->write(b2, n1); NIPn(2)) \ XV(bluetooth, "SerialBT.write", SERIALBT_WRITE, n0 = bt0->write(b2, n1); NIPn(2)) \
XV(bluetooth, "SerialBT.flush", SERIALBT_FLUSH, bt0->flush(); DROP) \ XV(bluetooth, "SerialBT.flush", SERIALBT_FLUSH, bt0->flush(); DROP) \
XV(bluetooth, "SerialBT.hasClient", SERIALBT_HAS_CLIENT, n0 = bt0->hasClient()) \ XV(bluetooth, "SerialBT.hasClient", SERIALBT_HAS_CLIENT, n0 = bt0->hasClient()) \
XV(bluetooth, "SerialBT.enableSSP", SERIALBT_ENABLE_SSP, bt0->enableSSP(); DROP) \ XV(bluetooth, "SerialBT.enableSSP", SERIALBT_ENABLE_SSP, BT0_ENABLE_SSP; DROP) \
XV(bluetooth, "SerialBT.setPin", SERIALBT_SET_PIN, n0 = bt0->setPin(c1); NIP) \ XV(bluetooth, "SerialBT.setPin", SERIALBT_SET_PIN, n0 = bt0->setPin(c1); NIP) \
XV(bluetooth, "SerialBT.unpairDevice", SERIALBT_UNPAIR_DEVICE, \ XV(bluetooth, "SerialBT.unpairDevice", SERIALBT_UNPAIR_DEVICE, \
n0 = bt0->unpairDevice(b1); NIP) \ n0 = bt0->unpairDevice(b1); NIP) \

View File

@ -47,3 +47,9 @@ internals DEFINED? serial-bluetooth-source [IF]
internals DEFINED? spi-flash-source [IF] internals DEFINED? spi-flash-source [IF]
spi-flash-source evaluate spi-flash-source evaluate
[THEN] forth [THEN] forth
internals DEFINED? HTTPClient [IF]
vocabulary HTTPClient HTTPClient definitions
transfer HTTPClient-buildtins
forth definitions
[THEN] forth

View File

@ -101,4 +101,5 @@
OPTIONAL_OLED_VOCABULARY \ OPTIONAL_OLED_VOCABULARY \
OPTIONAL_RMT_VOCABULARY \ OPTIONAL_RMT_VOCABULARY \
OPTIONAL_SPI_FLASH_VOCABULARY \ OPTIONAL_SPI_FLASH_VOCABULARY \
OPTIONAL_HTTP_CLIENT_VOCABULARY \
USER_VOCABULARIES USER_VOCABULARIES

View File

@ -31,6 +31,7 @@
#define OPTIONAL_RMT_SUPPORT #define OPTIONAL_RMT_SUPPORT
#define OPTIONAL_SERIAL_BLUETOOTH_SUPPORT #define OPTIONAL_SERIAL_BLUETOOTH_SUPPORT
#define OPTIONAL_SPI_FLASH_SUPPORT #define OPTIONAL_SPI_FLASH_SUPPORT
#define OPTIONAL_HTTP_CLIENT_SUPPORT
#define OPTIONAL_BLUETOOTH_VOCABULARY #define OPTIONAL_BLUETOOTH_VOCABULARY
#define OPTIONAL_CAMERA_VOCABULARY #define OPTIONAL_CAMERA_VOCABULARY
@ -38,6 +39,7 @@
#define OPTIONAL_OLED_VOCABULARY #define OPTIONAL_OLED_VOCABULARY
#define OPTIONAL_RMT_VOCABULARY #define OPTIONAL_RMT_VOCABULARY
#define OPTIONAL_SPI_FLASH_VOCABULARY #define OPTIONAL_SPI_FLASH_VOCABULARY
#define OPTIONAL_HTTP_CLIENT_VOCABULARY
#include "builtins.h" #include "builtins.h"

View File

@ -28,6 +28,7 @@
#define OPTIONAL_OLED_VOCABULARY #define OPTIONAL_OLED_VOCABULARY
#define OPTIONAL_RMT_VOCABULARY #define OPTIONAL_RMT_VOCABULARY
#define OPTIONAL_SPI_FLASH_VOCABULARY #define OPTIONAL_SPI_FLASH_VOCABULARY
#define OPTIONAL_HTTP_CLIENT_VOCABULARY
static cell_t *simulated(cell_t *sp, const char *op); static cell_t *simulated(cell_t *sp, const char *op);

View File

@ -721,6 +721,10 @@ These words are inside the <code>spi_flash</code> vocabulary.
NOTE: Starting in v7.0.7.13 the optional module spi-flash.h must be NOTE: Starting in v7.0.7.13 the optional module spi-flash.h must be
placed next to ESP32forth.ino to include this capability. placed next to ESP32forth.ino to include this capability.
</b></p> </b></p>
<p><b>
NOTE: Recent versions of Arduino tools seem to be incompatible
with this interface, this module is now deprecated.
</b></p>
<pre> <pre>
spi_flash_init ( -- ) Init driver access. spi_flash_init ( -- ) Init driver access.
spi_flash_get_chip_size ( -- n ) Get flash size. spi_flash_get_chip_size ( -- n ) Get flash size.
@ -998,6 +1002,40 @@ rmt_clr_intr_enable_mask --- DEPRECATED interrupt handled by driver
rmt_set_pin --- DEPRECATED use rmt_set_gpio instead rmt_set_pin --- DEPRECATED use rmt_set_gpio instead
</pre> </pre>
<h5 id="HTTPClient">HTTPClient</h5>
These words are inside the optional <code>HTTPClient</code> vocabulary.
<p><b>
NOTE: This vocabulary is optional, available by placing
http-client.h next to ESP32forth.ino to include this capability.
</b></p>
<pre>
NetworkClientSecure.new ( -- a ) Create a new secure client (for HTTPS)
NetworkClientSecure.delete ( a -- ) Delete a secure client
NetworkClientSecure.setCACert ( cacertz nc -- ) Set a CACert (cstring) for a secure client
HTTPClient.new ( -- a ) Create a new HTTPClient session
HTTPClient.delete ( a -- ) Delete an HTTPClient
HTTPClient.begin ( urlz hc -- f ) Begin an HTTP session with a url
HTTPClient.beginNC ( urlz nc hc -- f ) Begin an HTTPS session with a url and secure client
HTTPClient.end ( hc -- ) End an HTTP/S session
HTTPClient.connected ( hc -- f ) Check if a session is connected
HTTPClient.setReuse ( f hc -- ) Set if session keep-alive is enabled
HTTPClient.setUserAgent ( agentz hc -- ) Set user-agent string
HTTPClient.setAuthorization ( username password hc -- ) Set an authorization
HTTPClient.setFolowRedirects ( f hc -- ) Set if redirects can be followed
HTTPClient.setRedirectLimit ( n hc -- ) Set number of allowed redirects
HTTPClient.GET ( hc -- n ) Start a GET, return http code
HTTPClient.POST ( a n hc -- n ) Start a POST, with a data payload, return http code
HTTPClient.addHeader ( key value hc -- ) Set an HTTP header
HTTPClient.sendRequest ( methodz a n hc -- n ) Send a request with arbitrary method, payload
HTTPClient.getSize ( hc -- n ) Get size of response
HTTPClient.getString ( a n hc -- n ) Read result into a buffer
HTTPClient.getStreamPtr ( hc -- stream ) Get the result as a stream
NetworkClient.available ( stream -- n ) Get number of bytes available
NetworkClient.readBytes ( a n stream -- n ) Read into a buffer
</pre>
<h5 id="timers">Timers</h5> <h5 id="timers">Timers</h5>
These words are inside the <code>TIMERS</code> vocabulary. These words are inside the <code>TIMERS</code> vocabulary.
<p><b> <p><b>