The steps include:
1. Gathering the materials
2. Preparing the Raspberry Pi
3. Installing our software
4. Connecting our LED and PushButton
5. Connecting to our raspberry pi
6. Deploying our push button app
7. Connecting our app to IoT Hub
8. Connecting our app to weather data
1. Gathering the materials
For this workshop you’ll need about $55 worth of hardware, but all the software is free.
Sweet, now run both those apps at the same time, push the button, and see the glory that is Internet of things.
9. Connecting our app to weather data
Now that we’ve got it talking to the cloud, lets listen to what the clouds have to say!
We’re going to use forecast.io to provide weather data to our app, then use Speech. Synthesis to read it out over a the audio jack.
Navigate to forecast.io and signup register an account, then copy the complicated token highlighted here:
And replace what you see at line 168:
private const string FORECAST_URL = "https://api.forecast.io/forecast/YOURSECRETOKEN/";
Then if you want to be more specific about where you’re getting weather data replace the string on line 76.
var words = await GetWeatherString("37.8267,-122.423")
Make sure that the code in lines 72 through 81 are uncommented.
Deploy the app, press the button, and listen to the weather like never before!
It’s all very simple code and ready to be spun into lots of fun projects.
Here’s a list of all the ones that me and my friends could thing of:
Tap into the band app cloud
Send a random act of kindness
Tap into yammer
Time to finish breast feeding start and stop button
Random stats button
Gives you weather, or distance walked
Morse code each other
Send bro to someone random – twilio
Launch a middle
Listener recognition and ignore
Competitive button clicking
Best reflexes tester
Hope you had fun getting started with Windows IoT!
This week I’ve been making progress on the Huggable Cloud Pillow website.
The first thing to take note of is Flask.
Flask is the tiny server that allows us to host websites using Python to deliver content to the client. While on the server side you can manage complicated back ends or other processes using Python in conjunction with Flask.
This type of development is nice, because you can start seeing results right away but can take on big projects easily.
It might not be the most robust Framework, but its great for small projects…
If you want to get into Flask Web Development checkout this extensive MVA.
Small and simple, Flask is static on its own. This allows us to present static content, like templates and images easily and deals with input from the user using RESTful calls to receive input. This is great for static things with lots of user actions, but if we want something a bit more dynamic we’re going to need another tool.
In this case I’ve found Flask-SocketIO, similar to Flask-Sockets but with a few key differences highlighted by the creator (Miguel Grinberg) here.
Sockets are great for is providing live information with low latency. Basically, you can get info on the webpage without reloading or waiting for long-polling.
There are lots of ways you can extend this functionality to sharing rooms and providing communication with users and all sorts of fun stuff that is highlighted on GitHub with a great chunk of sample code. The following demo is based off of these samples.
For my project, I need the webpage to regularly check for differences in the state of the cloud and present them to the client, while also changing the image the user sees.
At first I tried to implement it using sockets passing information back and forth, but that wasn’t very stable.
The solution I’ve found, uses a background thread that is constantly running while the Flask-SocketIO Application is running, it provides a loop that I use to constantly check state of our queue.
Let’s break it down…
a. I need my website to display the current state of the cloud.
b. The Flask application can get the state by query our azure queue.
c. Once we determine a change of state we can display that information to the webpage.
d. To display the new state to the webpage we need to use a socket.
e. And pass the msg to be displayed.
This demo intends to break down problem a, c, d, and e.
I’ve created this little guide to help another developer get going quickly, with a nice piece of code available on GitHub.
The five steps to this little demo project are as follows:
1. Install Flask-SocketIO into our Virtual Environment
2. Create our background thread
3. Have it emit the current state to our client
4. Call the background thread when our page render_template’s
Celebrate! Its Friday!
Flask-SocketIO is a python package that is available for download using
So how do we call background_stuff?
We can call it wherever we want, but for this simple example we’ll put it right in our ‘/’ base route. So when we navigate to 127.0.0.1:5000 (Local Host) we’ll see the result of our background thread call.
Here’s our route:
if thread is None:
thread = Thread(target=background_stuff)
Pretty simple… Notice global thread and target=background_stuff
Creating different background threads is a good way to iterate through your changes.
I’m working with a raspberry pi and I’m learning how to collect and manage sensor data.
There is a lot of data and that’s awesome, but dealing with remote persistent storage has helped me understand some good ways of keeping stuff organized and safe.
For example: ‘Keys’ or ‘Tokens’ (Not to be confused with the Late English writer Tolkien)
These are the keys to the door of your data.
To access the contents behind these doors, you must establish that you are the key-holder. One of the ways to do this in software is to create a long complicated string that can passed to the database so you can input or output data.
As long as you keep this token secret nobody will be able to mess with your data, or use it without having to pay for it.
Now this sounds pretty simple, but what if you use that token in code that is stored in a public repository on GitHub? This is essentially like printing a bunch of keys to your house and leaving them all over town. Not safe or smart.
1. We need to keep these keys separate from the rest of your code. 2. We need to keep the file that contains those keys away from your public repository.
To do this I created a separate file called tokens.py that contains the strings of my tokens and a function called getStorageKey() that returns those strings.
Cool, we’ve satisfied our first goal.
Now we need to keep this file away from our repository. To do this we create a .gitignore file. This is a special ‘git’ file that allows us to specify which files will not be added to the remote repository.
To create a .gitignore file simply enter:
touch is a Unix command to create a file and update the access data, but not make any edits. Its the same as opening and closing without saving any changes.
After you’ve created this file you can edit it with any editor you like. I do it with sublime or VS Code because it helps me keep track of the separation occurring between visual studio and GitHub.
All you need to do is add on a separate lines the files you don’t want GitHub or just git to include.
When I first started all my .gitignore file had was:
Its expanded to include…
# the asterisk* acts as a wild card and will match any files with .pyc at the end
# anything that starts with a # is a comment and will be ignored from .gitignore
I saved this file (.gitignore) then added and committed it to the repository.
Now any files I add that end in .pyc or match tokens.py will not be added to my repository. And you will not be prompted to add them when you check git status.
What about files we’ve already have added???
If we add the rule after we added the file we want to ignore… We need to remove it from tracking on GitHub using the rm –cache command.
This will not remove it from your computer, but it will stop if from being tracked by GitHub, and will essentially be treated as if it was removed from your repository.
To pull this off simply type this command
git rm --cached filename.py
In this case I’m removing a file named ‘filename.py’.
After checking our git status we’ll see that this file is going to be removed.
Commit the changes and push to your remote repo.
You’ll see the files are still in your local directory, but are no longer in the remote or local repository. Hooray for keeping things safe!
Please let me know if you have any questions or comments.
The documentation is excellent and I recommend you spend some time reading through the resources below to round out your learning: