Artnet Protocol Blynk controller

Artnet is basically a top end ethernet dmx transmitting protocol using Udp.[Wiki]
This project is based on standalone ESP12’s. I started out experimenting with an Android Artnet controller, but then thought that for less complex control it might be nice to have Blynk sending out Artnet info.
Since each Artnet ‘universe’ can control 512 channels, this setup could be handy for controlling multiple lighting, or anything that needs controlling.

The quick youtube video shows one ESP Blynk’d device receiving Blynk rgb, brightness and device selection data. This data is used to send out up to 512 channels of 0-255 data in the Arnet format. It does this on the Artnet port 6454 Udp.

Four separate ESP’s set to individual channels, receive this data, and deal with it as required. In this case I have WS2812’s on each device ( including the ‘server’). The devices can be separately controlled or in any combination. Each device deals takes 4 channels, and could equally generate SPI, PWM etc.
I have other buttons and a terminal on the controller ready for two way communication status when I get to it.

It’s fast, although only really suitable for local server use. If it could be of interest I can post up code, after I have tidied it up, of course!

The shot of the laptop shows WireShark (free) monitoring UDP traffic and picking up the ArtNet send / recieve data. The ArtNet protocol is decoded by WireShark, so all (up to 512 channels) data is shown in a separate block. The 4 ESP’s are programmed to send back identifying data after receiving data, and all that is handled with ease.
Might be food for thought for someone.

short video

4 Likes

Super! @vshymanskyy have a look

Wow, cool stuff! :pray:
Would love to post on our FB later today

No problem. All for the good!

Did you ever publish the code?
It would be interesting…
I am trying to make slow moving lights and this would be helpful.
// Micki

Hi odzic,
Hmmmm, after finding the code I wrote, (never actually getting around to tidying up), I think it would be too confusing for anyone reading it! It included many other processes which were not included in the main process functions. It was at a stage when I was trying out and learning what could or could not be done.

Artnet itself is not really that clever, just a protocol that everyone has agreed on as a method of transmitting the required dmx data. It functions using UDP on a particular port, sending a defined packet header along with 512 bytes of 0-255 data. Sure, it’s fast and works, but unless you are going to use ‘artnet’ enabled devices or arnet apps etc, you might as well use your own UDP transmission. (An arduino UDP library is available). You can, for instance, control milight devices using this protocol.

All I did was to use the artnet defined header along with some data, and used the UDP library process to send that out. The recieving end accepted and decoded the header, so that the channel levels could be extracted and used to control what I wanted. This meant, that if desired, a standard artnet app could also be used.

Do you mean you want servo controlled moving lights, or control of lighting colour etc?
If you can expand on what you want to achieve, then maybe something I have may be of use to you?

Thanks for spending time to explain it to me. I am using servo and steppers to make a moving lights. I still haven’t find anywhere where I can find the code for it. I might get it from my brother in law soon though. If you still have your code, even if its a mess please post it. Thanks!

Ok… found what I did back then, and you are welcome to have whatever I have on it. It will take a bit of reading, but hopefully some of it may make sense!
There is quite a lot out there regarding Artnet which should also help.
I started by using an android App called Art-Net Conroller by Litux , which also has fixture libraries. This allowed me to view the actual UDP data format which is transmitted. I used Wireshark to monitor it.
From there I then used esp’s to receive this UDP data and control lights etc. Having then got an understanding I used Blynk as the actual controller.
Blynk would control an esp, which then sent actual Art-Net data out via UDP to ‘receivers’.
Note that the Art-Net port is 6454, although I might have well used different port numbers in my programs.
I also used the ‘broadcast’ format of n.n.n.255, which is not considered best when running on an already occupied network. Normally Art-Net is used in a standalone network structure.
Anyway here are some codes to take a look at …

// This is a trial for the UDP artnet server.



// This is a trial for spi controlled 5204 10K pots
// mqtt connect removed by comments in loop
// run spi at 1Mhz
// port 16 used as CS.
// low to get data in then high to send data to pot.
// V20 slider is used to control pots.


//* A simplified version of work begun by Tzapu and chriscook8
//*for saving local WiFi SSID and Passwords to the ESP8266.
//*This is further adaption of this to include server and auth code input.

// DHT11 seems to work fine... single port pin 4 used.

// Want to try SPI port .... what pins are use on 12E?



// ok... working from start reading flash.
// need a pin pull down at startup to set into ap mode for new variables input.
// pull pin2 low just after a reset (not at same time but within one second to clear ssid etc and start ap)
// entering server ip on ap webpage as 1.1.1.1 will connect to Blynk cloud.
// ap address is standard 192.168.4.1
// any other will be a local server connection.
// copy and paste auth code from Blynk project.
// reset after  to re-connect
// 

// working now tdonehat data is pulled from flash rather than relying on global variables.
// following just for info.
//IPAddress server_ip (10, 0, 0, 10);

// ///Mac address should be different for each device in your LAN
//byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
//IPAddress arduino_ip ( 10,   0,   0,  20);
//IPAddress dns_ip     (  8,   8,   8,   8);
//IPAddress gateway_ip ( 10,   0,   0,   1);
//IPAddress subnet_mask(255, 255, 255,   0);

//void setup()
//{
//  Serial.begin(9600);
//  Blynk.begin(auth, server_ip, 8442, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
  // Or like this:
  //Blynk.begin(auth, "cloud.blynk.cc", 8442, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);

// problem with parsing server ip overcome using the above method


#include <EEPROM.h>
#include "ESP8266WiFi.h"
#include <ESP8266mDNS.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp8266.h>
#include<SimpleTimer.h> 
#include <DHT.h>
#include <SPI.h>
#include <PubSubClient.h>
#include <WifiUdp.h>
#include <RgbColor.h>
#include <NeoPixelBus.h>

WiFiClient espClient;
PubSubClient client(espClient);
#define pixelCount 4


long lastMsg = 0;
char msg[50];
int value = 0;


DHT dht(4, DHT11,11);
MDNSResponder mdns;
WiFiServer server(80);
//char auth[] = "4.........."; // local server token 
//char auth[] = "8.................."; // Blynk token "YourAuthToken"
const char* APssid = "ESP8266"; // Name of access point
const char* servAuth; 
const char* servi ;
const char* mypass;
const char* mysid;
//const char* mysid1;
String st;
String rsid;
String rpass;
String rserv;
String rkey;
String epsid;
 String eppass;
 String epserv;
 String epauth;
boolean newSSID = false;
int dimmer = 1;
String key;
int checkV0= 0;

int pwr1=0;
int pwr2=0;
int pwr3=0;
int pwr4=0;
int r1=0;
int g1=0;
int b1=0;
int red;
int green;
int blue;



WidgetLED led1(0);

WidgetLCD lcd(6);
int pos = 0;
int slidV20val;
const int UDP_PACKET_SIZE = 512 ;
byte packetBuffer[UDP_PACKET_SIZE];
unsigned int localPort = 6454; //Artnet port     
int milight; //data to send to milight
IPAddress server_ip (0, 0, 0, 0);

IPAddress udpServer(255, 255, 255, 255);
WiFiUDP Udp;
NeoPixelBus strip = NeoPixelBus(pixelCount, 14);



