I'm new to networking and working with ESP8266. I have successfully setup my ESP8266 and can program it from Arduino IDE (tested a blinky code).

I want to send some data from a Python script running on my PC to ESP8266. Similar to a setup where use PySerial in Python, open a COM port and send my serial data to an Arduino. Arduino will parse my data bytes and will perform some action. Now, I am trying to achieve the same with ESP8266 and UART replaced with wireless communication.

First, I would like to connect my PC to ESP which will have its own SSID and password. Once connected, I would like to send my data bytes from Python script to ESP8266 wirelessly. Now, similarly, ESP will parse this received data and perform some function (like control its GPIOs).

How can I achieve this? It seems like a pretty simple task, but I'm really confused with what mode I've to use (AP? Client? Server?). What protocol for communication is the best (TCP? MQTT?). What do functions like Handle client/root do? I understand I've to use socket programming on Python, how to do that specifically in my case? How do I buffer my incoming data on ESP, so that I don't miss the bytes?

Could anyone please explain using an analogy with wireless communication and UART? Any links to tutorials will be helpful too. There are some tutorials online where they do this using a HTTP server and control the GPIOs from the browser, but no, I don't want this. I just simply want to send my data as I would with COM Port/UART/Arduino!

  • as a web dev, i find http to be the simplest interaction method: a clear req/res cycle, built-in parsers for GET params, status codes, easy debugging from other devices, etc. with streams, you have to sniff a lot out.
    – dandavis
    Commented Nov 3, 2017 at 21:45

3 Answers 3


Check my project: "Esp 2 Python"


The theori is you can create a localhost and get the sensor data or manage the module through arduino requests or urllib modules with a simple local mDNS server. This project allows you to control and read ESP. my  code's diagram

A screen shot from the code, you use only 3 functions to control it

  • I couldn't get your code to work
    – DrBwts
    Commented May 2, 2019 at 14:01
  • it was a literal soup, I radically simplified it, it's too easy to use now, try it again :3
    – Juko
    Commented May 3, 2019 at 22:53

The simplest IP equivalent to UART is TCP/IP sockets. Create a listening socket on the ESP8266 and connect to it from the PC (or do it the other way around if you like). Data fed in one end comes out the other - just like a serial port.

There's examples with the ESP8266 core that do just that.


You must configure the ESP as an AP, if you want it to have its own IP. You then set up a tcp-server on the ESP (i think there are example functions in the IDE).

Keep in mind, that the communication (server/client you mentioned) has nothing to do with the way PC and ESP are connected with (whether the ESP is providing an Access Point or logged into your WiFi). Those are different protocol layers, which means you will not need to make any changes if you want PC and ESP communicate over your router at all.

Actually the ESP (or at least for the ESP8266-12F I know for sure) is capable of running both ap and wificlient at the same time.

It's not a big difference to serial communication, you will need to poll for incomming messages in your loop if you want to run a server. Sending messages to your PC is like printing to the serial interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.