I have a model 3 running some python code as a service. It's never on for more than 30 minutes at a time and is maybe used once a day. However, when I do use it, it is often powered on and off multiple times in that period by simply unplugging it. Is my excessive power cycling without a proper shutdown the culprit here?

Here's the python code:

from sense_hat import SenseHat
import sys, requests, json

sense = SenseHat()
while True:
    raw = sense.get_accelerometer_raw()
    for k in raw:
        raw[k] = float(str(raw[k])[:7])
    r = requests.post('http://someurl/in', data=json.dumps(raw), headers={'Content-Type':'application/json'})

and the service file:

Description=runs data collection and sends to remote server

ExecStart=/usr/bin/python3 main.py

  • 1
    Similar post : raspberrypi.stackexchange.com/questions/50345/… Personally I always use 'sudo shutdown' or shutdown from the menu, unless I have no resort but to unplug. What psu are you using, do you see the lightning bolt icon? – CoderMike Nov 19 '17 at 23:59
  • 1
    why not just do a proper shutdown and see if that avoids the issue. How much time and money (your time is not free) are you spending buying and imaging new cards compared to doing a proper shutdown? – Steve Robillard Nov 20 '17 at 0:08
  • 1
    Is is something you are doing! I have had 2 SD Card problems with 6 Pi, 12 SD Cards over 4 years. One was a Card which totally failed after a few days use, and was replaced under warranty. The other was a failed update. It is very simple to add a safe poweroff switch, which I use on my headless Pi. See How to safely switch off the Raspberry Pi? this uses almost no resources - apart from a bit of RAM and a simple pushbutton. – Milliways Nov 20 '17 at 0:10
  • I'll look into making the joystick on the Sense Hat a power off switch, the end user doesn't have SSH access so it can't be shutdown properly. I do see the lightning bolt icon occasionally during testing. I'm powering it off a cellphone backup battery. Thank you all! – Josh Nov 21 '17 at 0:52

Get a larger battery, if seeing the lightning bolt icon, the unit is not getting enough current. Avoid shutting down the Pi by unplugging the power directly. Run a shutdown command by adding a button as described in the comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.