2013-02-03

Control My Pi - Easy web remote control for your Raspberry Pi projects

*** NOTE: ControlMyPi shutting down ***

I'm launching Control My Pi Beta today. In just a few lines of Python code you can create a control panel for your project accessible over the Internet. No firewall changes to make, no web servers to set up. Pick up your Raspberry Pi, take it to a friends house or work, school, a club, a coffee shop - connect it to 3G and carry it around or put it in your car - it doesn't matter where it is or what network you're on you'll be able to access your control panel on Control My Pi. It's no ordinary control panel either, every viewer establishes a "push" connection to the server so any update sent from your Raspberry Pi is pushed to every open control panel out there in the world.

If you're really proud of your control panel, and you don't mind anyone pressing buttons, you can make your panel public. It will appear as a link on the front page. (I may need to do something about this if this feature becomes very popular!) If you just want to share your panel with a few people send them a copy of your panel URL.

Instructions, FAQ and documentation are available on the web site plus some examples to get started. More write-ups of Control My Pi projects coming up soon from simple GPIO LED projects to 3G GPS bicycle telemetry systems!

I've got a couple of public examples up and running for you to take a look at. Remember to click the "Push status" button on public panels to start the connection if you want to interact with it. (This is done for you automatically on non-public panels).


Here's a video showing a control panel in action. This is taken from the easycontrol.py example available in the download at Control My Pi. In the background is a Nexus 7 tablet showing a zoom in on the control panel at Control My Pi. In the foreground you can see my Raspberry Pi connected to a breadboard with 4 GPIOs. Two for inputs from the buttons and two for outputs to the LEDs. It's a bit hard to see because of my jumper wires but when I push the hardware button the LED's state changes and this is pushed to the web page. Likewise, when I press a software button the same thing happens.



And here's the small Python script to make this happen: hardware inputs, outputs and multi-user, push status, Internet control panel!
from controlmypi import ControlMyPi
import json
import RPi.GPIO as GPIO
import time

JABBER_ID = 'me@my.jabber.domain'
JABBER_PASSWORD = 'password'
SHORT_ID = 'easy1'
FRIENDLY_NAME = 'Control my red and yellow LEDs'
PANEL_FORM = [
             [ ['L','Remote control Raspberry Pi LEDs - status pushed back to this page!'] ],
             [ ['O'] ],
             [ ['L','Yellow'],['B','18 on','on'],['B','18 off','off'],['S','GPIO18','-'] ],
             [ ['L','Red'],['B','23 on','on'],['B','23 off','off'],['S','GPIO23','-'] ],
             [ ['C'] ],
             ]

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(23, GPIO.OUT)
GPIO.setup(24, GPIO.IN)
GPIO.setup(25, GPIO.IN)

status = {18:False, 23:False}

def switch_led(n, state):
    if status[n] != state:
        GPIO.output(n, not state) #Low to glow!
        conn.update_status({'GPIO'+str(n): 'on' if state else 'off'})    
        status[n] = state

def on_control_message(conn, key, value):
    tokens = key.split(' ')
    number = int(tokens[0])
    state = tokens[1]
    if number in [18,23] and state in ['on','off']:
        switch_led(number, state == 'on')

def main_loop():
    switch_led(18,True)
    switch_led(23,True)
    debounced_one = True
    debounced_two = True
    while True:
        state_one = GPIO.input(24)
        state_two = GPIO.input(25)
        if state_one and debounced_one:
            switch_led(18, not status[18])
            debounced_one = False
        elif not state_one:
            debounced_one = True
            
        if state_two and debounced_two:
            switch_led(23, not status[23])
            debounced_two = False
        elif not state_two:
            debounced_two = True

        time.sleep(0.1)    


conn = ControlMyPi(JABBER_ID, JABBER_PASSWORD, SHORT_ID, FRIENDLY_NAME, PANEL_FORM, on_control_message)
if conn.start_control():
    try:
        main_loop()
    finally:
        conn.stop_control()
else:
    print("FAILED TO CONNECT")


Finally, here's a snapshot of the live dashboard of my 3G GPS bicycle telemetry system. My current position, heading, speed, height and X,Y and Z accelerations are pushed to Control My Pi and then out to anyone watching!

2 comments:

David Vitrant said...

Hi, I was following your mcp3008 info and stumbled on the control my pi. I'm thinking of using this for the remote plant watering system. Thanks for sharing that with us. I have a question about the mcp3008 code (I probably should post this on the other site). I'm not really a hardware/python guy but wanted to plug in a soil moisture sensor to it. It's wired properly but the signal is always at 777. I'm wondering if it has to do with your comments on the first int being ignored and your comments about continuous signal input. The project is here if you wanted to read http://www.raspberrypi.org/phpBB3/viewtopic.php?f=37&t=29760&p=298268#p298268.

Any help is appreciated. Thanks for posting all your raspberry pi adventures :)

jerbly said...

David, I just took a look at your project over in the forum. It'd be great if you wanted to use ControlMyPi for a web interface and I'd be happy to help you get it going. As for the troubles you're having with the moisture sensor have you tried something really basic like putting a volt meter across it to see if you do get a varying voltage out of it? If you want to mail me directly you can do it through the address on the FAQ page on ControlMyPi.