Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
324 views

Easy ESP8266 WiFi Debugging With Python

This document describes how to easily debug WiFi connectivity of an ESP8266 module using Python. It involves: 1. Connecting the ESP8266 to a PC using a FTDI USB to serial cable and a voltage regulator to supply 3.3V from the cable's 5V output. 2. Running Python scripts on the PC including a TCP server and client to test TCP connections from the ESP8266, and a script to send AT commands to control the ESP8266 over serial. 3. The Python ESP8266 script allows testing the module's WiFi connection and issuing AT commands to make a TCP connection to the server, verifying basic WiFi functionality.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
324 views

Easy ESP8266 WiFi Debugging With Python

This document describes how to easily debug WiFi connectivity of an ESP8266 module using Python. It involves: 1. Connecting the ESP8266 to a PC using a FTDI USB to serial cable and a voltage regulator to supply 3.3V from the cable's 5V output. 2. Running Python scripts on the PC including a TCP server and client to test TCP connections from the ESP8266, and a script to send AT commands to control the ESP8266 over serial. 3. The Python ESP8266 script allows testing the module's WiFi connection and issuing AT commands to make a TCP connection to the server, verifying basic WiFi functionality.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Food

Living

Outside

Play

Technology

Workshop

Easy ESP8266 WiFi Debugging with Python


by jimk3038 on November 4, 2014

Table of Contents
Easy ESP8266 WiFi Debugging with Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Intro: Easy ESP8266 WiFi Debugging with Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 1: Hardware Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 2: Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

http://www.instructables.com/id/Easy-ESP8266-WiFi-Debugging-with-Python/

Author:jimk3038

www.ph-elec.com
Founder of Powerhouse Electronics.
For more info goto: www.ph-elec.com

Intro: Easy ESP8266 WiFi Debugging with Python


The new sub $5 dollar ESP8266 WiFi module makes inexpensive IoT way more possible and easy for mere mortals like me. In fact, I just did a search on AliExpress.com
and I found the same module for $3.25 (free shipping, but of course) in quantities of one. How I can have one of these modules shipped from the other side of the earth
right to my door for $3.25 is still a mystery to me. Anyway...
In a nutshell, the ESP8266 module is a super inexpensive (note, I did not say cheap because they seem really good) WiFi module for embedded apps. It appears the
module has an ARM micro that is re-programmable and there are a lot of folks gaga over that.
For me, I just want a little IoT board that can chirp out some data onto my WiFi network now and again. You know, like when the mailman drops off the mail. The
ESP8266 right out of the box has a set of TTL Rx / Tx pins that communicate at a default 115k serial baud rate. Note, early modules came set with a default of 57.6k
baud rate. So, the default module communicates at 115k using an old modem style super simple AT command protocol. Basically, commands (all start with "AT" hence
the name) are sent to the module using something like "AT+RST" (commands the module to reset) and the module responds - usually responding to each command with
a "OK".
But the devil is in the details.
Before there is any hope of embedding a ESP8266 module in a mailbox detector IoT device the AT commands between the ESP8266 and the controlling micro really
must be understood fully. Therefore, to make it easier to test and debug controlling the ESP8266 module this Instructable will show how to hook up a new ESP8266 to a
PC and test / control it using some simple Python code.

Image Notes
1. 5V LED comes on whenever the USB cable is jacked in.
2. ESP8266 Red LED comes on when the Mic regulator is enabled.
3. MSOP parts are hard to work with. This is really ugly but it works. I should add a wad of epoxy over the tiny wires before they get broken.
4. The copper PCB acts like a heat-sink for the regulator.

Step 1: Hardware Setup


