def main():
    arduino = get_arduino_pyro()
    storage = get_storage_pyro()
    wait_for_server(logger)

    pin = None
    while pin == None:
        logger.info("Getting pin number by ID")
        pin = storage.get_pin_by_id(PIN_ID)
        logger.info(" + Got pin: %s", pin)
        if pin is None:
            logger.warn(" + The pin with ID '%s' was not found... Will retry in 5 secs", PIN_ID)
            time.sleep(5)
            continue

    logger.info("Wait until Arduino is connected...")
    while not arduino.is_connected():
        time.sleep(1)

    logger.info("Connected! :-D")

    logger.info("Starting to blink")
    arduino.pinMode(pin.pin, OUTPUT)
    while True:
        arduino.digitalWrite(pin.pin, HIGH)
        time.sleep(1)
        arduino.digitalWrite(pin.pin, LOW)
        time.sleep(1)
def main():
    arduino = get_arduino_pyro()
    storage = get_storage_pyro()
    wait_for_server(logger)

    pin = None
    while pin == None:
        logger.info("Getting pin number by ID")
        pin = storage.get_pin_by_id(PIN_ID)
        logger.info(" + Got pin: %s", pin)
        if pin is None:
            logger.warn(
                " + The pin with ID '%s' was not found... Will retry in 5 secs",
                PIN_ID)
            time.sleep(5)
            continue

    logger.info("Wait until Arduino is connected...")
    while not arduino.is_connected():
        time.sleep(1)

    logger.info("Connected! :-D")

    logger.info("Starting to blink")
    arduino.pinMode(pin.pin, OUTPUT)
    while True:
        arduino.digitalWrite(pin.pin, HIGH)
        time.sleep(1)
        arduino.digitalWrite(pin.pin, LOW)
        time.sleep(1)
Пример #3
0
import json
import Pyro4

from django.shortcuts import render
from django.http.response import HttpResponse, HttpResponseRedirect, \
    HttpResponseServerError
from django.core.urlresolvers import reverse
from django.contrib import messages

from py_arduino import DEVICE_FOR_EMULATOR, LOW, HIGH, \
    OUTPUT, INPUT
from py_arduino_web.pyroproxy.utils import get_arduino_pyro, server_is_up,\
    get_storage_pyro

ARDUINO_PYRO = get_arduino_pyro()
STORAGE_PYRO = get_storage_pyro()


class JsonResponse(HttpResponse):
    def __init__(self, data, *args, **kwargs):
        content = json.dumps(data)
        mimetype = kwargs.get('mimetype', 'application/json')
        super(JsonResponse, self).__init__(content=content,
                                           mimetype=mimetype,
                                           *args,
                                           **kwargs)


class JsonErrorResponse(HttpResponseServerError):
    def __init__(self, exception, *args, **kwargs):
        content = json.dumps({
Пример #4
0
import Pyro4

from django.shortcuts import render
from django.http.response import HttpResponse, HttpResponseRedirect, \
    HttpResponseServerError
from django.core.urlresolvers import reverse
from django.contrib import messages

from py_arduino import DEVICE_FOR_EMULATOR, LOW, HIGH, \
    OUTPUT, INPUT
from py_arduino_web.pyroproxy.utils import get_arduino_pyro, server_is_up,\
    get_storage_pyro


ARDUINO_PYRO = get_arduino_pyro()
STORAGE_PYRO = get_storage_pyro()


class JsonResponse(HttpResponse):
    def __init__(self, data, *args, **kwargs):
        content = json.dumps(data)
        mimetype = kwargs.get('mimetype', 'application/json')
        super(JsonResponse, self).__init__(content=content, mimetype=mimetype,
            *args, **kwargs)


class JsonErrorResponse(HttpResponseServerError):
    def __init__(self, exception, *args, **kwargs):
        content = json.dumps({
            'ok': False,
            'exception': str(exception),