Example #1
0
 def outputSequence(self, channel, args):
     self.checkDigitalChannelExported(channel)
     self.checkPostingValueAllowed()
     self.checkDigitalChannel(channel)
     (period, sequence) = args.split(",")
     period = int(period)
     GPIO.outputSequence(channel, period, sequence)
     return int(sequence[-1])
Example #2
0
 def outputSequence(self, channel, args):
     self.checkDigitalChannelExported(channel)
     self.checkPostingValueAllowed()
     self.checkDigitalChannel(channel)
     (period, sequence) = args.split(",")
     period = int(period)
     GPIO.outputSequence(channel, period, sequence)
     return int(sequence[-1])
Example #3
0
    def do_POST(self, relativePath):
        if relativePath.startswith("GPIO/"):
            (mode, s_gpio, operation, value) = relativePath.split("/")
            gpio = int(s_gpio)
            
            if operation == "value":
                if value == "0":
                    GPIO.output(gpio, GPIO.LOW)
                elif value == "1":
                    GPIO.output(gpio, GPIO.HIGH)
                else:
                    return (400, "Bad Value", M_PLAIN)
    
                return (200, value, M_PLAIN)

            elif operation == "function":
                value = value.lower()
                if value == "in":
                    GPIO.setFunction(gpio, GPIO.IN)
                elif value == "out":
                    GPIO.setFunction(gpio, GPIO.OUT)
                elif value == "pwm":
                    GPIO.setFunction(gpio, GPIO.PWM)
                else:
                    return (400, "Bad Function", M_PLAIN)

                value = GPIO.getFunctionString(gpio)
                return (200, value, M_PLAIN)

            elif operation == "sequence":
                (period, sequence) = value.split(",")
                period = int(period)
                GPIO.outputSequence(gpio, period, sequence)
                return (200, sequence[-1], M_PLAIN)
                
            elif operation == "pwm":
                if value == "enable":
                    GPIO.enablePWM(gpio)
                elif value == "disable":
                    GPIO.disablePWM(gpio)
                
                if GPIO.isPWMEnabled(gpio):
                    result = "enabled"
                else:
                    result = "disabled"
                
                return (200, result, M_PLAIN)
                
            elif operation == "pulse":
                GPIO.pulse(gpio)
                return (200, "OK", M_PLAIN)
                
            elif operation == "pulseRatio":
                ratio = float(value)
                GPIO.pulseRatio(gpio, ratio)
                return (200, value, M_PLAIN)
                
            elif operation == "pulseAngle":
                angle = float(value)
                GPIO.pulseAngle(gpio, angle)
                return (200, value, M_PLAIN)
                
            else: # operation unknown
                return (404, operation + " Not Found", M_PLAIN)
                
        elif relativePath.startswith("macros/"):
            (mode, fname, value) = relativePath.split("/")
            if fname in self.callbacks:
                callback = self.callbacks[fname]

                if ',' in value:
                    args = value.split(',')
                    result = callback(*args)
                elif len(value) > 0:
                    result = callback(value)
                else:
                    result = callback()
                     
                response = ""
                if result:
                    response = "%s" % result
                return (200, response, M_PLAIN)
                    
            else:
                return (404, fname + " Not Found", M_PLAIN)
                
        else: # path unknowns
            return (0, None, None)