void setup() {
  Serial.begin(115200);
  delay(10);
  Serial.println("Startup");
   EEPROM.begin(512);
  
  delay(1000);
  if (digitalRead(2)==0){
    eepromClearSid();
    setupAP();  
    }  
 
  eepromRead();

  int count=0;

  SPI.begin();
  WiFi.begin(mysid,mypass);     // gets from eeprom read.
  
  Serial.println(" trying wifi begin");
  
  //*****************************************************************
  
   pinMode(5,OUTPUT);
  pinMode(2,OUTPUT);
  digitalWrite(2,HIGH);
  pinMode(16,OUTPUT);
  digitalWrite(16,HIGH);
  strip.Begin();
  strip.Show();
 
  
  
  
  
  // Need to fill first part of packetBuffer with art net stuff
  // up to byte 18 (channel 1)
 // A R T - N E T   ..bytes 0-7
 // 0h  50h         .. bytes 8 9 ..Opcode
 // 0h  0eh         .. bytes 10 11 .. Pro Ver
 // 0h              .. bytes 12    sequence
 // 0h              .. byte  13    physical
 // 0h  0h          .. bytes 14 15 universe
 // nnh  nnh        .. bytes 16 17 datalength (number channels)

    packetBuffer[0]=0x41;
    packetBuffer[1]=0x72;
    packetBuffer[2]=0x74;
    packetBuffer[3]=0x2d;
    packetBuffer[4]=0x4e;
    packetBuffer[5]=0x65;
    packetBuffer[6]=0x74;
    packetBuffer[7]=0;
    packetBuffer[8]=0;
    packetBuffer[9]=0x50;
    packetBuffer[10]=0; 
    packetBuffer[11]=0x0e;
    packetBuffer[12]=0;
    packetBuffer[13]=0;
    packetBuffer[14]=0;
    packetBuffer[15]=0;
    packetBuffer[16]=0;
    packetBuffer[17]=0x40; // will be sending 64 channels
 
  
  
  
  if ( testWifi()) { 
      
   //****************************************
    // string epserv in the form of xxx#xxx$xxx%xxx*
          //need to extract each number string, convert to value, and put into server_ip
          String ip_one;
          String ip_two;
          String ip_three;
          String ip_four;
           
           ip_one=epserv.substring(0,epserv.indexOf('#'));
           ip_two=epserv.substring(epserv.indexOf('#')+1,epserv.indexOf('$'));
           ip_three=epserv.substring(epserv.indexOf('$')+1,epserv.indexOf('%'));
           ip_four=epserv.substring(epserv.indexOf('%')+1,epserv.indexOf('*'));
          
          Serial.println(ip_one);
          Serial.println(ip_two);
          Serial.println(ip_three);
          Serial.println(ip_four);
          
          server_ip[0]= ip_one.toInt();
          server_ip[1]= ip_two.toInt();
          server_ip[2]= ip_three.toInt();
          server_ip[3]= ip_four.toInt();
           
                           
         
           Serial.println ("Blynk begin?");
          
          
           if (server_ip[0]==1 && server_ip[1]==1 && server_ip[2]==1 && server_ip[3]==1) 
           {
           Serial.print("going Cloud");
           Blynk.config(servAuth);
           bool result = Blynk.connected();
          Serial.print(result);
          if (!result){digitalWrite(2,LOW);}
               }
           else
          {
           Serial.println("going local");
           Serial.println(server_ip);
           Blynk.begin(servAuth,mysid,mypass,server_ip); 
          bool result = Blynk.connected();
          Serial.print(result);
          if (!result){digitalWrite(2,LOW);}
          client.setServer("192.168.1.162", 1883);
          client.setCallback(callback);
          
          
          } 
           
           
          return;
          }
 
  //****************************************************************
  
  
  
  
  
  
  // otherwise, set up an access point to input SSID and password     
  else
    {  Serial.println("");
      Serial.println("Connect timed out, opening AP"); 
      setupAP();   }



 dht.begin();


//********** end of setup
}


void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();

  // Switch on the LED if an 1 was received as first character
 //*** if ((char)payload[0] == '1') {
 //***   digitalWrite(BUILTIN_LED, LOW);   // Turn the LED on (Note that LOW is the voltage level
    // but actually the LED is on; this is because
    // it is acive low on the ESP-01)
//***  } else {
//***    digitalWrite(BUILTIN_LED, HIGH);  // Turn the LED off by making the voltage HIGH
//  }

}
void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("ESP8266Client")) {
      Serial.println("connected");
      // Once connected, publish an announcement...
      client.publish("outTopic", "hello world");
      // ... and resubscribe
      client.subscribe("inTopic");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}












int testWifi(void) {
  long Timeout = (millis() + 10000);
  
  Serial.print("Waiting for Wifi to connect. ");  
  while (millis() < Timeout){
    delay(500);
    Serial.print(".");
    if (WiFi.status() == WL_CONNECTED) {
      Serial.println("");
      Serial.println("WiFi connected.");
      return(1); 
    }
  }      
  
  ESP.restart();
  //return(0);
} 

void launchWeb(int webtype) {
    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println(WiFi.localIP());
    Serial.println(WiFi.softAPIP());
    
   digitalWrite(2,LOW);
   delay(1000);
   digitalWrite(2,HIGH);
    
    
    
    // Start the server
    server.begin();
    Serial.println("Server started");   
    int b = 20;
    int c = 0;
    while(b == 20) { 
       b = mdns1(webtype);

       //If a new SSID and Password were sent, close the AP, and connect to local WIFI
       if (newSSID == true){
          newSSID = false;

          Serial.println ("reading eeprom");
          eepromRead();
          
          Serial.println("Connecting to local Wifi"); //Close the AP and connect with new SSID and P/W
          WiFi.softAPdisconnect(true);
          delay(500);
                 
          Serial.println(epsid);
          Serial.println(eppass);
          Serial.println(epauth); 
          Serial.println(epserv);
          mysid = epsid.c_str();
          mypass =eppass.c_str();
          servi = epserv.c_str();
          servAuth = epauth.c_str();
          
          WiFi.begin(mysid,mypass);
       
          delay(3000);
           
          // string epserv in the form of xxx#xxx$xxx%xxx*
          //need to extract each number string, convert to value, and put into server_ip
          String ip_one;
          String ip_two;
          String ip_three;
          String ip_four;
           
           ip_one=epserv.substring(0,epserv.indexOf('#'));
           ip_two=epserv.substring(epserv.indexOf('#')+1,epserv.indexOf('$'));
           ip_three=epserv.substring(epserv.indexOf('$')+1,epserv.indexOf('%'));
           ip_four=epserv.substring(epserv.indexOf('%')+1,epserv.indexOf('*'));
          
          Serial.println(ip_one);
          Serial.println(ip_two);
          Serial.println(ip_three);
          Serial.println(ip_four);
          
          server_ip[0]= ip_one.toInt();
          server_ip[1]= ip_two.toInt();
          server_ip[2]= ip_three.toInt();
          server_ip[3]= ip_four.toInt();
           
          if ( testWifi()) {
                     
         
           Serial.println ("Blynk begin?");
          
          
           if (server_ip[0]==1 && server_ip[1]==1 && server_ip[2]==1 && server_ip[3]==1) 
           {
           Serial.print("going Cloud");
           Blynk.config(servAuth);}
           bool result = Blynk.connected();
          Serial.print(result);
          if (!result){digitalWrite(2,LOW);}
           else
          {
           Serial.println("going local");
           Serial.println(server_ip);
           Blynk.begin(servAuth,mysid,mypass,server_ip); 
           bool result = Blynk.connected();
          Serial.print(result);
          if (!result){digitalWrite(2,LOW);}
           }
            
            Udp.begin(localPort);  // begin connection
            return;
          }

         else{
            Serial.println("");
            Serial.println("New SSID or Password failed. Reconnect to server, and try again.");
            setupAP();
            return;
         }
       }
     }
}


