WiFi and the Raspberry Pi

Web Server Code

The simplest web server code I've found for the Raspberry Pi (in Python) is located on GitHub [8]. Several other versions are available on the web, but they all basically had the same issues and problems. Using the AT command set is a simple way of getting a connection to a TCP socket or serving a website. Listing 2 shows the example code for connecting to a WiFi access point using AT commands from the above source. The results from the terminal window are shown in Listing 3.

Listing 2

AT Command Web Server Code

send_cmd( "AT+CWMODE=1" ) # set device mode (1=client, 2=AP, 3=both)
send_cmd( "AT+CWLAP", 30) # scan for WiFi hotspots
send_cmd( "AT+CWJAP=\""+ssid+"\",\""+pwd+"\"", 10 ) # connect
send_cmd( "AT+CIFSR", 5) # check IP address
send_cmd( "AT+CIPMUX=1" ) # multiple connection mode

Listing 3

AT Command Results

Sending command: AT+CWMODE=1
Command result:
Command result: OK
Sending command: AT+CWLAP
Command result: +CWLAP:(3,"HP-Print-55-Officejet 6700",-69,"c8:cb:b8:45:92:55",1)
Command result: +CWLAP:(4,"myqwest2705",-93,"00:24:7b:2d:f8:62",1)
Command result: +CWLAP:(3,"HP-Print-C6-Officejet Pro 8620",-83,"6c:c2:17:1d:2f:c6",1)
Command result: +CWLAP:(4,"HOME-F1B2",-91,"00:ac:e0:ec:f1:b0",1)
Command result: +CWLAP:(4,"HOME-F183-2.4",-73,"0c:54:a5:cd:25:28",6)
Command result: +CWLAP:(4,"HOME-9618",-92,"44:32:c8:c1:96:18",6)
Command result: +CWLAP:(0,"xfinitywifi",-90,"46:32:c8:c1:96:1a",6)
Command result: +CWLAP:(0,"xfinitywifi",-72,"0c:54:a5:cd:25:2a",6)
Command result: +CWLAP:(0,"xfinitywifi",-92,"06:ac:e0:ec:f1:b0",1)
Command result: +CWLAP:(4,"SharonsKitchen",-88,"cc:03:fa:c1:60:72",8)
Command result: +CWLAP:(4,"HOME-0CA3-2.4",-80,"0c:54:a5:7b:85:f8",11)
Command result: +CWLAP:(0,"xfinitywifi",-80,"0c:54:a5:7b:85:fa",11)
Command result:
Command result: OK
Sending command: AT+CWJAP="ssidxxx","passwordxxx"
Command result:
Command result: OK
Sending command: AT+CIFSR
Command result: +CIFSR:STAIP,"192.168.1.127"
Command result: +CIFSR:STAMAC,"18:fe:34:fd:92:xx"
Command result:
Command result: OK
Sending command: AT+CIPMUX=1
Command result:
Command result: OK
Sending command: AT
Command result:
Command result: OK
Sending command: AT+CIPSERVER=1,80

This is really pretty simple to implement. The whole web server is only 136 lines of code. However, the ESP8266 is flaky no matter what version of firmware I used for the AT command set.

I was very interested in the AT command set, because it is easy to implement and send/receive across a serial connection from a Raspberry Pi or Arduino computer to the ESP8266. I was quite disappointed that it just didn't seem to be reliable. I was planning to use the ESP8266 as a backup WiFi connection on the SunRover robot (see the "SunRover 2: Power Supply" article) connected to the Arduino using the AT command set. Now I will have to implement a more complex protocol using either NodeMCU or the Arduino IDE solutions discussed later.

AT Command Set Firmware Comments

One word fits: frustration. Although the code for a web server using the AT command set firmware on the ESP8266 was fairly straightforward, the ESP8266 was not reliable. I tried several different versions, and after a web page access or two, the ESP8266 would lock, reporting a busy p to any additional AT commands. After looking on the web, I see this is an extensive problem, and most people handle it by resetting the ESP8266 with the external RESET pin. It takes about 30 seconds for the ESP8266 to come back up, join the wireless network, and be ready to serve pages. That just doesn't work for most applications, nor does it work for mine.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content