Author Topic: Trials and tribulations of getting pwnagotchi 1.5.5 to work  (Read 1352 times)

0 Members and 1 Guest are viewing this topic.

Offline tocsa120lsTopic starter

  • Regular Contributor
  • *
  • Posts: 79
  • Country: hu
  • Electronic hobbyist living in Stuttgart
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 [1] 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: [Select]
pi@pwnagotchi:~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
...
50: -- 51 -- -- -- -- -- -- -- -- -- -- -- -- -- --

And, after adding the requisite dtoverlay=i2c-rtc,pcf8563 to the /boot/config.txt and rebooting, it is on the i2c bus, and it is recognized with the correct kernel module:

Code: [Select]
pi@pwnagotchi:~ $ lsmod | grep rtc
rtc_pcf8563            16384  0
pi@pwnagotchi:~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
...
50: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- --

But, on trying to read

Code: [Select]
i@pwnagotchi:~ $ sudo hwclock -r --verbose
hwclock from util-linux 2.33.1
System Time: 1550139193.951830
Trying to open: /dev/rtc0
Using 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 argument
Waiting in loop for time from /dev/rtc0 to change
hwclock: ioctl(RTC_RD_TIME) to /dev/rtc0 to read the time failed: Invalid argument
...synchronization failed

Darn. It is there in the i2c tree, the correct module is loaded, it worked on the test board, what gives? Logs do help:

Code: [Select]
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 the VL_seconds register is set automatically in the PCF8563:


Let's check...

Code: [Select]
pi@pwnagotchi:~ $ i2cdump -y -f -r 0-15 1 0x51
No size specified (using byte-data access)
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 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, value b9 is 0b10111001 so yes, in fact that bit is set. Let's clear it...

Code: [Select]
pi@pwnagotchi:~ $ i2cset -y -f -r 1 0x51 2 00
Value 0x00 written, readback matched

It works!

Code: [Select]
pi@pwnagotchi:~ $ sudo hwclock -w --verbose
hwclock from util-linux 2.33.1
System Time: 1550140271.765338
Trying to open: /dev/rtc0
Using the rtc interface to the clock.
Assuming hardware clock is kept in UTC time.
RTC type: 'rtc-pcf8563'
Using delay: 0.000000 seconds
missed 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 1969
ioctl(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 UTC
Code: [Select]
pi@pwnagotchi:~ $ sudo hwclock -r
2021-06-02 21:47:28.876202+01:00

2.) Second problem
(that caused a third one) is... it was constantly reporting that it is in Auto mode and never went into AI mode. 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: [Select]
[2021-06-02 22:01:19,040] [ERROR] 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] [WARNING] [ai] AI not loaded!

I found a github entry for this [2] 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 [3].

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: [Select]
pi@pwnagotchi:~ $ sudo cat /etc/network/interfaces.d/usb0-cfg
allow-hotplug usb0
iface usb0 inet static
  address 192.168.137.2
  netmask 255.255.255.0
  network 192.168.137.0
  broadcast 192.168.137.255
  gateway 192.168.137.1
  metric 20

Do this while the internet isn't shared yet; do a sysctl restart networking (RPi goes dark), enable the sharing in Windows, and SSH into the 'new' IP address:

Code: [Select]
tocsa120ls@DESKTOP ~
$ ssh pi@192.168.137.2
Linux pwnagotchi 4.19.127-Re4son+ #1 Sun Feb 21 21:13:51 AEDT 2021 armv6l
(◕‿‿◕) pwnagotchi

Hi! I'm a pwnagotchi, please take good care of me!
pi@pwnagotchi:~

Adjust /etc/resolv.conf to 8.8.8.8 and voila: network access!

Code: [Select]
pi@pwnagotchi:~ $ ping eevblog.com
PING 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 0ms
rtt min/avg/max/mdev = 142.468/142.468/142.468/0.000 ms

So then, onto the original problem that the unit does not switch to AI mode --- easy going from now on...

Code: [Select]
root@pwnagotchi:~# pip3 install --upgrade numpy
Looking in indexes: [url]https://pypi.org/simple,[/url] [url]https://www.piwheels.org/simple[/url]
Collecting numpy
  Downloading [url]https://www.piwheels.org/simple/numpy/numpy-1.20.3-cp37-cp37m-linux_armv6l.whl[/url] (11.6MB)
    100% |████████████████████████████████| 11.6MB 7.7kB/s
pwnagotchi 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: numpy
  Found existing installation: numpy 1.17.2
    Uninstalling numpy-1.17.2:
      Successfully uninstalled numpy-1.17.2
Successfully installed numpy-1.20.3
root@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  :palm: ) and 3D-print a case. Piece of cake, right? (will report)



[1] https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi
[2] https://github.com/evilsocket/pwnagotchi/issues/974
[3] https://modclouddownloadprod.blob.core.windows.net/shared/mod-duo-rndis.zip
« Last Edit: June 05, 2021, 05:25:50 am by tocsa120ls »
-------
Short circuit - long fire
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf