Tuesday, April 4, 2017

111: Particle Pi Bugs, Reprise

I've been working on other things and have ignored the Pi lately. But today (Apr 4) I decided to see if Particle's Pi interface had changed (i.e., was fixed). Spoiler! This is long and ugly.

So I logged into my Pi.

1. According to the "ps" command the Particle device process was running.
2. So I went to the WebIDE (https://build.particle.io/build/...) and tried to recompile a simple test sketch.
3. As I expected, this returned a "request timed out" error message.
4. So on my Pi I executed "sudo particle-agent restart". Ps now lists (the "?" stands for the device ID):

13591 ?        S     11:30 /var/lib/particle/devices/?/firmware.bin -v 70
30494 ?        Sl     0:00 /usr/bin/ruby /usr/bin/particle-agent-service (...)
30498 ?        S      0:00 /var/lib/particle/devices/?/firmware.bin -v 70

So now I appear to have 2 copies of this old firmware.bin running:

-rwxr--r-- 1 root root 664576 Mar 10 19:00 /var/lib/particle/devices/?/firmware.bin

So I do "kill -9 13591". That worked.
5. Then I tried another WebIDE compile. Same error.
6. Still wasting my time, I try this:
root@myPi:/home/pi# particle-agent setup
Let's connect your Raspberry Pi to the Particle Cloud!

You are already logged in as xyz@abc.com.

Do you want to stay logged in as this user? |yes| yes
How do you want your device to be labeled in the Particle tools?
Name: |pi4| 
Generating RSA private key, 1024 bit long modulus
e is ??? (0x10001)
writing RSA key
writing RSA key
⠏  Claiming the device to your Particle account 
Particle cloud error. Name already in use

That ended in an error message but -- wait for it -- it worked. Well, not quite. I have 2 processes again:
30498 ?        S      0:00 /var/lib/particle/devices/?/firmware.bin -v 70
30583 ?        S      0:00 /var/lib/particle/devices/?/firmware.bin -v 70

So? kill -9 30498. Worked. And I got sensible output to a file.
7. So, I try another compile. Timed out.
8. Back to "particle-agent stop" . Which stops the Ruby process but not the firmware.bin.
9. What else is left? Oh, yes: reboot!
10. After reboot a new compile works. Worked several times. But for how long?
11. Not long if you try to "fix" Particle's problem (my view) with running as root. I first tried this added above setup():

void uid_fix() {
    setuid(SAFE_UID); // don't be ROOT!

STARTUP( uid_fix() );

Didn't work. Output file (written by my program) still belonged to root.
12. So, I move the setuid/setgid into setup(). That's when firmware.bin stopped being changed when I recompiled -- though the WebIDE thought it worked.
-rwxr--r-- 1 root root 648192 Apr  4 11:24 /var/lib/particle/devices/?/firmware.bin

Flashed new code at 11:36, file is still the 11:24 compile.
13. So, now I suppose I have to go through process kill, "particle-agent setup" or reboot to get a WebIDE "flash" to actually work again. And the "root" problem hangs on.

No comments:

Post a Comment