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 Nov 3 '17 at 21:45

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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