[Home]Raspsberry Pi

HomePage | RecentChanges | Preferences | My Website home page

Revision 7 not available (showing current revision instead)

The Raspberry Pi

https://www.raspberrypi.com/

I like the PC version that runs off a USB memory stick in an old laptop.

some Raspberry Pi enabled ideas

The Raspberry Pi seems an ideal board for some home logging.

Reading the DS18B20 temperature chip is made simple on the Raspberry Pi.

http://ccgi.dougrice.plus.com/cgi-bin/wiki.pl?Plotting_DS18S20_Temperature_Readings_Using_SVG

It would be nice if the RPi could be made to start up logging on Reboot.

How do you get the readings off the Pi?

Use a Cron job to poll the DS1820 every minute and log to a file.

Maybe limit the size of the file by appending the date in a structured way.

temp_DS_YYYYMMDD.log

I had an idea of storing the samples in a simple function call in a file ending in .js and putting this file in the web server folder.

A remote webpage could include these, and is covered in my Guestbook idea is great for a simple experiment.

http://www.dougrice.plus.com/

It is possible to run a web server on the ESP01 devices and use it to poll the DS18B20 temperature chip.

http://ccgi.dougrice.plus.com/cgi-bin/wiki.pl?Function_Calls

wget can be used to get a web page.

curses can also be used.

Running a Python script and leave it running

The RaspberryPi is super as it is small and quiet, and useful to leave turned on.

It is easy to run scripts and compile c programs, but they get killed when you log out.

here are some tips on how to leave a script running after logging out.

Python script randomDHR.py loops and sleeps, I want it to keep running after I log out.

 python randomDHR.py

 #== start this in the background and exit()

 nohup python randomDHR.py &

 nohup prevents the command being killed when the login is "hungup"
 the & on the end runs the script in the background and allows you to exit the login.

 #==  list processes with rand in the filename
 pgrep rand -a -f

 #==  stop processes with rand in the filename
 pkill rand -f

 #== if process is not running start it
 prep -a f rand ||  python randomDHR.py

 #== if process is running start another copy
 prep -a f rand &&  python randomDHR.py

 #== run  python randomDHR.py

 Cntr-Z puts in in the background, and sometime stops it.
 "kill -SIGCONT pid " can be used to start it.
 fg brings it to the foregroud  

 #== List jobs running in the bacground
 jobs

 #== use commands: fg fb jobs disown to manage the job
 Cntrl-z puts the job in the background, jobs lists jobs, fg brings it to the foreground, disown disowns it, if it is stopped use pkill or kill to send SIGCONT to continue.

Starting a simple Busybox Webserver

https://oldforum.puppylinux.com/viewtopic.php?t=115252

 sudo busybox httpd -p 0.0.0.0:8086 -h /home/pi/www

I changed the hostname of my raspberry pi to patrickpi

 http://patrickpi:8086/

 http://patrickpi.local:8086/

The Broadband router, I have has a useful frontpage

 http://192.168.1.254/

A Way to start a web server when the RPi boots:-

cron -A super-simple way to run scripts on boot

https://learn.pimoroni.com/article/running-scripts-at-boot

 crontab -e 

 Add:

 @reboot python /home/pi/Pimoroni/blinkt/examples/rainbow.py &

 # start busybox
 @reboot sudo busybox httpd -p 0.0.0.0:8086 -h /home/pi/www 

 #run bash script every 15 minutes
 0,15,30,45 * * * *  /usr/bin/bash /home/pi/log18S20.sh

 #run python script
 0,15,30,45 * * * *  /usr/bin/python /home/pi/py_dhr_serial_XT_MD01_pi.py

A way to start a web server

A Way to start a web server when the RPi boots:-

A way to start a web server using /etc/rc.local

 # Howevery this already has two web servers you can use.
 #  *  busybox httpd
 #  *  python -m httpd.server 8080 &
 # 
 # To get it to boot on power up set up /etc/rc.local
 #
 # scp pi@patrickpi:/etc/rc.local rc.local.txt
 #
 #=================================================

sudo nano /etc/rc.local

 #!/bin/sh -e
 # owned by root
 # chmod 755 /etc/rc.local
 #!/usr/bin/ env python
 #
 # You could start a webserver using:-
 # python -m http.server 8080  &

 # log last boot time for debug purposes
 date > /home/pi/rclocal.txt

 # log env to file for debug purposes
 /usr/bin/env  >> /home/pi/rclocal.txt
 # check where busybox is
 whereis busybox >> /home/pi/rclocal.txt
 # 
 # Start busybox 
 #
 sudo /usr/bin/busybox httpd -p 0.0.0.0:8080 -h /home/pi/www

A way to start a web server using system.d

 python dhr.py

 sudo nano /lib/systemd/system/dhr.service

 sudo systemctl start dhr.service

 sudo systemctl stop dhr.service

 sudo systemctl enable dhr.service

 sudo systemctl disable dhr.service

 sudo nano /lib/systemd/system/dhr.service

 [Unit]
 Description=dhrPythonScript.
 After=network.target

 [Service]
 ExecStart=/usr/bin/python3 /home/pi/dhr.py
 Restart=always
 User=pi

 [Install]
 WantedBy=multi-user.target

Python Web server

This will start a webserver. this can be very useful for getting files off the Raspberry Pi.

 python -m http.server 8080 --directory /home/pi

