Coder Social home page Coder Social logo

alphalima / esp32-serial-bridge Goto Github PK

View Code? Open in Web Editor NEW
377.0 32.0 132.0 452 KB

Wifi to 3x Serial bridge based on a ESP32

Home Page: http://www.postfrontal.com/forum/topic.asp?TOPIC_ID=8467

License: MIT License

C++ 76.54% C 23.46%
wifi serial bridge telnet alphalima flarm

esp32-serial-bridge's Introduction

ESP32-Serial-Bridge

Transparent WiFi (TCP) to all three UART Bridge, supports both AP and STATION WiFi modes. The .ino file is the code for the ESP32. Use Arduino IDE for ESP32 to compile and upload it to the ESP32. I made this project in order to connect Flight equipment devices devices like (Radio, Vario FLARM), to a Flight Computer (Kobo, Smartphones etc.), but it is not limited to that. You can use it wherever you want, but on your own risk. Read license file for more details. Accesspoint
IPAdress: 192.168.4.1
AP SSID: LK8000
AP Password: Flightcomputer
Used Ports:
192.168.4.1:8880 <-> COM0
192.168.4.1:8881 <-> COM1
192.168.4.1:8882 <-> COM2

===============================================================

Used Libraries: (must be installed in the arduino IDE):

https://github.com/espressif/arduino-esp32

===============================================================

In some cases the memorylayout is to small for this scetch. If you face this problem you can either disable Bluetooth by removing #define BLUETOOTH in config.h or change the partition size as described here: https://desire.giesecke.tk/index.php/2018/04/20/change-partition-size-arduino-ide/

Arduino hardware configuration:

https://github.com/AlphaLima/ESP32-Serial-Bridge/blob/master/Settings.jpg

===============================================================

example usecases:

https://www.youtube.com/watch?v=K2Hia06IMtk

https://www.youtube.com/watch?v=GoSxlQvuAhg

Hardware

here is the wiring diagram recomendation: https://raw.githubusercontent.com/AlphaLima/ESP32-Serial-Bridge/master/ESP32-SerialBridge.jpg
Pinning
COM0 Rx <-> GPIO21
COM0 Tx <-> GPIO01
COM1 Rx <-> GPIO16
COM1 Tx <-> GPIO17
COM2 Rx <-> GPIO15
COM2 Tx <-> GPIO04

NOTE: The PIN assignment has changed and may not look straigt forward (other PINs are marked as Rx/Tx), but this assignment allows to flash via USB also with hooked MAX3232 serial drivers.

I recomend to start your project with a Node32s or compatible evaluation board. For a TTL to RS232 level conversion search google for "TTL RS3232 Converter"

https://tech.scargill.net/wp-content/uploads/2017/05/ESP326.jpg

esp32-serial-bridge's People

Contributors

alphalima 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp32-serial-bridge's Issues

Core 0 panic

I got problem connecting and got wrong password as response from my Android phone. When using com0 to read the debug messages I saw a restart every time I tried to connect. I tried to flash and also emptied the flash in the ESP32 before uploading the code again. I'm using Arduino IDE. The error message I saw was WiFi.softAPIP() causes Core 0 panic'ed (InstrFetchProhibited)
When searching for the message I found a discussion about timing issue. So I tried some different suggestion and found a working solution with a added delay and moving the softAPConfig line to run after the delay. Thanks AlphaLima for providing the original code, great for me flying sailplane and using Kobo with XCSoar.
Below is the part I changed. Might be useful for someone with same problem.
My HW is a Espressif ESP32 WLAN Dev Kit Board Development Bluetooth Wifi v1 WROOM32 NodeMCU.

if(debug) COM[DEBUG_COM]->println("\n\nWiFi serial bridge V1.10");
#ifdef MODE_AP 
if(debug) COM[DEBUG_COM]->println("Open ESP Access Point mode");
// AP mode (phone connects directly to ESP) (no router)
WiFi.mode(WIFI_AP);
// WiFi.softAPConfig(ip, ip, netmask); // configure ip address for softAP // workaround mj
WiFi.softAP(ssid, pw); // configure ssid and password for softAP
delay(2000);  // workaround mj
WiFi.softAPConfig(ip, ip, netmask);   // configure ip address for softAP 
#endif

invalid use of void

compiling the sketch in Arduino the compiler returns with the following message:

