2 firmware for ESP-Ledberg mod. Based on UDPSendReceive.pde
3 set STASSID and STAPSK; will listen on port 1337.
4 (c) 2019 Tobias Girstmair, GPLv3
5 https://gir.st/blog/esp8266-ledberg.htm
9 #include <ESP8266WiFi.h>
11 #include <ESP_EEPROM.h> // flash protective version of <EEPROM.h>
12 #include <WiFiManager.h>
13 typedef unsigned char uint8;
15 unsigned int localPort = 1337; // local port to listen on
16 uint8 rgb[3] = {0xff, 0x6b, 0x55}; // gives nice, slightly warm, white on boot
17 //very warm: {0x93, 0x35, 0x20}
23 const uint rgb_addr = 0;
34 EEPROM.begin(sizeof rgb);
37 EEPROM.get(rgb_addr,tmp);
38 if (!tmp[0] && !tmp[1] && !tmp[1]) {//XXX: untested
39 EEPROM.put(rgb_addr, rgb);
42 EEPROM.get(rgb_addr,rgb);
43 analogWrite(red, rgb[0]<<2);
44 analogWrite(grn, rgb[1]<<2);
45 analogWrite(blu, rgb[2]<<2);
47 WiFiManager wifiManager;
48 wifiManager.setHostname("girst-LEDBerg"); // needs at least wifimanager 2.0.12-beta (tested with 2.0.14-beta)
49 wifiManager.autoConnect("gir.st LEDBerg");
51 Serial.print("Connected! IP address: ");
52 Serial.println(WiFi.localIP());
53 Serial.printf("UDP server on port %d\n", localPort);
58 // if there's data available, read a packet
59 int packetSize = Udp.parsePacket();
62 Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
64 // read the packet into packetBufffer
68 case 0: // get current power,r,g,b
76 if (packetSize == 2) { //type+power
84 if (packetSize == 4) { //type+r+g+b
87 if (tmp[0]+tmp[1]+tmp[2] > 512) {
91 for (int i = 0; i < 3; i++) {
99 case 3: // save color to eeprom
100 EEPROM.put(rgb_addr, rgb);
109 analogWrite(red, rgb[0]<<2);
110 analogWrite(grn, rgb[1]<<2);
111 analogWrite(blu, rgb[2]<<2);