Example #4
0
    def do_POST(self):
        if not self.checkAuthentication():
            return

        relativePath = self.path.replace(self.server.context, "")
        if (relativePath.startswith("/")):
            relativePath = relativePath[1:]

        if (relativePath.startswith("GPIO/")):
            (mode, s_gpio, operation, value) = relativePath.split("/")
            gpio = int(s_gpio)

            if (operation == "value"):
                if GPIO.getFunction(gpio) != GPIO.OUT:
                    self.send_error(400, "Not Output")
                    return
                if (value == "0"):
                    GPIO.output(gpio, GPIO.LOW)
                elif (value == "1"):
                    GPIO.output(gpio, GPIO.HIGH)
                else:
                    self.send_error(400, "Bad Value")
                    return

                self.send_response(200)
                self.send_header("Content-type", "text/plain")
                self.end_headers()
                self.wfile.write(value.encode())

            elif (operation == "function"):
                value = value.lower()
                if value == "in":
                    GPIO.setFunction(gpio, GPIO.IN)
                elif value == "out":
                    GPIO.setFunction(gpio, GPIO.OUT)
                elif value == "pwm":
                    GPIO.setFunction(gpio, GPIO.PWM)
                else:
                    self.send_error(400, "Bad Function")
                    return
                value = GPIO.getFunctionString(gpio)
                self.send_response(200)
                self.send_header("Content-type", "text/plain")
                self.end_headers()
                self.wfile.write(value.encode())

            elif (operation == "sequence"):
                if GPIO.getFunction(gpio) != GPIO.OUT:
                    self.send_error(400, "Not Output")
                    return

                (period, sequence) = value.split(",")
                period = int(period)
                GPIO.outputSequence(gpio, period, sequence)
                self.send_response(200)
                self.send_header("Content-type", "text/plain")
                self.end_headers()
                self.wfile.write(sequence[-1].encode())

            elif (operation == "pwm"):
                if value == "enable":
                    GPIO.enablePWM(gpio)
                elif value == "disable":
                    GPIO.disablePWM(gpio)

                if GPIO.isPWMEnabled(gpio):
                    result = "enabled"
                else:
                    result = "disabled"

                self.send_response(200)
                self.send_header("Content-type", "text/plain")
                self.end_headers()
                self.wfile.write(result.encode())

            elif (operation == "pulse"):
                GPIO.pulse(gpio)
                self.send_response(200)
                self.send_header("Content-type", "text/plain")
                self.end_headers()
                self.wfile.write("OK".encode())

            elif (operation == "pulseRatio"):
                ratio = float(value)
                GPIO.pulseRatio(gpio, ratio)
                self.send_response(200)
                self.send_header("Content-type", "text/plain")
                self.end_headers()
                self.wfile.write(value.encode())

            elif (operation == "pulseAngle"):
                angle = float(value)
                GPIO.pulseAngle(gpio, angle)
                self.send_response(200)
                self.send_header("Content-type", "text/plain")
                self.end_headers()
                self.wfile.write(value.encode())

            else:  # operation unknown
                self.send_error(404, operation + " Not Found")
                return
        elif (relativePath.startswith("macros/")):
            (mode, fname, value) = relativePath.split("/")
            if (fname in self.server.callbacks):
                if ',' in value:
                    args = value.split(',')
                else:
                    args = [value]
                callback = self.server.callbacks[fname]
                self.send_response(200)
                self.send_header("Content-type", "text/plain")
                self.end_headers()
                self.wfile.write(callback(*args).encode())
            else:
                self.send_error(404, fname + " Not Found")
                return

        else:  # path unknowns
            self.send_error(404, "Not Found")
    def do_POST(self, relativePath):
        if relativePath.startswith("EGG/"):
            (mode, s_gpio, operation, value) = relativePath.split("/")
            if s_gpio == "1":
                gpio = 7
            elif s_gpio == "2":
                gpio = 8
            elif s_gpio == "3":
                gpio = 9
            elif s_gpio == "4":
                gpio = 10
            elif s_gpio == "5":
                gpio = 11
            elif s_gpio == "6":
                gpio = 22
            elif s_gpio == "7":
                gpio = 23
            elif s_gpio == "8":
                gpio = 24
            else:
                gpio = 25

            if operation == "value":
                if value == "off":
                    GPIO.output(gpio, GPIO.LOW)
                elif value == "on":
                    GPIO.output(gpio, GPIO.HIGH)
                else:
                    return (400, "Bad Value", M_PLAIN)
    
                return (200, value, M_PLAIN)

            elif operation == "function":
                value = value.lower()
                if value == "in":
                    GPIO.setFunction(gpio, GPIO.IN)
                elif value == "out":
                    GPIO.setFunction(gpio, GPIO.OUT)
                elif value == "pwm":
                    GPIO.setFunction(gpio, GPIO.PWM)
                else:
                    return (400, "Bad Function", M_PLAIN)

                value = GPIO.getFunctionString(gpio)
                return (200, value, M_PLAIN)

            elif operation == "sequence":
                (period, sequence) = value.split(",")
                period = int(period)
                GPIO.outputSequence(gpio, period, sequence)
                return (200, sequence[-1], M_PLAIN)
                
            elif operation == "pwm":
                if value == "enable":
                    GPIO.enablePWM(gpio)
                elif value == "disable":
                    GPIO.disablePWM(gpio)
                
                if GPIO.isPWMEnabled(gpio):
                    result = "enabled"
                else:
                    result = "disabled"
                
                return (200, result, M_PLAIN)
                
            elif operation == "pulse":
                GPIO.pulse(gpio)
                return (200, "OK", M_PLAIN)
                
            elif operation == "pulseRatio":
                ratio = float(value)
                GPIO.pulseRatio(gpio, ratio)
                return (200, value, M_PLAIN)
                
            elif operation == "pulseAngle":
                angle = float(value)
                GPIO.pulseAngle(gpio, angle)
                return (200, value, M_PLAIN)
                
            else: # operation unknown
                return (404, operation + " Not Found", M_PLAIN)
                
        elif relativePath.startswith("macros/"):
            (mode, fname, value) = relativePath.split("/")
            if fname in self.callbacks:
                callback = self.callbacks[fname]

                if ',' in value:
                    args = value.split(',')
                    result = callback(*args)
                elif len(value) > 0:
                    result = callback(value)
                else:
                    result = callback()
                     
                response = ""
                if result:
                    response = "%s" % result
                return (200, response, M_PLAIN)
                    
            else:
                return (404, fname + " Not Found", M_PLAIN)

        elif operation == "saca17":
            GPIO.setFunction(17, GPIO.OUT)
        
        elif operation == "saca171":
            GPIO.output(17,GPIO.HIGH)

        elif operation == "saca170":
            GPIO.output(17,GPIO.LOW)

        elif operation == "saca21":
            GPIO.setFunction(21, GPIO.OUT)
        
        elif operation == "saca211":
            GPIO.output(21,GPIO.HIGH)

        elif operation == "saca210":
            GPIO.output(21,GPIO.LOW)

        elif relativePath.startswith("EGGSOFF"):
            GPIO.output(7, GPIO.LOW)
            GPIO.output(8, GPIO.LOW)
            GPIO.output(9, GPIO.LOW)
            GPIO.output(10, GPIO.LOW)
            GPIO.output(11, GPIO.LOW)
            GPIO.output(22, GPIO.LOW)
            GPIO.output(23, GPIO.LOW)
            GPIO.output(24, GPIO.LOW)
            GPIO.output(25, GPIO.LOW)
            return (200, "ALL EGGS OFF", M_PLAIN)

        elif relativePath.startswith("EGGSON"):
            GPIO.output(7, GPIO.HIGH)
            GPIO.output(8, GPIO.HIGH)
            GPIO.output(9, GPIO.HIGH)
            GPIO.output(10, GPIO.HIGH)
            GPIO.output(11, GPIO.HIGH)
            GPIO.output(22, GPIO.HIGH)
            GPIO.output(23, GPIO.HIGH)
            GPIO.output(24, GPIO.HIGH)
            GPIO.output(25, GPIO.HIGH)
            return (200, "ALL EGGS ON", M_PLAIN)
    

        else: # path unknowns
            return (0, None, None)
