mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-28 15:40:23 +08:00
commit
db10b3821c
@ -1,30 +1,10 @@
|
|||||||
# A UART to network bridge for ESP32
|
# A UART to network bridge for ESP32
|
||||||
|
|
||||||
This example is a demonstration of how Mongoose Library could be integrated
|
|
||||||
into an embedded device and provide a UART-to-Network bridge capability:
|
|
||||||
|
|
||||||
- A device opens listening TCP port and Websocket port and waits for connections
|
|
||||||
- When a client connects, data is exchanged with the device's UART
|
|
||||||
- Everything that client send, is sent to the UART
|
|
||||||
- Everything that is read from the UART, gets sent to the client
|
|
||||||
- Multiple clients are allowed
|
|
||||||
- Live UART console allows to talk to the UART from the web page
|
|
||||||
- Web UI is hardcoded into the binary and does not need a filesystem
|
|
||||||
|
|
||||||
# Screenshots
|
|
||||||
|
|
||||||
![](../../uart-bridge/screenshots/dashboard.png)
|
![](../../uart-bridge/screenshots/dashboard.png)
|
||||||
|
|
||||||
# Build and flash
|
- See detailed tutorial at https://mongoose.ws/tutorials/esp32/uart-bridge/
|
||||||
|
|
||||||
Build requires Docker installed, and uses Espressif's ESP-IDF docker image:
|
## Flash pre-built firmware
|
||||||
|
|
||||||
```sh
|
|
||||||
make build
|
|
||||||
make flash PORT=/dev/YOURSERIAL
|
|
||||||
```
|
|
||||||
|
|
||||||
# Flash pre-built firmware
|
|
||||||
|
|
||||||
You can flash a pre-built firmware to the ESP32 device using the following
|
You can flash a pre-built firmware to the ESP32 device using the following
|
||||||
instructions:
|
instructions:
|
||||||
|
@ -1,22 +1 @@
|
|||||||
# An example ESP8266 application
|
See detailed tutorial at https://mongoose.ws/tutorials/esp8266/http-client-server/
|
||||||
|
|
||||||
To build this application, follow these steps:
|
|
||||||
|
|
||||||
1. Make sure you have Docker installed
|
|
||||||
2. Clone whole mongoose repository on your machine:
|
|
||||||
```sh
|
|
||||||
git clone https://github.com/cesanta/mongoose.git
|
|
||||||
```
|
|
||||||
3. Start command line or terminal, and go into the example's directory:
|
|
||||||
```sh
|
|
||||||
cd mongoose/examples/esp8266
|
|
||||||
```
|
|
||||||
4. Run `make`. This invokes a Docker-based build. A firmware will be built
|
|
||||||
in the `src/build/` directory:
|
|
||||||
```sh
|
|
||||||
make build
|
|
||||||
```
|
|
||||||
5. Flash your ESP8266. If you have esptool.py installed, the build process will end telling you the command to flash your device. You can just run `make` again to use Docker:
|
|
||||||
```sh
|
|
||||||
make flash PORT=/your/serial
|
|
||||||
```
|
|
@ -40,7 +40,7 @@ DEVICE_URL ?= https://dash.vcon.io/api/v3/devices/1
|
|||||||
update: firmware.bin
|
update: firmware.bin
|
||||||
curl --fail-with-body -su :$(VCON_API_KEY) $(DEVICE_URL)/ota --data-binary @$<
|
curl --fail-with-body -su :$(VCON_API_KEY) $(DEVICE_URL)/ota --data-binary @$<
|
||||||
|
|
||||||
test update: CFLAGS_EXTRA += -DUART_DEBUG=UART1
|
test update: CFLAGS_EXTRA += -DUART_DEBUG=UART0
|
||||||
test: update
|
test: update
|
||||||
curl --fail-with-body -su :$(VCON_API_KEY) $(DEVICE_URL)/tx?t=5 | tee /tmp/output.txt
|
curl --fail-with-body -su :$(VCON_API_KEY) $(DEVICE_URL)/tx?t=5 | tee /tmp/output.txt
|
||||||
grep 'READY, IP:' /tmp/output.txt # Check for network init
|
grep 'READY, IP:' /tmp/output.txt # Check for network init
|
||||||
|
@ -133,22 +133,18 @@ static inline void gpio_irq_attach(uint16_t pin) {
|
|||||||
#define UARTNO(u) ((uint8_t) (((unsigned int) (u) -UART0_BASE) / UART_OFFSET))
|
#define UARTNO(u) ((uint8_t) (((unsigned int) (u) -UART0_BASE) / UART_OFFSET))
|
||||||
|
|
||||||
static inline void uart_init(UART0_Type *uart, unsigned long baud) {
|
static inline void uart_init(UART0_Type *uart, unsigned long baud) {
|
||||||
struct uarthw {
|
uint8_t af = 1; // Alternate function
|
||||||
uint16_t rx, tx; // pins
|
uint16_t rx = 0, tx = 0; // pins
|
||||||
uint8_t af; // Alternate function
|
|
||||||
};
|
|
||||||
// rx, tx, af for UART0,1,2
|
|
||||||
struct uarthw uarthw[3] = {{PIN('A', 0), PIN('A', 1), 1},
|
|
||||||
{PIN('B', 0), PIN('B', 1), 1},
|
|
||||||
{PIN('A', 6), PIN('A', 7), 1}}; // or PD4, PD5...
|
|
||||||
|
|
||||||
uint8_t uartno = UARTNO(uart);
|
uint8_t uartno = UARTNO(uart);
|
||||||
|
|
||||||
SYSCTL->RCGCUART |= BIT(uartno); // Enable peripheral clock
|
SYSCTL->RCGCUART |= BIT(uartno); // Enable peripheral clock
|
||||||
|
|
||||||
gpio_init(uarthw[uartno].tx, GPIO_MODE_AF, GPIO_OTYPE_PUSH_PULL,
|
if (uart == UART0) tx = PIN('A', 0), rx = PIN('A', 1);
|
||||||
GPIO_SPEED_HIGH, 0, uarthw[uartno].af);
|
if (uart == UART1) tx = PIN('B', 0), rx = PIN('B', 1);
|
||||||
gpio_init(uarthw[uartno].rx, GPIO_MODE_AF, GPIO_OTYPE_PUSH_PULL,
|
if (uart == UART2) tx = PIN('A', 6), rx = PIN('A', 7); // or PD4, PD5...
|
||||||
GPIO_SPEED_HIGH, 0, uarthw[uartno].af);
|
|
||||||
|
gpio_init(tx, GPIO_MODE_AF, GPIO_OTYPE_PUSH_PULL, GPIO_SPEED_HIGH, 0, af);
|
||||||
|
gpio_init(rx, GPIO_MODE_AF, GPIO_OTYPE_PUSH_PULL, GPIO_SPEED_HIGH, 0, af);
|
||||||
// (16.3.2) ClkDiv = 16 (HSE=0)
|
// (16.3.2) ClkDiv = 16 (HSE=0)
|
||||||
// BRD = BRDI + BRDF = UARTSysClk / (ClkDiv * Baud Rate)
|
// BRD = BRDI + BRDF = UARTSysClk / (ClkDiv * Baud Rate)
|
||||||
// UARTFBRD[DIVFRAC] = integer(BRDF * 64 + 0.5)
|
// UARTFBRD[DIVFRAC] = integer(BRDF * 64 + 0.5)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user