I’ve just downloaded! Great job, thanks for sharing!
UPDATE: I’ve added a README to the repo, primarily to add install directions to the repo. After all, what good is a repo if nobody knows how to install it? Also gonna see about making a Docker container for this repo, as adding compilation tools into an image probably isn’t the brightest of ideas…
Thanks some little notes:
- typo in debian
- why install
libwebp-dev tcl8.6-dev tk8.6-dev python-tk
? Last3 imho are gui-libs,first is a -dev usally used for compiling own apps
Source: Pillow Installation Instructions
I just posted why I was told was needed to build the Python Pillow package. I’ll see if I can trim the package “requirements” down a bit later today…
does it need building (then i guess gcc/cpp ais also needed)? is there no binary package? building-tools on router is a huge security hole
Maybe this is the right way:
Most major Linux distributions, including Fedora, Debian/Ubuntu and ArchLinux also include Pillow in packages that previously contained PIL e.g.
python-imaging
https://pillow.readthedocs.io/en/stable/installation.html
For python3 this needs to be installed. https://packages.debian.org/buster/python3-pil
Tested with basic-script from https://zetcode.com/python/pillow/
I guess Adafruit_GPIO is also not needed as it is only imported for spi as far as i see
in your call to getIP-Address you use “wan” instead of the variable wan_interface. so in case wan_interface is set to anything else, either an exception is thrown (if interface does not exist like on my laptop) or the wrong ip is printed (if there is any)
get_ip_address(wan_interface)
i change the script locally a bit, to generate text (for printing it out) instead of printing to display…so i can catch the data, print it to cli for external debugging…if display is enabled the image is generated (not finished yet)
forked your repo and change these 2 little things: https://github.com/frank-w/bpi-r2-ssd1306-display
have also uploaded reworked version, works without display…still waiting for my display to arrive
Wow… These changes are quite interesting! Care to create a Pull request?
Cannot test on real display and currently disabled icons (to make it easier to run code without icons).i guess furumc and i need smaller icons because we have (i have ordered) 2 color displays. And it looks like yellow is ~16px top and blue 3/4 below
Try here for monochrome icons: flaticon.com. I’ve already selected icons and black-filled filters to aid your process. All you have to do is find the icon(s) you want. They will allow you to select the size of icon you want to download.
is there an easy way to reduce colors (1 bit) and invert them (make black to white)?
you have already white icons, but all i’ve found are black…
icons16.zip (3,0 KB)
i think i got it solved using pillow based on https://note.nkmk.me/en/python-pillow-invert/:
def loadinvert(f):
iconpath = os.path.dirname(__file__)
im = Image.open(iconpath+"/"+f).convert('RGB')
return ImageOps.invert(im).convert('1')
globe = loadinvert('earth16.png')
this works for my earth-icon but not for wifi/phone
wifi works if i first convert to 1bit, then to rgb, then invert, but phone still shows only a white square. Seems like i need to change it manually
Maybe this page has an answer: How to invert colors of image with PIL (Python-Imaging)?
Personally, I used GIMP to invert the colors before saving them to PNG. Having that functionality in Python would be great… My router image doesn’t have the script installed, so I can’t test at the moment.
EDIT: I don’t think that you should convert to RGB at any point during this process… I could be mistaken, though…
i had problems with the phone-icon also in other editors (e.g. gnome-paint). have now also used gimp (need to redraw the globe completely)
- colors-invert
- image-mode-indexed to get it into 1bit
icons-white.zip (7,8 KB)
Btw. Convert to rgb was necessary for the invert…see link above
i have uploaded my last version, maybe you can try on your display as i still waiting for it
simply uncomment
use_disp=True
currently working on voip-detection which is a bit tricky because r2 only moves traffic from ppp-interface to a external Voip-adapter. so i need to count sip-packets with an iptables rule, log it every 5 min to a file, read last 2 values from this file and calc difference…if this (packets in last full 5min block) is >0 (or maybe more) then i expect, the voip-adapter is logged in
i do this check after some basic checks like
ip link sh ppp9 | grep ,UP, >/dev/null;echo $? #check state of voip-interface
ping -c 1 192.168.0.8 >/dev/null;echo $? #check if voip-adapter is reachable
ip rule show | grep voip >/dev/null;echo $? #check if rule is set
ip route show | grep ppp9 >/dev/null;echo $? #check routing table for voip interface
slightly modified:
ip link sh ppp9 | grep ,UP, >/dev/null;u=$?
ping -c 1 192.168.0.8 >/dev/null;p=$?
ip rule show | grep voip >/dev/null;ru=$?
ip route show | grep ppp9 >/dev/null;ro=$?
res=$(($u + $p<<8 + $ru<<16 + $ro<<24)) #shifting each result 8bits (return value can be 255 max)
if [[ $res -eq 0 ]];then echo "all ok";fi
traffic-monitoring (in case anyone will do something similar):
#rules to monitor traffic
${ipt} -N voip1
${ipt} -N voip2
${ipt} -A FORWARD -s 192.168.0.8 -p udp --dport 5160 -j voip1
${ipt} -A FORWARD -d 192.168.0.8 -p udp --dport 5160 -j voip1
${ipt} -A FORWARD -s 192.168.0.8 -p udp --sport 5161 -j voip2
${ipt} -A FORWARD -d 192.168.0.8 -p udp --dport 5161 -j voip2
${ipt} -A voip1 -j ACCEPT
${ipt} -A voip2 -j ACCEPT
#read out (cronjob every 5 min)
iptables-legacy -L voip1 -v -nx | grep 'ACCEPT' | awk '{print $1}' >>$logdir/voip1.log
iptables-legacy -L voip2 -v -nx | grep 'ACCEPT' | awk '{print $1}' >>$logdir/voip2.log
#calculate difference (actually i have 40 packets on voip1 and 20packets on voip2, don't know why it is the half...)
bash -c 'str=$(tail -2 /var/log/voip1.log);ar=($str);res=$(( ${ar[1]} - ${ar[0]} ));echo $res'
I tried to rebase my changes on your latest state (i hope i have not break anything) and created pull request.
@furumc can you retest with pr branch in my repo?
I will do it! Which pr branch do you mean?
Strange it is not shown in dropdown on github…
have ordered a display from germany because the cn one is still not arrived…the german is now connected. but i don’t see i2c-bus in 5.11-main…any idea?
i2cdetect -y 2
Error: Could not open file `/dev/i2c-2' or `/dev/i2c/2': No such file or directory
and yes i have no /dev/i2c* on my test-device
zgrep 'I2C' /proc/config.gz | grep '=[ym]'
CONFIG_REGMAP_I2C=y
CONFIG_I2C=y
CONFIG_I2C_BOARDINFO=y
CONFIG_I2C_COMPAT=y
CONFIG_I2C_CHARDEV=m
CONFIG_I2C_HELPER_AUTO=y
CONFIG_I2C_ALGOBIT=y
CONFIG_I2C_MT65XX=y
CONFIG_VIDEO_V4L2_I2C=y
CONFIG_VIDEO_IR_I2C=y
CONFIG_SND_SOC_I2C_AND_SPI=y
CONFIG_RTC_I2C_AND_SPI=y
see nothing i2c-related on dmesg
got it…need to load chardev-module
modprobe i2c-dev
but i do not see the display…
root@bpi-r2:~# i2cdetect -y 2
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
i have connected it to 3V3 (pin 1+9) and use also i2c2 (27+28). should it show anything on only power connected? also tried swapping 27+28
mhm, simply did the echo and it works
echo "ssd1306 0x3C" > /sys/class/i2c-adapter/i2c-2/new_device
add user (which wants to run the script) to i2c-group
adduser frank i2c
and needed to change the iconpath-line a bit
iconpath = os.path.dirname(os.path.abspath(__file__))
and run
python3 stats.py
don’t know why i2cdetect don’t show the device
I’ve faced exactly with this in the past! Do you remember, on my r2 hdmi collapsed after running i2c-detect? You have figured out, i2c-detect won’t detect it, you have to add it manually as device!
Can I choose pr branch from drop-down menu yet?
no, i guess on github the branch is interpreted as pullrequest because of name pr and filtered out
but you can access it via the link https://github.com/frank-w/bpi-r2-ssd1306-display/tree/pr or by cloning my repo and switching to it by “git checkout pr”
if i use -r flag of i2cdetect, display is shown
root@bpi-r2:~# i2cdetect -y -r 2
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
i moved some code in functions and added a uptime (currently not displayed)