This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
projects:neopixel-bandwidth-room-light [2017-10-14 20:21] – [Overview] mrweedwood | projects:neopixel-bandwidth-room-light [2017-12-23 11:49] (current) – [Motion detection notification] trinitor | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== NeoPixel Bandwidth Room Light ====== | ====== NeoPixel Bandwidth Room Light ====== | ||
+ | |||
+ | {{: | ||
===== Overview ===== | ===== Overview ===== | ||
Line 11: | Line 13: | ||
**Light wars incoming!** | **Light wars incoming!** | ||
- | The ESPP8266 | + | The ESP8266 |
{{: | {{: | ||
Line 47: | Line 49: | ||
===== Programm ===== | ===== Programm ===== | ||
< | < | ||
- | Todo | + | #include < |
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #ifdef __AVR__ | ||
+ | #include < | ||
+ | #endif | ||
+ | |||
+ | ///////////////////////////// | ||
+ | // Network | ||
+ | const char* ssid = " | ||
+ | const char* password | ||
+ | unsigned int localUdpPort = 2342; | ||
+ | char incomingPacket[255]; | ||
+ | char replyPacekt[] = " | ||
+ | |||
+ | // neopixel | ||
+ | const int LEDPIN | ||
+ | const int NUMPIXELS | ||
+ | |||
+ | int displayrefresh | ||
+ | int shiftpixels | ||
+ | int alwaysoff | ||
+ | ////////////////////////////////////////////////////////////////// | ||
+ | |||
+ | // usage examples: | ||
+ | // echo " | ||
+ | // echo " | ||
+ | // echo " | ||
+ | // echo " | ||
+ | // echo " | ||
+ | // echo " | ||
+ | // echo " | ||
+ | // echo " | ||
+ | |||
+ | |||
+ | WiFiUDP Udp; | ||
+ | Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | Serial.begin(115200); | ||
+ | Serial.println(); | ||
+ | Serial.printf(" | ||
+ | |||
+ | WiFi.begin(ssid, | ||
+ | while (WiFi.status() != WL_CONNECTED) | ||
+ | { | ||
+ | delay(500); | ||
+ | Serial.print(" | ||
+ | } | ||
+ | Serial.println(" | ||
+ | |||
+ | Udp.begin(localUdpPort); | ||
+ | Serial.printf(" | ||
+ | |||
+ | pixels.begin(); | ||
+ | pixels.show(); | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | int red = 0; | ||
+ | int green = 0; | ||
+ | int blue = 0; | ||
+ | int refresh | ||
+ | int scroll | ||
+ | int pixel = 0; | ||
+ | int all = 0; | ||
+ | int clearall | ||
+ | int effect | ||
+ | int option1 | ||
+ | |||
+ | int packetSize = Udp.parsePacket(); | ||
+ | if (packetSize) | ||
+ | { | ||
+ | // receive incoming UDP packets | ||
+ | // Serial.printf(" | ||
+ | int len = Udp.read(incomingPacket, | ||
+ | |||
+ | if (len > 0) | ||
+ | { | ||
+ | incomingPacket[len] = 0; | ||
+ | // Serial.printf(" | ||
+ | StaticJsonBuffer< | ||
+ | JsonObject& | ||
+ | if (!json.success()) | ||
+ | { | ||
+ | Serial.println(" | ||
+ | } else { | ||
+ | // for (JsonObject:: | ||
+ | // { | ||
+ | // Serial.println(it-> | ||
+ | // Serial.println(it-> | ||
+ | // } | ||
+ | red = json[" | ||
+ | green = json[" | ||
+ | blue = json[" | ||
+ | refresh | ||
+ | pixel = json[" | ||
+ | all = json[" | ||
+ | clearall = json[" | ||
+ | scroll | ||
+ | effect | ||
+ | option1 | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // send back a reply, to the IP address and port we got the packet from | ||
+ | // Serial.println(" | ||
+ | // Udp.beginPacket(Udp.remoteIP(), | ||
+ | // Udp.write(replyPacekt); | ||
+ | // Udp.endPacket(); | ||
+ | } | ||
+ | |||
+ | // new refreshrate received | ||
+ | if (refresh > 0) { | ||
+ | Serial.println(" | ||
+ | displayrefresh = refresh; | ||
+ | } | ||
+ | |||
+ | // change of scroll parameter | ||
+ | if (scroll > 0) { | ||
+ | Serial.printf(" | ||
+ | if (scroll == 1) { | ||
+ | shiftpixels = 1; | ||
+ | } else { | ||
+ | shiftpixels = 2; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // set all pixel to color | ||
+ | if(all == 1) { | ||
+ | Serial.printf(" | ||
+ | for(int i=0; i< | ||
+ | pixels.setPixelColor(i, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // set all pixel to black if clearall was set to 1 | ||
+ | if(clearall == 1) { | ||
+ | Serial.println(" | ||
+ | for(int i=0; i< | ||
+ | pixels.setPixelColor(i, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | //shift pixels | ||
+ | if (shiftpixels == 2) { | ||
+ | // Serial.println(" | ||
+ | for(int i=NUMPIXELS; | ||
+ | uint32_t color = pixels.getPixelColor(i); | ||
+ | pixels.setPixelColor(i+1, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if (effect == 1) { | ||
+ | if (option1 == 0) { option1 = 128; } | ||
+ | fade(option1); | ||
+ | } | ||
+ | else if (effect == 2) { | ||
+ | if (option1 == 0) { option1 = 20; } | ||
+ | rainbow(option1); | ||
+ | } | ||
+ | // set color of Pixel | ||
+ | // new color proviced color changed? | ||
+ | else if (red >0 || green >0 || blue >0) { | ||
+ | //read current color | ||
+ | uint32_t CurrentColor = pixels.getPixelColor(1); | ||
+ | uint8_t | ||
+ | uint8_t | ||
+ | uint8_t | ||
+ | |||
+ | // if no new color was set -> reuse the old color | ||
+ | if (red == 0) {red = CurrentRed; | ||
+ | if (green == 0) {green = CurrentGreen; | ||
+ | if (blue == 0) {blue = CurrentBlue; | ||
+ | |||
+ | // set pixel 0 in case no spesific pixel was requested | ||
+ | if (pixel == 0) { | ||
+ | // Serial.printf(" | ||
+ | pixels.setPixelColor(0, | ||
+ | } else { | ||
+ | // if spesific pixel was request change the color and also copy pixel 1 to pixel 0 | ||
+ | // Serial.printf(" | ||
+ | pixels.setPixelColor(pixel, | ||
+ | if (shiftpixels == 2) { | ||
+ | uint32_t color = pixels.getPixelColor(1); | ||
+ | pixels.setPixelColor(0, | ||
+ | } | ||
+ | } | ||
+ | } else { | ||
+ | // Serial.printf(" | ||
+ | if (shiftpixels == 2) { | ||
+ | uint32_t color = pixels.getPixelColor(1); | ||
+ | if (alwaysoff = 1) { | ||
+ | pixels.setPixelColor(0, | ||
+ | } else { | ||
+ | pixels.setPixelColor(0, | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | pixels.show(); | ||
+ | |||
+ | delay(displayrefresh); | ||
+ | } | ||
+ | |||
+ | // Effects | ||
+ | void fade(int maxBrightness){ | ||
+ | for(int brightness = 0; brightness < maxBrightness; | ||
+ | for(int i = 0; i < NUMPIXELS; i++ ) { | ||
+ | pixels.setPixelColor(i, | ||
+ | } | ||
+ | pixels.show(); | ||
+ | delay(5); | ||
+ | } | ||
+ | // Fade OUT | ||
+ | for(int brightness = maxBrightness; | ||
+ | for(int i = 0; i < NUMPIXELS; i++ ) { | ||
+ | pixels.setPixelColor(i, | ||
+ | } | ||
+ | pixels.show(); | ||
+ | delay(5); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void rainbow(uint8_t wait) { | ||
+ | uint16_t i, j; | ||
+ | |||
+ | for(j=0; j<256; j++) { | ||
+ | for(i=0; i < NUMPIXELS; i++) { | ||
+ | pixels.setPixelColor(i, | ||
+ | } | ||
+ | pixels.show(); | ||
+ | delay(wait); | ||
+ | } | ||
+ | for(int i=0; i< | ||
+ | pixels.setPixelColor(i, | ||
+ | } | ||
+ | pixels.show(); | ||
+ | } | ||
+ | |||
+ | uint32_t Wheel(byte WheelPos) { | ||
+ | WheelPos = 255 - WheelPos; | ||
+ | if(WheelPos < 85) { | ||
+ | return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3); | ||
+ | } | ||
+ | if(WheelPos < 170) { | ||
+ | WheelPos -= 85; | ||
+ | return pixels.Color(0, | ||
+ | } | ||
+ | WheelPos -= 170; | ||
+ | return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0); | ||
+ | } | ||
</ | </ | ||
Line 62: | Line 318: | ||
* / | * / | ||
- | ===== Test ===== | + | ===== Flash OTA (OverTheAir) ==== |
+ | The ESP8266 with an Arduino Core provieds a possibility for a OverTheAir Update. | ||
+ | |||
+ | http:// | ||
+ | |||
+ | ===== LED Test ===== | ||
< | < | ||
#!/bin/bash | #!/bin/bash | ||
IP=192.168.x.x | IP=192.168.x.x | ||
PORT=2342 | PORT=2342 | ||
- | for i in 16 48 96 256 128 64 32 16 1 | + | SLEEP=0.1 |
- | do | + | |
- | | + | while : ; do |
- | | + | for i in $(seq 32 -4 0); do |
- | | + | |
- | echo "{red:1, | + | |
- | | + | done |
+ | | ||
+ | for i in $(seq 32 -4 0); do | ||
+ | echo Led intensity: $i | ||
+ | echo "{red:0, | ||
+ | | ||
+ | sleep 1 | ||
+ | for i in $(seq 32 -4 0); do | ||
+ | echo Led intensity: $i | ||
+ | echo "{red:0,green:0, | ||
+ | done | ||
+ | | ||
done | done | ||
</ | </ | ||
- | ===== SNMP Example | + | ===== snmp2neopixel.sh |
< | < | ||
- | Todo | + | # |
+ | |||
+ | GATEWAYIP=192.168.x.1 | ||
+ | SNMPCOMMUNITY=public | ||
+ | INTNUMBER=1 | ||
+ | MESASURETIME=1 | ||
+ | INBOUNDBANDWIDTH=300000 | ||
+ | OUTBOUNDBANDWIDTH=100000 #Max Interface bandwidth | ||
+ | MAXBRIGHTNESS=32 | ||
+ | NEOPIXELIP=192.168.x.10 | ||
+ | NEOPIXELPORT=2342 | ||
+ | |||
+ | while true; do | ||
+ | TIME=$(date +%s) | ||
+ | OUT=$(snmpget -v2c -c $SNMPCOMMUNITY $GATEWAYIP ifOutOctets.$INTNUMBER | awk ' | ||
+ | IN=$(snmpget -v2c -c $SNMPCOMMUNITY $GATEWAYIP ifInOctets.$INTNUMBER | awk ' | ||
+ | |||
+ | if [ -z " | ||
+ | | ||
+ | exit 2 | ||
+ | else | ||
+ | sleep $MESASURETIME | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | if [ " | ||
+ | | ||
+ | if [ " | ||
+ | | ||
+ | fi | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | echo Inbound: $INPUTBW" | ||
+ | echo Outbound: $OUTPUTBW" | ||
+ | | ||
+ | | ||
+ | echo Inbound %: $INPUTPERCENT" | ||
+ | echo Outbound %: $OUTPUTPERCENT" | ||
+ | | ||
+ | | ||
+ | echo " | ||
+ | echo " | ||
+ | | ||
+ | echo "no change" | ||
+ | fi | ||
+ | fi | ||
+ | done | ||
</ | </ | ||
+ | |||
+ | ===== Webcam Motion Detection Notification ===== | ||
+ | You can use a RPi, a webcam and [[https:// | ||
+ | < | ||
+ | on_event_start echo " | ||
+ | on_event_end echo " | ||
+ | </ |