linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: SSD1306 OLED headless system monitor

Fri Nov 04, 2016 9:16 pm

hey folks, hope you are all having a lot of fun with your RPi families!

just thought i'd post a little 'bullet-proofing' code i added to my sensor-reading script; this code reboots the system in 10 minutes following a failed sensor reading... this has helped me with my RPi in the garage, which takes readings from outside and logs them onto a lighttpd Web directory for pickup by other RPis in the casa:

Code: Select all

def reboot():
  text_file = open("/var/www/html/weather.txt", "a")
  text_file.write(str(datetime.now().strftime('%F %H:%M ')))
  text_file.write("error reading sensor - rebooting\n")
  text_file.close()
  time.sleep(600)
  cmd = "/usr/bin/sudo /sbin/shutdown -r now"
  import subprocess
  process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
  output = process.communicate()[0]
  return  "%s" % output
the reboot() function above is called inside a Python 'try' statement like this:

Code: Select all

# Read temperature/pressure/humidity
  try:
        data = bus.read_i2c_block_data(addr, REG_DATA, 8)
  except IOError:
        reboot()
it helped me a lot yesterday when our electrical grid seemed to be having problems... things started going awry at 0200, but normalized by 0716:

Code: Select all

2016-11-03 02:10 error reading sensor - rebooting
2016-11-03 02:20 error reading sensor - rebooting
2016-11-03 02:31 67.6 22.7 100.0
2016-11-03 02:41 error reading sensor - rebooting
2016-11-03 02:51 67.6 22.7 100.0
2016-11-03 03:01 error reading sensor - rebooting
2016-11-03 03:11 67.6 22.7 100.0
2016-11-03 03:21 error reading sensor - rebooting
2016-11-03 03:31 67.6 22.7 100.0
2016-11-03 03:41 error reading sensor - rebooting
2016-11-03 03:52 67.6 22.7 100.0
2016-11-03 04:02 error reading sensor - rebooting
2016-11-03 04:12 67.6 22.7 100.0
2016-11-03 04:22 error reading sensor - rebooting
2016-11-03 04:32 error reading sensor - rebooting
2016-11-03 04:44 error reading sensor - rebooting
2016-11-03 04:54 error reading sensor - rebooting
2016-11-03 05:04 67.6 22.7 100.0
2016-11-03 05:14 error reading sensor - rebooting
2016-11-03 05:25 67.6 22.7 100.0
2016-11-03 05:35 error reading sensor - rebooting
2016-11-03 05:45 67.6 22.7 100.0
2016-11-03 05:55 error reading sensor - rebooting
2016-11-03 06:05 67.6 22.7 100.0
2016-11-03 06:15 error reading sensor - rebooting
2016-11-03 06:25 error reading sensor - rebooting
2016-11-03 06:36 error reading sensor - rebooting
2016-11-03 06:46 error reading sensor - rebooting
2016-11-03 06:56 67.6 22.7 100.0
2016-11-03 07:06 error reading sensor - rebooting
2016-11-03 07:16 69.7 30.2 58.9
Note the bogus BME280 readings (temp/barometric/humidity) until the end. Things have been running smoothly since then (and had been running OK for a couple weeks previously).

Hope this helps someone!

willie
on the cooling Gulf of Mexico

notholmen
Posts: 31
Joined: Tue Dec 25, 2012 10:10 am

Re: SSD1306 OLED headless system monitor

Wed Nov 16, 2016 5:26 pm

Hey guys,
I'm super happy that I found this script!
It's exactly what I have been looking for! - I'll also add my small code snippet to show last few messages of syslog output.

* But first, I'm having issues getting lib_oled96 installed. Any one else has this issue?

Do you have any clue what it could be?

Code: Select all

user@rpi:~/Adafruit_Python_SSD1306/examples$ sudo pip install git+git://github.com/BLavery/lib_oled96.git
Downloading/unpacking git+git://github.com/BLavery/lib_oled96.git
  Cloning git://github.com/BLavery/lib_oled96.git to /tmp/pip-tLdUf8-build
  Running setup.py (path:/tmp/pip-tLdUf8-build/setup.py) egg_info for package from git+git://github.com/BLavery/lib_oled96.git
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
    IOError: [Errno 2] No such file or directory: '/tmp/pip-tLdUf8-build/setup.py'
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 17, in <module>

IOError: [Errno 2] No such file or directory: '/tmp/pip-tLdUf8-build/setup.py'

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip-tLdUf8-build
Storing debug log for failure in /root/.pip/pip.log
1 user@rpi:~/Adafruit_Python_SSD1306/examples$ sudo cat /root/.pip/pip.log
------------------------------------------------------------
/usr/local/bin/pip run on Wed Nov 16 19:02:54 2016
Downloading/unpacking git+git://github.com/BLavery/lib_oled96.git
  Cloning git://github.com/BLavery/lib_oled96.git to /tmp/pip-tLdUf8-build
  Found command 'git' at '/usr/bin/git'
  Running command /usr/bin/git clone -q git://github.com/BLavery/lib_oled96.git /tmp/pip-tLdUf8-build
  Running setup.py (path:/tmp/pip-tLdUf8-build/setup.py) egg_info for package from git+git://github.com/BLavery/lib_oled96.git
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
    IOError: [Errno 2] No such file or directory: '/tmp/pip-tLdUf8-build/setup.py'
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 17, in <module>

IOError: [Errno 2] No such file or directory: '/tmp/pip-tLdUf8-build/setup.py'

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip-tLdUf8-build
Exception information:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 290, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1230, in prepare_files
    req_to_install.run_egg_info()
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 326, in run_egg_info
    command_desc='python setup.py egg_info')
  File "/usr/lib/python2.7/dist-packages/pip/util.py", line 716, in call_subprocess
    % (command_desc, proc.returncode, cwd))
InstallationError: Command python setup.py egg_info failed with error code 1 in /tmp/pip-tLdUf8-build

User avatar
bitbank
Posts: 252
Joined: Sat Nov 07, 2015 8:01 am
Location: Sarasota, Florida
Contact: Website

Re: SSD1306 OLED headless system monitor

Fri Feb 03, 2017 4:30 pm

Did you ever try sending a reset command (0xe0) to the BME280 instead of rebooting the whole machine?
The fastest code is none at all :)

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: SSD1306 OLED headless system monitor

Fri Feb 03, 2017 6:17 pm

bitbank wrote:Did you ever try sending a reset command (0xe0) to the BME280 instead of rebooting the whole machine?
that's a very good idea - i'll put it into the script and run some tests (takes until a failure, but logging should pinpoint where and when)... the bme280s i got may/may not be actual Bosch units... i've had one running for months inside the house with no problems whatsoever... but when these units are in high-humidity/high-temp conditions, they seem to crap out...

tks!

willie
on the sunny and beautiful Gulf of Mexico

Bbuschke
Posts: 16
Joined: Tue Jan 31, 2017 4:02 am

Re: SSD1306 OLED headless system monitor

Tue Jun 12, 2018 1:41 am

im new to this. I have a script that im using that displays ip, cpu, mem usage, and disk space. I want to use your script but i cant get it to work

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: SSD1306 OLED headless system monitor

Tue Jun 12, 2018 10:52 am

sorry you can't get it working - but you'll have to be more specific by posting your code or offending error messages

do you have all the requisite support libs/code installed?

please note that i have not revisited this project in some time and do not even have a working system up to test
(it has been a while, and i've moved on to other projects - in general, i was disappointed in the performance and robustness of the sensors)

willie

Return to “General discussion”