void setupAP(void) {
  
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);
  int n = WiFi.scanNetworks();
  Serial.println("scan done");
  if (n == 0)
    Serial.println("no networks found");
  else
  {
    Serial.print(n);
    Serial.println(" networks found");
  }
  Serial.println(""); 
  st = "<ul>";
  for (int i = 0; i < n; ++i)
    {
      // Print SSID and RSSI for each network found
      st += "<li>";
      st += WiFi.SSID(i);
      st += " (";
      st += WiFi.RSSI(i);
      st += ")";
      st += (WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*";
      st += "</li>";
    }
  st += "</ul>";
  delay(100);
  WiFi.softAP(APssid);
  Serial.println("softAP");
  Serial.println("");
  launchWeb(1);
}


String urldecode(const char *src){ //fix encoding
  String decoded = "";
    char a, b;
    
  while (*src) {     
    if ((*src == '%') && ((a = src[1]) && (b = src[2])) && (isxdigit(a) && isxdigit(b))) {      
      if (a >= 'a')
        a -= 'a'-'A';       
      if (a >= 'A')                
        a -= ('A' - 10);                   
      else               
        a -= '0';                  
      if (b >= 'a')                
        b -= 'a'-'A';           
      if (b >= 'A')                
        b -= ('A' - 10);            
      else                
        b -= '0';                        
      decoded += char(16*a+b);            
      src+=3;        
    } 
    else if (*src == '+') {
      decoded += ' ';           
      *src++;       
    }  
    else {
      decoded += *src;           
      *src++;        
    }    
  }
  decoded += '\0';        
  return decoded;
}


int mdns1(int webtype){
  
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return(20);
  }
  Serial.println("");
  Serial.println("New client");

  // Wait for data from client to become available
  while(client.connected() && !client.available()){
    delay(1);
   }
  
  // Read the first line of HTTP request
  String req = client.readStringUntil('\r');
  
  // First line of HTTP request looks like "GET /path HTTP/1.1"
  // Retrieve the "/path" part by finding the spaces
  int addr_start = req.indexOf(' ');
  int addr_end = req.indexOf(' ', addr_start + 1);
  if (addr_start == -1 || addr_end == -1) {
    Serial.print("Invalid request: ");
    Serial.println(req);
    return(20);
   }
  req = req.substring(addr_start + 1, addr_end);
  Serial.print("Request: ");
  Serial.println(req);
  client.flush(); 
  String s;
  if ( webtype == 1 ) {
      if (req == "/")
      {
        IPAddress ip = WiFi.softAPIP();
        String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
        s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>";
        s += "<font face='arial,helvetica' size='7'>";
        s += "<b><label>Hello from ESP8266 at ";
        s += ipStr;
        s += "</label></b><p>";
        s += st;
        s += "<form method='get' action='a'><label>SSID: </label><input name='ssid' style='width:200px; height:60px; font-size:50px;'>   ";
        s += "<label>Password: </label><input name='pass*' style='width:200px; height:60px; font-size:50px;'>";
        s += "<p><label>Server: </label><input name='serv+' style='width:200px; height:60px; font-size:50px;'>";
        s += "<p><label>Token: </label><input name='key' style='width:300px;height:60px; font-size:50px;'>";
        s += "<p><input type='submit' style='font-size:60px'></form>";
        s += "</html>\r\n\r\n";
        Serial.println("Sending 200");
      }
      else if ( req.startsWith("/a?ssid=") ) {

        newSSID = true;
        String qsid; //WiFi SSID 
        qsid = urldecode(req.substring(8,req.indexOf('&')).c_str()); //correct coding for spaces as "+"
        Serial.println(qsid);
        Serial.println("");
        rsid = qsid;
        
        String qpass; //Wifi Password
        qpass = urldecode(req.substring(req.indexOf('*')+2,req.lastIndexOf('%')-5).c_str());//correct for coding spaces as "+"
        Serial.println(qpass);
        Serial.println("");
        rpass = qpass;
  
      
        String qserv; //Wifi server port
        
        qserv = urldecode(req.substring(req.lastIndexOf('%')+4,req.lastIndexOf('&')).c_str());//correct for coding spaces as "+"
        Serial.println(qserv);
        Serial.println("");
        rserv = qserv;

         String qkey; //Wifi auth 
        qkey = urldecode(req.substring(req.lastIndexOf('=')+1).c_str());//correct for coding spaces as "+"
        Serial.println(qkey);
        Serial.println("");
        rkey = qkey;
       
       // conversion allocation of string to const char
       // const char* conv_my_str = my_str.c_str();
        
        mysid=qsid.c_str();
        mypass=qpass.c_str();
        servi=qserv.c_str();
        servAuth = qkey.c_str();
        Serial.print("at eeprom write stage");
        Serial.println ( mysid);
        Serial.println ( mypass);
        Serial.println ( servi);
        Serial.println ( servAuth);



        String allintoEP;
         allintoEP += qsid;
         allintoEP += qpass;
         allintoEP += qserv;
         allintoEP += qkey;
               
         char epssid[allintoEP.length()];
          allintoEP.toCharArray(epssid, allintoEP.length());

         int epcount=0;
         while (epcount < allintoEP.length()){
        if (allintoEP[epcount] == 0) {allintoEP[epcount]=42;}  // puts a "*" between variables
        
         EEPROM.write(epcount,allintoEP[epcount]); 
          epcount ++;
          }
         EEPROM.commit();
     
      
      // const char* conv_my_str = my_str.c_str();
      //  servi= rserv.c_str();
        
        s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>Hello from ESP8266 ";
        s += "<p> New SSID and Password accepted</html>\r\n\r\n"; 
      }
      else
      {
        s = "HTTP/1.1 404 Not Found\r\n\r\n";
        Serial.println("Sending 404");
      }
  } 
  else
  {
      if (req == "/")
      {
        s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>Hello from ESP8266";
        s += "<p>";
        s += "</html>\r\n\r\n";
        Serial.println("Sending 200");
      }
      else
      {
        s = "HTTP/1.1 404 Not Found\r\n\r\n";
        Serial.println("Sending 404");
      }       
  }
  client.print(s);
  Serial.println("Done with client");
  return(20);
}


void eepromClearSid(){
  byte value=0;
  int count=0;  
  int len = 61;
  int addr;
  while (addr < len){
  value= 65;
  if (count ==15 || count ==30 || count == 45 || count == 60){ value=42;}
  EEPROM.write(addr,value);
  addr++;
  count++;
  }
  EEPROM.commit();
 
 }