Example #6
0
    def do_POST(self):
        if not self.checkAuthentication():
            return

        relativePath = self.path.replace(self.server.context, "")
        if (relativePath.startswith("/")):
            relativePath = relativePath[1:];

        if (relativePath.startswith("GPIO/")):
            (mode, s_gpio, operation, value) = relativePath.split("/")
            gpio = int(s_gpio)
            
            if (operation == "value"):
                if GPIO.getFunction(gpio) != GPIO.OUT:
                    self.send_error(400, "Not Output")
                    return;
                if (value == "0"):
                    GPIO.output(gpio, GPIO.LOW)
                elif (value == "1"):
                    GPIO.output(gpio, GPIO.HIGH)
                else:
                    self.send_error(400, "Bad Value")
                    return
    
                self.send_response(200)
                self.send_header("Content-type", "text/plain");
                self.end_headers()
                self.wfile.write(value.encode())

            elif (operation == "function"):
                value = value.lower()
                if value == "in":
                    GPIO.setFunction(gpio, GPIO.IN)
                elif value == "out":
                    GPIO.setFunction(gpio, GPIO.OUT)
                else:
                    self.send_error(400, "Bad Function")
                    return
                value = GPIO.getFunctionString(gpio)
                self.send_response(200)
                self.send_header("Content-type", "text/plain");
                self.end_headers()
                self.wfile.write(value.encode())

            elif (operation == "sequence"):
                if GPIO.getFunction(gpio) != GPIO.OUT:
                    self.send_error(400, "Not Output")
                    return;

                (period, sequence) = value.split(",")
                period = int(period)
                GPIO.outputSequence(gpio, period, sequence)
                self.send_response(200)
                self.send_header("Content-type", "text/plain");
                self.end_headers()
                self.wfile.write(sequence[-1].encode())
                
            else: # operation unknown
                self.send_error(404, operation + " Not Found")
                return
        elif (relativePath.startswith("macros/")):
            (mode, fname, value) = relativePath.split("/")
            if (fname in self.server.callbacks):
                callback = self.server.callbacks[fname]
                self.send_response(200)
                self.send_header("Content-type", "text/plain");
                self.end_headers()
                self.wfile.write(callback(value).encode())
            else:
                self.send_error(404, fname + " Not Found")
                return
                
        else: # path unknowns
            self.send_error(404, "Not Found")
Example #7
0
    def do_POST(self, relativePath):
        if relativePath.startswith("GPIO/"):
            (mode, s_gpio, operation, value) = relativePath.split("/")
            gpio = int(s_gpio)

            if operation == "value":
                if value == "0":
                    GPIO.output(gpio, GPIO.LOW)
                elif value == "1":
                    GPIO.output(gpio, GPIO.HIGH)
                else:
                    return (400, "Bad Value", M_PLAIN)

                return (200, value, M_PLAIN)

            elif operation == "function":
                value = value.lower()
                if value == "in":
                    GPIO.setFunction(gpio, GPIO.IN)
                elif value == "out":
                    GPIO.setFunction(gpio, GPIO.OUT)
                elif value == "pwm":
                    GPIO.setFunction(gpio, GPIO.PWM)
                else:
                    return (400, "Bad Function", M_PLAIN)

                value = GPIO.getFunctionString(gpio)
                return (200, value, M_PLAIN)

            elif operation == "sequence":
                (period, sequence) = value.split(",")
                period = int(period)
                GPIO.outputSequence(gpio, period, sequence)
                return (200, sequence[-1], M_PLAIN)

            elif operation == "pwm":
                if value == "enable":
                    GPIO.enablePWM(gpio)
                elif value == "disable":
                    GPIO.disablePWM(gpio)

                if GPIO.isPWMEnabled(gpio):
                    result = "enabled"
                else:
                    result = "disabled"

                return (200, result, M_PLAIN)

            elif operation == "pulse":
                GPIO.pulse(gpio)
                return (200, "OK", M_PLAIN)

            elif operation == "pulseRatio":
                ratio = float(value)
                GPIO.pulseRatio(gpio, ratio)
                return (200, value, M_PLAIN)

            elif operation == "pulseAngle":
                angle = float(value)
                GPIO.pulseAngle(gpio, angle)
                return (200, value, M_PLAIN)

            else:  # operation unknown
                return (404, operation + " Not Found", M_PLAIN)

        elif relativePath.startswith("macros/"):
            (mode, fname, value) = relativePath.split("/")
            if fname in self.callbacks:
                callback = self.callbacks[fname]

                if "," in value:
                    args = value.split(",")
                    result = callback(*args)
                elif len(value) > 0:
                    result = callback(value)
                else:
                    result = callback()

                response = ""
                if result:
                    response = "%s" % result
                return (200, response, M_PLAIN)

            else:
                return (404, fname + " Not Found", M_PLAIN)

        else:  # path unknowns
            return (0, None, None)
