Unable to get Enviro+ to work from crontab when keyboard not connected

I’ve built the air quality monitor and connected it to Luftdaten following all the instructions here:

https://learn.pimoroni.com/tutorial/sandyj/enviro-plus-and-luftdaten-air-quality-station

Everything works fine if I run the luftdaten.py script by hand. Everything also runs fine from crontab on reboot as long as I have my keyboard attached. It all goes wrong as when I reboot without the keyboard attached.

I’ve directed output to a log file so I can see what’s going on and in the case of it not working when the keyboard is not attached I get the following:

Raspberry Pi serial: 000000008a8fe1d4
Wi-Fi: connected

{‘P2’: ‘2’, ‘pressure’: ‘62699.62’, ‘P1’: ‘2’, ‘temperature’: ‘4.80’, ‘humidity’: ‘50.59’}
(“bad handshake: Error([(’’, ‘osrandom_rand_bytes’, ‘getrandom() initialization failed.’)],)”,)
{‘P2’: ‘2’, ‘pressure’: ‘102746.46’, ‘P1’: ‘2’, ‘temperature’: ‘22.86’, ‘humidity’: ‘26.47’}
(“bad handshake: Error([(’’, ‘osrandom_rand_bytes’, ‘getrandom() initialization failed.’)],)”,)

The other symptom of the problem is that the LCD on the Enviro+ starts up all pixellated and never displays the serial number and ‘WiFi connected’ message that appears when it is working properly and logging data to Luftdaten.

So, it’s clear there’s a problem but I can’t for the life of me think why simply removing the keyboard would matter.

The keyboard and mouse I’m using and wireless and so I’m putting the wireless dongle into the USB port on the Pi to get the keyboard and mouse working.

Anyway, I’m baffled and this is driving me nuts. If anyone can explain what the problem is and how to resolve it I’d be most grateful. Obviously I can’t deploy this monitoring station until I can make it boot successfully without screen, keyboard and mouse attached.

Alice

I run a couple of Pi’s headless and start my python code via crontab. No problems here running without a keyboard and mouse.
Is there any keyboard code in your python file, something like press ctrl + x to exit etc.
I don’t own an enviro +, just so you know. I’m currently using a sense hat in those headless setups.

It’s not my code but it what’s provided by Pimoroni for this project so I sort of expected it to just work. When their script starts it does say press CTRL-C to exit but that’s the standard exit of any running command so I don’t think that’s it.

Ok, just a guess on my part to be honest.

Looking at the error message, I have the suspicion that this is a problem of the standard random generator that is part of Raspbian. It assumes the presence of a mouse and won’t initialize properly without it. Not sure if it needs a keyboard too. I had similar problems running a PI-zero headless with VNC. Try installing haveged (an entropy generator that does not need a mouse)

sudo apt-get install haveged

I was wondering whether something like this might be the reason. That’s a really helpful suggestion, I’ll try it. Will I need to change the Pimoroni code to use haveged rather than the standard random number generator?

Totally missed the error message in the first post some how. =(
Sorry about that. I should probably wait until I’ve had at least one full cup of coffee before posting. lol.

No, there is no need to change anything. Just install haveged and reboot. If the entropy gathering was the problem, it should simply work now

Yes, that did the trick. Thank you so much.

Alice

Thats good to hear. Now have some fun with your new tech. =)