void eepromRead() {


 epsid="";
 eppass="";
 epserv="";
 epauth="";
 String llit;
 int len = 200;
 int addr=0;
 int count=0;
 byte value; 
 byte marker=35; // "#"
 while (count < len) {
 value= EEPROM.read(addr);
 if (value != 42){ 
 epsid += char(value);} 
 count++;
 addr++;
 if (value == 42){ break; }
 }
Serial.print("epsid =");
 Serial.println(epsid);
while (count < len) {
 value= EEPROM.read(addr);
 if (value != 42){ 
 eppass += char (value);}
 count++;
 addr++;
 if (value == 42){ break; }
 }
 Serial.print("eppass =");
 Serial.println(eppass);
 
 //epserv = char(34);  //"
 while (count < len) {
 value= EEPROM.read(addr);
 if (value != 42){                  //  *
 if (value == 46){ value = marker;marker++;}     //46 = .  marker starts with # then $ then %
 epserv += char(value);}
  count++;
 addr++;
if (value == 42){ break; }
 }
  epserv += char(42);   //*
 
 
 Serial.print("epserv =");
 Serial.println(epserv);
 while (count < len) {
 value= EEPROM.read(addr);
 if (value != 42){ 
 epauth += char(value);}
  count++;
 addr++;
 if (value == 42){ break; }
 }
Serial.print("epauth =");
 Serial.println(epauth);


// mysid= fill.c_str(); assign string to const char
// const char* conv_my_str = my_str.c_str();
  mysid = epsid.c_str();
  mypass =eppass.c_str();
  servi = epserv.c_str();
  servAuth = epauth.c_str();
Serial.print("mysid=");
Serial.println(mysid);
Serial.print("mypass=");
Serial.println(mypass);
Serial.print("servi=");
Serial.println(servi);
Serial.print("servAuth=");
Serial.println(servAuth);
  
}

BLYNK_WRITE(V20){
// hopefully will read slider 3;  
String pinData = param.asStr();  // data comingin
Serial.print("Got a slider value =");
// 0 -1024 data string

slidV20val = param.asInt()/4;
const char* slid_dat =  pinData.c_str();   

Serial.println (pinData);
Serial.print ("slid_dat published data =");
Serial.println(slid_dat);
client.publish("outTopic", slid_dat);
 
 SPI.beginTransaction(SPISettings(1000000,MSBFIRST,SPI_MODE0));
  byte spidata = slidV20val; //133;
  Serial.print(spidata);
  byte spiback;
  int numdata=0;
  //while (numdata <100){ 
  // send channel number then data value:
  digitalWrite(16,LOW); //chip select low
  
  SPI.transfer(0);
  SPI.transfer(spidata);
  digitalWrite(16,HIGH);
  Serial.print("");
  digitalWrite(16,LOW);   
  SPI.transfer(1);
  SPI.transfer(spidata); 
  SPI.endTransaction();
  digitalWrite(16,HIGH); //chip cs high and transfer data 
}



BLYNK_WRITE(V1) 
{
  lcd.clear();
  int pinData = param.asInt(); 
  Blynk.virtualWrite(5,millis()/1000);
  digitalWrite(5,pinData);
  Blynk.virtualWrite(V0,pinData);
  Serial.print("Virtualport = ");
  Serial.println(pinData);
  if (pinData == 0)
  { 
    led1.off();
    }
    else
  {
  led1.on() ;
  } 
lcd.print(pos,1,"uptime");
 +pos;
 Blynk.notify("switch has been used");
} 
   
  // BLYNK_WRITE(V5)
   BLYNK_WRITE(V10)
   {
 //dimmer in this case
    dimmer = param.asInt(); 
   Serial.print("dimmer = ");
   Serial.println(dimmer);
    OutToUdp();
  }

 

   BLYNK_WRITE(V22)
  {
   
   memset(packetBuffer,0,UDP_PACKET_SIZE);
   packetBuffer[0]=0x45;
   packetBuffer[1]=0x00;
   packetBuffer[2]=0x55;
   Udp.beginPacket(udpServer, 8899);
   Udp.write(packetBuffer,UDP_PACKET_SIZE);
   Udp.endPacket();  
  }
BLYNK_WRITE(V5) {
pwr1=param.asInt();
}
BLYNK_WRITE(V6) {
pwr2=param.asInt();

}
BLYNK_WRITE(V7){
pwr3=param.asInt();

} 
BLYNK_WRITE(V8) {
pwr4=param.asInt();
}   


BLYNK_WRITE(V9)    //is rgb wigdet
{
   r1 = param[0].asInt();
   g1 = param[1].asInt();
   b1 = param[2].asInt();
   Serial.print("rgb from widget ");
   Serial.print(r1);
   Serial.print(" ");
   Serial.print(g1);
   Serial.print(" ");
   Serial.println(b1);
   
  
  OutToUdp();

}
void OutToUdp()
{
 int  r1a = (r1*1000)/(255000/dimmer);
 int  g1a = (g1*1000)/(255000/dimmer);
 int  b1a = (b1*1000)/(255000/dimmer);
   
   Serial.print("rla / dimmer ");
   Serial.print(r1a);
   Serial.print(" ");
   Serial.print(g1a);
   Serial.print(" ");
   Serial.println(b1a);
   r1a =(r1a*r1a)/255;
   g1a = (g1a*g1a)/255;
   b1a = (b1a*b1a)/255 ;
   red=r1a;
   green=g1a;
   blue=b1a;
 
 
 Serial.print("rla's x2 curve ");
   Serial.print(r1a);
   Serial.print(" ");
   Serial.print(g1a);
   Serial.print(" ");
   Serial.println(b1a);
 
 if (pwr1 == 1){
  packetBuffer[18]=r1a;
  packetBuffer[19]=g1a;
  packetBuffer[20]=b1a;}
  if (pwr2 == 1){
  packetBuffer[22]=r1a;
  packetBuffer[23]=g1a;
  packetBuffer[24]=b1a;}
   if (pwr3 == 1){
  packetBuffer[26]=r1a;
  packetBuffer[27]=g1a;
  packetBuffer[28]=b1a;}
   if (pwr4 == 1){
  packetBuffer[30]=r1a;
  packetBuffer[31]=g1a;
  packetBuffer[32]=b1a;} 
   Serial.print(" rgb sent out  ");
   Serial.print(r1a);
   Serial.print(" ");
   Serial.print(g1a);
   Serial.print(" ");
   Serial.println(b1a);
   Udp.beginPacket(udpServer, 6454);
   Udp.write(packetBuffer,UDP_PACKET_SIZE);
   Udp.endPacket();
   writeCol();

}
BLYNK_WRITE(V23)
  {
   memset(packetBuffer,0,UDP_PACKET_SIZE);
   packetBuffer[0]=0x46;
   packetBuffer[1]=0x00;
   packetBuffer[2]=0x55;
   Udp.beginPacket(udpServer, 8899);
   Udp.write(packetBuffer,UDP_PACKET_SIZE);
   Udp.endPacket();  
  }

  BLYNK_WRITE(V25) // colour slider
{
   unsigned int colData = param.asInt();
   
   memset(packetBuffer,0,UDP_PACKET_SIZE);
   packetBuffer[0]=0x40; //command change colour
   packetBuffer[1]=colData; //0x00; // colour number 0-255
   packetBuffer[2]=0x55;
   Udp.beginPacket(udpServer, 8899);
   Udp.write(packetBuffer,UDP_PACKET_SIZE);
   Udp.endPacket();  
  }

  BLYNK_WRITE(V26)
  {
    int tim = param.asInt();
     Serial.print("timer has functioned = ");
     Serial.println(tim);
     if (tim == 1)
     { 
   memset(packetBuffer,0,UDP_PACKET_SIZE);
   packetBuffer[0]=0x45;
   packetBuffer[1]=0x00;
   packetBuffer[2]=0x55;
   Udp.beginPacket(udpServer, 8899);
   Udp.write(packetBuffer,UDP_PACKET_SIZE);
   Udp.endPacket();  
     }
      else
      {
   memset(packetBuffer,0,UDP_PACKET_SIZE);
   packetBuffer[0]=0x46;
   packetBuffer[1]=0x00;
   packetBuffer[2]=0x55;
   Udp.beginPacket(udpServer, 8899);
   Udp.write(packetBuffer,UDP_PACKET_SIZE);
   Udp.endPacket();  
      }
  
  }

