Remote Debug your Pyton Code on the Arduino YUN with Visual Studio

Here is my first Python code ever! It contains comments on how to remote debug (over Wi-Fi) python code with Visual Studio Community 2013 (which is free) - I just want to share this as I think it could be very useful to others playing with the Arduino YUN.

PythonApplication1.py

#!/usr/bin/python
"""
    -------------------------------------------------------------------------------
    Debuggin your Arduino YUN Python code with Visual Studio by Carsten Knop, 2015.
    -------------------------------------------------------------------------------
    Please spread this guide as it's properly very usefull to others that are having fun with the Arduino YUN :-)

    Installing Python Tools for Visual Studio: https://pytools.codeplex.com/
        Install Microsoft Visual Studion Community 2013 & Pyton Tools...

    Installing Pip on the Arduino YUN: http://codybonney.com/installing-pip-on-the-arduino-yun/
        * Start cmd.exe
        > ssh -l root 192.168.1.178
        # <password>
        # opkg update
        # opkg install distribute
        # opkg install python-openssl
        # easy_install pip

    Cross-platform remote Python debugging on Arduino YUN: https://pytools.codeplex.com/wikipage?title=Remote%20Debugging%20for%20Windows%2C%20Linux%20and%20OS%20X
        # pip install ptvsd

    Start Debuggin your Python code running on the Arduino YUN:
        * Start Visual Studio and create a new project: File->New->Project...
        * Select: Installed->Templates->Other Languages->Pyton -> Pyton Application
        * Type in the code in this file or any other code you want to debug, remember to import ptvsd like below...
        * Select menu: PROJECT->PythonApplication1 Properties...
        * Select Publish and type: X:\mnt\sda1\arduino\py
          (i have a SD CARD in the Arduino YUN and mounted it as a drive in Windows with Sshfs Manager 0.0.1.5)
          (Just follow the 'Getting started with Arduino Yun and Autobahn' guide: http://tavendo.com/blog/post/arduino-yun-with-autobahn/
        * Deploy you pyton application by Right-Clicking your PythonApplication1 in the Solution Explorer and press Publish...
          (you code is copied to the Arduino YUN. You could do this any other way you like)
        * Start cmd.exe
        > ssh -l root 192.168.1.178
        # <password>
        # python -u //mnt/sda1/arduino/py/PythonApplication1.py
          (it should say 'wait_for_attach...' as it is running the code below...)
        * In Visual Studio, select menu: DEBUG->Attach to Process...
        * Type in Qualifier: tcp://joshua@192.168.1.178:5678
          (joshua is an optional secret defined in your code, see below...)
        * Press Refresh, select the correct process and click Attach

        Now you are debuggin (with Breakpoints and state information) your python code that is running on the Arduino YUN...
"""
import ptvsd
ptvsd.enable_attach(secret = 'joshua')
print('wait_for_attach...')
ptvsd.wait_for_attach()
print('Hello World')
ptvsd.break_into_debugger()
print('This line occurs after the breakpoint')

import sys
import random

guesses_made = 0
name = raw_input('Hello! What is your name?\n')
number = random.randint(1, 20)
print('Well, {0}, I am thinking of a number between 1 and 20.'.format(name))

while guesses_made < 6:
    guess = int(raw_input('Take a guess: '))
    guesses_made += 1
    if guess < number:
        print('Your guess is too low.')
    if guess > number:
        print('Your guess is too high.')
    if guess == number:
        break
if guess == number:
    print('Good job, {0}! You guessed my number in {1} guesses!'.format(name, guesses_made))
else:
    print('Nope. The number I was thinking of was {0}'.format(number))

CarstenK: Here is my first Python code ever! It contains comments on how to remote debug (over Wi-Fi) python code with Visual Studio Community 2013 (which is free) - I just want to share this as I think it could be very useful to others playing with the Arduino YUN.

::::SNIP::::

@CarstenK, thanks for you posting your code. I am Documenting the Yun. I'll make sure to list your notes. Thanks again. I think this will be very useful.

Jesse