diff --git a/mqttwuerfel.py b/mqttwuerfel.py new file mode 100644 index 0000000..b039bfa --- /dev/null +++ b/mqttwuerfel.py @@ -0,0 +1,55 @@ +import paho.mqtt.client as mqtt +import serial +import time + +ser = serial.Serial( + port='COM4', + baudrate=115200 + #parity=serial.PARITY_ODD, + #stopbits=serial.STOPBITS_TWO, + #bytesize=serial.SEVENBITS +) + +ser.isOpen() + +FRAMERATE=20 +fadetime=1000/FRAMERATE /10 *4 #fadetime in centiseconds SMOOOOTH + +# The callback for when the client receives a CONNACK response from the server. +def on_connect(client, userdata, flags, rc): + print("Connected with result code "+str(rc)) + + # Subscribing in on_connect() means that if we lose the connection and + # reconnect then subscriptions will be renewed. + client.subscribe("wuerfel/#") + +# The callback for when a PUBLISH message is received from the server. +def on_message(client, userdata, msg): + #print(msg.topic+" "+str(msg.payload)) + + stopic=msg.topic.split('/') + if (stopic[2]=="set"): + color=(msg.payload).decode() + writestring='B,' + stopic[1] +','+str(int(fadetime))+','+color+'\r\n' + #writestring=writestring + print(writestring) + ser.write(writestring.encode()) + ser.flush() + time.sleep(0.01) + #ser.reset_input_buffer() + #sPort.write("B,"+str(boxiTree[x][y])+","+str(fadetime)+","+int(red(colorTree[x][y]))+","+int(green(colorTree[x][y]))+","+int(blue(colorTree[x][y]))+"\n"); + + +client = mqtt.Client() +client.on_connect = on_connect +client.on_message = on_message + +client.connect("nodered.atd.theater.digital", 1883, 60) + +# Blocking call that processes network traffic, dispatches callbacks and +# handles reconnecting. +# Other loop*() functions are available that give a threaded interface and a +# manual interface. +client.loop_forever() + +ser.close() \ No newline at end of file diff --git a/test/test.pde b/test/test.pde new file mode 100644 index 0000000..2a4f42c --- /dev/null +++ b/test/test.pde @@ -0,0 +1,65 @@ +import processing.serial.*; + +static int FRAMERATE=20; + +int fadetime=1000/FRAMERATE /10 *4; //fadetime in centiseconds SMOOOOTH + +Serial sPort; + +//int boxnum = 1+2+3+4+5+6+7; +int boxnum=50; +color box[] = new color[boxnum]; +int boxid[] = new int[boxnum]; + + +float testcolorhue=0; + +float time=0; + +void setup() { + size(200, 200); + frameRate(FRAMERATE); + + for (int i=0;i