Thursday, April 5, 2018

Weather Visualization API Project

This project took a lot of time to formulate and to make, but produced a product that is definitely very cool to use. When starting the project, I originally wanted to use the WiFi shield to collect data from an API. I started soldering one and then later realized that I had received the wrong shield, so I acquired the correct one.

Adafruit WINC1500 WiFi Shield

Soldering the WiFi board involved attaching 5 sets of header pins to the outside pin holes, and one upside down on the right-most section of the image above.


Using the soldering iron to properly attach the header pins at the correct angles and positions

We then set to work brainstorming possible applications of the WiFi Shield. The idea we decided to execute was one that utilized the weather API to collect weather data and display it in a creative way.

Our initial sketch of the finished product

We decided to use the LCD panel to display the location name and temperature, and two LEDs to indicate whether the two attributes shown on the bottom of the panel, i.e. Cloudy and Humid were either true or false. A lit LED would indicate true, and unlit would indicate false.

To add more dynamic behavior to our project, we decided to use two states to display the data. One state would show the temperature in Fahrenheit, and the other would show the temperature in Celsius. The two attributes on the bottom of the LCD would also be different. The program alternates between the two states every 4 seconds to allow for equal viewing of each set of data.

The next step was programming the board to make a GET request to the API of our choice: OpenWeatherData. We created an account on OpenWeatherData to authenticate the request. The request would receive a response including a JSON body which would contain the data that we needed. We initially encountered a problem when setting this up, because our board did not have enough memory to support all the libraries that were recommended for this task.

We were kindly provided a Metro Express board, but we had trouble with the driver to connect it. Some research that we did online suggested that the cable we were using to connect was either sync or non-sync and was not compatible with the serial connection needed to establish with the board. Another option we would have been able to use was using multiple Arduino Genuino Uno boards, but we ultimately decided a different solution to the problem.

Most implementations of the API recommend using a library called ArduinoJSON to parse the JSON data directly from the response. However, because we did not have enough memory, we chose to omit the ArduinoJSON library from our implementation. We replaced the library with our own parsing  which breaks the stream of data from the response by quotation mark characters, and uses an indexing system to extract the desired data field. Once the indexed data field is extracted, we go further and take a substring from it to remove miscellaneous characters that are part of the JSON body structure. Once these characters are removed, we must then cast the String into the desired object, such as double or int. Arduino has helpful functions such as toInt() to accomplish this.

Sample Extracted Data

Now that the data was properly being retrieved from the API, it was time to wire up the components. We used the existing wiring for the LCD and attached the two required LEDs which would indicate whether the attributes on the bottom of the  LCD were true or false.

Establishing the proper wiring for the board


While we were fixing some initial problems in the wiring, we also were working on the thresholds for which each set of data would trigger the true or false output. We found averages of each of the values in the extracted data and made thresholds that would result in true or false if they were above the average. For example, above 63% humidity would trigger the LED for that attribute.

We discovered a problem using UNIX time to compare the sunrise and sunset data, because it seemed that Arduino did not have a great way of establishing the current time without a RTC component. Furthermore, it was surprising to discover that there were not many tools within the libraries related to UNIX time. We later replaced the sunrise and sunset data with Rain.

After fixing the wiring and other issues, we were able to produce a working prototype:


A view of State 1
A view of State 2







No comments:

Post a Comment