Advertisement
Guest User

Untitled

a guest
Jul 27th, 2018
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.92 KB | None | 0 0
  1. #define  FASTLED_ESP8266_RAW_PIN_ORDER
  2. #include "FastLED.h"
  3. #include <ESP8266WiFi.h>
  4. #include <WiFiUdp.h>
  5.  
  6. #define ARTNET_ARTDMX 0x5000 //20480 as a decimal ArtNet OP Code
  7. #define DATA_PIN 0
  8. #define CLOCK_PIN 2
  9. #define CHIPSET     WS2801
  10. #define COLOR_ORDER RGB
  11. #define NUM_LEDS    150
  12. #define BRIGHTNESS  255
  13. CRGB leds[NUM_LEDS];
  14.  
  15. //WiFi Setup
  16. char ssid[] = "yournet";
  17. char pass[] = "passhere";
  18. IPAddress local_ip(192, 168, 0, 20);
  19. IPAddress gateway(192, 168, 0, 1);
  20. IPAddress subnet(255, 255, 255, 0);
  21. #define ART_NET_PORT 6454
  22. WiFiUDP Audp; //UDP socket for ArtNet
  23. #define BUFFER_SIZE 640
  24. unsigned char PacketBuffer[BUFFER_SIZE]; //buffer to hold incoming packet data
  25.  
  26. void setup() {
  27.   WiFi.mode(WIFI_AP);
  28.   WiFi.begin(ssid, pass); //Connect to Network
  29.   //WiFi.config(local_ip, gateway, subnet); //Set static IP information
  30.   while (WiFi.status() != WL_CONNECTED)  //wait until we are connected
  31.   {
  32.     delay(500);
  33.   }
  34.   Audp.begin(ART_NET_PORT); //Open ArtNet port
  35.   FastLED.addLeds<CHIPSET, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  36.   FastLED.setBrightness(  BRIGHTNESS );
  37. }
  38.  
  39. // the loop function runs over and over again forever
  40. void loop() {
  41.     int packetSize = Audp.parsePacket(); //Parse Packet
  42.     if ( packetSize ) //ArtNet packet size is 530
  43.     {
  44.       Audp.read(PacketBuffer, BUFFER_SIZE); //Read packet into buffer
  45.       int opcode = artNetOpCode(PacketBuffer); //Check to see if packet is ArtNet
  46.       if ( opcode == ARTNET_ARTDMX ) //If code returned is correct
  47.       {
  48.         for(int i=0; i<NUM_LEDS; i++) {
  49.           int d = i*3+18;
  50.           leds[i].r = PacketBuffer[d];
  51.           leds[i].g = PacketBuffer[d+1];
  52.           leds[i].b = PacketBuffer[d+2];
  53.         }
  54.         FastLED.show();
  55.       }
  56.       else
  57.       {
  58.           Audp.beginPacket(Audp.remoteIP(), Audp.remotePort());
  59.           byte headermessage[] = {'A', 'r', 't', '-', 'N', 'e', 't', '\0' };
  60.           Audp.write(headermessage, sizeof(headermessage));
  61.           Audp.write((byte)0x00); //OpCode
  62.           Audp.write(0x21); //OpCode
  63.           byte ipmessage[] = {192, 168, 178, 55 }; // IP address
  64.           Audp.write(ipmessage, sizeof(ipmessage));
  65.           // Audp.print(WiFi.localIP());
  66.           Audp.write(0x36); // The Port low
  67.           Audp.write(0x19); // The Port High
  68.           Audp.write(0x01); // VerInfoH
  69.           Audp.write(0x01); // VerInfoL
  70.           Audp.write((byte)0x00); // NetSwitch
  71.           Audp.write((byte)0x00); // SubSwitch
  72.           Audp.write(0x01); // OemHi
  73.           Audp.write(0x01); // Oem
  74.           Audp.write((byte)0x00); // Ubea
  75.           Audp.write((byte)0x00); // Status1
  76.           Audp.write('J');  // EstaManLo
  77.           Audp.write('M');  // EstaManHi
  78.           byte shortmessage[18] = {'L', 'E', 'D', 's' }; // ShortName
  79.           Audp.write(shortmessage, sizeof(shortmessage));
  80.           byte longmessage[64] = {'L', 'E', 'D', 's' }; // LongName
  81.           Audp.write(longmessage, sizeof(longmessage));
  82.           byte reportmessage[64] = {'L', 'E', 'D', 's' }; // NodeReport
  83.           Audp.write(reportmessage, sizeof(reportmessage));
  84.           Audp.write((byte)0x00); // NumPortsHi
  85.           Audp.write(0x01); // NumPortsLo
  86.           Audp.write(0xC5); // PortTypes
  87.           Audp.write(0xC5);
  88.           Audp.write(0xC5);
  89.           Audp.write(0xC5);
  90.           Audp.write(0x80); // GoodInput
  91.           Audp.write((byte)0x00);
  92.           Audp.write((byte)0x00);
  93.           Audp.write((byte)0x00);
  94.           Audp.write((byte)0x00); // GoodOutput
  95.           Audp.write((byte)0x00);
  96.           Audp.write((byte)0x00);
  97.           Audp.write((byte)0x00);
  98.           Audp.write((byte)0x00); // SwIn
  99.           Audp.write((byte)0x00);
  100.           Audp.write((byte)0x00);
  101.           Audp.write((byte)0x00);
  102.           Audp.write((byte)0x00); // SwOut
  103.           Audp.write((byte)0x00);
  104.           Audp.write((byte)0x00);
  105.           Audp.write((byte)0x00);
  106.           Audp.write((byte)0x00); // SwVideo
  107.           Audp.write((byte)0x00); // SwMacro
  108.           Audp.write((byte)0x00); // SwRemote
  109.           Audp.write((byte)0x00); // Spare
  110.           Audp.write((byte)0x00); // Spare
  111.           Audp.write((byte)0x00); // Spare
  112.           Audp.write((byte)0x00); // Style
  113.           Audp.write((byte)0x18); // MAC Hi
  114.           Audp.write((byte)0xFE); // MAC
  115.           Audp.write((byte)0x34);
  116.           Audp.write((byte)0xF9);
  117.           Audp.write((byte)0x40);
  118.           Audp.write((byte)0x7F);
  119.           Audp.write((byte)0x00); // BindIp
  120.           Audp.write((byte)0x00);
  121.           Audp.write((byte)0x00);
  122.           Audp.write((byte)0x00);
  123.           Audp.write((byte)0x00); // BindIndex
  124.           Audp.write((byte)0x00); // Status2
  125.           Audp.write((byte)0x00); // Filler 1
  126.           Audp.write((byte)0x00);
  127.           Audp.write((byte)0x00);
  128.           Audp.write((byte)0x00);
  129.           Audp.write((byte)0x00);
  130.           Audp.write((byte)0x00);
  131.           Audp.write((byte)0x00);
  132.           Audp.write((byte)0x00);
  133.           Audp.write((byte)0x00);
  134.           Audp.write((byte)0x00);
  135.           Audp.write((byte)0x00); // Filler 11
  136.           Audp.write((byte)0x00);
  137.           Audp.write((byte)0x00);
  138.           Audp.write((byte)0x00);
  139.           Audp.write((byte)0x00);
  140.           Audp.write((byte)0x00);
  141.           Audp.write((byte)0x00);
  142.           Audp.write((byte)0x00);
  143.           Audp.write((byte)0x00);
  144.           Audp.write((byte)0x00);
  145.           Audp.write((byte)0x00); // Filler 21
  146.           Audp.write((byte)0x00);
  147.           Audp.write((byte)0x00);
  148.           Audp.write((byte)0x00);
  149.           Audp.write((byte)0x00);
  150.           Audp.write((byte)0x00);
  151.           Audp.endPacket();
  152.       }
  153.     }
  154. }
  155. int artNetOpCode(unsigned char* pbuff) {
  156.   String test = String((char*)pbuff);
  157.   if ( test.equals("Art-Net") )
  158.   {
  159.     if ( pbuff[11] >= 14 )
  160.     {            //protocol version [10] hi byte [11] lo byte
  161.       return pbuff[9] *256 + pbuff[8];  //opcode lo byte first
  162.     }
  163.   }
  164.   return 0;
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement