-->
Page 1 of 25

ESP8266 UART to TCP socket absolutely transparent bridge

PostPosted: Mon Dec 15, 2014 11:49 am
by dacb
https://github.com/beckdac/ESP8266-transparent-bridge

Image

Many thanks to petgit on github for some nice new features...
Also, many thanks to jvandenbroek for the GPIO2 features that can be used to reset an arduino for remote bootloading.

This is really basic firmware for the ESP that creates a totally transparent TCP socket to ESP UART0 bridge. Characters come in on one interface and go out the other. The totally transparent bridge mode is something that has been missing and is available on higher priced boards.

Pros:
  • It works. Do you already have a serial project to which you just want to add WiFi? This is your ticket. No more dealing with the AT command set.
  • You can program your Arduino over WiFi. Just hit the reset button and upload your sketch using avrdude's socket port, e.g.
    Code: Select allavrdude -c avrisp -p m328p -P net:169.254.4.1:23 -F -U flash:w:mySketch.hex:i
  • Optional by compile time defines:
    • Static configuration each time the unit boots from values defined in user/config.h. Uncomment the following line in user/config.h:
      Code: Select all#define CONFIG_STATIC
    • Dynamic configuration by remote telnet using +++AT prefixed commands. Enabled by default. To disable, comment the following line in user
      /config.h:
      Code: Select all#define CONFIG_DYNAMIC

      Telnet into the module and issue commands prefixed by +++AT to escape each command from bridge mode. The dynamic configuration commands are:
      Code: Select all+++AT                                    # do nothing, print OK
      +++AT MODE                               # print current opmode
      +++AT MODE <mode: 1= STA, 2= AP, 3=both> # set current opmode
      +++AT STA                                # print current ssid and password connected to
      +++AT STA <ssid> <password>              # set ssid and password to connect to
      +++AT AP                                 # print the current soft ap settings
      +++AT AP <ssid>                          # set the AP as open with specified ssid
      +++AT AP <ssid> <pw> [<authmode> [<ch>]]]# set the AP ssid and password, authmode:1= WEP,2= WPA,3= WPA2,4= WPA+WPA2 , channel: 1..13
      +++AT BAUD                               # print current UART settings
      +++AT BAUD <baud> [data [parity [stop]]] # set current UART baud rate and optional data bits = 5/6/7/8 , parity = N/E/O, stop bits = 1/1.5/2
      +++AT PORT                               # print current incoming TCP socket port
      +++AT PORT <port>                        # set current incoming TCP socket port (restarts ESP)
      +++AT FLASH                              # print current flash settings
      +++AT FLASH <1|0>                        # 1: The changed UART settings (++AT BAUD ...) are saved ( Default after boot), 0= no save to flash.
      +++AT RESET                              # software reset the unit
      +++AT GPIO2 <0|1|2 100>                  # 1: pull GPIO2 pin up (HIGH) 0: pull GPIO2 pin down (LOW) 2: reset GPIO2, where 100 is optional to specify reset delay time in ms (default 100ms)
      Upon success, all commands send back "OK" as their final output. Note that passwords may not contain spaces.

      The settings are saved after the commands +++AT PORT +++AT BAUD ...

      After +++AT FLASH 0 the parameter of command +++AT BAUD ... are NOT saved to the flash memory. The new settings are applied to the UART and saved only in RAM. But a following +++AT PORT need to flash the settings for the necessary reboot. Then also the changed UART setting are saved to flash.

      The disable of flash the settings is for devices with baud rate changes to avoid permanently flash of the setting sector.

Cons:
  • Limited buffered TCP writes. The first buffer is the UART FIFO. The second buffer is to collect new uart chars until the previous packet is sent. From SDK 0.9.4 the next espconn_sent must after espconn_sent_callback of the pre-packet. All incoming UART characters in the FIFO gets sent immediately via the tx-buffer. The resulting TCP packet has only some bytes.

Re: ESP8266 UART to TCP socket absolutely transparent bridge

PostPosted: Mon Dec 15, 2014 2:36 pm
by Bananis
Good work!

Thanks
/Bananis

Re: ESP8266 UART to TCP socket absolutely transparent bridge

PostPosted: Mon Dec 15, 2014 7:34 pm
by dacb
Thanks for the kind words.

I've partially implemented an over-the-wire remote configuration option. You can enable it by defining CONFIG_DYNAMIC in user/config.h. When enabled, it allows the user to enter AT style commands via the socket, e.g. telnet, when prefixed by '+++'. Any other data is passed through to the UART transparently. Right now I'm putting in:
Code: Select all+++AT MODE <mode: 1= STA, 2= AP, 3=both>
+++AT STA <ssid> <password>
+++AT AP <ssid> <password>
+++AT RESET

Super basic. The AP forces channel 6 and AUTH_WPA_PSK, at the moment. Changing the mode forces a reset per the ESP8266 docs.

Any other must haves?

Re: ESP8266 UART to TCP socket absolutely transparent bridge

PostPosted: Tue Dec 16, 2014 4:00 am
by dacb
Original post has been updated with info about the now complete (but optional by compile time define) remote (over-the-wire) configuration. This can be done via telnet and escape the commands from the bridge mode by prefixing all commands with +++AT. Command list:

Code: Select all+++AT                                    # do nothing, print OK
+++AT MODE                               # print current opmode
+++AT MODE <mode: 1= STA, 2= AP, 3=both> # set current opmode
+++AT STA                                # print current ssid and password connected to
+++AT STA <ssid> <password>              # set ssid and password to connect to
+++AT AP                                 # print the current soft ap settings
+++AT AP <ssid>                          # set the AP as open with specified ssid
+++AT AP <ssid> <password>               # set the AP as WPA with password
+++AT RESET                              # software reset the unit


Example session:
Code: Select alluser@host:~$ telnet 192.168.1.197
Trying 192.168.1.197...
Connected to 192.168.1.197.
Escape character is '^]'.
+++AT MODE
MODE=3
OK
+++AT AP
SSID=ESP_9E2EA6 PASSWORD= AUTHMODE=0 CHANNEL=3
OK
+++AT AP newSSID password
OK
+++AT AP
SSID=newSSID PASSWORD=password AUTHMODE=2 CHANNEL=3
OK
+++AT AP ESP_9E2EA6
OK
+++AT AP
SSID=ESP_9E2EA6 PASSWORD= AUTHMODE=0 CHANNEL=3
OK
^]c

telnet> c
Connection closed.


In order, this gets the current opmode. Good, it is 3 for STA + AP. Next, the current AP settings are retrieved. Next, the AP ssid is changed to newSSID and the authmode set to WPA and a password set. The AP settings are retrieved again to verify. Finally, the AP SSID is changed back to the original and by not using a password, the authmode is set to OPEN.