Introduction: Sparkcore MetLamp
This project is a SparkCore based mood lamp which uses weather data from the UK Met Office to choose the colour of the lamp. It's main parts are the SparkCore and their internet button shield, which includes a NEOPixel ring!
Step 1: The Parts
1x Internet Button shield
1x phone charger
1x micro USB lead
1/2x Clear plastic ball - this only needs to be big enough to cover the entire button shield and doesn't need to be particularly clear!
1x old plastic container. I used an old fish food tub!
4x short lengths of single core wire, stripped of insulation.
a sharp point
Step 2: Connecting the Spark Core to the Shield
The Internet Button shield comes with two pieces of plastic over the connector. This is the bottom of the shield and are to prevent the core being inserted incorrectly. leave these in place.
The top side of the shield has an outline for the orientation, simple line up the core and push it firmly into the board. you should hear a click when it locks into place.
Step 3: Build the Case
Take the lid of the container and pierce four holes, one for each of the outer corner holes in the button shield.
Take a craft knife and cut a small hole for the USB cable, make sure it's big enough to fit the cable through.
Then push the four short lengths of single core wire into the outer corner holes of the shield and through the lid. Bend these four wires to secure the board to the lid. Snip any excess from these wires to ensure they don't short onto any other metal part. If you are unhappy with leaving the bare wires, you could sew the shield to the lid instead.
Cut another hole for the USB cable, this time in the base of the container, push the cable through both holes and plug into the SparkCore. I added some extra weight to the base to prevent the cable from pulling the Lamp across the table. Glue the lid in place and your ready to place the Ball on top to complete the build! The Ball I used fit snugly into the upturned lid so didn't require fixing in place.
Step 4: Software
Get an API key
In order to access the weather data, we need an API key. these are free, but you need to sign up for a Met Office DataPoint account. This can be done here. once registered, which may take a little while to be processed, you can log in and get your API key from the link on the right hand side You will need this in a moment.
Setup your software
If you haven't already done so connect your SparkCore to your WiFi using the Spark App. Then Add your SparkCore to the web IDE.
Then start a new project called MetLamp and add the NEOPixel Library. This is a popular Library and is normally at the top of the list. Then Copy and paste the MetLamp Code as attached into the MetLamp.cpp file. we now need to alter a couple of lines near to the top of the file. There are comments to guide you, but all you need to do is copy and paste your API key over the multiple Xs and choose your location. A list of possible locations can be found in the second attachment, if you don't know the weather station you need, the MET Office website has a map of all the locations in the UK here. If you are using another set of NEOPixels, the number and type of these can be set here too.
Once these are set, your ready to Flash your core and your done!! The Lamp will check the weather and update the display automatically every hour.
If you take a look at the code you may notice a function called update_location. This is connected to a Spark function API call for "location". this can be used along with your SparkCore Device ID, an Access token and another 4 digit access code String to change the location of the weather station. For example the Linux console call to change the location to Glasgow - Bishopton would be:
curl https://api.spark.io/v1/devices//location -d access_token= -d "args=3134"