Debugging WiFi ESP8266 Client and Server Mode

by sergei_iliev in Circuits > Microcontrollers

38 Views, 0 Favorites, 0 Comments

Debugging WiFi ESP8266 Client and Server Mode

wifi_debug_1.png

The objective of this project is debugging ESP-01 WiFi ESP8266 Serial to WiFi module using AT commands from AVR mega1608 microcontroller. AVR mega1608 has more then one USART channel that we are going to use concurrently using acorn micro kernel operating system.

The first task (WiFi task) controls the USART channel connected to ESP-01 sending AT commands and processing their responses.

The second task (Serial task) controls the USART channel connected to PC Serial interface. It mirrors the communication in first task and sends it to a Serial Terminal program for monitoring debugging and investigation.

Producer Consumer pattern is used to transfer data from one task to another task utilizing an 8 bit memory buffer

Components

  1. AVR128DA32 adaptor board
  2. TTL Serial Port Converter Module DB9 Connector For Arduino
  3. ESP-01 ESP8266 adaptor
  4. ATINY416-XNANO board in programming mode

ESP8266 Client Mode

wifi_debug_2.png

Enabling WiFi client mode requires setting

.EQU TCP_MODE=1

in main.asm so that client task wifi_client_Tx1Rx4_task.asm is included in project.

Java demo program is used to create a listenning socket which will accept 1 byte and send back to our client 4 bytes. In each step the debug task will send AT commands based request response traffic to serial terminal program which we can investigate.

Block schema describes WiFi task main blocks of execution as client

One-time init (wfmn_00 → wfmn_01)

  1. send_disable_echo — retry loop until ESP responds OK
  2. send_start — AT test
  3. send_client_mode — AT+CWMODE=1 (station/client)
  4. send_connect_wifi — AT+CWJAP join AP

Transaction loop (wfmn_02) — runs forever

  1. send_tcp_connect — AT+CIPSTART open TCP to server
  2. send_tcp_data — send 1 byte ('L') via AT+CIPSEND
  3. recv_tcp_data — receive 4 bytes into recv_buffer (parse +IPD,...:)
  4. send_at_command — AT+CIPCLOSE
  5. rjmp wfmn_02 — repeat

Each AT command step is preceded by send_usart_queue('?') for debug tracing on the terminal USART task

Serial Monitor for Client Mode

wifi_debug_4.png

I ve used a simple Serial terminal program to monitor request and responses of each AT command.

Each AT Command from the WiFi block of execution has a corresponding response captured by the Serial terminal.

ESP8266 Server Mode

wifi_debug_3.png

Enabling WiFi server mode requires setting

.EQU TCP_MODE=2

in main.asm so that server task wifi_server_Tx1Rx4_task.asm is included in project.

Java demo program is used to create a client socket to connect to our listenning server which will accept 1 byte and send back to our server 4 bytes. In each step the debug task will send AT commands based request response traffic to serial terminal program which we can investigate.

Block schema describes tasks main blocks of execution as server

Boot / reset

  1. Sleep 60s — wait for ESP-01 to finish self-init
  2. send_reset — AT+RST

One-time init (wfmn_00 → wfmn_01)

  1. send_disable_echo — retry loop until OK
  2. send_server_mode — AT+CWMODE=3 (AP + station)
  3. send_multiple_connections — AT+CIPMUX=1
  4. send_read_ip_address — AT+CIFSR
  5. start_tcp_server — AT+CIPSERVER=1,9090 (listen on port 9090)

Server loop (server_repeat) — runs forever

  1. recv_tcp_data — wait for 1 byte from client → recv_byte
  2. Debug trace — send_usart_queue('?') + echo received byte
  3. send_tcp_data — send 4 bytes (A B C D) back to client
  4. LED ON — sbi VPORTD_OUT, PIN1
  5. rjmp server_repeat

Each AT command step is preceded by send_usart_queue('?') for debug tracing on the terminal USART task

Serial Monitor for Server Mode

wifi_debug_5.png

I ve used a simple Serial terminal program to monitor request and responses of each AT command.

Each AT Command from the WiFi block of execution has a corresponding response captured by the Serial terminal.

Project Source Code

Build Project From Source Code

Firmware project is based on acorn micro kernel operating system driving 2 separate tasks


  1. Download firmware source code from github repo - WiFi_ESP8266_client_server
  2. Find and open project file esp-01-adaptor.atsln in Microchip AVR Studio
  3. Build project to generate HEX file
  4. Flash Hex file using AVR Microchip programmer