├── log.sh ├── enable_changes_to_flash.sh ├── data ├── styles.css ├── config.json ├── cache.manifest ├── index.htm └── scripts.js ├── flash.sh ├── upload_files.sh ├── README.md ├── LYTv2.ino ├── a10_globals.ino ├── a20_wifi.ino ├── a90_main.ino ├── a40_LED.ino ├── a30_webserver.ino └── LICENSE /log.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | IP="lyt8266.fritz.box" 4 | 5 | if [ $# -eq 1 ]; then 6 | IP="$1" 7 | fi 8 | 9 | watch -n1 "curl http://$IP/log 2>/dev/null | tail -n 40" 10 | -------------------------------------------------------------------------------- /enable_changes_to_flash.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | IP="lyt8266.fritz.box" 4 | 5 | if [ $# -eq 1 ]; then 6 | IP="$1" 7 | fi 8 | 9 | curl http://$IP/unlock?password=securitybyobscurity 10 | echo -------------------------------------------------------------------------------- /data/styles.css: -------------------------------------------------------------------------------- 1 | #staticcolor .sp-container { 2 | width: 100%; 3 | max-width: 450px; 4 | } 5 | 6 | #staticcolor .sp-picker-container { 7 | width: 80%; 8 | width: calc(100% - 20px); 9 | } 10 | 11 | .quickButtons { 12 | text-align: center !important; 13 | } -------------------------------------------------------------------------------- /data/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "state":"constantcolor", 3 | "remoteurl":"http://lyt.naaa.de/", 4 | "hostname":"LYT8266", 5 | "r":0, 6 | "g":255, 7 | "b":0, 8 | "hexcolor":"#00ff00", 9 | "delay_before_going_remotecontrolled":65, 10 | "send_WLAN_keep_alive_packet":true 11 | } -------------------------------------------------------------------------------- /flash.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | IP="lyt8266.fritz.box" 4 | 5 | if [ $# -eq 1 ]; then 6 | IP="$1" 7 | fi 8 | 9 | 10 | curl http://$IP/unlock?password=securitybyobscurity 11 | echo 12 | sleep 2 13 | 14 | FW="$(ls /tmp/arduino_build_*/*.bin)" && curl -F "image=@$FW" $IP/update 15 | echo 16 | -------------------------------------------------------------------------------- /data/cache.manifest: -------------------------------------------------------------------------------- 1 | CACHE MANIFEST 2 | # v14 3 | 4 | CACHE: 5 | http://lyt.naaa.de/spectrum.css 6 | http://lyt.naaa.de/jquery.mobile-1.4.5.min.js 7 | http://lyt.naaa.de/spectrum.js 8 | http://lyt.naaa.de/images/icon200x200.png 9 | http://lyt.naaa.de/images/ajax-loader.gif 10 | http://lyt.naaa.de/jquery-2.1.4.min.js 11 | http://lyt.naaa.de/jquery.mobile-1.4.5.min.css 12 | http://code.createjs.com/easeljs-0.8.2.min.js 13 | /styles.css 14 | / 15 | /index.htm 16 | /scripts.js 17 | 18 | 19 | NETWORK: 20 | /all 21 | /color 22 | /config.json 23 | /reset 24 | /state 25 | -------------------------------------------------------------------------------- /upload_files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | IP="lyt8266.fritz.box" 4 | FOLDER="data" 5 | 6 | if [ $# -eq 2 ]; then 7 | echo "uploading: /$2" 8 | IP="$1" 9 | 10 | curl http://$IP/unlock?password=securitybyobscurity 11 | echo 12 | 13 | curl -F "file=@$FOLDER/$2;filename=/$2" $IP/edit 14 | exit 15 | fi 16 | 17 | if [ $# -eq 1 ]; then 18 | IP="$1" 19 | fi 20 | 21 | curl http://$IP/unlock?password=securitybyobscurity 22 | echo 23 | 24 | for i in $(find data -type f | sed -e "s/data\///g"); do 25 | echo "uploading: /$i" 26 | curl -F "file=@$FOLDER/$i;filename=/$i" $IP/edit 27 | done 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LYT-SCRIPTED 2 | An alternative firmware for LYT8266 RGBW LED lamps 3 | 4 | Features: 5 | - Switches on almost immediatly after powering the bulb, no 500 ms delay 6 | - Does not use the regular LYT8266 library which contained a lot of code 7 | - Features an iOS Webapp Icon to give the native look and feel of an App on iOS 8 | - Nice colorpicker that automatically switches to white LEDs 9 | - can poll a webserver for colors (example JSON: http://lyt.naaa.de) 10 | - startup behaviour can be configured (Static color or polling a webserver) 11 | - uses a jQuery Mobile Interface 12 | - Several clients can control the lamp in parallel 13 | - changes to firmware are only possible after accessing a special URL 14 | - allows HTTP Update of firmware 15 | - provides a FiFo log of latest 100 Log-messages accessible at http://lyt8266/log 16 | 17 | [![IMAGE ALT TEXT](http://img.youtube.com/vi/ZmReog0DOrA/0.jpg)](http://www.youtube.com/watch?v=ZmReog0DOrA "LYT-Scripted") 18 | -------------------------------------------------------------------------------- /LYTv2.ino: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | # # 3 | # LYT-SCRIPTED, an alternative firmware for LYT8266 RGBW LED lamps # 4 | # # 5 | # # 6 | # Copyright (C) 2017 Tom Stöveken # 7 | # # 8 | # This program is free software; you can redistribute it and/or modify # 9 | # it under the terms of the GNU General Public License as published by # 10 | # the Free Software Foundation; version 2 of the License. # 11 | # # 12 | # This program is distributed in the hope that it will be useful, # 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 15 | # GNU General Public License for more details. # 16 | # # 17 | # You should have received a copy of the GNU General Public License # 18 | # along with this program; if not, write to the Free Software # 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # 20 | # # 21 | ******************************************************************************** 22 | 23 | Compiler: 24 | - Arduino 1.8.2 25 | 26 | Hardware: 27 | - LYT8266 Lamp 28 | 29 | Arduino Settings: 30 | - Generic ESP8266 Module 31 | - CPU Frequency 80 Mhz 32 | - Flash Size 1 M (64k SPIFFS) 33 | - Flash Mode is DIO 34 | - Crystal Frequency is 26 MHz 35 | Due to the limited SPIFFS, the Javascript libraries are fetched from CDN or 36 | hosted at your site if you do not like CDNs 37 | 38 | *******************************************************************************/ 39 | -------------------------------------------------------------------------------- /a10_globals.ino: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | # # 3 | # LYT-SCRIPTED, an alternative firmware for LYT8266 RGBW LED lamps # 4 | # # 5 | # # 6 | # Copyright (C) 2017 Tom Stöveken # 7 | # # 8 | # This program is free software; you can redistribute it and/or modify # 9 | # it under the terms of the GNU General Public License as published by # 10 | # the Free Software Foundation; version 2 of the License. # 11 | # # 12 | # This program is distributed in the hope that it will be useful, # 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 15 | # GNU General Public License for more details. # 16 | # # 17 | # You should have received a copy of the GNU General Public License # 18 | # along with this program; if not, write to the Free Software # 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # 20 | # # 21 | *******************************************************************************/ 22 | 23 | #include 24 | #include 25 | 26 | //determine array length 27 | #define LENGTH_OF(x) (sizeof(x)/sizeof(x[0])) 28 | 29 | /* current state of the device */ 30 | enum STATES {UNDEF=0, CONSTANTCOLOR, REMOTEURL, REMOTEURL_POSTPONED, BOOTUP, FLASH, DISCO}; 31 | struct { 32 | STATES state; 33 | String human_readable_string; 34 | String state_as_string; 35 | } state_map[] = { 36 | { UNDEF, "Undefined State", "undef" }, 37 | { CONSTANTCOLOR,"Static Color Mode", "constantcolor" }, 38 | { REMOTEURL, "Polling Remote Address", "remotecontrol" }, 39 | { REMOTEURL_POSTPONED, "Waiting before polling", "remotecontrol_postponed" }, 40 | { BOOTUP, "Booting up...", "bootup" }, 41 | { FLASH, "Flashing Firmware...", "flash" }, 42 | { DISCO, "Disco Mode", "disco" } 43 | }; 44 | STATES state = UNDEF; 45 | 46 | /* Variables for RGB (and implicitly white) color 47 | Note that RGB and White LEDs are not supposed to be lit at the same time */ 48 | uint8_t g_red, g_green, g_blue; 49 | 50 | /* Hostname, this name will show up in DHCP requests */ 51 | String g_hostname; 52 | 53 | /* remote URL, this will be used to poll a color value */ 54 | String g_remoteurl; 55 | 56 | /* an optional delay in seconds before switching from bootup to remoteURL */ 57 | uint16_t g_delay_before_going_remotecontrolled; 58 | 59 | bool g_send_WLAN_keep_alive_packet; 60 | 61 | /* Storage for most recent logging messages */ 62 | std::deque log_messages; 63 | 64 | #define LOG_LENGTH 100 65 | 66 | /* logging messages, maintain length of entries */ 67 | void Log(String text) { 68 | log_messages.push_back(text); 69 | log_messages.pop_front(); 70 | 71 | Serial.println(text); 72 | } 73 | 74 | /* only allow to write to flash if commando was set */ 75 | bool enableUpdates = false; 76 | -------------------------------------------------------------------------------- /a20_wifi.ino: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | # # 3 | # LYT-SCRIPTED, an alternative firmware for LYT8266 RGBW LED lamps # 4 | # # 5 | # # 6 | # Copyright (C) 2017 Tom Stöveken # 7 | # # 8 | # This program is free software; you can redistribute it and/or modify # 9 | # it under the terms of the GNU General Public License as published by # 10 | # the Free Software Foundation; version 2 of the License. # 11 | # # 12 | # This program is distributed in the hope that it will be useful, # 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 15 | # GNU General Public License for more details. # 16 | # # 17 | # You should have received a copy of the GNU General Public License # 18 | # along with this program; if not, write to the Free Software # 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # 20 | # # 21 | *******************************************************************************/ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | WiFiUDP Udp; 30 | uint8_t buffer[10] = {1}; 31 | 32 | /****************************************************************************** 33 | Description.: prepare the WiFi settings, uses WiFi Manager Library 34 | Input Value.: - 35 | Return Value: - 36 | ******************************************************************************/ 37 | void setup_wifi() { 38 | WiFiManager wifiManager; 39 | 40 | //reset settings - for testing 41 | //wifiManager.resetSettings(); 42 | 43 | wifiManager.setConfigPortalTimeout(600); 44 | wifiManager.autoConnect("LYT8266"); 45 | 46 | Log("WiFi connected, RSSI: "+ String(WiFi.RSSI())); 47 | } 48 | 49 | /****************************************************************************** 50 | Description.: no permanent task necessary 51 | Input Value.: - 52 | Return Value: - 53 | ******************************************************************************/ 54 | void loop_wifi() { 55 | 56 | //because of having issues with an unresposive connection 57 | //just meaningless data traffic will hopefully fix it 58 | //a single UDP packet is send to the gateway IP 59 | static unsigned long then = 0; 60 | 61 | // for using millis be aware of overflow every ~50 days 62 | // but using substraction is "overflow-safe" 63 | if( g_send_WLAN_keep_alive_packet && (millis()-then >= 30000) ) { 64 | then = millis(); 65 | 66 | //UDP port 9 is supposed to discard packets or it will simply not return 67 | //anything because no service is running at the gateway-IP,port9 68 | Udp.beginPacket(WiFi.gatewayIP(), 9); 69 | Udp.write(buffer, LENGTH_OF(buffer)); 70 | Udp.endPacket(); 71 | 72 | Log("WiFi kept busy, RSSI: "+ String(WiFi.RSSI()) +", Connected: "+ String(WiFi.isConnected())); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /data/index.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Loading... 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
34 |
35 |

Overview

36 | Startup Config 37 |
38 | 42 |
43 |
44 | 45 |
46 | 56 |
57 | 58 |
59 |
...
60 |
61 |
62 | 63 | 64 |
65 |
66 |

Static Color

67 | Startup Config 68 |
69 | 73 |
74 |
75 | 76 |
77 |
Color Value
78 |
79 |
80 | 81 |
82 |
83 |
84 | 85 |
86 |
...
87 |
88 |
89 | 90 | 91 |
92 |
93 |

Startup Settings

94 |
95 |
96 |
97 |
98 |
99 | Operating mode: 100 | 101 | 102 | 103 | 104 |
105 |
106 | 107 |
108 | 109 | 110 |
111 | 112 |
113 | 114 | 115 |
116 | 117 |
118 | 119 | 120 | 121 | 122 | 123 |
124 | 125 |
126 | 127 | 128 |
129 | 130 | 131 | 132 | Cancel 133 |
134 |
135 |
136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /data/scripts.js: -------------------------------------------------------------------------------- 1 | var _getInProgress = false; 2 | var _queueFunc = null; 3 | var _queueURL = null; 4 | 5 | // set timeout in case the server responds very slow or not at all 6 | // also applies to GET requests, since they are build onto AJAX requests 7 | $.ajaxSetup({timeout: 6000}); 8 | 9 | // refresh values from server if this IntervallTimer is active 10 | var pollTimer; 11 | 12 | function pollAll() { 13 | $.get("/all", null).done( function( data ) { 14 | /* hide the loader icon */ 15 | $.mobile.loading( "hide" ); 16 | 17 | var color = tinycolor("rgb("+data.red+","+data.green+","+data.blue); 18 | 19 | $("#flat").spectrum("set", color); 20 | $("#flat").spectrum("reflow"); 21 | $("#flat").spectrum("show"); 22 | 23 | var txtcolor = tinycolor.mostReadable(color, ["#afafaf", "#000"]); 24 | $("#cvalue,#current_color").css("background-color", color.toHexString()); 25 | $("#cvalue,#current_color").css("color", txtcolor.toHexString()); 26 | $("#cvalue,#current_color").text("R: "+data.red+", "+"G: "+data.green+", "+"B: "+data.blue); 27 | 28 | var d = new Date(); 29 | d.setTime(data.uptime); 30 | debug("Up: "+ d.toUTCString().split(" ")[4] +", RSSI: "+data.RSSI.toString()); 31 | 32 | $("#current_state").text(data.state_human_readable); 33 | }); 34 | } 35 | 36 | function debug(text) { 37 | $(".deb").text(text) 38 | .stop() 39 | .animate({opacity: '1'}, 100) 40 | .animate({opacity: '0'}, 4000); 41 | } 42 | 43 | function myGet(URL, func) { 44 | // if we are still busy (server did not respond yet), queue this new request, overwrite previously queued request 45 | if (_getInProgress) { 46 | _queueFunc = func, _queueURL = URL; 47 | console.log("kept the last request, GET still busy..."); 48 | return; 49 | } 50 | 51 | console.log("requesting: "+URL); 52 | _getInProgress = true; 53 | 54 | // initiate communication with server via HTTP GET request 55 | var jqxhr = $.get(URL, function( data ) { 56 | // GET returns without error, execute passed function 57 | func(data); 58 | }) 59 | .done(function() { 60 | console.log("AJAX returned without errors"); 61 | }) 62 | .fail(function() { 63 | console.log("AJAX returned with ERROR!"); 64 | }) 65 | .always(function() { 66 | console.log("AJAX returned"); 67 | 68 | _getInProgress = false; 69 | 70 | // check if there is a queued request 71 | if (_queueURL != null && _queueFunc != null) { 72 | var _dequeueURL = _queueURL, _dequeueFunc = _queueFunc; 73 | _queueURL = null; 74 | _queueFunc = null; 75 | console.log("GET not busy anymore, dequeue"); 76 | 77 | // recursive call 78 | myGet(_dequeueURL, _dequeueFunc); 79 | } 80 | }); 81 | } 82 | 83 | $( document ).ready(function() { 84 | /* show loader */ 85 | $.mobile.loading( "show", { 86 | text: "Connecting...", 87 | textVisible: true, 88 | theme: "b", 89 | textonly: false 90 | }); 91 | 92 | /* start a timer */ 93 | pollTimer = setInterval(pollAll, 1000); 94 | 95 | /* init the color picker */ 96 | $("#flat").spectrum({ 97 | flat: true, 98 | showInput: false, 99 | showButtons: false, 100 | preferredFormat: "rgb", 101 | move: function(color) { 102 | var txtcolor = tinycolor.mostReadable(color, ["#afafaf", "#000"]); 103 | $("#cvalue").css("background-color", color.toHexString()); 104 | $("#cvalue").css("color", txtcolor.toHexString()); 105 | 106 | $("#cvalue").text("R: "+Math.round(color._r).toString()+", " + 107 | "G: "+Math.round(color._g).toString()+", " + 108 | "B: "+Math.round(color._b).toString()/*+", " + 109 | "W: "+Math.round(255-color._a*255).toString()*/ ); 110 | 111 | myGet("/color?"+ 112 | "red="+Math.round(color._r).toString()+"&" + 113 | "green="+Math.round(color._g).toString()+"&" + 114 | "blue="+Math.round(color._b).toString(), function( data ) { 115 | //$(".deb").text("GET done: "+JSON.stringify(data)); 116 | }); 117 | } 118 | }); 119 | 120 | $('.sp-val,.sp-hue').on('touchstart mousedown', function(evt) { clearInterval(pollTimer); }); 121 | $('.sp-val,.sp-hue').on('touchend mouseup', function(evt) { clearInterval(pollTimer); pollTimer = setInterval(pollAll, 1000); }); 122 | 123 | $("#startupcolor").spectrum({ 124 | preferredFormat: "hex", 125 | localStorageKey: "lyt8266", 126 | showPalette: true 127 | }); 128 | 129 | $(document.body).on('pageshow', function(evt) { 130 | if( $.mobile.activePage.attr("id") != "config" ) { 131 | clearInterval(pollTimer); 132 | pollAll(); 133 | pollTimer = setInterval(pollAll, 1000); 134 | return; 135 | } 136 | 137 | clearInterval(pollTimer); 138 | 139 | $("#configform input").prop("disabled", true); 140 | $("#configform input[type='radio']").checkboxradio("refresh"); 141 | 142 | $.get("/config.json", function( data ) { 143 | $("#configform input").prop("disabled", false); 144 | $("input[name='opmode']:checked").removeAttr("checked"); 145 | $("input[name='opmode']").val([data.state]).checkboxradio("refresh"); 146 | 147 | $("#remoteurl").val(data.remoteurl); 148 | $("#startupcolor").spectrum("set", data.hexcolor); 149 | $("#hostname").val(data.hostname); 150 | $("#delay_before_going_remotecontrolled").val(data.delay_before_going_remotecontrolled); 151 | 152 | $("#configform input[type='radio']").checkboxradio("refresh"); 153 | }); 154 | }); 155 | 156 | $('#configform').on('submit', function(evt) { 157 | //convert the color value to something easy to digest at the controller side 158 | var newcolor = $("#startupcolor").spectrum('get').toHexString(); 159 | var color = tinycolor(newcolor); 160 | $("input[name='startupcolor_r']").val(Math.round(color._r).toString()); 161 | $("input[name='startupcolor_g']").val(Math.round(color._g).toString()); 162 | $("input[name='startupcolor_b']").val(Math.round(color._b).toString()); 163 | 164 | // transmit form 165 | $.get("/config.json?"+$('#configform').serialize(), function( data ) { 166 | debug("values submitted"); 167 | $.mobile.back(); 168 | }); 169 | 170 | evt.preventDefault(); 171 | }); 172 | 173 | $('.quickButtons,#sOn,#sOff,#sRC,#sCC').on('click', function(evt, ui) { 174 | debug($(this).attr("href")); 175 | evt.preventDefault(); 176 | 177 | $.get($(this).attr("href"), function( data ) { 178 | debug("done"); 179 | }); 180 | }); 181 | 182 | $('#rebootbtn').on('click', function(evt, ui) { 183 | debug('Sending restart command...'); 184 | $.get("/reset", function( data ) { 185 | debug(data); 186 | $.mobile.back(); 187 | }); 188 | }); 189 | 190 | /* draw visualization */ 191 | var stage = new createjs.Stage("visu"); 192 | var width = 64; 193 | var heigth = 64; 194 | 195 | /*var background = new createjs.Shape() 196 | background.graphics.beginFill("#000").drawRoundRect(0, 0, width, height, 2); 197 | stage.addChild(background); 198 | */ 199 | var dotSize = 3; 200 | var LEDCount = 24; 201 | 202 | var LEDs = Array(); 203 | for(i=0; i 24 | #include 25 | 26 | Ticker timer1, timer2; 27 | bool checkURL = true; 28 | 29 | /****************************************************************************** 30 | Description.: read config file from SPIFFS 31 | Input Value.: - 32 | Return Value: true if config read, false in case of error 33 | ******************************************************************************/ 34 | bool loadConfig() { 35 | File configFile = SPIFFS.open("/config.json", "r"); 36 | 37 | if (!configFile || (configFile.size() > 1024)) { 38 | g_hostname = "LYT8266"; 39 | g_remoteurl = "http://lyt.naaa.de/"; 40 | state = CONSTANTCOLOR; 41 | g_red = 255; 42 | g_green = 0; 43 | g_blue = 0; 44 | g_delay_before_going_remotecontrolled = 0; 45 | g_send_WLAN_keep_alive_packet = true; 46 | 47 | return false; 48 | } 49 | 50 | int size = configFile.size(); 51 | 52 | // Allocate a buffer to store contents of the file. 53 | std::unique_ptr buf(new char[size]); 54 | 55 | // We don't use String here because ArduinoJson library requires the input 56 | // buffer to be mutable. If you don't use ArduinoJson, you may as well 57 | // use configFile.readString instead. 58 | configFile.readBytes(buf.get(), size); 59 | 60 | StaticJsonBuffer<500> jsonBuffer; 61 | JsonObject& json = jsonBuffer.parseObject(buf.get()); 62 | 63 | if (!json.success()) { 64 | return false; 65 | } 66 | 67 | g_hostname = strdup(json["hostname"]); 68 | g_remoteurl = strdup(json["remoteurl"]); 69 | 70 | /* read state from config file, will be UNDEF if string from config is not found */ 71 | state = UNDEF; 72 | for(int i=0; i 0) { 108 | // HTTP header has been send and Server response header has been handled 109 | Log("[HTTP] GET... code: " + String(httpCode)); 110 | 111 | // file found at server 112 | if(httpCode == HTTP_CODE_OK) { 113 | payload = http.getString(); 114 | Log("Payload: " + payload); 115 | } 116 | } else { 117 | Log("[HTTP] GET... failed, error: " + http.errorToString(httpCode)); 118 | } 119 | 120 | http.end(); 121 | 122 | DynamicJsonBuffer jsonBuffer; 123 | // accessing the char array is not intended use, but ArduinoJSON works with the string in place 124 | // so it should be fine 125 | JsonObject& json = jsonBuffer.parseObject(payload.c_str()); 126 | 127 | if (!json.success()) { 128 | return false; 129 | } 130 | 131 | r = json["r"]; 132 | g = json["g"]; 133 | b = json["b"]; 134 | 135 | return true; 136 | } 137 | 138 | /****************************************************************************** 139 | Description.: prepares everything, sets the light up first and then does the 140 | more time consuming tasks 141 | Input Value.: - 142 | Return Value: - 143 | ******************************************************************************/ 144 | void setup(void){ 145 | state = BOOTUP; 146 | 147 | Serial.begin(115200); 148 | Serial.println("LYT8266 starting up\nCompiled at: " __DATE__ " - " __TIME__); 149 | 150 | log_messages.resize(LOG_LENGTH, "-"); 151 | Log("LYT8266 starting up"); 152 | Log("Compiled at: " __DATE__ " - " __TIME__); 153 | 154 | if( !SPIFFS.begin() ) { 155 | Log("SPIFFS not mounted correctly, retrying..."); 156 | delay(1000); 157 | if( !SPIFFS.begin() ) { 158 | Log("mounting failed twice, formatting and then restarting"); 159 | SPIFFS.format(); 160 | ESP.restart(); 161 | } else { 162 | Log("SPIFFS mounted at second try, proceeding as usual"); 163 | } 164 | } 165 | 166 | // read configuration file 167 | bool r = loadConfig(); 168 | Log("loadConfig() --> result: "+String(r)); 169 | 170 | // apply hostname 171 | wifi_station_set_hostname((char *)g_hostname.c_str()); 172 | 173 | setup_LEDs(); 174 | setup_wifi(); 175 | setup_webserver(); 176 | 177 | // setup timer (Ticker) to check every 60 seconds an URL for color values 178 | timer1.attach(60.0, [](){ 179 | checkURL = true; 180 | }); 181 | 182 | // Count down value if URL check is to be postponed 183 | timer2.attach(1.0, [](){ 184 | 185 | // postpone URL check if a delay was set 186 | if (g_delay_before_going_remotecontrolled > 0) { 187 | Log("Postponed URL check, because g_delay_before_going_remotecontrolled is "+ String(g_delay_before_going_remotecontrolled)); 188 | if(state == REMOTEURL) { 189 | state = REMOTEURL_POSTPONED; 190 | } 191 | g_delay_before_going_remotecontrolled -= 1; 192 | return; 193 | } 194 | 195 | // if control reaches this point the delay has passed, clean up and stop this timer 196 | g_delay_before_going_remotecontrolled = 0; 197 | 198 | if(state == REMOTEURL_POSTPONED) { 199 | state = REMOTEURL; 200 | } 201 | 202 | // job is done, remove this lambda function from timer2 203 | timer2.detach(); 204 | }); 205 | } 206 | 207 | /****************************************************************************** 208 | Description.: execute the different subtasks, none may block or not return 209 | Input Value.: - 210 | Return Value: - 211 | ******************************************************************************/ 212 | void loop(void){ 213 | loop_wifi(); 214 | loop_webserver(); 215 | loop_LEDs(); 216 | 217 | if(state == REMOTEURL && checkURL) { 218 | loadURL(g_remoteurl, g_red, g_green, g_blue); 219 | checkURL = false; 220 | } 221 | 222 | delay(1); 223 | } 224 | 225 | -------------------------------------------------------------------------------- /a40_LED.ino: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | # # 3 | # LYT-SCRIPTED, an alternative firmware for LYT8266 RGBW LED lamps # 4 | # # 5 | # # 6 | # Copyright (C) 2017 Tom Stöveken # 7 | # # 8 | # This program is free software; you can redistribute it and/or modify # 9 | # it under the terms of the GNU General Public License as published by # 10 | # the Free Software Foundation; version 2 of the License. # 11 | # # 12 | # This program is distributed in the hope that it will be useful, # 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 15 | # GNU General Public License for more details. # 16 | # # 17 | # You should have received a copy of the GNU General Public License # 18 | # along with this program; if not, write to the Free Software # 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # 20 | # # 21 | *******************************************************************************/ 22 | 23 | #include 24 | 25 | #define RED_PIN 13 26 | #define GREEN_PIN 12 27 | #define BLUE_PIN 14 28 | #define WHITE_PIN 2 29 | #define POWER_ENABLE_LED 15 30 | 31 | // how often will the animation ticker call the callback, defined in ms 32 | #define ANI_RES 10 33 | 34 | /****************************************************************************** 35 | Description.: The visual impression of the LEDs is not linear like the PWM, 36 | thus to make the range match the visual impression better 37 | a gamma correction is usual. Here, just one color channel 38 | is adjusted, which fixes the most important issues. Dependencies 39 | of one color with the others is not improved this way, so color 40 | shifts in mixed colors are still possible. 41 | Credit for the LUT values goes to 42 | http://rgb-123.com/ws2812-color-output/ 43 | Input Value.: brightness level for one color (0 .. 255) 44 | Return Value: gamma corrected value (0 .. 255) 45 | ******************************************************************************/ 46 | uint8_t gamma_correction(uint8_t value) { 47 | uint8_t gammaE[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48 | 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 49 | 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 50 | 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 51 | 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 52 | 19, 19, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, 27, 27, 28, 53 | 29, 29, 30, 31, 31, 32, 33, 34, 34, 35, 36, 37, 37, 38, 39, 40, 54 | 40, 41, 42, 43, 44, 45, 46, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55 | 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 56 | 71, 72, 73, 74, 76, 77, 78, 79, 80, 81, 83, 84, 85, 86, 88, 89, 57 | 90, 91, 93, 94, 95, 96, 98, 99,100,102,103,104,106,107,109,110, 58 | 111,113,114,116,117,119,120,121,123,124,126,128,129,131,132,134, 59 | 135,137,138,140,142,143,145,146,148,150,151,153,155,157,158,160, 60 | 162,163,165,167,169,170,172,174,176,178,179,181,183,185,187,189, 61 | 191,193,194,196,198,200,202,204,206,208,210,212,214,216,218,220, 62 | 222,224,227,229,231,233,235,237,239,241,244,246,248,250,252,255}; 63 | 64 | return gammaE[value]; 65 | } 66 | 67 | /****************************************************************************** 68 | Description.: set the LED, if RGB are set to the same value the white LEDs are 69 | used. Operating White and RGB LEDs is not OK according to 70 | the manufacturer (operating all at once would damage the bulb). 71 | Input Value.: brightness level for RGB, if R=G=B the white LEDs are used 72 | Return Value: - 73 | ******************************************************************************/ 74 | void setLeds(uint8_t red, uint8_t green, uint8_t blue) { 75 | if(red == green && green == blue) { 76 | analogWrite(RED_PIN, 0); 77 | analogWrite(GREEN_PIN, 0); 78 | analogWrite(BLUE_PIN, 0); 79 | analogWrite(WHITE_PIN, gamma_correction(red)); 80 | } else { 81 | analogWrite(RED_PIN, gamma_correction(red)); 82 | analogWrite(GREEN_PIN, gamma_correction(green)); 83 | analogWrite(BLUE_PIN, gamma_correction(blue)); 84 | analogWrite(WHITE_PIN, 0); 85 | } 86 | 87 | //without delay I had issues when setting all values 0 88 | //delay(1); 89 | } 90 | 91 | /****************************************************************************** 92 | Description.: animation function performs a fade animation 93 | Input Value.: a pointer to context variables required for the animation 94 | Return Value: - 95 | ******************************************************************************/ 96 | struct _animation_context { 97 | uint8_t next_red; 98 | uint8_t next_green; 99 | uint8_t next_blue; 100 | 101 | uint8_t previous_red; 102 | uint8_t previous_green; 103 | uint8_t previous_blue; 104 | 105 | uint8_t current_red; 106 | uint8_t current_green; 107 | uint8_t current_blue; 108 | 109 | bool busy; 110 | uint32_t ani_time; 111 | uint32_t ani_duration; 112 | 113 | Ticker animationTicker; 114 | } animation_context; 115 | 116 | void animation(void *vctx) { 117 | float progress; 118 | _animation_context *ctx = (_animation_context *)vctx; 119 | 120 | ctx->ani_time += ANI_RES; 121 | progress = _min(1.0, (float)ctx->ani_time / (float)ctx->ani_duration); 122 | 123 | ctx->current_red = ctx->previous_red + (ctx->next_red - ctx->previous_red) * progress; 124 | ctx->current_green = ctx->previous_green + (ctx->next_green - ctx->previous_green) * progress; 125 | ctx->current_blue = ctx->previous_blue + (ctx->next_blue - ctx->previous_blue) * progress; 126 | 127 | setLeds(ctx->current_red, ctx->current_green, ctx->current_blue); 128 | 129 | if( progress >= 1.0 ) { 130 | // stop timer, we reached 100% 131 | ctx->animationTicker.detach(); 132 | ctx->ani_time = 0; 133 | ctx->previous_red = ctx->next_red; 134 | ctx->previous_green = ctx->next_green; 135 | ctx->previous_blue = ctx->next_blue; 136 | ctx->busy = false; 137 | } 138 | } 139 | 140 | /****************************************************************************** 141 | Description.: set the LEDs, not immediatly but fading from previous color 142 | to the specified within the specified time 143 | Input Value.: brightness level for RGB, if R=G=B the white LEDs are used 144 | fade_time is the time of animation in milliseconds 145 | Return Value: - 146 | ******************************************************************************/ 147 | void setLedsAnimated(uint8_t red, uint8_t green, uint8_t blue, uint32_t duration) { 148 | 149 | // guard against restarting the animation unless new target color specified 150 | if( (red == animation_context.next_red) && (green == animation_context.next_green) && (blue == animation_context.next_blue) ) { 151 | // leave if we already currently animate towards or already have set desired color 152 | return; 153 | } 154 | 155 | // if animation is still running 156 | if(animation_context.busy) { 157 | // already/still busy: stop timer first 158 | animation_context.animationTicker.detach(); 159 | 160 | // restart animation from current colors 161 | animation_context.previous_red = animation_context.current_red; 162 | animation_context.previous_green = animation_context.current_green; 163 | animation_context.previous_blue = animation_context.current_blue; 164 | } 165 | 166 | animation_context.ani_duration = duration; 167 | animation_context.ani_time = 0; 168 | animation_context.busy = true; 169 | 170 | // animate towards this color 171 | animation_context.next_red = red; 172 | animation_context.next_green = green; 173 | animation_context.next_blue = blue; 174 | 175 | animation_context.animationTicker.attach_ms(ANI_RES, animation, (void *)&animation_context); 176 | } 177 | 178 | /****************************************************************************** 179 | Description.: prepare the LEDs, switch on to show bulb is working and provide 180 | light 181 | Input Value.: - 182 | Return Value: - 183 | ******************************************************************************/ 184 | void setup_LEDs() { 185 | pinMode(RED_PIN, OUTPUT); 186 | pinMode(GREEN_PIN, OUTPUT); 187 | pinMode(BLUE_PIN, OUTPUT); 188 | pinMode(WHITE_PIN, OUTPUT); 189 | pinMode(POWER_ENABLE_LED, OUTPUT); 190 | 191 | analogWriteFreq(500); 192 | analogWriteRange(255); 193 | 194 | animation_context.next_red = 0; 195 | animation_context.next_green = 0; 196 | animation_context.next_blue = 0; 197 | 198 | animation_context.previous_red = 0; 199 | animation_context.previous_green = 0; 200 | animation_context.previous_blue = 0; 201 | 202 | animation_context.current_red = 0; 203 | animation_context.current_green = 0; 204 | animation_context.current_blue = 0; 205 | 206 | animation_context.busy = false; 207 | 208 | setLedsAnimated(g_red, g_green, g_blue, 1000); 209 | 210 | digitalWrite(POWER_ENABLE_LED, 1); 211 | } 212 | 213 | /****************************************************************************** 214 | Description.: set the RGBW LEDs as defined by state and global colors variables 215 | Input Value.: - 216 | Return Value: - 217 | ******************************************************************************/ 218 | void loop_LEDs() { 219 | switch(state) { 220 | case BOOTUP: 221 | setLeds(g_red, g_green, g_blue); 222 | break; 223 | 224 | case CONSTANTCOLOR: 225 | case REMOTEURL: 226 | setLedsAnimated(g_red, g_green, g_blue, 1000); 227 | //setLeds(g_red, g_green, g_blue); 228 | break; 229 | 230 | case DISCO: 231 | if(animation_context.busy == false) { 232 | setLedsAnimated(random(0, 255), random(0, 255), random(0, 255), random(50, 500)); 233 | } 234 | break; 235 | 236 | default: 237 | ; 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /a30_webserver.ino: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | # # 3 | # LYT-SCRIPTED, an alternative firmware for LYT8266 RGBW LED lamps # 4 | # # 5 | # # 6 | # Copyright (C) 2017 Tom Stöveken # 7 | # # 8 | # This program is free software; you can redistribute it and/or modify # 9 | # it under the terms of the GNU General Public License as published by # 10 | # the Free Software Foundation; version 2 of the License. # 11 | # # 12 | # This program is distributed in the hope that it will be useful, # 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 15 | # GNU General Public License for more details. # 16 | # # 17 | # You should have received a copy of the GNU General Public License # 18 | # along with this program; if not, write to the Free Software # 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # 20 | # # 21 | *******************************************************************************/ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | ESP8266WebServer server(80); 28 | File fsUploadFile; 29 | 30 | ESP8266HTTPUpdateServer httpUpdater; 31 | 32 | 33 | /****************************************************************************** 34 | Description.: Return MIME type based on file extension 35 | Input Value.: filename with extension as String 36 | Return Value: return the MIME type as String or text/plain as default type 37 | ******************************************************************************/ 38 | String getContentType(String filename){ 39 | if(server.hasArg("download")) return "application/octet-stream"; 40 | else if(filename.endsWith(".htm")) return "text/html"; 41 | else if(filename.endsWith(".html")) return "text/html"; 42 | else if(filename.endsWith(".css")) return "text/css"; 43 | else if(filename.endsWith(".js")) return "application/javascript"; 44 | else if(filename.endsWith(".png")) return "image/png"; 45 | else if(filename.endsWith(".gif")) return "image/gif"; 46 | else if(filename.endsWith(".jpg")) return "image/jpeg"; 47 | else if(filename.endsWith(".ico")) return "image/x-icon"; 48 | else if(filename.endsWith(".xml")) return "text/xml"; 49 | else if(filename.endsWith(".pdf")) return "application/x-pdf"; 50 | else if(filename.endsWith(".zip")) return "application/x-zip"; 51 | else if(filename.endsWith(".gz")) return "application/x-gzip"; 52 | else if(filename.endsWith(".manifest")) return "text/cache-manifest"; 53 | else if(filename.endsWith(".json")) return "text/json"; 54 | return "text/plain"; 55 | } 56 | 57 | /****************************************************************************** 58 | Description.: Sends file to client 59 | Input Value.: full path to file or /, then the path will be extended with 60 | index.htm 61 | Return Value: true if file was send, false no file found 62 | ******************************************************************************/ 63 | bool handleFileRead(String path){ 64 | if(path.endsWith("/")) path += "index.htm"; 65 | String contentType = getContentType(path); 66 | String pathWithGz = path + ".gz"; 67 | if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)){ 68 | if(SPIFFS.exists(pathWithGz)) 69 | path += ".gz"; 70 | File file = SPIFFS.open(path, "r"); 71 | size_t sent = server.streamFile(file, contentType); 72 | file.close(); 73 | return true; 74 | } 75 | return false; 76 | } 77 | 78 | /****************************************************************************** 79 | Description.: handles a request to path "/color" 80 | accepts HTTP-GET parameters for color, sets state accordingly 81 | Input Value.: - 82 | Return Value: - 83 | ******************************************************************************/ 84 | void handleColorGET() { 85 | StaticJsonBuffer<500> jsonBuffer; 86 | JsonObject& root = jsonBuffer.createObject(); 87 | String json; 88 | 89 | if(server.hasArg("red") && server.hasArg("green") && server.hasArg("blue")) { 90 | Log("received new color values, setting state and colors (R:"+ 91 | server.arg("red") + ", G:" + 92 | server.arg("green") + ", B:" + 93 | server.arg("blue") + ")"); 94 | state = CONSTANTCOLOR; 95 | g_red = server.arg("red").toInt(); 96 | g_green = server.arg("green").toInt(); 97 | g_blue = server.arg("blue").toInt(); 98 | } 99 | 100 | root["red"] = g_red; 101 | root["green"] = g_green; 102 | root["blue"] = g_blue; 103 | 104 | root.printTo(json); 105 | server.send(200, "text/json", json); 106 | } 107 | 108 | /****************************************************************************** 109 | Description.: handles uploaded files 110 | this is needed to handle new files to be stored in the SPIFFS 111 | partition of the flash. 112 | A convenient way to update the HTML and config files is using 113 | a BASH file which is part of the project 114 | Input Value.: - 115 | Return Value: - 116 | ******************************************************************************/ 117 | void handleFileUpload() { 118 | if ( !enableUpdates ) { 119 | server.send(200, "text/plain", "locked"); 120 | return; 121 | } 122 | 123 | if(server.uri() != "/edit") return; 124 | 125 | HTTPUpload& upload = server.upload(); 126 | 127 | if(upload.status == UPLOAD_FILE_START){ 128 | String filename = upload.filename; 129 | 130 | if( !filename.startsWith("/") ) 131 | filename = "/"+filename; 132 | 133 | fsUploadFile = SPIFFS.open(filename, "w"); 134 | filename = String(); 135 | } else if(upload.status == UPLOAD_FILE_WRITE) { 136 | if(fsUploadFile) 137 | fsUploadFile.write(upload.buf, upload.currentSize); 138 | } else if(upload.status == UPLOAD_FILE_END) { 139 | if(fsUploadFile) 140 | fsUploadFile.close(); 141 | } 142 | } 143 | 144 | /****************************************************************************** 145 | Description.: handle request to "/all", answers with a JSON encoded details of 146 | all states, important variables etc at once. 147 | Input Value.: - 148 | Return Value: - 149 | ******************************************************************************/ 150 | void handleAllGET() { 151 | StaticJsonBuffer<500> jsonBuffer; 152 | JsonObject& root = jsonBuffer.createObject(); 153 | String json; 154 | 155 | // translate current state to string 156 | for(int i=0; i jsonBuffer; 219 | JsonObject& root = jsonBuffer.createObject(); 220 | 221 | if(server.hasArg("remoteurl") && 222 | server.hasArg("hostname") && 223 | server.hasArg("opmode") && 224 | server.hasArg("startupcolor_r") && 225 | server.hasArg("startupcolor_g") && 226 | server.hasArg("startupcolor_b") && 227 | server.hasArg("startupcolor") && 228 | server.hasArg("delay_before_going_remotecontrolled")) { 229 | 230 | Log("a new config was submitted"); 231 | 232 | root["state"] = server.arg("opmode"); 233 | root["remoteurl"] = server.arg("remoteurl"); 234 | root["hostname"] = server.arg("hostname"); 235 | root["r"] = server.arg("startupcolor_r").toInt(); 236 | root["g"] = server.arg("startupcolor_g").toInt(); 237 | root["b"] = server.arg("startupcolor_b").toInt(); 238 | root["hexcolor"] = server.arg("startupcolor"); 239 | root["delay_before_going_remotecontrolled"] = server.arg("delay_before_going_remotecontrolled"); 240 | root["send_WLAN_keep_alive_packet"] = g_send_WLAN_keep_alive_packet; 241 | 242 | // store to file 243 | File fsConfig = SPIFFS.open("/config.json", "w"); 244 | if (fsConfig) { 245 | root.printTo(fsConfig); 246 | fsConfig.close(); 247 | } 248 | } 249 | 250 | if(!handleFileRead("/config.json")) 251 | server.send(404, "text/plain", "FileNotFound"); 252 | } 253 | 254 | /****************************************************************************** 255 | Description.: prepares the webserver, sets up the special paths and their 256 | handler-functions 257 | Input Value.: - 258 | Return Value: - 259 | ******************************************************************************/ 260 | void setup_webserver() { 261 | //called when the url is not defined here 262 | //use it to load content from SPIFFS 263 | server.onNotFound([](){ 264 | if(!handleFileRead(server.uri())) 265 | server.send(404, "text/plain", "FileNotFound"); 266 | }); 267 | 268 | server.on("/all", HTTP_GET, handleAllGET); 269 | server.on("/color", HTTP_GET, handleColorGET); 270 | server.on("/config.json", HTTP_GET, handleConfigGET); 271 | server.on("/state", HTTP_GET, handleStateGET); 272 | 273 | /* deleted the files present on SPIFFS file system */ 274 | server.on("/format", HTTP_GET, [](){ 275 | if ( !enableUpdates ) { 276 | server.send(200, "text/plain", "locked"); 277 | return; 278 | } 279 | 280 | String result=SPIFFS.format()?"OK":"NOK"; 281 | server.send(200, "text/plain", result); 282 | }); 283 | 284 | server.on("/reset", HTTP_GET, [](){ 285 | server.send(200, "text/plain", "restarting..."); 286 | ESP.restart(); 287 | }); 288 | 289 | server.on("/unlock", HTTP_GET, [](){ 290 | if( server.arg("password") == "securitybyobscurity" ) { 291 | enableUpdates = true; 292 | httpUpdater.setup(&server, "/update"); 293 | } 294 | 295 | server.send(200, "text/plain", "enableUpdates: "+String(enableUpdates)); 296 | }); 297 | 298 | server.on("/log", HTTP_GET, [](){ 299 | std::deque::const_iterator i; 300 | String response = "Log:\n"; 301 | uint32_t counter = 0; 302 | 303 | for(i=log_messages.begin(); i!=log_messages.end(); ++i){ 304 | response += String(counter) + ": " + (*i) + "\n"; 305 | counter++; 306 | } 307 | 308 | server.send(200, "text/plain", response); 309 | }); 310 | 311 | server.on("/edit", HTTP_POST, [](){ 312 | if ( !enableUpdates ) { 313 | server.send(200, "text/plain", "locked"); 314 | return; 315 | } 316 | 317 | server.send(200, "text/plain", ""); 318 | }, handleFileUpload); 319 | 320 | server.begin(); 321 | } 322 | 323 | /****************************************************************************** 324 | Description.: handle HTTP-clients 325 | Input Value.: - 326 | Return Value: - 327 | ******************************************************************************/ 328 | void loop_webserver() { 329 | server.handleClient(); 330 | } 331 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------