Spacebar and Enter were autocompleting with the sugestions if VS code and I wanted to change that behavior, because my suggestions are rarely aligning with my development.
Anyways, this is the setting you want to look for.
Uncheck “Accept Suggestion on Commit Character”
&
Turn off “Accept Suggestion on Enter”
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.
Seriously though, they did an awesome job with the documentation.
If you followed along to their step 4 you’re ready for our step 5.
5. Connecting our LED and PushButton
Now that we have our pi configured and Visual Studio up to date, let’s plug in our neat hardware!
Here’s an overview of the pin layout for the raspberry pi 3:
And the wiring diagram for the led + push button looks like this:
Sweet, lets light it up!
6. Connecting to our raspberry pi
We need our raspberry pi’s IP address before we try to deploy our code.
Power it up with a micro USB cord and connect it to a monitor with HDMI and see the landing page for your machine.
With the Windows IOT Core Come a super helpful web portal that allows you to configure your machine through a browser.
Navigate to that IP:
http://you.have.an.ip:8080/
https://192.168.1.145:8080/ is the IP address of my machine when I tried this
You’ll be prompted with a login panel.
The default user name is:
Administrator
The default password is:
p@ssw0rd
Here’s what you should see in the portal:
From here you can configure the name/password, get network info like the MAC address under Networking, and even test out some samples.
Sweet! This is one of my favorite Window IoT Features.
7. Deploying our push button app
The pi is setup, our computer is updated with the newest build tools, now its time to deploy some code!
And setup visual studio debugging by right clicking on PushButton project like this:
Then under debug set the remote machine ip to the ip you collect from the IoT Dashboard or from the raspberry pi itself by plugging in a monitor.
You will then need to rebuild your solution, and restore nuget packages.
Poke around for a minute, put a break point in the buttonPin_ValueChanged method and step around to see what’s going on with the push button.
8. Connecting our app to IoT Hub
Next we’re going to turn on the IoT Hub Connection.
Go into the azure portal and create a new IoT Hub like this:
Then create a new device called MyDevice in the IoT Hub.
More information about the IoT Hub can be found RIGHT HERE.
Then we’ll want to add our connecting strings to the app at the very bottom of MainPage.xaml.cs
static string iotHubUri = "YOURHUB.azure-devices.net";
static string deviceKey = "TOKENasQOPUesD1BmSOMETHINGCOMPLICATED";
static string deviceId = "MyDevice"; // your device name
Next we’ll uncomment this line of code on line 78:
SendDeviceToCloudMessagesAsync();
To see what’s happening in the event hub there is a small console application that we’ll run alongside to see what’s making into the cloud.
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
Morse code
Dance party
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
Obscure metadata
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.
In the process I’ve learned about some sweet stuff you can do with Javascript, Python, and Flask-SocketIO.
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
5. Have the Javascript Catch the emit and format our HTML.
Celebrate! Its Friday!
1.
Flask-SocketIO is a python package that is available for download using
*Edit Here’s the top part of the “main.py” for reference:
#main.py
from gevent import monkey
monkey.patch_all()
import time
from threading import Thread
from flask import Flask, render_template, session, request
from flask.ext.socketio import SocketIO, emit, join_room, disconnect
app = Flask(__name__)
app.debug = True
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
thread = None
2.
Create our background thread.
You’ll see in the sample code from Flask-SocketIO’s github a simple way to send data to the client regardless of their requests.
For this example we’ll be changing the current time every second and display that to our client.
Background Thread:
def background_stuff():
""" python code in main.py """
print 'In background_stuff'
while True:
time.sleep(1)
t = str(time.clock())
socketio.emit('message', {'data': 'This is data', 'time': t}, namespace='/test')
3
This is the emit statement from above, but is the meat of our interface with SocketIO. Notice how it breaks down…
This emit will be sending to the client (Javascript) a message called ‘message’.
When the Javascript catches this message it will be able to pull from the python dicionary msg.data and msg.time to get the result of this package.
4
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:
@app.route('/')
def index():
global thread
if thread is None:
thread = Thread(target=background_stuff)
thread.start()
return render_template('index.html')
Pretty simple… Notice global thread and target=background_stuff
Creating different background threads is a good way to iterate through your changes.
I’ve been working in Visual Studio pretty heavily in the last two weeks, but every once in a while I need to make quick edits to my .gitignore file, which isn’t in my project directory.
I usually open up a small text editor right from PowerShell and now that VS Code is out I thought ‘why not use that?’
Here’s how you can easily open files using code from PowerShell in three steps:
1.Find the path to VS Code
2. Edit your PowerShell profile
3. Open Files!
1. Find the VS Code Path
First thing we need to do is find where VS Code is in our directory.
If you have Code pinned to your start menu or on your desktop simply right click the icon and ‘select open file location’.
File explorer should now open to the location of the .exe.
Right click the Code.exe file and select ‘properties’.
If you selected a Shortcut Icon you should see a screen like this:
If you navigated to the actual location in directory of VS Code it should look like this:
Now right click and copy the path.
In my case: C:\Users\tireilly\AppData\Local\Code\app-0.1.0
2. Edit our PowerShell profile
To edit our profile we need to find the Microsoft.PowerShell_profile.ps1 file.
My file is located here:
I open the file in notepad to make my edits:
Now that we have our profile open we’ll create an alias for labeled code followed by the path to our .exe
eg: Set-Alias code ‘C:\Users\user\AppData\Local\Code\app-0.1.0\Code.exe
noticed how I added the Code.exe to the path so the program will launch!
Here’s a photo of my current PowerShell profile for reference:
Now we can save and close this file and open a new PowerShell window!
3. Edit some files!
Let’s edit our PowerShell profile with Code this time!
Something oddly satisfying about getting exactly what you want with words.
And there we go. The brand new Code editor at your fingertips whenever you need it!
Let me know if you have any comment or questions!
Professor Chang Yun is an excellent man with an amazing imagine cup record. His mentorship has led teams to US finals for 8 years straight. With 6 teams making it into the World Finals.
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.
So…
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 .gitignore
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:
tokens.py
Its expanded to include…
tokens.py
*.pyc
# 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:
touch (Unix) GitHub .gitignore
If you enter: ‘git ignore –help’ in your gitshell you can find more helpful documentation about using .gitignore
Setting up Code for Powershell
Setting up sublime for Powershell
Evangelists in their natural habitat. Behind a booth and with a computer.
I ran into some troubles migrating/configuring my tables for a new app in my Django project.
I’ve been following this excellent tutorial, and ran into a bump I thought needed some clarification/update. As I’m not sure if the guide is up to date with the current version of Django.
Things I searched:
no module named models
manage.py sqlall
django not creating db
models are not being created in sqlite3 Django
sqlite3 not creating table django
No migrations to apply
django sqlite3 unable to create tables
manage.py shell
sqlite3 python package
Do these correlate with what you’re having issues with?
If so this was my solution.
First Install SQLite3 and add it too your Environment Variables -> Path
Install Page — Select: Source Code -> Zip for windows machines
I extracted it to C:/.
Now I have SQLite.exe in my root directory.
This is what the end of my Path looks like:
C:\Program Files\Microsoft\Web Platform Installer\;C:\SQLITE3.EXE\;
Sweet, now we can use SQLite in Powershell.
Configuration of Visual Studio:
Create a new app by right clicking on your Project file.
Then “Add” -> Select “Django App”
In this case my app is named book.
Sweet, now we have another Python app.
Go into your settings file and add it to the INSTALLED_APPS tuple.
eg. ‘book’,
Okay, now we’re configured make sure you’re SQLiteDB is properly configured as well.
Next we’ll create a model.
Following along with the tutorial.
We go into: book -> models.py and create our models.
Eg:
class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()
Sweet. Model made. Let’s get it into our SQLite DB.
Alright now in DjangoProject1Hack (Where ‘ls’ will show db.sqlite3 among others)
We’ll be doing the migration.
1. Validate:
Run- C:\Python27\python.exe manage.py validate
2. makemigrations
Run- C:\Python27\python.exe manage.py makemigrations
Output:
Migrations for ‘book’:
0001_initial.py:
– Create model Author
– Create model Book
– Create model Publisher
– Add field publisher to book
3. Sync (This just makes sure we add what’s missing)
Run- C:\Python27\python.exe manage.py syncdb
Output:
Operations to perform:
Apply all migrations: book
Running migrations:
Applying book.0001_initial… OK
Sweeeeeeet!
Okay now we manage the db:
Run- C:\Python27\python.exe manage.py shell
Sample workflow in Shell:
Python is an excellent teaching programming language. It has all the tools to inspire students out of the box with plenty to grow on.
Development requires a basic understanding of computer science but will teach essentials for large scale software development, object oriented design, polymorphism, and development environments.
I like python. The Zen is magnificent. It inspires me every time I practice and learn.
Microsoft arrives in the form of PTVS (Python Tools for Visual Studio) a powerful extension for Visual Studio that can be installed in all Versions of VS.
PTVS turns Visual Studio into a Python Dev Environment. Complete with Debugging, in window REPL (with autocomplete assistance), IntelliSense, configurable environments and virtual environments.
Its an extremely powerful tool.
While getting into PTVS I would recommend watching these two videos:
The second one especially will help you get a grip on how to configure development environments in Python, one of the most crucial parts of taking development to the next level.
Also, configuration of PIP, Setuptools, and virtualenv is all handled for you from there. Its freakin sweet. You can do all of this for free with Visual Studio Express.