There are two problems that make hooking up the ESP8266 directly to PC difficult. First, the module uses 3.3Vdc TTL Rx and Tx lines to communicate. Second, the
module's datasheet indicates the module will need up to 300mA of 3.3Vdc supply voltage.
The easy solution to the first problem is to simply use a FTDI 3.3V USB serial cable. I've had a couple of these USB-to-Serial cables for years. Looks like Adafruit has
these in stock for around $20 bucks. There are some other types around but the FTDI is the gold standard. Only problem with the FTDI converter is that the Vcc output
from the cable is 5Vdc and not the needed 3.3Vdc. Seems strange given the TTL signals on the FTDI cable are at 3.3Vdc - guess they got cheap and dropped putting a
step down regulator in the converter.
So, the second problem is to down convert the FTDI 5Vdc output to 3.3Vdc @ 300mA. My solution was to use a little regulator I had in my parts bin. Specifically, I used a
Mic5239 which can be found at Mouser. Since I had ten of these in my parts bin I decided to sacrifice one for the greater good. I solder the regulator down to a little hunk
of PCB and hot glued the whole mess to a DIP socket. In the first picture in this Instructable the regulator is visible on the right-hand edge of the breadboard. It's ugly but
seems to work well. Would have been much easier if I had originaly order the regulator in a larger SOIC package instead of the tiny MSOP-8 package. Rule to self - no
more super tiny parts.
As a plus, in the 8 pin package of the Mic5239 regulator there is an enable pin. The enable pin must be pulled high for the 3.3Vdc output to come on. So, as a trick, I tied
the regulator enable pin to the FTDI RTS output pin. Therefore, using Python, power to the ESP8266 can be turned on and off! Turns out, even though I did NOT turn on
hardware flow control in the Python code the Python serial driver (called PySerial) still allows control over the RTS output pin.

http://www.instructables.com/id/Easy-ESP8266-WiFi-Debugging-with-Python/

Image Notes
1. Pin #1
2. ESP8266 WiFi Module

Step 2: Software
There are three bits of Python code for this Instructable.
1) "tcp_server.py" -> This Python code provides a TCP server that the ESP8266 can connect to. Simply edit the code so that the IP number in the source code matches
the IP number of the machine your running this on. The server simply allows a client to make a TCP connection, accepts some data, and sends back some junk data.
That's it. The server just starts up and then waits in an endless loop for clients to connect.
2) "tcp_client.py" -> This Python code provides a way to test "tcp_server.py" is working correctly. So, with the server code running on one machine, run "tcp_client.py" on
another computer on your network. Run the client as "tcp_client.py Some data to send goes here." The client app sends whatever is given on the command line. In this
case, the client would send "Some data goes here." to the server. Both the server and the client will show some output that indicates a successful transfer.
3) Finally, "Test_ESP8266.py" can now be used to test for a TCP connection to the Python server. If all goes well, the server and "Test_ESP8266.py" will show some
output that indicates a successful transfer. Once again, before running "Test_ESP8266.py" edit the code so that the IP numbers match. Run as "Test_ESP8266.py
MySSID MyPasscode" - the SSID and passcode must match your WiFi settings.
Using the Python Test_ESP8266 code I learned a couple things about the module. After getting everything working and verified with the server I simply tried using a bad
passcode, as a test to see what would happen. Everything appeared normal until the actual command to form the TCP connection. The command that failed was
"AT+CIPSTART='TCP','192.168.1.130',9999". However, I would have expected the command "AT+CWJAP?" to fail first. The "AT+CWJAP?" command returns the SSID
and RSSI of the AP the ESP8266 is connected to. With a bad passcode it should not have been able to connect.
Goofing with the code I think I've discovered a trick. After connecting to the AP, ask for the ESP8266 IP number. Even with a good passcode it may return "ERROR". No
worries, just dwell a couple seconds and ask again. With a good SSID and passcode the ESP8266 will eventually return the IP number. After a good IP number is
returned the TCP connection command always seems to work.
Another trick, if a bad passcode is used the ESP8266 module gets stuck! Regardless of the command sent the module returns "buzy now ...". Even the "AT+RST" (reset)
command is ignored. The work around is to use the regulator to cycle power to the module. Using the RTS pin on the FTDI USB-to-Serial converter - which connects to
the regulator enable pin - the regulator 3.3Vdc output can be switched off. An off time of 10 seconds seems to work well.
Well, that's is. Hope this helps,
Jim
BTW: For the latest and greatest updates please visit my web site: www.ph-elec.com

http://www.instructables.com/id/Easy-ESP8266-WiFi-Debugging-with-Python/

File Downloads

tcp_client.py (485 bytes)


[NOTE: When saving, if you see .tmp as the file ext, rename it to 'tcp_client.py']

tcp_server.py (1 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'tcp_server.py']

Test_ESP8266.py (3 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'Test_ESP8266.py']

Related Instructables

Use ESP8266 to
Internet enabled
AC Appliances
by shinteo

ESP8266 WiFi
ESP8266 WiFi
temperature and relay switch by
humidity sensor EasyIoT
by EasyIoT

ESP8266 WiFI
water leak
sensor by
EasyIoT

A newbie's
guide to setup
ESP8266 with
Arduino Mega
2560 or Uno by
shinteo

An inexpensive
IoT enabler
using ESP8266
by
gopinath.marappan

Advertisements

Comments
7 comments

Add Comment

doctek says:

Nov 18, 2014. 7:45 PM REPLY

Your website is AWESOME! Thanks for sharing all your projects.

doctek says:

Nov 18, 2014. 8:06 PM REPLY


I'd really like to see more and comment on your site. So I registered, but after half an hour or so, I still haven't gotten an email with a password. How long
should I expect to wait??

Akin Yildiz says:

Nov 10, 2014. 10:06 AM REPLY


hello everyone, can anybody do a simpler project with this? I just want to collect data using arduino Analog0 input with an LDR photoresistor. collect the data
and simply post it on Thingspeak ?!?!
.
all the examples I find are very complicated and include libraries. I need my project to be much simpler. just read some data from the analog sensor and
display the value on the cloud.
.
can anybody please help me with this? I have updated the firmware on my ESP8266 and I can connect to my house network using the CoolTerm software.
.
any help is highly appreciated !!!
thank you,
akin

jimk3038 says:

Nov 10, 2014. 5:41 PM REPLY

Have a look at the following TI CC3200 Launchpad board:


http://www.ti.com/tool/cc3200-launchxl
This board cost $30 bucks and has built in WiFi right in the TI micro. The best part is, the board works with Energia open-source programming software
which is kind of a drop in duplicate of Arduino.

http://www.instructables.com/id/Easy-ESP8266-WiFi-Debugging-with-Python/

The latest Energia software has a bunch of examples just for the CC3200 board. One of the examples measured the internal temperature sensor that is
internal to the micro. After the measurement is made the WiFi connection is used to upload the data to a cloud service. The cloud service charts and
plots the data to either a web page or your smart phone real-time!
Truly amazing to be able to take a new board and have it connected to the cloud in about 10 minutes. Most of that time consumed with downloading and
installing Energia. Running the demo only takes 30 seconds.
I was really impressed - and no, I have no ties to TI,
Jim

Akin Yildiz says:

Nov 10, 2014. 7:32 PM REPLY


hello Jim, thank you for your reply. I checked out the board, it seems really nice and would love to work with one. although size is critical for my
project, an ESP8266 is much smaller compared to the TI. also the price, for $30 we can get 6x ESP wifi modules.
.
I have gotten some help on my question, you should check it out; http://www.instructables.com/answers/ESP8266-wifi-...
I am still not able to upload data, but seems like everything is correct..

Silent_Shadow says:

Nov 4, 2014. 7:58 PM REPLY

Step three was quite funny in my opinion...

jimk3038 says:
OK, I'm over ranting about loosing my work to bugs. Step three now has real comments.

http://www.instructables.com/id/Easy-ESP8266-WiFi-Debugging-with-Python/

Nov 5, 2014. 5:58 PM REPLY

You might also like