Ada Developers Academy Capstone: Day 13

Since I went to bed at around 1 a.m. last night, this is another next day post. I must be really excited to do some more work on my capstone though, because I’m awake at 6:30 a.m. (What’s happening right now, self?)

Anyhow, let’s recap yesterday. Yesterday was a day spent connecting my hardware to the internet, getting data from the API, and then manipulating said data.

The day was off to a good start after I found out that connecting to the internet wasn’t that hard if you spelled the wifi password correctly. Okay, so far so good with the “new” programming language; C++. The Arduino IDE is treating me pretty well also. I now know that the examples provided for my board are really quite helpful.

Something else that’s really helpful, tutorials like Calling API using ESP8266. I would say that most of my wifi connectivity, and absolutely the API call, in my code comes from this tutorial. Thank you electroSome and author Basamma B! The one thing that they might add to this article though is that HTTPClient needs more information if the API is https. It took me a while to find this article about why I wasn’t getting a positive number for my HTTP GET request → Simple GET request with ESP8266HTTPClient. And then I found this → HTTPClient https request fails if no fingerprint is provided. For the life of me I couldn’t find a way to do it without a fingerprint though. So I spent some time looking for where to find the fingerprint. Turns out that since SSLs sometimes change, I may at some point run into a problem where my code doesn’t work because it. I put a note in my code to remind me of this. I may need to put a note in the readme of the repository as well. It also turns out that to find the fingerprint of a site, you can view certificate in the security tab of dev tools. I used SHA-1 and that seemed to work as the “thumbprint”. I was so happy to finally see API data in my serial monitor!

From there, I learned about space allocation with JSONBuffers, and did a bit more reading about ArduinoJson (ArduinoJson Github). I thought that maybe it would be easy to parse the json from my API in order to use the rgb color values in the strings. Oh, was I wrong. One cannot just manipulate strings in C++. As a matter of fact, strings are basically arrays of numbers in C++; which makes it easy in some ways and very difficult in others. Shout out to Rudy Schlaf, Make Course, and the University of South Florida for some awesome videos that have helped me a bunch already.

Did you know that instead of using the double equal there’s a special way to compare strings in C++? I didn’t know that either, but turns out that if you go to cplusplus.com you can find all sorts of interesting C++ methods, like this one to compare two strings → string::compare. If comparing two strings results in a 0, then they match!

I would be remiss if I didn’t mention that the Adafruit NeoPixel Überguide section on Arduino Library Use was also a huge help. I now know so much about how to light-up NeoPixels. I also used quite a bit of code from the NeoPixel Example, RGBWstrandtest. Oh, so helpful! Thanks adafruit!

Okay, so with this newly learned information, I was able to hard code in all of the colors and do a string compare with the strings I was getting through my call to the API. The code is NOT at all DRY or all that easy to read, the colors need to be optimized, and the server keeps crashing, but…

IT WORKS!!

I HAVE A WEB APP THAT CONTROLS LEDs!!

Now it’s time to clean some stuff up!