diff --git a/README.md b/README.md index 9a2877a2d5d13b827ae9e08b4303e910aa65cc00..fde558c29ad98ad96097dd30c4627b477bae5d1d 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ The node listens on udp port 1234 and expects packets of following layout: - [VER:8][SEQ:8][ OFFSET:16 ] + [VER:8][SEQ:8][ID:8 ][RES:8] [ PIXEL:32*n ] [ ... ] [ ... ] @@ -19,8 +19,11 @@ The node listens on udp port 1234 and expects packets of following layout: - value: 2 - SEQ: sequence number - this should be incremented for each datagram - - OFFSET: (ignored/WIP) defines where the first pixel should be drawn + - ID: receiver address id + - ID of the node is the number in its hostname. can be 0 to address all + - RES: reserved for future use. + - (WIP/idea) defines where the first pixel should be drawn - default: 0 - - PIXEL: colors in grbw format + - PIXEL: colors in GRBW format - 1 <= n <= pixel count diff --git a/esp/main.py b/esp/main.py index 321544d8fbfc28cbe5a98191ee17cafd16d62594..1160b9790d46f3ef8ed503d8e283250f49476a36 100644 --- a/esp/main.py +++ b/esp/main.py @@ -2,13 +2,17 @@ import socket import machine import neopixel import utime +import wifi_config + +# config PORT = 1234 SIGNAL_LED_PIN = 2 LED_PIN = 0 LED_NUM = 42 -LED_PIXEL = 4 # pixel per led (3 or 4) +LED_PIXEL = 4 # pixel per led (4 for RGBW) +ESP_ID = int(''.join(c for c in wifi_config.HOSTNAME if c.isdigit())) machine.freq(160000000) gamma8 = [ @@ -102,9 +106,24 @@ class UDPled: @micropython.native def run_fast_seq(self): - """Receives SEQ|GRBW|... as a UDP packet. Must contain all LEDs""" + """Receives a UDP packet with header. Must contain all LEDs. + + Packet format: + [VER:8][SEQ:8][ID:8 ][RES:8] + [ PIXEL:4*8 ] + [ ... ] + + VER: protocol version number (currently 2) + SEQ: sequence number + ID: the host id of this ESP. Ignored if 0 + RES: reserved for future use + PIXEL: 8bit GRBW values for a pixel + """ while True: self.sock.readinto(self.udp_buffer) + if self.udp_buffer[2] not in [0, ESP_ID]: + # ignore packet if it's not for us or everyone + continue if (self.udp_buffer[0] == 2 and (self.udp_buffer[1] - self.udp_seq)%256 <= 128): self.udp_seq = self.udp_buffer[1] self.np.buf = self.udp_buffer[4:]