timfield

Untitled

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