This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import zmq | |
import wiringpi | |
RED_PIN = 0 | |
GREEN_PIN = 1 | |
BLUE_PIN = 2 | |
def main(): | |
context = zmq.Context() | |
socket = context.socket(zmq.SUB) | |
socket.setsockopt(zmq.SUBSCRIBE, '') | |
socket.connect('tcp://192.168.2.1:7777') | |
wiringpi.wiringPiSetup() | |
wiringpi.softPwmCreate(RED_PIN, 0, 255) | |
wiringpi.softPwmCreate(GREEN_PIN, 0, 255) | |
wiringpi.softPwmCreate(BLUE_PIN, 0, 255) | |
while True: | |
data = socket.recv() | |
red = int(data[:3]) | |
green = int(data[3:6]) | |
blue = int(data[6:9]) | |
wiringpi.softPwmWrite(RED_PIN, red) | |
wiringpi.softPwmWrite(GREEN_PIN, green) | |
wiringpi.softPwmWrite(BLUE_PIN, blue) | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import zmq | |
from bottle import run, route, static_file, template | |
import signal | |
zmq_port = '7777' | |
context = zmq.Context().instance() | |
socket = context.socket(zmq.PUB) | |
socket.bind('tcp://*:%s' % zmq_port) | |
@route('/') | |
def index(): | |
return template('index', var='value') | |
@route('/color/:param') | |
def color(param): | |
socket.send(param) | |
return '' | |
@route('/static/:filename#.*#') | |
def server_static(filename): | |
return static_file(filename, root=os.path.join(os.path.dirname(__file__), 'static')) | |
run(host='0.0.0.0', port=80) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment