Umbrella Stand

From openPicus Wiki
Jump to: navigation, search

Contents

Introduction

This hack was made to DO NOT FORGET my umbrella at home anymore!!! Yes, that's it... I always forget to take my umbrella when I'm leaving home.
I tried lot of solutions. I installed apps on my smartphone to remind me that the weather was not sunny the first time I unlock my phone, I tried fancy widgets, etc... but there was no way out!

What I was searching for was a system that actually reminds me to take my umbrella when I'm in front of my door and near my umbrella stand, nor when I get up of my bed nor when it's too late and my phone GPS reaches the signal to understand I'm on my way on my car...

So, I took the time to develop my own system ;)

Firmware

The concept

The idea is to retreive a weather feed from the web and turn RGB LEDs on when I pass near my umbrella stand if I should take my umbrella.
After some web searching on internet, I found lots of free weather services that exposes their APIs to get weather condition in almost real time. Sadly a big part of them have limits on the number of request user can perform. Those limits are not so strictly in any application, but since I would like to rapidly test my app on Flyport without waste of time, I choosen World Weather Online. This service has very permissive limits, it's free, and their replies can be selected in XML, CSV and JSON format.
Since I would like to play a bit with both Grove system and JSON, I chose to get JSON weather feeds.

Weather APIs

To use the APIs exposend by World Weather Online any user must register for free at their website, to get a API key.
Once you have your own API key, you can generate your request using this easy tool: Free Local Weather API Request Builder.
To generate the request used in the example I used:

  • Format: JSON;
  • Search by: City and Town Name - with "Rome" as City and "Italy" as country;
  • Number of Days: 2 Day;

After click on the "Generate Request URL and Show Output" button and copy the content of the Request URL text box. This is the request you have to send with your Flyport, but you must change the days number to 1 to get a shorter reply!

The complete TCP packet Flyport should send is:

http://free.worldweatheronline.com/feed/weather.ashx?q=Rome,Italy&format=json&num_of_days=1&key=YOUR_API_KEY_HERE  HTTP/1.1
Host: free.worldweatheronline.com


The structure of Free Local Weather API Request Builder JSON reply can be seen here:

Umbrella Stand JSON Reply.png

In this application Flyport parses JSON string to get both precipMM and weatherCode of both current_condition and weather parameters of the feed. This is done to give flexibility to developer and choose between weatherCode and precipMM values in code.
Plus, Flyport automatically chooses the worst case between current_condition and weather to be sure the warning comes out if both in current status or in the whole day it could be rainy.

Weather Code

Every weather condition is also encoded with a weather code. Since it is a numeric value, we use it to know if it is needed the umbrella or not. Anyway also the precipitation (mm) could be used...
I use those levels of warning:

  • 0 - 118: no need umbrella (from clear/sunny to Cloudy);
  • 119 - 283: needs umbrella and / or freezing warning;
  • 284 - 395: RAIN!!!;



Flyport Firmware

DOWNLOAD the zip archive of firmware.

Remember to change API Key (const char weatherKey[] string), the cityNation value and Wi-Fi parameters with your own router/access point settings (this application does not work without an internet connection...)

The firmware loaded on Flyport Wi-Fi module uses Grove libraries and JSON parsing library.

To performs the request every 15 minutes the TickGetDiv64K() function is used to generate time controlled instructions inside the while(1) loop. Following is the related code:

// Send a new request every 15 minutes...
tick2 = TickGetDiv64K();
if( (tick2 - tick1) > 900) // 900 ticks is about 900 seconds, or 15 minutes... not accurate calculation, but right enough for application purposes
{
	// Update tick1...
	tick1 = TickGetDiv64K();
	vTaskDelay(1);
	UARTWrite(1, "sending request...");
	SendWeatherRequest();
}


The request can be also manually sent by pressing the button connected at DIG1 port

The LEDs are turned ON if the PIR sensor (connected at DIG2 port)detects movement in its near range:

// Catch and store the passage only once at time
if( passageCatch == FALSE )
{
	if( get(PIRmotion) == TRUE )
	{
		passageCatch = TRUE;
	}
}		
 
if (passageCatch == TRUE)
{
	passageCatch = FALSE;
	IOPut(p21, on);
	set(rgb, ON);
}
else
{
	IOPut(p21, off);
	set(rgb, OFF);
}

Pay Attention! PIR sensor should be manually regulated with its 2 potentiomenters as user needs. Further info are described here.

Every time the TCPClient receive packets, Flyport performs a JSON Parsing using the developed function ParseWeather(). If the parsing can reach every object needed by the application, the flag weatherUpdate is set as true. Then the main loop updates LEDs values with the new weather values, in function of weatherCode received:

  • 0 - 118 -> rgb leds are set as GREEN;
  • 119 - 283 -> rgb leds are set as BLUE;
  • 284 - 395 -> rgb leds are set as RED;

User can customize the values and color as prefered by changing the code inside the if (weatherUpdated == TRUE) condition.


Hardware

Following are hardware needs of this Hack.

Bills of Materials



Mounting procedure

Step #1

Start by mounting Flyport, Grove Nest and Grove devices:

Step #1

Step #2

Flash the firmware with miniUSB programmer and test it:

Step #2

Step #3

Mount it inside the Umbrella Stand and connect the power supply:

Step #3a

Step #4

Enjoy it:


Personal tools
Namespaces

Variants
Actions
START HERE
DEVELOPMENT
HARDWARE INFO
RESOURCES
PHASED OUT
Toolbox