ESP32-Serial-Bridge:101:5: error: invalid use of 'void'
.onEnd( { <--- here it stops

I have no clue to solve this.
Can anybody show me a way?

does it works as a transparent wireless serial-to-serial interface

Hi,

what is not clear to me is:
can this code be used to have a full hardware-transparent serial--to---serial-interface.

Imagine an Arduino Uno which is connected to an extra-USB-to-TTL-converter on Arduino-no-Pins 0 and 1

Arduino-Uno-0-Rx--------Tx-of-USB-to-TTL---------------USB-port of computer
Arduino-Uno-1-Tx--------Rx-of-USB-to-TTL---------------USB-port of computer

Now instead of using a wire a pair of wireless serial shall be used
Arduino-Uno-0-Rx-------wireless-serial.............over.....the.........air.....wireless-serial-Tx--------computer
Arduino-Uno-0-Tx-------wireless-serial.............over.....the.........air.....wireless-serial-Rx--------computer

Can this code be used in this hardware-configuration as a pure hardware-replacement of a cable?

best regards Stefan

ERROR: "NUM_COM" was not declared in this scope

when I run this code, there is an error saying that "NUM_COM" was not declared in this scope, I don't know how can I fix this error.
The error is in line 186, in for loop: for(int num= 0; num < NUM_COM ; num++).

Invert Serial request

I have been using esplink wich is the same as this, but for esp8266.
Can inverted serial be done in chip and added to this project?

Im not that good with programming to get the thing done :(

I want to step up to an esp32.
And i use the small devices for HAN P1-Port electricity meters.
They use inverted serial to communicate.
Im aware the esp can invert serial in the chip, at least esp8266 can.

This is a commit on esplink to enable inverted serial:
jeelabs/esp-link@master...de-wolff:esp-link:add_invert_uart_lines

Regards

Warning: When Using old Version of Arduino-ESP32: Serial Transmit Buffer Overflow?

In line 212: COM[num]->write(buf1[num], i1[num]); // now send to UART(num):
it can happen that i1[num] is > 127, but if I remember correctely the size of the hardware serial tx buffer is only 128, so if your transmission is bigger than 128 you could lose data. So at least for me it only worked out if I send the data in chunks of 128.

I would recommend adding something like:

if(debug) COM[DEBUG_COM]->println((char*)buf1[num]);  
*/  
//add begin (above line 212)  
  byte NumberOfTransmissions;  
  NumberOfTransmissions = (i1[num] / 128);  
  for (byte TransPlusOne = 0; TransPlusOne < NumberOfTransmissions; TransPlusOne++) { //for more than one transmission (TransPlusOne is the index if we have more than one transmission)
    COM[num]->write(buf1[num] + 128 * TransPlusOne, 128);  
  }  
  COM[num]->write(buf1[num] + NumberOfTransmissions * 128, i1[num] % 128); //last transmission  
//add end (below line 212)  
i1[num] = 0;  

Consuming Virtual Coms

Thanks for this library

Got it installed and it works fine up to the telnet part.

Can you reference any libraries or code for NodeJS or the browser itself to consume these virtual COM's
I found this one:
https://github.com/papnkukn/remote-serial-port-client
But this is specifically written for NodeJS Virtual Com server

Thanks in advance
Theo Boomsma

compile error

Dear All,

when I try to compile I recive this error:

Compilation error: 'union arduino_event_info_t' has no member named 'disconnected'; did you mean 'eth_connected'?

Anyone know how to solve it?

Thanks

pretty mess of code...

Sorry to say that, but this code is a mess... Just a few things you should definitely change:

  1. Don't name the Uart connections "Serial1" and "Serial2", these names are almost always already defined. If you want to setup your own (like you do it) rename them!
  2. Udp protocol is only half implemented, finish it, or remove it totally!
  3. In config.h you define software serial, but never use it again. Remove it!
  4. If Bluetooth is not defined, the index of buffer 2 (what you call i2[num]) will never reset!! This will lead to a fail as soon the buffer is full! If the buffer is full, it should be also printed at least in debug mode to debug com!
  5. In station mode, the ssid and password still has to be defined, missing in your header!!
  6. Last but not least, i recommend you to use functions! This would make the code way easier to read!!

I have not tried ota, and bluetooth, don't know if these things are working....

(Solved) Buffer Index Overflow

In line 96:
uint8_t i1[NUM_COM]={0,0,0};
you use uint8_t to index your buffer which has the size #define bufferSize 8192. This leads to an buffer overflow if we recieve tcp packets which are greater than 256 or if we recieve multiple packets with short delay.

Youtube links

When i run the sketch in a standard esp32, the local comm port seems to see com1 com2 com3...com17 many com ports open on the serial monitor.
If i close one of the clients, the servers resets. My own software does the same, hence I was looking for something that doesnt crash the server when a client(esp32) powers down etc I am sending NMEA data.
Your code works well. Worked first time.

Is there a way to make it work @1MBps ?

Hi,
I spend a lot of time to make it work at more than the baudrate of 230400 bps.
I need to use it at > 1 000 000 bps but whatever I do, it doesn't :(
Any idea ? Did you make it ?
Thanks for your help!

Can't get mavlink to work

I am receiving the serial data but it is not recognizable. The fc wil not register a connection. If I open serial monitor on vscode or arduino. I see ascii , but I have the baud rate set at 115200.

telnet character mode

In some telnet clients, it may be necessary to enable mode chacter in order to properly send control characters:

ctrl-]
telnet> mode character

It might be helpful to include this as a note in the README

Otherwise, I LOVE this. It's exactly what I was looking for. I needed to be able to connect at least two devices to a single ESP32. This saved me many days of development. Thank you.

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.