Example #8
0
    def do_POST(self):
        if not self.checkAuthentication():
            return

        relativePath = self.path.replace(self.server.context, "")
        if (relativePath.startswith("/")):
            relativePath = relativePath[1:];

        if (relativePath.startswith("GPIO/")):
            (mode, s_gpio, operation, value) = relativePath.split("/")
            gpio = int(s_gpio)
            
            if (operation == "value"):
                if GPIO.getFunction(gpio) != GPIO.OUT:
                    self.send_error(400, "Not Output")
                    return;
                if (value == "0"):
                    GPIO.output(gpio, GPIO.LOW)
                elif (value == "1"):
                    GPIO.output(gpio, GPIO.HIGH)
                else:
                    self.send_error(400, "Bad Value")
                    return
    
                self.send_response(200)
                self.send_header("Content-type", "text/plain");
                self.end_headers()
                self.wfile.write(value.encode())

            elif (operation == "function"):
                value = value.lower()
                if value == "in":
                    GPIO.setFunction(gpio, GPIO.IN)
                elif value == "out":
                    GPIO.setFunction(gpio, GPIO.OUT)
                elif value == "pwm":
                    GPIO.setFunction(gpio, GPIO.PWM)
                else:
                    self.send_error(400, "Bad Function")
                    return
                value = GPIO.getFunctionString(gpio)
                self.send_response(200)
                self.send_header("Content-type", "text/plain");
                self.end_headers()
                self.wfile.write(value.encode())

            elif (operation == "sequence"):
                if GPIO.getFunction(gpio) != GPIO.OUT:
                    self.send_error(400, "Not Output")
                    return;

                (period, sequence) = value.split(",")
                period = int(period)
                GPIO.outputSequence(gpio, period, sequence)
                self.send_response(200)
                self.send_header("Content-type", "text/plain");
                self.end_headers()
                self.wfile.write(sequence[-1].encode())
                
            elif (operation == "pwm"):
                if value == "enable":
                    GPIO.enablePWM(gpio)
                elif value == "disable":
                    GPIO.disablePWM(gpio)
                
                if GPIO.isPWMEnabled(gpio):
                    result = "enabled"
                else:
                    result = "disabled"
                
                self.send_response(200)
                self.send_header("Content-type", "text/plain");
                self.end_headers()
                self.wfile.write(result.encode())
                
            elif (operation == "pulse"):
                GPIO.pulse(gpio)
                self.send_response(200)
                self.send_header("Content-type", "text/plain");
                self.end_headers()
                self.wfile.write("OK".encode())
                
            elif (operation == "pulseRatio"):
                ratio = float(value)
                GPIO.pulseRatio(gpio, ratio)
                self.send_response(200)
                self.send_header("Content-type", "text/plain");
                self.end_headers()
                self.wfile.write(value.encode())
                
            elif (operation == "pulseAngle"):
                angle = float(value)
                GPIO.pulseAngle(gpio, angle)
                self.send_response(200)
                self.send_header("Content-type", "text/plain");
                self.end_headers()
                self.wfile.write(value.encode())
                
            else: # operation unknown
                self.send_error(404, operation + " Not Found")
                return
        elif (relativePath.startswith("macros/")):
            (mode, fname, value) = relativePath.split("/")
            if (fname in self.server.callbacks):
                if ',' in value:
                    args = value.split(',')
                else:
                    args = [value]
                callback = self.server.callbacks[fname]
                self.send_response(200)
                self.send_header("Content-type", "text/plain");
                self.end_headers()
                self.wfile.write(callback(*args).encode())
            else:
                self.send_error(404, fname + " Not Found")
                return
                
        else: # path unknowns
            self.send_error(404, "Not Found")
