Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define FASTLED_ESP8266_RAW_PIN_ORDER
- #include "FastLED.h"
- #include <ESP8266WiFi.h>
- #include <WiFiUdp.h>
- #define ARTNET_ARTDMX 0x5000 //20480 as a decimal ArtNet OP Code
- #define DATA_PIN 0
- #define CLOCK_PIN 2
- #define CHIPSET WS2801
- #define COLOR_ORDER RGB
- #define NUM_LEDS 150
- #define BRIGHTNESS 255
- CRGB leds[NUM_LEDS];
- //WiFi Setup
- char ssid[] = "yournet";
- char pass[] = "passhere";
- IPAddress local_ip(192, 168, 0, 20);
- IPAddress gateway(192, 168, 0, 1);
- IPAddress subnet(255, 255, 255, 0);
- #define ART_NET_PORT 6454
- WiFiUDP Audp; //UDP socket for ArtNet
- #define BUFFER_SIZE 640
- unsigned char PacketBuffer[BUFFER_SIZE]; //buffer to hold incoming packet data
- void setup() {
- WiFi.mode(WIFI_AP);
- WiFi.begin(ssid, pass); //Connect to Network
- //WiFi.config(local_ip, gateway, subnet); //Set static IP information
- while (WiFi.status() != WL_CONNECTED) //wait until we are connected
- {
- delay(500);
- }
- Audp.begin(ART_NET_PORT); //Open ArtNet port
- FastLED.addLeds<CHIPSET, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
- FastLED.setBrightness( BRIGHTNESS );
- }
- // the loop function runs over and over again forever
- void loop() {
- int packetSize = Audp.parsePacket(); //Parse Packet
- if ( packetSize ) //ArtNet packet size is 530
- {
- Audp.read(PacketBuffer, BUFFER_SIZE); //Read packet into buffer
- int opcode = artNetOpCode(PacketBuffer); //Check to see if packet is ArtNet
- if ( opcode == ARTNET_ARTDMX ) //If code returned is correct
- {
- for(int i=0; i<NUM_LEDS; i++) {
- int d = i*3+18;
- leds[i].r = PacketBuffer[d];
- leds[i].g = PacketBuffer[d+1];
- leds[i].b = PacketBuffer[d+2];
- }
- FastLED.show();
- }
- else
- {
- Audp.beginPacket(Audp.remoteIP(), Audp.remotePort());
- byte headermessage[] = {'A', 'r', 't', '-', 'N', 'e', 't', '\0' };
- Audp.write(headermessage, sizeof(headermessage));
- Audp.write((byte)0x00); //OpCode
- Audp.write(0x21); //OpCode
- byte ipmessage[] = {192, 168, 178, 55 }; // IP address
- Audp.write(ipmessage, sizeof(ipmessage));
- // Audp.print(WiFi.localIP());
- Audp.write(0x36); // The Port low
- Audp.write(0x19); // The Port High
- Audp.write(0x01); // VerInfoH
- Audp.write(0x01); // VerInfoL
- Audp.write((byte)0x00); // NetSwitch
- Audp.write((byte)0x00); // SubSwitch
- Audp.write(0x01); // OemHi
- Audp.write(0x01); // Oem
- Audp.write((byte)0x00); // Ubea
- Audp.write((byte)0x00); // Status1
- Audp.write('J'); // EstaManLo
- Audp.write('M'); // EstaManHi
- byte shortmessage[18] = {'L', 'E', 'D', 's' }; // ShortName
- Audp.write(shortmessage, sizeof(shortmessage));
- byte longmessage[64] = {'L', 'E', 'D', 's' }; // LongName
- Audp.write(longmessage, sizeof(longmessage));
- byte reportmessage[64] = {'L', 'E', 'D', 's' }; // NodeReport
- Audp.write(reportmessage, sizeof(reportmessage));
- Audp.write((byte)0x00); // NumPortsHi
- Audp.write(0x01); // NumPortsLo
- Audp.write(0xC5); // PortTypes
- Audp.write(0xC5);
- Audp.write(0xC5);
- Audp.write(0xC5);
- Audp.write(0x80); // GoodInput
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00); // GoodOutput
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00); // SwIn
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00); // SwOut
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00); // SwVideo
- Audp.write((byte)0x00); // SwMacro
- Audp.write((byte)0x00); // SwRemote
- Audp.write((byte)0x00); // Spare
- Audp.write((byte)0x00); // Spare
- Audp.write((byte)0x00); // Spare
- Audp.write((byte)0x00); // Style
- Audp.write((byte)0x18); // MAC Hi
- Audp.write((byte)0xFE); // MAC
- Audp.write((byte)0x34);
- Audp.write((byte)0xF9);
- Audp.write((byte)0x40);
- Audp.write((byte)0x7F);
- Audp.write((byte)0x00); // BindIp
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00); // BindIndex
- Audp.write((byte)0x00); // Status2
- Audp.write((byte)0x00); // Filler 1
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00); // Filler 11
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00); // Filler 21
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.write((byte)0x00);
- Audp.endPacket();
- }
- }
- }
- int artNetOpCode(unsigned char* pbuff) {
- String test = String((char*)pbuff);
- if ( test.equals("Art-Net") )
- {
- if ( pbuff[11] >= 14 )
- { //protocol version [10] hi byte [11] lo byte
- return pbuff[9] *256 + pbuff[8]; //opcode lo byte first
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement