So I'm sure at this point most of you are familiar with the Arduino IDE. We will be using that to upload our weather getter code to the Arduino. I've attached a cleaned and documented version of the code to this step, but we'll go over it a bit here (not laboriously, just enough so you understand what's going on).

The first part of the code is our #defines, just to make life a little easier. We also have a few variable at the top that help us parse out the data a little easier.

setup() Function

Here we go, this is how we connect our ESP to our Arduino. I reserved some space at the top for the string response. This is a hold-over from a previous iteration of code that had repeated stack crashes because the .JSON just overwhelmed my little micro. You can probably throw this line of code out, I kept it. After that you see I start up an I2C (TWI, Wire, SMB, whatever...) connection. This is where my data is actually going. Next comes the Serial. This is the connection to the ESP, notice the 115200 baud. That's SUPER important to get right, otherwise your Arduino is speaking English and the ESP is speaking Cantonese and everyone is confused. You'll notice the AT commands are back, I told you they'd be important! First our code checks to make sure the device is ready by performing a software reset and waiting for the ESP to respond. After that we set the ESP to station mode and allow multiple connections. We can connect to multiple APs, but for our use now we only will be using one of the connections. Following that is an attempt to connect to the WiFi (next function we look at). Once we've successfully (hopefully) connected to the WiFi we push on and connect to our host (in this case Wunderground).

connectWiFi() Function

This function is the meat and potatoes of our code. So what we have here is a command (AT+CWJAP) that is telling our ESP to join an access point. It is followed by the AP SSID and password. If the ESP returns "OK" then we've successfully joined the AP. If not, the connection failed. If you're using a MEGA or other multi-serial microcontroller you can set it up to send the PC messages of what's going on. I'm sending my data over I2C to an FPGA, so I just threw away the responses.

loop() Function

This is the last major portion of the code. This area connects to the Weather Underground API and downloads the data. Once the ESP starts to send data back we push it into the response string variable we declared earlier. I captured the data line by line (starting with " and ending with ,) and looked for the data I needed (temp_f and weather). This keeps the amount of data the Arduino is trying to store/parse at one time down to a minimum.

Other Functions

Most of this code is pretty well documented, so you should be able to figure out what is going on in the rest of it. I go through and look for temp_f and weather. I then convert those values into bytes to send to my FPGA (keeping the size minimal). I converted the weather into a 1 byte value. This gives me up to 256 different weather codes. I then used a simple method to convert the temperature into Binary Coded Decimal and send that to the FPGA in 2 1-byte packets (4 digits total on a seven segment display).

Credits

This code came partially from my own work and partially from that of others. I don't remember all the sources that I gleaned ideas and code from, but if any of you happen upon other work that looks like this, let me know. I'd love to give the credit where it is due.