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 typedef unsigned char uint8;
14 #define STASSID "FIXME"
15 #define STAPSK "FIXME"
18 unsigned int localPort = 1337; // local port to listen on
19 uint8 rgb[3] = {0xff, 0x6b, 0x55}; // gives nice, slightly warm, white on boot
36 WiFi.begin(STASSID, STAPSK);
37 while (WiFi.status() != WL_CONNECTED) {
41 Serial.print("Connected! IP address: ");
42 Serial.println(WiFi.localIP());
43 Serial.printf("UDP server on port %d\n", localPort);
48 // if there's data available, read a packet
49 int packetSize = Udp.parsePacket();
52 Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
54 // read the packet into packetBufffer
58 case 0: // get current power,r,g,b
66 if (packetSize == 2) { //type+power
74 if (packetSize == 4) { //type+r+g+b
77 if (tmp[0]+tmp[1]+tmp[2] > 512) {
81 for (int i = 0; i < 3; i++) {
89 case 3: // save color to eeprom
90 Udp.write(NAK); //TODO: not implemented
92 case 4: // set ssid and wpa2psk; write to non-volatile memory
93 Udp.write(NAK); //TODO: not implemented
95 case 5: //set static ip / dhcp
96 Udp.write(NAK); //TODO: not implemented
103 analogWrite(red, rgb[0]<<2);
104 analogWrite(grn, rgb[1]<<2);
105 analogWrite(blu, rgb[2]<<2);