void writeCol()
{

  RgbColor pixelCol = RgbColor(red, green, blue);
  //    Serial.println (red);
  //    Serial.println(green);
  //    Serial.println(blue);
  for (int i = 0; i <= pixelCount - 1; i++)
  {
    strip.SetPixelColor(i, pixelCol);
  }
  strip.Show();
}






void loop() {
  // put your main code here, to run repeatedly:
   if (WiFi.status() != WL_CONNECTED) {
    ESP.restart();
   }
  Blynk.run();
  yield();
// if (server_ip[0]!=1 && server_ip[1]!=1 && server_ip[2]!=1 && server_ip[3]!=1) 
// {
// if (!client.connected()) {
 //   reconnect();
//  }
//  client.loop();
 // }


}

@Roffey could you please edit your last post so we can read the sketch.

Needs to be:
3 backticks cpp
sketch posted on next line
3 backticks on line after last line of the sketch.

Hi Costas … driving me nuts trying to format it at the moment … not taking it … but will keep trying or just delete it.

@Roffey a backtick looks like this ` and I think you are using this ’
Backticks are far right of keyboard below esc key on many keyboards but might be elsewhere on yours.

Finally this old man has found it! Sorry…

Some other files that might or might not help … used to start out with the actual Art-Net app in order to move forward into blynk…

 // works fine, now try pixel leds.
  
//  WiFi UDP Send and Receive String

 


#include <SPI.h>
#include "ESP8266WiFi.h"
#include <WiFiUdp.h>
#include <BlynkSimpleEsp8266.h>
#include <NeoPixelBus.h>
#include <RgbColor.h>
#include <ESPDMX.h>
#define pixelCount 4

int red;
int green;
int blue;

int status = WL_IDLE_STATUS;
char ssid[] = "m....."; //"TAL...."; //  your network SSID (name)
char pass[] = "ro....";  //"6....";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)

unsigned int localPort = 6454;      // local port to listen on
uint16_t dmxDataLength;
char packetBuffer[756]; //buffer to hold incoming packet
char  ReplyBuffer[] = "acknowledged";       // a string to send back

NeoPixelBus strip = NeoPixelBus(pixelCount, 14);
DMXESPSerial dmx;
WiFiUDP Udp;

void setup() {
  //Initialize serial and wait for port to open:
  pinMode(12,OUTPUT);
  pinMode(13,OUTPUT);
  pinMode(14,OUTPUT);
  analogWrite(12,1023);  // leds are tied high sided
  analogWrite(13,1023);
 // analogWrite(14,1023);
  
  dmx.init();
  
  
  analogWriteFreq(200);
  pinMode(16,OUTPUT);
   digitalWrite(16,1);
 // analogWrite(16,512);
  strip.Begin();
  strip.Show();
  
  Serial.begin(115200);
  
  
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the presence of the shield:
  

   // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid,pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();

  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  Udp.begin(localPort);
}

void writeCol()
  {
    
    RgbColor pixelCol= RgbColor(red,green,blue);
    Serial.println (red);
    Serial.println(green);
    Serial.println(blue);
     for (int i =0; i <= pixelCount-1; i++)
     {
     strip.SetPixelColor(i,pixelCol);
     }
    strip.Show(); 
  }

void dmxSend()
  {
    for(uint16_t i = 18; i<dmxDataLength+18; i++)
    { 
      byte val = packetBuffer[i];
      dmx.write(i-17,val); 
      // dmx.write(channel,value) sets up buffer   
    } 
    
      dmx.update();    
  }





void loop() {

  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remoteIp = Udp.remoteIP();
    Serial.print(remoteIp);
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    // read the packet into packetBufffer
    int len = Udp.read(packetBuffer, 756);
    if (len > 0) {
      packetBuffer[len] = 0;
    }
    Serial.println("Contents:");
    Serial.println(packetBuffer);
    dmxDataLength=(packetBuffer[17] | packetBuffer[16] <<8);
    Serial.print("dataLength = ");
    Serial.println(dmxDataLength);
    //dmx data starts at 18
    for(uint16_t i = 18; i<dmxDataLength+18; i++)
    { 
      Serial.print(packetBuffer[i],DEC);
      Serial.print(" ");
      
    }
      Serial.println("*");
      Serial.println(packetBuffer[18]);
      int data1 = 1020 -(packetBuffer[18]*4);
      int data2 = 1020 -(packetBuffer[19]*4);
      int data3 = 1020 -(packetBuffer[20]*4);
      red = packetBuffer[18];
      green= packetBuffer[19];
      blue = packetBuffer[20];
      Serial.println(data1);
      analogWrite(12,data1);
      analogWrite(13,data2);
    //    analogWrite(14,data3);
      Serial.println();
     writeCol();   // send it out in WS12 rgb led serial form
     
     // now try to write it out to dmx, say 24 channels
      dmxSend();
     
     }
}


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

******************************************************

// TODO UDP transmit of identity of each 'device'.
// will use WifiUdp.h
// at present it is used to recieve packets only.
// o.k. this will work. but onlt seen by wireshark
//when send back ip is .255 on end.i.e trnasmit to all
// when two or more sending this creates a feedback loop.
// the data must be filtered to reject any messages
// starting with R? ie response. 

// Udp.beginPacket(Udp.address), port);
// Udp.write(Reply);
// Udp.endPacket();
// char Reply has DMX number on channel n live";

//First Ip address will be the chanel number
//server_ip[0] = channel
//server_ip[1] = universe 0-3 (4 universes.)
// line 483 changed to Chan.Universe
//then use universe_ip[0] as chan number. 
// use int chanset as assigned channel
// and add to dmxpacket[17] (dmxpacket[18] = dmx chan1.

//  TODO would like to have ability to store the channle address
// channel 4 will store the rgb vales and reuse them on startup.
// need to input channel start address and universe 
// which will be MSB,LSB of 0-127,0-255.
// ie (univ 0,0 )=0 univ 1,0 = 256. 1,1 =257. 1,2 = 258.
// and channel number 1-512
// could be ip address format ie univ 0.1.4.4
//meaning  universe 0 1 start channel 4, 4 channels used. 


/*The following table shows a typical packet, ArtDMX, for transmitting lighting values. It is sent to the fixed UDP port 0x1936 (6454 decimal).

The pink portion is the same on all Art-Net packets; the green portion is variable. 
The opcode tells the recipient this is a packet containing DMX data in the data portion, intended to be output of the specified universe.
Sequence is a sequential number allowing the recipient to reorder packets to address out-of-order delivery; physical is an information packet 
showing the original   physical universe of this data, if required. Then follows up to 512 lighting values in the range 0 to 255. 
Conceptually, this packet is broadcast to all nodes; but is ignored by all nodes except the one which is configured to listen for this universe.
In practice the packet is typically unicast to the correct node.
offset (bytes)   0                1           2             3
0               'A'              'r'         't'           '-'
4               'N'              'e'         't'            0
8            Opcode ArtDMX (0x5000)          Protocol Version (14)
12           Sequence         Physical           Universe
16            Length (2 to 512, even)       Data           Data
20            Data ...
 */

// if the dmx disconnects then store the red,blue, green
// into eeprom.
// going to try and and artnetudp, dmx and neopixel  
// this will be from Artnetudp.

// trial of basic server so that routines can be added

// if port 2 held low within 1 second of start up
// then ap will be started at 192.168.1.4
// else will attempt to continually reconnect.


//* A simplified version of work begun by Tzapu and chriscook8
//*for saving local WiFi SSID and Passwords to the ESP8266.
//*This is further adaption of this to include server and auth code input.

// ok... working from start reading flash.
// need a pin pull down at startup to set into ap mode for new variables input.
// pull pin2 low just after a reset (not at same time but within one second to clear ssid etc and start ap)
// entering server ip on ap webpage as 1.1.1.1 will connect to Blynk cloud.
// ap address is standard 192.168.4.1
// any other will be a local server connection.
// copy and paste auth code from Blynk project.
// reset after  to re-connect
//

// working now tdonehat data is pulled from flash rather than relying on global variables.
// following just for info.
//IPAddress server_ip (10, 0, 0, 10);

// ///Mac address should be different for each device in your LAN
//byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
//IPAddress arduino_ip ( 10,   0,   0,  20);
//IPAddress dns_ip     (  8,   8,   8,   8);
//IPAddress gateway_ip ( 10,   0,   0,   1);
//IPAddress subnet_mask(255, 255, 255,   0);



#include <EEPROM.h>
#include "ESP8266WiFi.h"

#include <ESP8266mDNS.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp8266.h>
#include<SimpleTimer.h>
#include <SPI.h>
#include <RgbColor.h>
#include <ESPDMX.h>
#include <WiFiUdp.h>
#include <NeoPixelBus.h>







#define pixelCount 4



WiFiClient espClient;
long lastMsg = 0;
char msg[50];
int value = 0;
MDNSResponder mdns;
WiFiServer server(80);
//char auth[] = "47e...."; // local server token
//char auth[] = "88b......"; // Blynk token "YourAuthToken"
const char* APssid = "12345"; // Name of access point
const char* servAuth;
const char* servi ;
const char* mypass;
const char* mysid;
//const char* mysid1;
String st;
String rsid;
String rpass;
String rserv;
String rkey;
String epsid;
String eppass;
String epserv;
String epauth;
boolean newSSID = false;

String key;
int checkV0 = 0;
int red;
int green;
int blue;
unsigned int localPort = 6454;      // local port to listen on
uint16_t dmxDataLength;
char packetBuffer[756]; //buffer to hold incoming packet
char  ReplyBuffer[] = "acknowledged";       // a string to send back


struct pixCols {  // eeprom colour store
  int eRed;
  int eGreen;
  int eBlue;
};
int colStored = 0;
int chan4 = 0;
int colGot = 0;
int chanSet =1; // assigned by user in server_ip[0]


NeoPixelBus strip = NeoPixelBus(pixelCount, 14);
DMXESPSerial dmx;

IPAddress udpServer(255, 255, 255, 255);
WiFiUDP Udp;






IPAddress server_ip (0, 0, 0, 0);

void setup() {


  Udp.begin(localPort);

  Serial.begin(115200);
  delay(10);
  Serial.println("Startup");
  EEPROM.begin(512);

  delay(2000);
  if (digitalRead(2) == 0) {
    eepromClearSid();
    Serial.println("");
    Serial.println("Connect timed out, opening AP");
    setupAP();

  }

  // added for artnet etc

  //Initialize serial and wait for port to open:
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(14, OUTPUT);
  analogWrite(12, 1023); // leds are tied high sided
  analogWrite(13, 1023);
  // analogWrite(14,1023);

  dmx.init();


  analogWriteFreq(200);
  pinMode(16, OUTPUT);
  digitalWrite(16, 1);
  // analogWrite(16,512);
  strip.Begin();
  strip.Show();

  // above added for artnet etc






  eepromRead();

  int count = 0;

  WiFi.begin(mysid, mypass);    // gets from eeprom read.

  Serial.println(" trying wifi begin");

  //*****************************************************************

  pinMode(5, OUTPUT);
  pinMode(2, OUTPUT);
  digitalWrite(2, HIGH);
  pinMode(16, OUTPUT);
  digitalWrite(16, HIGH);

  if ( testWifi()) {

    //****************************************
    // string epserv in the form of xxx#xxx$xxx%xxx*
    //need to extract each number string, convert to value, and put into server_ip
    String ip_one;
    String ip_two;
    String ip_three;
    String ip_four;

    ip_one = epserv.substring(0, epserv.indexOf('#'));
    ip_two = epserv.substring(epserv.indexOf('#') + 1, epserv.indexOf('$'));
    ip_three = epserv.substring(epserv.indexOf('$') + 1, epserv.indexOf('%'));
    ip_four = epserv.substring(epserv.indexOf('%') + 1, epserv.indexOf('*'));

    Serial.println(ip_one);
    Serial.println(ip_two);
    Serial.println(ip_three);
    Serial.println(ip_four);

    server_ip[0] = ip_one.toInt();
    server_ip[1] = ip_two.toInt();
    server_ip[2] = ip_three.toInt();
    server_ip[3] = ip_four.toInt();
    chanSet = server_ip[0];
    return;
  }

  //****************************************************************






  // otherwise, set up an access point to input SSID and password
  //  else
  //    {  Serial.println("");
  //      Serial.println("Connect timed out, opening AP");
  //      setupAP();   }




  //********** end of setup
}




//}

int testWifi(void) {
  long Timeout = (millis() + 10000);

  Serial.print("Waiting for Wifi to connect. ");
  while (millis() < Timeout) {
    delay(500);
    Serial.print(".");
    if (WiFi.status() == WL_CONNECTED) {
      Serial.println("");
      Serial.println("WiFi connected.");
      return (1);
    }
  }
  ESP.restart();
}

void launchWeb(int webtype) {
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println(WiFi.localIP());
  Serial.println(WiFi.softAPIP());

  digitalWrite(2, LOW);
  delay(1000);
  digitalWrite(2, HIGH);



  // Start the server
  server.begin();
  Serial.println("Server started");
  int b = 20;
  int c = 0;
  while (b == 20) {
    b = mdns1(webtype);

    //If a new SSID and Password were sent, close the AP, and connect to local WIFI
    if (newSSID == true) {
      newSSID = false;

      Serial.println ("reading eeprom");
      eepromRead();

      Serial.println("Connecting to local Wifi"); //Close the AP and connect with new SSID and P/W
      WiFi.softAPdisconnect(true);
      delay(500);

      Serial.println(epsid);
      Serial.println(eppass);
      Serial.println(epauth);
      Serial.println(epserv);
      mysid = epsid.c_str();
      mypass = eppass.c_str();
      servi = epserv.c_str();
      servAuth = epauth.c_str();

      WiFi.begin(mysid, mypass);

      delay(3000);

      // string epserv in the form of xxx#xxx$xxx%xxx*
      //need to extract each number string, convert to value, and put into server_ip
      String ip_one;
      String ip_two;
      String ip_three;
      String ip_four;

      ip_one = epserv.substring(0, epserv.indexOf('#'));
      ip_two = epserv.substring(epserv.indexOf('#') + 1, epserv.indexOf('$'));
      ip_three = epserv.substring(epserv.indexOf('$') + 1, epserv.indexOf('%'));
      ip_four = epserv.substring(epserv.indexOf('%') + 1, epserv.indexOf('*'));

      Serial.println(ip_one);
      Serial.println(ip_two);
      Serial.println(ip_three);
      Serial.println(ip_four);

      server_ip[0] = ip_one.toInt();
      server_ip[1] = ip_two.toInt();
      server_ip[2] = ip_three.toInt();
      server_ip[3] = ip_four.toInt();

      if ( testWifi()) {



        return;
      }

      else {
        Serial.println("");
        Serial.println("New SSID or Password failed. Reconnect to server, and try again.");
        setupAP();
        return;
      }
    }
  }
}


void setupAP(void) {

  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);
  int n = WiFi.scanNetworks();
    Serial.println("scan done");
  if (n == 0)
    Serial.println("no networks found");
  else
  {
    Serial.print(n);
    Serial.println(" networks found");
  }
  Serial.println("");
  st = "<ul>";
  for (int i = 0; i < n; ++i)
  {
    // Print SSID and RSSI for each network found
    st += "<li>";
    st += WiFi.SSID(i);
    st += " (";
    st += WiFi.RSSI(i);
    st += ")";
    st += (WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*";
    st += "</li>";
  }
  st += "</ul>";
  delay(100);
  WiFi.softAP(APssid);
  Serial.println("softAP");
  Serial.println("");
  launchWeb(1);
}


String urldecode(const char *src) { //fix encoding
  String decoded = "";
  char a, b;

  while (*src) {
    if ((*src == '%') && ((a = src[1]) && (b = src[2])) && (isxdigit(a) && isxdigit(b))) {
      if (a >= 'a')
        a -= 'a' - 'A';
      if (a >= 'A')
        a -= ('A' - 10);
      else
        a -= '0';
      if (b >= 'a')
        b -= 'a' - 'A';
      if (b >= 'A')
        b -= ('A' - 10);
      else
        b -= '0';
      decoded += char(16 * a + b);
      src += 3;
    }
    else if (*src == '+') {
      decoded += ' ';
      *src++;
    }
    else {
      decoded += *src;
      *src++;
    }
  }
  decoded += '\0';
  return decoded;
}


int mdns1(int webtype) {

  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return (20);
  }
  Serial.println("");
  Serial.println("New client");

  // Wait for data from client to become available
  while (client.connected() && !client.available()) {
    delay(1);
  }

  // Read the first line of HTTP request
  String req = client.readStringUntil('\r');

  // First line of HTTP request looks like "GET /path HTTP/1.1"
  // Retrieve the "/path" part by finding the spaces
  int addr_start = req.indexOf(' ');
  int addr_end = req.indexOf(' ', addr_start + 1);
  if (addr_start == -1 || addr_end == -1) {
    Serial.print("Invalid request: ");
    Serial.println(req);
    return (20);
  }
  req = req.substring(addr_start + 1, addr_end);
  Serial.print("Request: ");
  Serial.println(req);
  client.flush();
  String s;
  if ( webtype == 1 ) {
    if (req == "/")
    {
      IPAddress ip = WiFi.softAPIP();
      String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
      s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>";
      s += "<font face='arial,helvetica' size='7'>";
      s += "<b><label>Hello from ESP8266 at ";
      s += ipStr;
      s += "</label></b><p>";
      s += st;
      s += "<form method='get' action='a'><label>SSID: </label><input name='ssid' style='width:200px; height:60px; font-size:50px;'>   ";
      s += "<label>Password: </label><input name='pass*' style='width:200px; height:60px; font-size:50px;'>";
      s += "<p><label>Chan.Universe: </label><input name='serv+' style='width:200px; height:60px; font-size:50px;'>";
      s += "<p><label>Token: </label><input name='key' style='width:300px;height:60px; font-size:50px;'>";
      s += "<p><input type='submit' style='font-size:60px'></form>";
      s += "</html>\r\n\r\n";
      Serial.println("Sending 200");
    }
    else if ( req.startsWith("/a?ssid=") ) {

      newSSID = true;
      String qsid; //WiFi SSID
      qsid = urldecode(req.substring(8, req.indexOf('&')).c_str()); //correct coding for spaces as "+"
      Serial.println(qsid);
      Serial.println("");
      rsid = qsid;

      String qpass; //Wifi Password
      qpass = urldecode(req.substring(req.indexOf('*') + 2, req.lastIndexOf('%') - 5).c_str()); //correct for coding spaces as "+"
      Serial.println(qpass);
      Serial.println("");
      rpass = qpass;


      String qserv; //Wifi server port

      qserv = urldecode(req.substring(req.lastIndexOf('%') + 4, req.lastIndexOf('&')).c_str()); //correct for coding spaces as "+"
      Serial.println(qserv);
      Serial.println("");
      rserv = qserv;

      String qkey; //Wifi auth
      qkey = urldecode(req.substring(req.lastIndexOf('=') + 1).c_str()); //correct for coding spaces as "+"
      Serial.println(qkey);
      Serial.println("");
      rkey = qkey;

      // conversion allocation of string to const char
      // const char* conv_my_str = my_str.c_str();

      mysid = qsid.c_str();
      mypass = qpass.c_str();
      servi = qserv.c_str();
      servAuth = qkey.c_str();
      Serial.print("at eeprom write stage");
      Serial.println ( mysid);
      Serial.println ( mypass);
      Serial.println ( servi);
      Serial.println ( servAuth);



      String allintoEP;
      allintoEP += qsid;
      allintoEP += qpass;
      allintoEP += qserv;
      allintoEP += qkey;

      char epssid[allintoEP.length()];
      allintoEP.toCharArray(epssid, allintoEP.length());

      int epcount = 0;
      while (epcount < allintoEP.length()) {
        if (allintoEP[epcount] == 0) {
          allintoEP[epcount] = 42; // puts a "*" between variables
        }

        EEPROM.write(epcount, allintoEP[epcount]);
        epcount ++;
      }
      EEPROM.commit();


      // const char* conv_my_str = my_str.c_str();
      //  servi= rserv.c_str();

      s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>Hello from ESP8266 ";
      s += "<p> New SSID and Password accepted</html>\r\n\r\n";
    }
    else
    {
      s = "HTTP/1.1 404 Not Found\r\n\r\n";
      Serial.println("Sending 404");
    }
  }
  else
  {
    if (req == "/")
    {
      s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>Hello from ESP8266";
      s += "<p>";
      s += "</html>\r\n\r\n";
      Serial.println("Sending 200");
    }
    else
    {
      s = "HTTP/1.1 404 Not Found\r\n\r\n";
      Serial.println("Sending 404");
    }
  }
  client.print(s);
  Serial.println("Done with client");
  return (20);
}


void eepromClearSid() {
  byte value = 0;
  int count = 0;
  int len = 61;
  int addr;
  while (addr < len) {
    value = 65;
    if (count == 15 || count == 30 || count == 45 || count == 60) {
      value = 42;
    }
    EEPROM.write(addr, value);
    addr++;
    count++;
  }
  EEPROM.commit();

}

void eepromRead() {


  epsid = "";
  eppass = "";
  epserv = "";
  epauth = "";
  String llit;
  int len = 200;
  int addr = 0;
  int count = 0;
  byte value;
  byte marker = 35; // "#"
  while (count < len) {
    value = EEPROM.read(addr);
    if (value != 42) {
      epsid += char(value);
    }
    count++;
    addr++;
    if (value == 42) {
      break;
    }
  }
  Serial.print("epsid =");
  Serial.println(epsid);
  while (count < len) {
    value = EEPROM.read(addr);
    if (value != 42) {
      eppass += char (value);
    }
    count++;
    addr++;
    if (value == 42) {
      break;
    }
  }
  Serial.print("eppass =");
  Serial.println(eppass);

  //epserv = char(34);  //"
  while (count < len) {
    value = EEPROM.read(addr);
    if (value != 42) {                 //  *
      if (value == 46) {
        value = marker;  //46 = .  marker starts with # then $ then %
        marker++;
      }
      epserv += char(value);
    }
    count++;
    addr++;
    if (value == 42) {
      break;
    }
  }
  epserv += char(42);   //*


  Serial.print("epserv =");
  Serial.println(epserv);
  while (count < len) {
    value = EEPROM.read(addr);
    if (value != 42) {
      epauth += char(value);
    }
    count++;
    addr++;
    if (value == 42) {
      break;
    }
  }
  Serial.print("epauth =");
  Serial.println(epauth);


  // mysid= fill.c_str(); assign string to const char
  // const char* conv_my_str = my_str.c_str();
  mysid = epsid.c_str();
  mypass = eppass.c_str();
  servi = epserv.c_str();
  servAuth = epauth.c_str();
  Serial.print("mysid=");
  Serial.println(mysid);
  Serial.print("mypass=");
  Serial.println(mypass);
  Serial.print("servi=");
  Serial.println(servi);
  Serial.print("servAuth=");
  Serial.println(servAuth);

}





void writeCol()
{

  RgbColor pixelCol = RgbColor(red, green, blue);
  //    Serial.println (red);
  //    Serial.println(green);
  //    Serial.println(blue);
  for (int i = 0; i <= pixelCount - 1; i++)
  {
    strip.SetPixelColor(i, pixelCol);
  }
  strip.Show();
}

void dmxSend()
{
  for (uint16_t i = 18; i < dmxDataLength + 18; i++)
  {
    byte val = packetBuffer[i];
    dmx.write(i - 17, val);
    // dmx.write(channel,value) sets up buffer
  }

  dmx.update();
}

void getColours() // gets colour vals from eeprom in form
{ // of 'ledColors' structure as defined
  // in variables area.
  pixCols dataget;
  EEPROM.get(128, dataget);
  red = dataget.eRed;
  green = dataget.eGreen;
  blue = dataget.eBlue;

}

void putColours()  // store the red,green blue brightness values
{
  pixCols datafill = {red, green, blue};
  EEPROM.put(128, datafill);
  EEPROM.commit();
}




void loop() {
  if (WiFi.status() != WL_CONNECTED) {
    ESP.restart();
  }
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    //  Serial.print("Received packet of size ");
    //  Serial.println(packetSize);
    //  Serial.print("From ");
    IPAddress remoteIp = Udp.remoteIP();
    //  Serial.print(remoteIp);
    //  Serial.print(", port ");
    //  Serial.println(Udp.remotePort());

    // read the packet into packetBufffer
    int len = Udp.read(packetBuffer, 756);
    if (len > 0) {
      packetBuffer[len] = 0;
    }
    // Serial.println("Contents:");
    // Serial.println(packetBuffer);
    dmxDataLength = (packetBuffer[17] | packetBuffer[16] << 8);
    // Serial.print("dataLength = ");
    //  Serial.println(dmxDataLength);
    //dmx data starts at 18
    int res = packetBuffer[0];
    if( res == 82){return;}  // ascii 82 =R
    
    for (uint16_t i = 18; i < dmxDataLength + 18; i++)
    {
      // Serial.print(packetBuffer[i],DEC);
      // Serial.print(" ");

    }
    //  Serial.println("*");
    //  Serial.println(packetBuffer[18]);
    int data1 = 1020 - (packetBuffer[17+chanSet]*4);// for pwm (packetBuffer[18] * 4);
    int data2 = 1020 - (packetBuffer[18+chanSet]*4);//(packetBuffer[19] * 4);
    int data3 = 1020 - (packetBuffer[19+chanSet]*4);//(packetBuffer[20] * 4);
    red = packetBuffer[17+chanSet]; //18 is channel 1
    green = packetBuffer[18+chanSet];
    blue = packetBuffer[19+chanSet];
    chan4 = packetBuffer[20+chanSet];  //packetBuffer[21];
    int chan5 = packetBuffer[22];
    int chan6 = packetBuffer[23];
    int chan7 = packetBuffer[24];
    int chan8 = packetBuffer[25];
    int chan9 = packetBuffer[26];
    int chan10 = packetBuffer[27];

   // Send a response
   Udp.beginPacket("192.168.1.255", localPort);
   Udp.write("R Dmx4 channel 13 universe 0 online");
   Udp.endPacket();
   Serial.print("send udp data back  ");
   Serial.print(Udp.remoteIP());
   Serial.print("  Port ");
   Serial.println(localPort);
   
    //  Serial.println(data1);
    analogWrite(12, data1);
    analogWrite(13, data2);
    //    analogWrite(14,data3);
    //  Serial.println();
    writeCol();   // send it out in WS12 rgb led serial form

    // now try to write it out to dmx, say 24 channels
    dmxSend();
    Serial.print ("Red = ");
    Serial.print (red);
    Serial.print (" Green = ");
    Serial.print (green);
    Serial.print (" Blue = ");
    Serial.println (blue);
    Serial.print (" Chan4 = ");
    Serial.println (chan4);
    Serial.print (" Chan5 = ");
    Serial.println (chan5);
    Serial.print (" Chan6 = ");
    Serial.println (chan6);
    Serial.print (" Chan7 = ");
    Serial.println (chan7);
    Serial.print (" Chan8 = ");
    Serial.println (chan8);
    Serial.print (" Chan9 = ");
    Serial.println (chan9);
    Serial.print (" Chan10 = ");
    Serial.println (chan10);

  }
  if (chan4 < 10 && colGot == 0)
  {
    getColours();
    writeCol();
    colGot = 1;
    colStored = 1;
    Serial.println("eeprom data fetch and use");
  }
  if (chan4 > 200 && colStored == 1)
  {
    putColours();
    colStored = 0;
    Serial.println("eeprom data stored");
  }
  if (chan4 < 10 && colGot == 1)
  {
    colStored = 1;
  }

}

2 Likes

While not strictly related to Blynk, there may be something in this project you can use. It is firmware for the ESP8266 that implements an ArtNet receiver (E1.31) for controlling a string of WS2812 pixels. Written for a project they call ESPixelStick using the minimalist ESP8266 hardware, I loaded it onto an E-12 from Banggood and had it up and running quickly. It includes a web interface that is really spiffy. For me, no changes were required except that there is an issue with the clock frequency on my board that results in a weird baud rate after boot so you need to use a different terminal program (I used putty) set to 115200 to find out what DHCP has given it for an IP address. The code is open so you can tinker.

PS: He wrote his own pixel driver and doesn’t use the Adafruit or FastLED libraries. Just noticed that.

1 Like