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-15 08:32] – [Test] trinitor | 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 57: | Line 59: | ||
///////////////////////////// | ///////////////////////////// | ||
// Network | // Network | ||
- | const char* ssid = "your_wifi_ssid"; | + | const char* ssid = "yourSSID"; |
- | const char* password | + | const char* password |
unsigned int localUdpPort = 2342; | unsigned int localUdpPort = 2342; | ||
- | char incomingPacket[255]; | + | char incomingPacket[255]; |
- | char replyPacket[] = " | + | char replyPacekt[] = " |
// neopixel | // neopixel | ||
const int LEDPIN | const int LEDPIN | ||
const int NUMPIXELS | const int NUMPIXELS | ||
+ | |||
int displayrefresh | int displayrefresh | ||
+ | int shiftpixels | ||
+ | int alwaysoff | ||
////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////// | ||
- | // usage examples: | + | // usage examples: |
- | // echo " | + | // echo " |
- | // echo " | + | // echo " |
- | // echo " | + | // echo " |
+ | // echo " | ||
+ | // echo " | ||
+ | // echo " | ||
+ | // echo " | ||
+ | // echo " | ||
Line 101: | Line 111: | ||
void loop() | void loop() | ||
{ | { | ||
- | int red = -1; | + | int red |
- | int green = -1; | + | int green |
- | int blue | + | int blue = 0; |
- | int refresh | + | int refresh |
- | int all = 0; | + | int scroll |
- | int clearall = 0; | + | int pixel |
+ | int all | ||
+ | int clearall | ||
+ | int effect | ||
+ | int option1 | ||
| | ||
int packetSize = Udp.parsePacket(); | int packetSize = Udp.parsePacket(); | ||
if (packetSize) | if (packetSize) | ||
{ | { | ||
- | // Serial.println(" | ||
// receive incoming UDP packets | // receive incoming UDP packets | ||
// Serial.printf(" | // Serial.printf(" | ||
Line 120: | Line 133: | ||
incomingPacket[len] = 0; | incomingPacket[len] = 0; | ||
// Serial.printf(" | // Serial.printf(" | ||
- | // Serial.println(" | ||
StaticJsonBuffer< | StaticJsonBuffer< | ||
JsonObject& | JsonObject& | ||
Line 136: | Line 148: | ||
blue = json[" | blue = json[" | ||
refresh | refresh | ||
+ | pixel = json[" | ||
all = json[" | all = json[" | ||
clearall = json[" | clearall = json[" | ||
+ | scroll | ||
+ | effect | ||
+ | option1 | ||
} | } | ||
} | } | ||
Line 144: | Line 160: | ||
// Serial.println(" | // Serial.println(" | ||
// Udp.beginPacket(Udp.remoteIP(), | // Udp.beginPacket(Udp.remoteIP(), | ||
- | // Udp.write(replyPacket); | + | // Udp.write(replyPacekt); |
// Udp.endPacket(); | // Udp.endPacket(); | ||
} | } | ||
- | // new refresh rate received | + | // new refreshrate |
if (refresh > 0) { | if (refresh > 0) { | ||
Serial.println(" | Serial.println(" | ||
Line 154: | Line 170: | ||
} | } | ||
- | // set all pixel to black if clearall was set to 1 | + | |
+ | if (scroll > 0) { | ||
+ | Serial.printf(" | ||
+ | if (scroll == 1) { | ||
+ | shiftpixels = 1; | ||
+ | } else { | ||
+ | shiftpixels = 2; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | | ||
if(all == 1) { | if(all == 1) { | ||
- | // | + | |
for(int i=0; i< | for(int i=0; i< | ||
pixels.setPixelColor(i, | pixels.setPixelColor(i, | ||
Line 164: | Line 190: | ||
// set all pixel to black if clearall was set to 1 | // set all pixel to black if clearall was set to 1 | ||
if(clearall == 1) { | if(clearall == 1) { | ||
- | // | + | |
for(int i=0; i< | for(int i=0; i< | ||
pixels.setPixelColor(i, | pixels.setPixelColor(i, | ||
Line 171: | Line 197: | ||
//shift pixels | //shift pixels | ||
- | for(int i=NUMPIXELS; | + | |
- | uint32_t color = pixels.getPixelColor(i); | + | // Serial.println(" |
- | pixels.setPixelColor(i+1, | + | |
+ | uint32_t color = pixels.getPixelColor(i); | ||
+ | pixels.setPixelColor(i+1, | ||
+ | } | ||
} | } | ||
- | //set color of Pixel 0 | + | |
+ | if (option1 == 0) { option1 = 128; } | ||
+ | fade(option1); | ||
+ | } | ||
+ | else if (effect == 2) { | ||
+ | if (option1 == 0) { option1 = 20; } | ||
+ | rainbow(option1); | ||
+ | } | ||
+ | | ||
// new color proviced color changed? | // new color proviced color changed? | ||
- | if (red >=0 || green >=0 || blue >=0) { | + | |
//read current color | //read current color | ||
uint32_t CurrentColor = pixels.getPixelColor(1); | uint32_t CurrentColor = pixels.getPixelColor(1); | ||
Line 185: | Line 222: | ||
uint8_t | uint8_t | ||
- | //if new color < 0 reuse the old color | + | // if no new color was set -> reuse the old color |
- | if (red < 0) {red | + | if (red == 0) {red = CurrentRed; |
- | if (green | + | if (green |
- | if (blue | + | if (blue |
- | + | ||
- | // Serial.printf(" | + | // set pixel 0 in case no spesific pixel was requested |
- | pixels.setPixelColor(0, | + | if (pixel == 0) { |
+ | // | ||
+ | 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 { | } else { | ||
// Serial.printf(" | // Serial.printf(" | ||
- | uint32_t color = pixels.getPixelColor(1); | + | |
- | pixels.setPixelColor(0, | + | |
+ | if (alwaysoff = 1) { | ||
+ | | ||
+ | } else { | ||
+ | pixels.setPixelColor(0, | ||
+ | } | ||
+ | } | ||
} | } | ||
Line 201: | Line 255: | ||
delay(displayrefresh); | 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 247: | Line 349: | ||
</ | </ | ||
- | ===== 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 " | ||
+ | </ |