rpiarduinomusings

Raspberry Pi, Arduino, Sensors and the data they produce

A Python Zone Sentry Program

Introduction

This post presents ZoneSentry.py. As the name implies it is a sentry application that uses a Passive Infrared (PIR) sensor in the same manner as the PIRLEDeMail.py program does. ZoneSentry.py is a total rewrite and renders PIRLEDeMail.py obsolete.
Read more of this post

Python Thread Processing

Introduction

This post presents code that shows thread coding techniques that is useful for asynchronous processing.
Read more of this post

Shutdown the OS using an OSEPP button

Introduction

This page presents a program that shuts down the OS when a button is pressed. The narrative is more about the problems associated with normally open button circuits and how they are managed using edge detection techniques.
Read more of this post

Python code for TCP Communications

Introduction

This post presents the base Python code required for a client/server relationship between two programs communicating using TCP.
Read more of this post

Basic Configuration for Raspberry Pi

Introduction

This post presents the steps for a base configuration of a Raspberry Pi. The model used is the newer Raspberry Pi 3, Model B.

The steps that follow pick up after Raspbian (Jessie) has been installed and functioning. There will be little in the way of discussion, letting the instructions for each step act as the documentation.
Read more of this post

A Ping Module

The module presented below is intended to be called by a program that is running as a service on a machine that is operating on a UPS. Its purpose is to detect when utility power has failed so that it can power down the machine. It does this by pinging either a router or another machine on the network either of which are not operating on a UPS.

The overarching goal is to save the file system from being corrupted by a power failure.

When a power failure is detected this module will call os.system(“sudo shutdown -h now”) to stop the operating system.

 
The service program is listed below.

#!/usr/bin/python #********************************************************************** # Program : Ping.py # Date : 20060707 # Description : This module is intended to be used by a program that is # running as a service on a machine that is operating on # a UPS. Its purpose is to detect when utility power has # failed so that it can power down the machine. # # The overarching goal is to save the file system from # being corrupted by a power failure. # # It does this by pinging either a router or another # machine on the network either of which are not # operating on a UPS. # # Using this program as a module within a service program # allows the pinging process and potential shutdown to # take place during non-critical operations such as when # writting data to a file. If running as a stand-alone # service, the potential exists for a shutdown to happen # when files have been opened by other service programs. # # To use: import Ping # Example Call: Ping.pingIt("192.168.128.4") # Outcome: If the ping determines that there is power then control # returns to the caller, otherwise the system will be # brought down and the caller will not be in a critical # phase of processing when that occurs. # #********************************************************************** import os import platform import sys import time import datetime from datetime import datetime #********************************************************************** #***** VARIABLES ***** #********************************************************************** progName = os.path.basename(__file__) # Full path of this python script mypath=os.path.abspath(__file__) # Path location only (excluding script name) baseDir=mypath[0:mypath.rfind("/")+1] baseFileName=mypath[mypath.rfind("/")+1:mypath.rfind(".")] #********************************************************************** #***** FUNCTION DECLARATIONS ***** #********************************************************************** #---------------------------------------------------------------------- def myFunction(): print "Entered myFunction()" return; #---------------------------------------------------------------------- # This function accepts a value to be compared with the low and high # values that are also provided. These values are expressed as integers # and if the value (the first parameter) falls between the low and high # values (inclusive), True will be returned, otherwise False. #---------------------------------------------------------------------- def inRange(value, low, high): intVal = int(value) intLow = int(low) intHigh = int(high) if intLow <= intHigh: return intLow <= intVal <= intHigh else: return intLow <= intVal or intVal <= intHigh #---------------------------------------------------------------------- def execute(): hostname = "10.0.0.8" #Sacrificial Pi pingIt(hostname) return #---------------------------------------------------------------------- def pingIt(hostname): print (" ") print ("In pingIt using " + hostname ) # Construct ping parameters as a function of OS ping_str = "-n 1" if platform.system().lower()=="windows" else "-c 1" response = os.system("ping " + ping_str + " " + hostname) if response == 0: print hostname, 'is up!' else: print hostname, 'is down!' #If the router is on a UPS, you can send an Email to notify #you of the fact that utility power has failed. Also sleep #for a specified time before trying again. After the number #of attempts have occurred, power down this Pi. #Uncomment this before going live!!!!! #os.system("sudo shutdown -h now") #********************************************************************** #***** M A I N L I N E C O N T R O L L E R ***** #********************************************************************** if __name__ == '__main__': print("+++++++++++++++++++++++++++++++++++") print("%s - Entering Program" % progName) print "Path to program = " + mypath print sys.version_info print "The O/S = " + platform.system() try: execute() finally: print("%s - Exiting Program" % progName) print("+++++++++++++++++++++++++++++++++++") print("") #********************************************************************** #********************************************************************** #***** E N D O F S O U R C E ***** #********************************************************************** #**********************************************************************

 
The ATXRaspi Power Board ($15) could be incorporated into this scheme. While the Ping.py program will safely bring down the OS, saving the SD card(s) which is the overarching goal, it doesn’t actually shutdown the Pi. This board could do that without actually having to push a physical button. See this video.

The board can be ordered from here.

A Python sensor program for Raspberry Pi

Introduction

This page presents a Python program that is designed to be a proximity sensor operating on a local network using WIFI. This sensor employs a Passive Infrared sensor (PIR), an LED to give a visual indication that movement has been detected by the PIR, a Picamera and the program presented here.

When the program, PIRLEDeMail.py detects movement, it will turn on the green LED, take a photo using the camera and then send an email with the jpg file attached to the intended recipient.
Read more of this post

A Module to Test When Time is Within a Defined Range

Introduction

This post presents a Python module that determines when the current time falls between a time range for given days of the week. The days and times are in a configuration file that makes it easy to make scheduling changes.
Read more of this post

Email Module

This is intended to be used as a module. To test it just supply your specific email connection criteria and run the module from the command line.
Read more of this post

A Python Program Template

Introduction

This page presents a skeleton or template for Python programs.
Read more of this post