0 Replies Latest reply on Jul 10, 2015 9:44 PM by RGee

    DAYTIME Client - Gen 1 / ESP8266-11

    RGee

      The ESP8266-11 Wireless Transceiver 

       

      I have been hearing a lot about the ESP8266 wireless modules. In fact, I have been hearing too much about them. I hate it when some new chip comes out to the mass market of engineers, makers, hackers, hobbyists and fiddlers and I'm not participating. There are more than a dozen varieties of these SoC modules around that include an Xtensa LX3 Customizable DPU with WiFi. Most of them come preprogrammed such that right out of the bag you get 802.11/client/server/TCP/UDP functionality that is accessible through, relatively straightforward, AT commands. These are serial port WiFi transceivers for less than $5 US. Ok, I want in. Not sure what I would (or could) do with one, but for about the price of a burger, I want in! So, I picked one up - and by picked one up I mean I ordered one and after a month or two it came along in a bag with a bunch of other stuff that I had already forgotten ordering. Here is the write-up of my weekend project with the ESP8266-11 and my Galileo Generation 1.

       

      First, it’s back online to read about the board and then read some more. I’m not sure that the ESP8266 has been around for much more than a year, but there are a ton of tutorials and projects out there already. Second, I needed to determine what my goal was – weekend project-wise.  I decided I would: 1) learn enough to hook up the board and do a sufficient amount of testing to convince myself that it worked, and 2) construct some kind of “formal” program. In other words, get the board to do something that is, at least arguably, useful. This is a tried-and-true approach for me.

       

      The ESP8266-11 is not particularly bread-board friendly. Spacing and hole size are such that the usual plugs and sockets that I have were not going to work. Folks use various methods to break the pins out and I made use of one of a number of SOIC break-out boards that I had stashed away.

       

      An SOIC Breakout board

       

      With a little careful soldering, I was ready for the next step.

       

      The ESP8266-11 Wireless Transceiver mounted on an SOIC board and ready for the Breadboard 

       

      To interact with the board you need a terminal/controller of some kind and two other essential components: a 3.3v power supply and a serial interface. If you already have some expertise with the ESP8266 then you know that, when programmed properly, it can function as a stand-alone unit – but that’s not where I was going to start. As it turns out, the Galileo G1 has what I needed – a 3.3v power supply, a serial interface and an easy to use IDE. In this case I mean the TTL serial port, pins 0 and 1, that you can access as Serial1 from within the Arduino IDE.

       

      The ESP8266 is a 3.3v device, so I wanted to translate the 3.3v signals to 5.0v and vice versa. I chose to use a level shifter because I have several of these little boards and they have worked out quite well for me. While I knew that I wanted to shift the TX and RX lines, I also considered the RST line and one of the GPIO lines – assuming I could get it to work at all. This one has four channels and would fit the bill nicely. I could probably have used resistor voltage dividers, and perhaps I will at some point, but when I am trying to set up a circuit for the first time, the fewer chances for error, the better.

       

      The four channel 3.3v/5.0v level shifter

       

      Now, I was ready to hook it up the Gen 1 and these are the connections that I used.

       

      ESP8266-11 to Galileo Generation 1 connections 

       

       

       

      With just these few lines of code-

       

      void setup() {

        Serial1.begin(115200);

        Serial.begin(115200);

      }

       

      void loop() {

        while(Serial1.available()) Serial.write(Serial1.read());

        while(Serial.available()) Serial1.write(Serial.read());

      }

           

      - The Galileo will act as a serial terminal to the ESP8266-11. Whatever I type in Serial will be sent to Serial1 which is attached to the ESP8266. Whatever it sends back appears on Serial. This is exactly what I need to learn to interact with the board. You can find all of the AT commands online but the very first one I used was the simple AT…and what I got back was…OK…sweet, it’s alive! Here is the result from the command AT+GMR which replies with version information (the AT commands version and the internal SDK version).

       

      ESP8266-11 response to AT+GMR

       

      On to the, "arguably useful", program. The Galileo Gen 1 has an onboard Real Time Clock (RTC). If you have installed a battery, it will retain the time when powered down. Either way, you need to set the time accurately. To do that, you can contact a server and ask for the time. There are several time standards and, frankly, the DAYTIME protocol that I used here is not the best. It is, however, easy to understand and easy to implement. Basically, you simply connect to an appropriate server (TCP or UDP) on port 13. The server will respond with a coded time string that contains the date/time and a few other elements. You can go to NIST.gov and get all the details. The attached program does that and sets the Galileo RTC with the accurate UTC time and date.

       

      This is what I am running on my Galileo:

      My Galileo Generation 1 setup

       

      Hopefully, you will find the attached program to be easy to follow. These are the basic steps:

       

      1. Reset the ESP8266 board.

      2. Log on to your router/access point (with SSID and password.

      3. Enable multiple connections (I don’t know if I really have to do this).

      4. Connect to the time server

      5. Identify the time string in the response

      6. Scan the returned time string for what you need (time and date) and fill in a string.

      7. Set the Galileo RTC using the Linux command (via system) and the string you just built.

        

      That’s pretty much all there is. I am also synching the hardware clock but my Linux knowledge is so elementary, I’m not even sure why I am doing that. Here is an example output screen from the program:

       

        Output from the DAYTIME client program

       

       

      So, I declare last weekend’s project a success. Moreover, I am pretty impressed with the ESP8266 and I am not sure that I even have scratched the surface of its capabilities. I ordered a couple more today.

       

       

      Cheers.