Example #9
0
    def do_POST(self, relativePath):
        if relativePath.startswith("EGG/"):
            (mode, s_gpio, operation, value) = relativePath.split("/")
            if s_gpio == "1":
                gpio = 7
            elif s_gpio == "2":
                gpio = 8
            elif s_gpio == "3":
                gpio = 9
            elif s_gpio == "4":
                gpio = 10
            elif s_gpio == "5":
                gpio = 11
            elif s_gpio == "6":
                gpio = 22
            elif s_gpio == "7":
                gpio = 23
            elif s_gpio == "8":
                gpio = 24
            else:
                gpio = 25

            if operation == "value":
                if value == "off":
                    GPIO.output(gpio, GPIO.LOW)
                elif value == "on":
                    GPIO.output(gpio, GPIO.HIGH)
                else:
                    return (400, "Bad Value", M_PLAIN)

                return (200, value, M_PLAIN)

            elif operation == "function":
                value = value.lower()
                if value == "in":
                    GPIO.setFunction(gpio, GPIO.IN)
                elif value == "out":
                    GPIO.setFunction(gpio, GPIO.OUT)
                elif value == "pwm":
                    GPIO.setFunction(gpio, GPIO.PWM)
                else:
                    return (400, "Bad Function", M_PLAIN)

                value = GPIO.getFunctionString(gpio)
                return (200, value, M_PLAIN)

            elif operation == "sequence":
                (period, sequence) = value.split(",")
                period = int(period)
                GPIO.outputSequence(gpio, period, sequence)
                return (200, sequence[-1], M_PLAIN)

            elif operation == "pwm":
                if value == "enable":
                    GPIO.enablePWM(gpio)
                elif value == "disable":
                    GPIO.disablePWM(gpio)

                if GPIO.isPWMEnabled(gpio):
                    result = "enabled"
                else:
                    result = "disabled"

                return (200, result, M_PLAIN)

            elif operation == "pulse":
                GPIO.pulse(gpio)
                return (200, "OK", M_PLAIN)

            elif operation == "pulseRatio":
                ratio = float(value)
                GPIO.pulseRatio(gpio, ratio)
                return (200, value, M_PLAIN)

            elif operation == "pulseAngle":
                angle = float(value)
                GPIO.pulseAngle(gpio, angle)
                return (200, value, M_PLAIN)

            else:  # operation unknown
                return (404, operation + " Not Found", M_PLAIN)

        elif relativePath.startswith("macros/"):
            (mode, fname, value) = relativePath.split("/")
            if fname in self.callbacks:
                callback = self.callbacks[fname]

                if ',' in value:
                    args = value.split(',')
                    result = callback(*args)
                elif len(value) > 0:
                    result = callback(value)
                else:
                    result = callback()

                response = ""
                if result:
                    response = "%s" % result
                return (200, response, M_PLAIN)

            else:
                return (404, fname + " Not Found", M_PLAIN)

        elif operation == "saca17":
            GPIO.setFunction(17, GPIO.OUT)

        elif operation == "saca171":
            GPIO.output(17, GPIO.HIGH)

        elif operation == "saca170":
            GPIO.output(17, GPIO.LOW)

        elif operation == "saca21":
            GPIO.setFunction(21, GPIO.OUT)

        elif operation == "saca211":
            GPIO.output(21, GPIO.HIGH)

        elif operation == "saca210":
            GPIO.output(21, GPIO.LOW)

        elif relativePath.startswith("EGGSOFF"):
            GPIO.output(7, GPIO.LOW)
            GPIO.output(8, GPIO.LOW)
            GPIO.output(9, GPIO.LOW)
            GPIO.output(10, GPIO.LOW)
            GPIO.output(11, GPIO.LOW)
            GPIO.output(22, GPIO.LOW)
            GPIO.output(23, GPIO.LOW)
            GPIO.output(24, GPIO.LOW)
            GPIO.output(25, GPIO.LOW)
            return (200, "ALL EGGS OFF", M_PLAIN)

        elif relativePath.startswith("EGGSON"):
            GPIO.output(7, GPIO.HIGH)
            GPIO.output(8, GPIO.HIGH)
            GPIO.output(9, GPIO.HIGH)
            GPIO.output(10, GPIO.HIGH)
            GPIO.output(11, GPIO.HIGH)
            GPIO.output(22, GPIO.HIGH)
            GPIO.output(23, GPIO.HIGH)
            GPIO.output(24, GPIO.HIGH)
            GPIO.output(25, GPIO.HIGH)
            return (200, "ALL EGGS ON", M_PLAIN)

        else:  # path unknowns
            return (0, None, None)