dhr.py - python web server

 sudo nano /home/ip/dhr.py

 import http.server
 import socketserver

 PORT = 8080
 DIRECTORY = "/home/pi"

 class Handler( http.server.SimpleHTTPRequestHandler ):
	def __init__(self, *args, **kwargs):
 		super().__init__(*args, directory=DIRECTORY, **kwargs)

 # Handler = http.server.SimpleHTTPRequestHandler

 with socketserver.TCPServer(("", PORT), Handler ) as httpd:
    print("serving at port", PORT)
    httpd.serve_forever()

Using a cron job

Somewhere you need a process that polls the sensors on a timer tick and stores the measurements.

This should happen when the user is not logged in with their laptop or smart phone.

You could use a CRON job on a RPi to poll the NETIOM board to read the state of the pins.

An Arduino could also be used and log the data to an SD Card.

http://ccgi.dougrice.plus.com/cgi-bin/wiki.pl?Arduino_Based_Logger_And_SVG_Graph

The Netiom could remotely read and set outputs but did not seem to support a regular timer tick.

At the time I was using Microchip PIC's in assembler.

http://www.dougrice.plus.com/rt004/sr3/Logger.html - A not very successful attempt to measure the performance of a solar powered light.

MODBUS RS-485

I brought a module that measures temperature and humidity and some RS-485 dongles. The page below can be used to send and receive commands over the MODBUS.

https://homepages.plus.net/dougrice/dev/modbus/Simpleterm_XY-MD01v2.htm

http://www.dougrice.plus.com/dev/modbus/Simpleterm_XY-MD01v2.htm is the same page. It needs to be connected via HTTPS to read the RS-485 plugged into the laptop's USB port and use EDGE or Chrome.

http://www.dougrice.plus.com/dev/modbus/py_dhr_serial_XT_MD01.py is a python script.

http://www.dougrice.plus.com/dev/modbus/py_dhr_serial_XT_MD01_pi.py is a python script for my Raspberry Pi. It appends readings to gbFat.js

Add this to cron job on the RaspberryPi, so it run every 15 minutes.

 crontab -e

Add:-

 #run python script
 0,15,30,45 * * * *  /usr/bin/python /home/pi/py_dhr_serial_XT_MD01_pi.py

some datasheet links

https://github.com/TronixLab/ModBus-RTU-Temperature-Humidity-SHT20-Sensor

https://www.hestore.hu/prod_getfile.php?id=18062

Running a Python script and leave it running

Python script randomDHR.py loops and sleeps, I want it to keep running

 python randomDHR.py

 #== start this in the background and exit()

 nohup python randomDHR.py &

 #==  list processes with rand in the filename
 pgrep rand -a -f

 #==  stop processes with rand in the filename
 pkill rand -f

 #== if process is not running start it
 prep -a f rand ||  python randomDHR.py

 #== if process is running start another copy
 prep -a f rand &&  python randomDHR.py

some Raspberry Pi enabled ideas

http://ccgi.dougrice.plus.com/cgi-bin/wiki.pl?Plotting_DS18S20_Temperature_Readings_Using_SVG

http://ccgi.dougrice.plus.com/cgi-bin/wiki.pl?Function_Calls

http://ccgi.dougrice.plus.com/cgi-bin/wiki.pl?ESP01

http://ccgi.dougrice.plus.com/cgi-bin/wiki.pl?Esp8226

http://ccgi.dougrice.plus.com/cgi-bin/wiki.pl?Arduino_Based_Logger_And_SVG_Graph

Netiom Products - Using MicroChip's TCP/IP stack

I had an idea of storing the samples in a simple function call in a file ending in .js and putting this file in the web server folder.

A remote webpage could include these, and is covered in my Guestbook idea is great for a simple experiment.

http://www.dougrice.plus.com/

A long time ago, in 2012, before the Raspberry Pi I brought one of these:-

http://www.phaedrusltd.com/index.html -

http://www.phaedrusltd.com/acatalog/Netiom_Produtcs.html

 Netiom Web enabled boards. 
 Standard Netiom
 Ref: Netiom-std
 Netiom is a stand-alone network aware Input / Output module which can be controlled over most networks including the Internet. It can be accessed from the Internet over a standard ADSL or other always 
 on connection making remote monitoring and control a cost effective option.

You could upload a web page of your own design and read the state of switches and analogue inputs.

I uploaded this file so I could include it into my web pages and read the values.

http://www.dougrice.plus.com/dev/js2_new.cgi

 ioF( "%31,analogue,%01,%02,%03,%04,"); %99

 ioF( "%31,digital1,%05,%06,%07,%08,"); %99

 ioF( "%31,digital2,%27,%28,%29,%30,"); %99

 ioF( "%31,counts,%11,%12,%13,%14,"); %99

 ioF( "%31,digital3,%41,%42,%43,%44,%47,%48,%49,%50,%51,%52,%53,%54,%55,%56,"); %99

 ioF( "%31,serial,%00,%12,%13,%14"); %99

http://www.dougrice.plus.com/dev/netiom.svg included the file and try and plot them:-

 < script  language = "JavaScript" type = "text/javascript" src = "_http://192.168.1.22/js2.cgi" >  < / script >

I do not think it was possible to get it to poll the inputs and store in a file until the unit was polled.

http://www.emacsys.com/index.html is a later version.

Using a Raspberry Pi, this can now be done.

The WiFi enabled ESP01 chips can also do this.

Conclusion

Some ideas. It is not that simple, but the Raspberry Pi and Arduino boards make it much simpler.


HomePage | RecentChanges | Preferences | My Website home page
This page is read-only | View other revisions
Last edited December 17, 2025 8:10 am by dougrice.plus.com
Search: