Trials and tribulations of getting pwnagotchi 1.5.5 to work - Page 1
Forum section: electronics / general

author: tocsa120ls
author_rank: Regular Contributor
timestamp: June 03, 2021, 10:34:10 am
content: Hi all,bit of a long one. I just want to describe the problems I've had getting this pocket-sized AI to work. The usual warnings apply, if you're not comfortable messing around with $50 of hardware, if your country restricts the gathering of anonymized personal data, etc... follow at your own risk.This is one of those interesting projects that I thought would be fun to 'throw together' one evening and have some fun with. Well, 2 days later it is working as intended and described on their homepage. What were my issues?1.) that darn RTC- LadyAda  has an _excellent_ guide on how to add a real time clock to any Raspberry Pi, but it does not go into detail what to do when the dreaded ioctl "Invalid argument" error comes. They just say make sure you use a good battery. I made my own RTC panel on a SOIC breakout board with an PCF8563, a Lithium battery and some passives. It worked well enough on my test board, so I soldered it permanently to the pwnagotchi and spent 2 hours debugging.It reported back all right:Code:pi@pwnagotchi:~ $ sudo i2cdetect -y 10 1 2 3 4 5 6 7 8 9 a b c d e f...50: -- 51 -- -- -- -- -- -- -- -- -- -- -- -- -- --And, after adding the requisitedtoverlay=i2c-rtc,pcf8563to the/boot/config.txtand rebooting, it is on the i2c bus, and it is recognized with the correct kernel module:Code:pi@pwnagotchi:~ $ lsmod | grep rtcrtc_pcf8563 16384 0pi@pwnagotchi:~ $ sudo i2cdetect -y 10 1 2 3 4 5 6 7 8 9 a b c d e f...50: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- --But, on trying to readCode:i@pwnagotchi:~ $ sudo hwclock -r --verbosehwclock from util-linux 2.33.1System Time: 1550139193.951830Trying to open: /dev/rtc0Using the rtc interface to the clock.Assuming hardware clock is kept in UTC time.Waiting for clock tick...ioctl(3, RTC_UIE_ON, 0): Invalid argumentWaiting in loop for time from /dev/rtc0 to changehwclock: ioctl(RTC_RD_TIME) to /dev/rtc0 to read the time failed: Invalid argument...synchronization failedDarn. It is there in the i2c tree, the correct module is loaded, it worked on the test board, what gives? Logs do help:Code:pi@pwnagotchi:~ $ sudo dmesg | grep rtc[ 15.474815] rtc-pcf8563 1-0051: rtc core: registered rtc-pcf8563 as rtc0[ 16.499897] rtc-pcf8563 1-0051: low voltage detected, date/time is not reliable.Ohferchrissakes... I must have bumped one of the power pins when I was messing around mounting it. Battery's soldered... the kernel module documentation says this error comes when the seventh bit of theVL_secondsregister is set automatically in the PCF8563:Let's check...Code:pi@pwnagotchi:~ $ i2cdump -y -f -r 0-15 1 0x51No size specified (using byte-data access)0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef00: 08 80 b9 a4 82 81 b9 20 00 a8 9d 90 92 38 3b 20 ??????? .????8;VL_seconds is the third from the left, valueb9is 0b10111001 so yes, in fact that bit is set. Let's clear it...Code:pi@pwnagotchi:~ $ i2cset -y -f -r 1 0x51 2 00Value 0x00 written, readback matchedIt works!Code:pi@pwnagotchi:~ $ sudo hwclock -w --verbosehwclock from util-linux 2.33.1System Time: 1550140271.765338Trying to open: /dev/rtc0Using the rtc interface to the clock.Assuming hardware clock is kept in UTC time.RTC type: 'rtc-pcf8563'Using delay: 0.000000 secondsmissed it - 1550140271.792381 is too far past 1550140271.000000 (0.792381 > 0.001000)1550140272.000000 is close enough to 1550140272.000000 (0.000000 < 0.002000)Set RTC to 1550140272 (1550140271 + 1; refsystime = 1550140271.000000)Setting Hardware Clock to 10:31:12 = 1550140272 seconds since 1969ioctl(RTC_SET_TIME) was successful.Not adjusting drift factor because the --update-drift option was not used.New /etc/adjtime data:0.000000 1550140271 0.000000 1550140271 UTCCode:pi@pwnagotchi:~ $ sudo hwclock -r2021-06-02 21:47:28.876202+01:002.) Second problem(that caused a third one) is... it was constantly reporting that it is inAutomode and never went intoAImode. I mean the wiki says to wait 15-30 minutes for everything to load, but after 2 hours it was still in auto mode. Check logs!Code:[2021-06-02 22:01:19,040]  error while starting AI (numpy.ndarray size changed, may indicate binary incompatibility. Expected 44 from C header, got 40 from PyObject)File "/usr/local/lib/python3.7/dist-packages/pwnagotchi/ai/__init__.py", line 21, in load...ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 44 from C header, got 40 from PyObject[2021-06-02 22:01:19,203]   AI not loaded!I found a github entry for this  which says just update the Python 'numpy' package. Issue of course, this gadget is made to sniff wifi, so the wlan kernel module is patched, the wpa_supplicant is gutted/not installed, so even if I stop the pwnagotchi service, there won't be any internet connection. So far I've been connecting to it over USB, where the RPi0W acts as an RNDIS Ethernet Gadget over the USB cable plugged into the second micro-USB port. After the RPi0W gets recognized+installed as a standard ethernet port, you need to install the driver manually because if not, it just reports a new COM port in the device tree. You need to update that port with the correct RNDIS driver .The standard config for this is (IP 10.0.0.1, Netmask 255.255.255.0, GW 10.0.0.1, DNS 8.8.8.8 ) - I've been using this so far and it worked. But when you right-click your main internet connection's icon to set up internet sharing, Windows says it will reconfigure the new port with a 192.168.137.1 IP address. Great! An IP pulled seemingly out of some programmer's arse. Update the configuration in the RPi:Code:pi@pwnagotchi:~ $ sudo cat /etc/network/interfaces.d/usb0-cfgallow-hotplug usb0iface usb0 inet staticaddress 192.168.137.2netmask 255.255.255.0network 192.168.137.0broadcast 192.168.137.255gateway 192.168.137.1metric 20Do this while the internet isn't shared yet; do asysctl restart networking(RPi goes dark), enable the sharing in Windows, and SSH into the 'new' IP address:Code:tocsa120ls@DESKTOP ~$ ssh pi@192.168.137.2Linux pwnagotchi 4.19.127-Re4son+ #1 Sun Feb 21 21:13:51 AEDT 2021 armv6l(◕‿‿◕) pwnagotchiHi! I'm a pwnagotchi, please take good care of me!pi@pwnagotchi:~Adjust/etc/resolv.confto 8.8.8.8 and voila: network access!Code:pi@pwnagotchi:~ $ ping eevblog.comPING eevblog.com (192.154.109.3) 56(84) bytes of data.64 bytes from 192-154-109-3.static.gorillaservers.com (192.154.109.3): icmp_seq=1 ttl=47 time=142 ms^C--- eevblog.com ping statistics ---1 packets transmitted, 1 received, 0% packet loss, time 0msrtt min/avg/max/mdev = 142.468/142.468/142.468/0.000 msSo then, onto the original problem that the unitdoes not switch to AI mode--- easy going from now on...Code:root@pwnagotchi:~# pip3 install --upgrade numpyLooking in indexes: https://pypi.org/simple, https://www.piwheels.org/simpleCollecting numpyDownloading https://www.piwheels.org/simple/numpy/numpy-1.20.3-cp37-cp37m-linux_armv6l.whl (11.6MB)100% |████████████████████████████████| 11.6MB 7.7kB/spwnagotchi 1.5.5 has requirement numpy==1.17.2, but you'll have numpy 1.20.3 which is incompatible.matplotlib 3.4.1 has requirement pillow>=6.2.0, but you'll have pillow 5.4.1 which is incompatible.Installing collected packages: numpyFound existing installation: numpy 1.17.2Uninstalling numpy-1.17.2:Successfully uninstalled numpy-1.17.2Successfully installed numpy-1.20.3root@pwnagotchi:~# reboot(do this as root or with sudo!)Everything works! Now I only need to wait for a battery shield (which will attach where I hacked my RTC on) and 3D-print a case. Piece of cake, right? (will report)https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pihttps://github.com/evilsocket/pwnagotchi/issues/974https://modclouddownloadprod.blob.core.windows.net/shared/mod-duo-rndis.zip