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
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
- AVR128DA32 adaptor board
- TTL Serial Port Converter Module DB9 Connector For Arduino
- ESP-01 ESP8266 adaptor
- ATINY416-XNANO board in programming mode
ESP8266 Client Mode
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)
- send_disable_echo — retry loop until ESP responds OK
- send_start — AT test
- send_client_mode — AT+CWMODE=1 (station/client)
- send_connect_wifi — AT+CWJAP join AP
Transaction loop (wfmn_02) — runs forever
- send_tcp_connect — AT+CIPSTART open TCP to server
- send_tcp_data — send 1 byte ('L') via AT+CIPSEND
- recv_tcp_data — receive 4 bytes into recv_buffer (parse +IPD,...:)
- send_at_command — AT+CIPCLOSE
- rjmp wfmn_02 — repeat
Each AT command step is preceded by send_usart_queue('?') for debug tracing on the terminal USART task
Downloads
Serial Monitor for Client Mode
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
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
- Sleep 60s — wait for ESP-01 to finish self-init
- send_reset — AT+RST
One-time init (wfmn_00 → wfmn_01)
- send_disable_echo — retry loop until OK
- send_server_mode — AT+CWMODE=3 (AP + station)
- send_multiple_connections — AT+CIPMUX=1
- send_read_ip_address — AT+CIFSR
- start_tcp_server — AT+CIPSERVER=1,9090 (listen on port 9090)
Server loop (server_repeat) — runs forever
- recv_tcp_data — wait for 1 byte from client → recv_byte
- Debug trace — send_usart_queue('?') + echo received byte
- send_tcp_data — send 4 bytes (A B C D) back to client
- LED ON — sbi VPORTD_OUT, PIN1
- rjmp server_repeat
Each AT command step is preceded by send_usart_queue('?') for debug tracing on the terminal USART task
Downloads
Serial Monitor for Server Mode
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
- Download firmware source code from github repo - WiFi_ESP8266_client_server
- Find and open project file esp-01-adaptor.atsln in Microchip AVR Studio
- Build project to generate HEX file
- Flash Hex file using AVR Microchip programmer