Advertisement
GyroGearloose

ESP8266_WebServer_and_AccessPoint_w_FastLED_v04

Feb 20th, 2016
9,370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 27.56 KB | None | 0 0
  1.  /*-----------------------------------------------------------------------------------------------------
  2.    Access Point                        Web Server  e.g.
  3.    http://192.168.4.1                  http://192.168.1.252 (depends on your network)
  4.    
  5.  
  6.    Works with generic ESP01, Huzzah, NodeMCU ESP12E, WeMos D1 Mini, and Sparkfun Thing, ;
  7.    other modules not tested yet.
  8.    Upload: Keep >Prog< pressed, press shortly >Reset<, and release >Prog<   circuit here:
  9.    http://www.esp8266.com/wiki/lib/exe/detail.php?id=getting-started-with-the-esp8266&media=esp8266_flash_prog_board_sch.png
  10.    or:  http://ediy.com.my/index.php/blog/item/133-upload-sketch-to-the-esp8266-esp-07-esp-12-using-arduino-ide
  11.    
  12.    If you run in noise / flickering issues add a 470 Ohm resistor in series to the Data Line
  13.  
  14.    v01:   webserver extended to 7 on and off switches
  15.    v02:   added demo reel. Had to declare FastLED before
  16.           the webserver. Then put the complete webserver
  17.           into a void webserver() and leave in the loop
  18.           just the case statements and the FastLEDshow.
  19.           Added power control
  20.    v02.1  changed to a drop down menu  
  21.    v02.2  Added a slider for overall brightness  // OMG how many hours ...
  22.    v03    my private extended version
  23.    v04    Combined Webserver and Access Point in one sketch
  24.  
  25.   Usage:  ACCESS Point:
  26.           After upload search with your device (Phone, Tablet, etc.) for
  27.           new WiFi. Select ESP_FastLED_Access_Point.
  28.           Open in your webbrowser the URL 192.168.4.1
  29.           Optional print a QR-Code with the URL on your lamp http://goqr.me/
  30.          
  31.           WEB SERVER:
  32.           After upload open the Serial Monitor in Arduino and see what
  33.           IP address is returned. In my case it is 192.168.1.252
  34.           Open this IP address in a browser (PC or phone)
  35.  
  36.    Gyro Gearloose J. Bruegl, Feb 2016
  37.  
  38.  
  39.    ToDo:  Create more sliders for CRGB and CHSV control
  40.  
  41. /*------------------------------------------------------------------------------------------------------
  42. HTTP 1.1 Webserver for ESP8266 adapted to Arduino IDE
  43.  
  44. From Stefan Thesen 04/2015
  45. https://blog.thesen.eu/http-1-1-webserver-fuer-esp8266-als-accesspoint/
  46. https://blog.thesen.eu/stabiler-http-1-1-wlan-webserver-mit-dem-esp8266-microcontroller/
  47.  
  48. Running stable for days                                    // in combination w FastLED I get timeouts
  49. (in difference to all samples I tried)
  50.  
  51. Does HTTP 1.1 with defined connection closing.
  52. Reconnects in case of lost WiFi.
  53. Handles empty requests in a defined manner.
  54. Handle requests for non-exisiting pages correctly.
  55.  
  56. This demo allows to switch two functions:
  57. Function 1 creates serial output and toggels GPIO2         // GPIO switch not used here
  58. Function 2 just creates serial output.
  59.  
  60. Serial output can e.g. be used to steer an attached
  61. Arduino, Raspberry etc.
  62. -----------------------------------------------------------------------------------------------------*/
  63.  
  64. // FastLED setup ----------   FastLED has to be declared BEFORE the Webserver     ---------------------
  65. #include "FastLED.h"
  66. FASTLED_USING_NAMESPACE
  67.  
  68. #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
  69. #warning "Requires FastLED 3.1 or later; check github for latest code."
  70. #endif
  71.  
  72. #define DATA_PIN      13     // for Huzzah: Pins w/o special function:  #4, #5, #12, #13, #14; // #16 does not work :(
  73. //#define CLK_PIN     12
  74. //#define LED_TYPE    APA102
  75. //#define COLOR_ORDER BGR
  76. #define LED_TYPE      WS2811
  77. #define COLOR_ORDER   GRB
  78. #define NUM_LEDS      133    
  79. CRGB leds[NUM_LEDS];
  80.  
  81. //#define BRIGHTNESS       128
  82. int BRIGHTNESS =           128;   // this is half brightness
  83. int new_BRIGHTNESS =       128;   // shall be initially the same as brightness
  84.  
  85. #define MILLI_AMPERE      2000    // IMPORTANT: set here the max milli-Amps of your power supply 5V 2A = 2000
  86. #define FRAMES_PER_SECOND  120    // here you can control the speed. With the Access Point / Web Server the
  87.                                   // animations run a bit slower.
  88.  
  89. int ledMode = 2;                  // this is the starting animation
  90.  
  91.  
  92. // Select EITHER ACCESS-Point  OR  WEB SERVER setup
  93.  
  94. // ACCESS-Point setup ------------------------------------------------------------------------------------------------------
  95. #include <ESP8266WiFi.h>
  96. // comes with Huzzah installation. Enter in Arduino settings:
  97. // http://arduino.esp8266.com/package_esp8266com_index.json
  98.  
  99. const char* ssid = "ESP_FastLED_Access_Point";
  100. const char* password = "";  // set to "" for open access point w/o password; or any other pw (min length = 8 characters)
  101.  
  102. unsigned long ulReqcount;
  103.  
  104. // Create an instance of the server on Port 80
  105. WiFiServer server(80);
  106. //IPAddress apIP(192, 168, 10, 1);                                        // if you want to configure another IP address
  107. void setup()
  108. {
  109.   // setup globals
  110.   ulReqcount=0;
  111.  
  112.   // prepare GPIO2       // not necessary for FastLED
  113.   pinMode(2, OUTPUT);
  114.   digitalWrite(2, 0);
  115.   // start serial
  116.   Serial.begin(9600);
  117.   delay(1);
  118.  
  119.   // AP mode
  120.   WiFi.mode(WIFI_AP);
  121. //  WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));          // if you want to configure another IP address
  122.   WiFi.softAP(ssid, password);
  123.   server.begin();
  124. // end ACCESS-Point setup ---------------------------------------------------------------------------------------------------
  125.  
  126.  
  127. /*
  128. // WEB SERVER setup ---------------------------------------------------------------------------------------------------------
  129. #include <ESP8266WiFi.h>
  130. // comes with Huzzah installation. Enter in Arduino settings:
  131. // http://arduino.esp8266.com/package_esp8266com_index.json
  132.  
  133. //const char* ssid = "your WLAN Name here";  
  134. //const char* password = "Your password here";
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141. unsigned long ulReqcount;
  142. unsigned long ulReconncount;
  143.  
  144. WiFiServer server(80);  // Create an instance of the server on Port 80
  145.  
  146. void setup()
  147. {
  148.  
  149.   ulReqcount=0;         // setup globals for Webserver
  150.   ulReconncount=0;
  151.  
  152.   // prepare GPIO2      // not necessary for FastLED
  153.   pinMode(2, OUTPUT);
  154.   digitalWrite(2, 0);
  155.  
  156.   // start serial
  157.   Serial.begin(9600);
  158.   delay(1);
  159.  
  160.   // inital connect
  161.   WiFi.mode(WIFI_STA);
  162.   WiFiStart();
  163. // end WEB SERVER setup -----------------------------------------------------------------------------------------------------
  164. */
  165.  
  166. // now the settings for FastLED  
  167.   delay(2000);          // sanity delay for LEDs
  168.   FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(DirectSunlight);           // for WS2812 (Neopixel)
  169.   //FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(DirectSunlight); // for APA102 (Dotstar)
  170.   FastLED.setBrightness(BRIGHTNESS);
  171.   set_max_power_in_volts_and_milliamps(5, MILLI_AMPERE);
  172. }
  173.  
  174. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  175.  
  176. void WiFiStart()
  177. {
  178.  
  179.   // Connect to WiFi network
  180.   Serial.println();
  181.   Serial.println();
  182.   Serial.print("Connecting to ");
  183.   Serial.println(ssid);
  184.  
  185.   WiFi.begin(ssid, password);
  186.  
  187.   while (WiFi.status() != WL_CONNECTED) {
  188.     delay(500);
  189.     Serial.print(".");
  190.   }
  191.   Serial.println("");
  192.   Serial.println("WiFi connected");
  193.  
  194.   // Start the server
  195.   server.begin();
  196.   Serial.println("Server started");
  197.  
  198.   // Print the IP address
  199.   Serial.println(WiFi.localIP());
  200. }
  201.  
  202. void loop() {
  203.   webserver();
  204.  
  205.   if (ledMode != 999) {
  206.  
  207.      switch (ledMode) {
  208.       case  1: all_off(); break;
  209.       case  2: rainbow(); break;
  210.       case  3: rainbowWithGlitter(); break;
  211.       case  4: confetti(); break;
  212.       case  5: sinelon(); break;
  213.       case  6: juggle(); break;
  214.       case  7: bpm(); break;
  215.       }
  216.       }
  217.   show_at_max_brightness_for_power();
  218.   delay_at_max_brightness_for_power(1000/FRAMES_PER_SECOND);
  219. //  FastLED.show();  
  220. //  FastLED.delay(1000/FRAMES_PER_SECOND);
  221.   EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  222.  
  223. } // end of loop ************************************************************************************************************
  224.  
  225.  
  226. void webserver() {   /// complete web server (same for access point) ////////////////////////////////////////////////////////
  227.   // Check if a client has connected
  228.   WiFiClient client = server.available();
  229.   if (!client)
  230.   {
  231.     return;
  232.   }
  233.  
  234.   // Wait until the client sends some data
  235.   Serial.println("new client");
  236.   unsigned long ultimeout = millis()+250;
  237.   while(!client.available() && (millis()<ultimeout) )
  238.   {
  239.     delay(1);
  240.   }
  241.   if(millis()>ultimeout)
  242.   {
  243.     Serial.println("client connection time-out!");
  244.     return;
  245.   }
  246.  
  247.   // Read the first line of the request
  248.  
  249.   String sRequest = client.readStringUntil('\r');
  250.   Serial.println(sRequest);
  251.   client.flush();
  252.  
  253.   // stop client, if request is empty
  254.   if(sRequest=="")
  255.   {
  256.     Serial.println("empty request! - stopping client");
  257.     client.stop();
  258.     return;
  259.   }
  260.  
  261.   // get path; end of path is either space or ?
  262.   // Syntax is e.g. GET /?pin=MOTOR1STOP HTTP/1.1
  263.   String sPath="",sParam="", sCmd="";
  264.   String sGetstart="GET ";
  265.   int iStart,iEndSpace,iEndQuest;
  266.   iStart = sRequest.indexOf(sGetstart);
  267. //  Serial.print("iStart ");
  268. //  Serial.println(iStart);
  269.  
  270.   if (iStart>=0)
  271.   {
  272.     iStart+=+sGetstart.length();
  273. //  Serial.print("iStart + sGetstart ");
  274. //  Serial.println(iStart);
  275.     iEndSpace = sRequest.indexOf(" ",iStart);
  276. //  Serial.print("iEndSpace ");
  277. //  Serial.println(iEndSpace);
  278.     iEndQuest = sRequest.indexOf("?",iStart);
  279. //  Serial.print("iEndQuest ");
  280. //  Serial.println(iEndQuest);    
  281.     // are there parameters?
  282.     if(iEndSpace>0)
  283.     {
  284.       if(iEndQuest>0)
  285.       {
  286.         // there are parameters
  287.         sPath  = sRequest.substring(iStart,iEndQuest);
  288.         sParam = sRequest.substring(iEndQuest,iEndSpace);
  289.       }
  290.       else
  291.       {
  292.         // NO parameters
  293.         sPath  = sRequest.substring(iStart,iEndSpace);
  294.       }
  295.     }
  296.   }
  297.  
  298.   //////////////////////////////////////////////////////////////////////////////////
  299.   // output parameters to serial, you may connect e.g. an Arduino and react on it //
  300.   //////////////////////////////////////////////////////////////////////////////////
  301.   if(sParam.length()>0)
  302.   {
  303.     int iEqu=sParam.indexOf("=");
  304.     if(iEqu>=0)
  305.     {
  306.       sCmd = sParam.substring(iEqu+1,sParam.length());
  307.       Serial.print("We are in output Parameters, value is: ");
  308.       Serial.println(sCmd);
  309.       char carray[4];                                // values 0..255 = 3 digits; array = digits + 1
  310.       sCmd.toCharArray(carray, sizeof(carray));      // convert char to the array
  311.       new_BRIGHTNESS = atoi(carray);                 // atoi() converts an ascii character array to an integer
  312.       if (new_BRIGHTNESS == 0) {new_BRIGHTNESS = BRIGHTNESS; }   // if something else is selected (no change in brightness)
  313.       BRIGHTNESS = new_BRIGHTNESS;                 // works not this way
  314.          FastLED.setBrightness(new_BRIGHTNESS);      // that's how the new value is assigned  
  315.       Serial.print("new Brightness: ");
  316.       Serial.println(new_BRIGHTNESS);
  317.     }
  318.   }
  319.  
  320.   //////////////////////////////
  321.   // format the html response //
  322.   //////////////////////////////
  323.   String sResponse,sHeader;
  324.  
  325.   ///////////////////////////////
  326.   // 404 for non-matching path //
  327.   ///////////////////////////////
  328.   if(sPath!="/")
  329.   {
  330.     sResponse="<html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL was not found on this server.</p></body></html>";
  331.    
  332.     sHeader  = "HTTP/1.1 404 Not found\r\n";
  333.     sHeader += "Content-Length: ";
  334.     sHeader += sResponse.length();
  335.     sHeader += "\r\n";
  336.     sHeader += "Content-Type: text/html\r\n";
  337.     sHeader += "Connection: close\r\n";
  338.     sHeader += "\r\n";
  339.   }
  340.   //////////////////////////
  341.   // format the html page //
  342.   //////////////////////////
  343.   else
  344.   {
  345.     ulReqcount++;
  346.     sResponse  = "<html><head><title>ESP_FastLED_Access_Point</title></head><body>";
  347. //    sResponse += "<font color=\"#FFFFF0\"><body bgcolor=\"#000000\">";  
  348.     sResponse += "<font color=\"#FFFFF0\"><body bgcolor=\"#151B54\">";  
  349.     sResponse += "<FONT SIZE=-1>";
  350.     sResponse += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\">";
  351.     sResponse += "<h1>ESP FastLED DemoReel 100<br>";
  352.     sResponse += " Light Controller</h1>";
  353.  
  354. /*  this creates a list with ON / OFF buttons
  355.     // &nbsp is a non-breaking space; moves next character over
  356.     sResponse += "<p>Rainbow &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION1ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION1OFF\"><button>--OFF--</button></a><br>";
  357.     sResponse += "<p>Rainbow Glitter<a href=\"?pin=FUNCTION2ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION2OFF\"><button>--OFF--</button></a><br>";
  358.     sResponse += "<p>Confetti &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION3ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION3OFF\"><button>--OFF--</button></a><br>";
  359.     sResponse += "<p>Sinelon &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION4ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION4OFF\"><button>--OFF--</button></a><br>";
  360.     sResponse += "<p>Juggle&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION5ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION5OFF\"><button>--OFF--</button></a></p>";
  361.     sResponse += "<p>BPM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION6ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION6OFF\"><button>--OFF--</button></a></p>";
  362.     sResponse += "<p>Function 7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION7ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION7OFF\"><button>--OFF--</button></a></p><br>";
  363. */
  364. //  This is a nice drop down menue
  365.     sResponse += "<FONT SIZE=+1>";
  366.     sResponse += "<form>";
  367. //    sResponse += "Select Animation<br>";
  368.     sResponse += "<p>Select:</p>";
  369.     sResponse += "<select name=\"sCmd\" size=\"7\" >";
  370.     sResponse += "<option value=\"FUNCTION1OFF\">All OFF</option>";
  371.     sResponse += "<option value=\"FUNCTION1ON\"selected>Rainbow</option>";
  372.     sResponse += "<option value=\"FUNCTION2ON\">Rainbow Glitter</option>";
  373.     sResponse += "<option value=\"FUNCTION3ON\">Confetti</option>";
  374.     sResponse += "<option value=\"FUNCTION4ON\">Sinelon</option>";
  375.     sResponse += "<option value=\"FUNCTION5ON\">Juggle</option>";
  376.     sResponse += "<option value=\"FUNCTION6ON\">BPM</option><br>";
  377.     sResponse += "</select>";
  378.     sResponse += "<br><br>";
  379.     sResponse += "<input type= submit>";
  380.     sResponse += "</form>";
  381. //    sResponse += "<FONT SIZE=-1>";
  382.  
  383. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  384. // Slider          this works, however I got http://192.168.4.1/sCmd?FUNCTION_200=80  and the page was not found
  385. //                 I needed to take the FUNCTION_200=80 apart and call only FUNCTION_200 and assign
  386. //                 the value (=80) in "react on parameters" (line 512) to new_BRIGHTNESS
  387.  
  388. sResponse += "</p>";
  389. sResponse += "<form action=\"?sCmd\" >";    // ?sCmd forced the '?' at the right spot  
  390. sResponse += "<BR>Brightness &nbsp;&nbsp";  // perhaps we can show here the current value
  391. sResponse += round(new_BRIGHTNESS /2.5);    // this is just a scale depending on the max value; round for better readability
  392. sResponse += " %";
  393. sResponse += "<BR>";
  394. sResponse += "<input style=\"width:200px; height:50px\" type=\"range\" name=\"=FUNCTION_200\" id=\"cmd\" value=\"";   // '=' in front of FUNCTION_200 forced the = at the right spot
  395. sResponse += BRIGHTNESS;
  396. sResponse += "\" min=10 max=250 step=10 onchange=\"showValue(points)\" />";
  397. sResponse += "<BR><BR>";
  398. sResponse += "<input type=\"submit\">";
  399. sResponse += "</form>";
  400. sResponse += "<p>";
  401. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  402.  
  403.  sResponse += "<FONT SIZE=-1>";
  404.  
  405.  
  406.     /////////////////////////
  407.     // react on parameters //
  408.     /////////////////////////
  409.     if (sCmd.length()>0)
  410.     {
  411.       // write received command to html page
  412.  //     sResponse += "Command: " + sCmd + "<BR>";
  413.      
  414.       // switch the animiation (based on your choice in the case statement (main loop)
  415.       if(sCmd.indexOf("FUNCTION1ON")>=0)
  416.       {
  417.         Serial.println("1 ON");
  418.         ledMode = 2;
  419.       }
  420.       else if(sCmd.indexOf("FUNCTION1OFF")>=0)
  421.       {
  422.         Serial.println("1 OFF");
  423.         ledMode = 1;
  424.       }
  425.  
  426.       if(sCmd.indexOf("FUNCTION2ON")>=0)
  427.       {
  428.          Serial.println("2 ON");
  429.         ledMode = 3;
  430.       }
  431.       else if(sCmd.indexOf("FUNCTION2OFF")>=0)
  432.       {
  433.         Serial.println("2 OFF");
  434.         ledMode = 1;
  435.       }
  436.  
  437.       if(sCmd.indexOf("FUNCTION3ON")>=0)
  438.       {
  439.         Serial.println("3 ON");
  440.         ledMode = 4;
  441.  
  442.       }
  443.       else if(sCmd.indexOf("FUNCTION3OFF")>=0)
  444.       {
  445.         Serial.println("3 OFF");
  446.         ledMode = 1;
  447.  
  448.       }
  449.       if(sCmd.indexOf("FUNCTION4ON")>=0)
  450.       {
  451.         Serial.println("4 ON");
  452.         ledMode = 5;
  453.  
  454.       }
  455.       else if(sCmd.indexOf("FUNCTION4OFF")>=0)
  456.       {
  457.         Serial.println("4 OFF");
  458.         ledMode = 1;
  459.  
  460.       }
  461.       if(sCmd.indexOf("FUNCTION5ON")>=0)
  462.       {
  463.          Serial.println("5 ON");
  464.         ledMode = 6;
  465.  
  466.       }
  467.       else if(sCmd.indexOf("FUNCTION5OFF")>=0)
  468.       {
  469.         Serial.println("5 OFF");
  470.         ledMode = 1;
  471.  
  472.       }
  473.  
  474.       if(sCmd.indexOf("FUNCTION6ON")>=0)
  475.       {
  476.          Serial.println("6 ON");
  477.         ledMode = 7;
  478.  
  479.       }
  480.       else if(sCmd.indexOf("FUNCTION6OFF")>=0)
  481.       {
  482.         Serial.println("6 OFF");
  483.         ledMode = 1;
  484.  
  485.       }
  486.       if(sCmd.indexOf("FUNCTION7ON")>=0)
  487.       {
  488.         Serial.println("7 ON");
  489.         ledMode = 8;
  490.  
  491.       }
  492.       else if(sCmd.indexOf("FUNCTION7OFF")>=0)
  493.       {
  494.          Serial.println("7 OFF");
  495.         ledMode = 1;
  496.  
  497.       }
  498.  
  499. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  500. // oh well, I was a bit frustrated. Came up with the idea to make
  501. // 10 digits increments and let the URL (not) react on it.
  502. // However, I was able to assign a new_BRIGHTNESS value;
  503. // what after all serves the purpose. Maybe someone comes up with
  504. // a more ellegant way - HOPEFULLY
  505. // (more than 400 have downloaded my code but nobody felt the need  
  506. // to help. wtf - this is my very first attempt on HTML !
  507. // Guys, I'm a simple electrician, so PLEASE help  :(          )
  508.  
  509. // do not call a new page when the slider is moved, but assign the new value
  510. // to BRIGHTNESS (this is done in "output parameters to serial", line 314
  511.  
  512.       if(sCmd.indexOf("FUNCTION_200=20")>=0) { }
  513.       if(sCmd.indexOf("FUNCTION_200=30")>=0) { }
  514.       if(sCmd.indexOf("FUNCTION_200=40")>=0) { }
  515.       if(sCmd.indexOf("FUNCTION_200=50")>=0) { }
  516.       if(sCmd.indexOf("FUNCTION_200=60")>=0) { }
  517.       if(sCmd.indexOf("FUNCTION_200=70")>=0) { }
  518.       if(sCmd.indexOf("FUNCTION_200=80")>=0) { }
  519.       if(sCmd.indexOf("FUNCTION_200=90")>=0) { }
  520.       if(sCmd.indexOf("FUNCTION_200=100")>=0) { }
  521.       if(sCmd.indexOf("FUNCTION_200=110")>=0) { }
  522.       if(sCmd.indexOf("FUNCTION_200=120")>=0) { }
  523.       if(sCmd.indexOf("FUNCTION_200=130")>=0) { }
  524.       if(sCmd.indexOf("FUNCTION_200=140")>=0) { }
  525.       if(sCmd.indexOf("FUNCTION_200=150")>=0) { }
  526.       if(sCmd.indexOf("FUNCTION_200=160")>=0) { }
  527.       if(sCmd.indexOf("FUNCTION_200=170")>=0) { }
  528.       if(sCmd.indexOf("FUNCTION_200=180")>=0) { }
  529.       if(sCmd.indexOf("FUNCTION_200=190")>=0) { }
  530.       if(sCmd.indexOf("FUNCTION_200=200")>=0) { }
  531.       if(sCmd.indexOf("FUNCTION_200=210")>=0) { }
  532.       if(sCmd.indexOf("FUNCTION_200=220")>=0) { }
  533.       if(sCmd.indexOf("FUNCTION_200=230")>=0) { }
  534.       if(sCmd.indexOf("FUNCTION_200=240")>=0) { }
  535.       if(sCmd.indexOf("FUNCTION_200=250")>=0) { }
  536. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  537.  
  538.     } // end sCmd.length()>0
  539.    
  540.    
  541. //    sResponse += "<FONT SIZE=-2>";
  542. //    sResponse += "<BR>clicks on page =";
  543. //    sResponse += ulReqcount;
  544.     sResponse += "<BR>";
  545.     sResponse += "<BR>";
  546.     sResponse += "Powered by FastLED<BR><BR>";
  547.     sResponse += "<FONT SIZE=-2>";
  548.     sResponse += "<font color=\"#FFDE00\">";
  549.     sResponse += "DemoReel 100 by Mark Kriegsman<BR>";
  550.     sResponse += "Webserver by Stefan Thesen<BR>";
  551.     sResponse += "<font color=\"#FFFFF0\">";
  552.     sResponse += "Gyro Gearloose &nbsp;&nbsp;Feb 2016<BR>";
  553.     sResponse += "</body></html>";
  554.     sHeader  = "HTTP/1.1 200 OK\r\n";
  555.     sHeader += "Content-Length: ";
  556.     sHeader += sResponse.length();
  557.     sHeader += "\r\n";
  558.     sHeader += "Content-Type: text/html\r\n";
  559.     sHeader += "Connection: close\r\n";
  560.     sHeader += "\r\n";
  561.   }
  562.  
  563.   // Send the response to the client
  564.   client.print(sHeader);
  565.   client.print(sResponse);
  566.  
  567.  
  568.   // and stop the client
  569.   client.stop();
  570.   Serial.println("Client disonnected");  
  571.   }  // end of web server
  572.  
  573. /// END of complete web server //////////////////////////////////////////////////////////////////
  574.  
  575. // LED animations ###############################################################################
  576. void all_off() {
  577.   fill_solid(leds, NUM_LEDS, CRGB::Black);
  578. //  show_at_max_brightness_for_power();
  579. //  delay_at_max_brightness_for_power(1000/FRAMES_PER_SECOND);  
  580.   FastLED.show();
  581.   FastLED.delay(1000/FRAMES_PER_SECOND);
  582. }
  583.  
  584. void rainbow()
  585. {
  586.   // FastLED's built-in rainbow generator
  587.   EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  588.   fill_rainbow( leds, NUM_LEDS, gHue, 7);
  589.   show_at_max_brightness_for_power();
  590.   delay_at_max_brightness_for_power(1000/FRAMES_PER_SECOND);
  591. //  FastLED.show();  
  592. //  FastLED.delay(1000/FRAMES_PER_SECOND);
  593. }
  594.  
  595. void rainbowWithGlitter()
  596. {
  597.   // built-in FastLED rainbow, plus some random sparkly glitter
  598.   rainbow();
  599.   addGlitter(80);
  600. }
  601.  
  602. void addGlitter( fract8 chanceOfGlitter)
  603. {
  604.   if( random8() < chanceOfGlitter) {
  605.     leds[ random16(NUM_LEDS) ] += CRGB::White;
  606.   }
  607. }
  608.  
  609. void confetti()
  610. {
  611.   // random colored speckles that blink in and fade smoothly
  612.   fadeToBlackBy( leds, NUM_LEDS, 10);
  613.   int pos = random16(NUM_LEDS);
  614.   leds[pos] += CHSV( gHue + random8(64), 200, 255);
  615.   show_at_max_brightness_for_power();
  616.   delay_at_max_brightness_for_power(1000/FRAMES_PER_SECOND);
  617. //  FastLED.show();  
  618. //  FastLED.delay(1000/FRAMES_PER_SECOND);
  619. }
  620.  
  621. void sinelon()
  622. {
  623.   // a colored dot sweeping back and forth, with fading trails
  624.   fadeToBlackBy( leds, NUM_LEDS, 20);
  625.   int pos = beatsin16(13,0,NUM_LEDS);
  626.   leds[pos] += CHSV( gHue, 255, 192);
  627.   show_at_max_brightness_for_power();
  628.   delay_at_max_brightness_for_power(1000/FRAMES_PER_SECOND);
  629. //  FastLED.show();  
  630. //  FastLED.delay(1000/FRAMES_PER_SECOND);
  631. }
  632.  
  633. void bpm()
  634. {
  635.   // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
  636.   uint8_t BeatsPerMinute = 62;
  637.   CRGBPalette16 palette = PartyColors_p;
  638.   uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  639.   for( int i = 0; i < NUM_LEDS; i++) { //9948
  640.     leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  641.   }
  642.   show_at_max_brightness_for_power();
  643.   delay_at_max_brightness_for_power(1000/FRAMES_PER_SECOND);
  644. //  FastLED.show();  
  645. //  FastLED.delay(1000/FRAMES_PER_SECOND);
  646. }
  647.  
  648. void juggle() {
  649.   // eight colored dots, weaving in and out of sync with each other
  650.   fadeToBlackBy( leds, NUM_LEDS, 20);
  651.   byte dothue = 0;
  652.   for( int i = 0; i < 8; i++) {
  653.     leds[beatsin16(i+7,0,NUM_LEDS)] |= CHSV(dothue, 200, 255);
  654.     dothue += 32;
  655.   }
  656.   show_at_max_brightness_for_power();
  657.   delay_at_max_brightness_for_power(1000/FRAMES_PER_SECOND);
  658. //  FastLED.show();  
  659. //  FastLED.delay(1000/FRAMES_PER_SECOND);
  660. }
  661. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  662. /*  HTML code to try changes on w3schools.com  http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_a_href
  663.  
  664. copy this pure HTML code and see how it looks before you upload the code to your ESP
  665. However, as we create a text with sResponse += in the normal HTML code \" have to be added at the right places.
  666. Believe me, there is a lot of trial and error involved ....
  667.  
  668. <!DOCTYPE html>
  669. <html>
  670. <font color =   #fffff0><body bgcolor=\"#000000\">   //FFFFFF0 has to be written in fffff0
  671. <FONT SIZE=-1>
  672. <h1>ESP8266 control <br>
  673. for DemoReel100</h1>
  674. <body>
  675.  
  676. <p>Rainbow &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION1ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION1OFF\"><button>--OFF--</button></a><br>
  677.  
  678. <p>Rainbow Glitter<a href=\"?pin=FUNCTION2ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION2OFF\"><button>--OFF--</button></a><br>
  679.  
  680. <p>Confetti &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION3ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION3OFF\"><button>--OFF--</button></a><br>
  681.  
  682. <p>Sinelon &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION4ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION4OFF\"><button>--OFF--</button></a><br>
  683.  
  684. <p>Juggle&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION5ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION5OFF\"><button>--OFF--</button></a></p>
  685.  
  686. <p>BPM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION6ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION6OFF\"><button>--OFF--</button></a></p>
  687.  
  688. <p>Function 7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION7ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION7OFF\"><button>--OFF--</button></a></p><br>
  689.  
  690. <FONT SIZE=+1>
  691. <form>
  692. <p>Select Animation</p>
  693. <select name=\"sCmd\" size=\"7\" >
  694. <option value=\"FUNCTION1OFF\"selected>All OFF</option>
  695. <option value=\"FUNCTION1ON\">Rainbow</option>
  696. <option value=\"FUNCTION2ON\">Rainbow Glitter</option>
  697. <option value=\"FUNCTION3ON\">Confetti</option>
  698. <option value=\"FUNCTION4ON\">Sinelon</option>
  699. <option value=\"FUNCTION5ON\">Juggle</option>
  700. <option value=\"FUNCTION6ON\">BPM</option><br>
  701. </select>
  702. <br><br>
  703. <input type= submit>
  704. </form>
  705. <FONT SIZE=-1>
  706.  
  707. <FONT SIZE=-2>
  708. <BR>clicks on page =
  709.  - connections to page =
  710. <BR>
  711. <font color= #ff0000>
  712. DemoReel 100 by Mark Kriegsman<BR>
  713. Webserver by Stefan Thesen<BR>
  714.  
  715. </body>
  716. </html>
  717.  
  718. // slider
  719. <html>
  720.  
  721.  
  722.    <title>BRIGHTNESS</title></head>
  723.    <body><center><h1>Brightness</h1></center>
  724.    <br /><br />
  725.    <form action="/" name="dimmer" oninput="outputUpdate(cmd.value"
  726.                      method="POST">
  727.    <font color=red><b>ON </b></font><input style="width:550px; height:50px"
  728.                      type="range" name="cmd" id="cmd" value="
  729.    status
  730.    " min=1 max=128 step=1 />
  731.    <font color=red><b>OFF</b></font></form>
  732.    <br><center>Dimmer Value: <b>        
  733.       status
  734.        pts</b></center>
  735.    <script type="text/javascript">
  736.    function outputUpdate(dim {document.query}Selector("#cmd".value = dim;)
  737.    document.forms[0].submit();}</script>
  738.    </body></html>
  739.  
  740.  
  741. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement