Sunday, March 22, 2015

ESP8266 Program Examples

Back in December I had ordered and received an Olimex MOD-WIFI-ESP8266-DEV.  I posted some overview and setup information.

Now I have developed some examples that demonstrate native programming of the ESP8266 in c. The examples were built on Windows using Cygwin64 and the Unofficial Development Kit for Expressif ESP8266.

The examples contain a good bit of documentation in the hopes that they will help other people with their projects.

The basic flow of an ESP8266 program using the Espressif SDK is an event / callback model.  The user defines a set of callbacks in user_init.c.  The callbacks are triggered when events such as a timer also setup in user_init.c expires. 

Another example is a callback that is triggered when a connection is made to the ESP8266 by a client.  This callback can take action based on the connection and may in turn setup additional callbacks.

The example code is on GitHub at digitalhack / dhESP8266.

Hello Digitalhack Example

The first example is a take on the standard helloworld.  I demonstrates use of the user_init.c function for setting up the program, a timer and timer callback function ands printing output to UART0 and UART1.

UART0 is a full UART with both TX and RX that is used to load your code to the ESP8266.  UART1 only has a TX signal and is used for debug messages.

Screen capture from Cygwin of make and flashing the code to the esp8266.

image

UART0 Output from Example

image

UART1 Output from Example

image

Basic Connect Example

This example shows how to setup the ESP8266 to connect to a wireless access point.  The ssid and password for the wireless network are in user_config.h in the examples include file.

UART1 Output from Example

image

Once you see the ip address the EXP8266 has acquired on the debug line (UART1) you should be able to ping the ip address and get a response.

image

Simple Server Example

This example shows how to setup a very simple server.  When a user telnets to the ESP8266 they are prompted for a name.  Once this is entered it is echoed name back to the user before disconnecting.  It demonstrates the callbacks necessary to for TCP communication.

UART1 Output from Example

image

Cygwin screen capture of a session.

image

The example code is on GitHub at digitalhack / dhESP8266.

2 comments:

Anonymous said...

In ssRecvCb(), there is no guarantee that *data is a zer-terminated "string".

niazi said...

This blog awesome and i learn a lot about programming from here.The best thing about this blog is that you doing from beginning to experts level.

Love from