- External Extra Sensors
- Windbarbs in Charts (see CDL)
1)
The External Extra Sensors have been in beta for some time and apparently nobody is using it, but now that I had my geiger counter working I can use that as an example of what it is meant to do. Many sensors exist in this world and most of those are not being logged by CMX which means they can not be integrated easily with the existing charts. Charting those data anyway required dedicated coding for chart and data to display.
The goal of why I got involved with the geiger counter may have been a bit obfuscated by the time I got it running, but the essence is that I want to create the possibility for CUtils to have any sensor a user may come up with, to be charted automatically after configuration. That means that I just define the interface to any - whatever type - sensor. It will be the users responsibility to comply to that interface in any way he/she wants.
The idea is you name your External Extra Sensor in the configuration file and supply a CSV file with the data in the data directory of CMX. That's it. See the wiki for the detail of the format.
I named it External Extra Sensors to emphasize the sensor lies outside the CMX/CUtils system : it is not being logged by CMX, it is not recognized by CMX it is just completely unknown to the preprogrammed possibilities of the system. And yet, when configured correctly the sensor blends in with the existing sensors and the chart can be combined with other Plot Variables. Note this is not limited to the CUtils website but it is a feature of the ExtraSensors module / ChartsCompiler which will generate the charts. The charts can be used independently in any website. Up to the datafile, the responsibility is with the user. Picking up the datafile and creating the charts is CUtils.
Example description:
I connected my DIY Geiger Counter to a separate RPi and had the Python program running to read out the device and log the data in the required format:
Code: Select all
dd/MM/yy HH:mm, value
Code: Select all
ExternalExtraSensors=geiger
What can be done/needs to be done: currently only one value per sensor can be in the datafile. Multiple values from one sensor can not be handled. This will be implemented on demand (lets first see this being used )
As usual: any remarks or suggestions are welcome.
Code: Select all
# Raspberry Pi connection for the DIY Geiger Counter:
# Maybe the code can be optimized but it works and that's good.
# VIN = INT connected to pin#12 (via a 100nF decoupling capacitor: not used)
# 5V to pin#2
# GND to pin#6
# Modified to create logfile by Hans Rottier on 1 july 2022
# For use with Cutils, to be modified for automatic logfile change at month rollover
#
import time
from datetime import datetime
import RPi.GPIO as GPIO
import locale
GPIO.setmode(GPIO.BOARD) # use RaspPi board layout pin numbering
GPIO.setup(12, GPIO.IN) # Only works if do NOT have a pull up or down
counter = 0
thisYear = datetime.now().year
thisMonth = datetime.now().month
tmp = "geiger{}{:02}"
Filename = tmp.format(thisYear, thisMonth) + ".txt"
#print(Filename)
logFile = open(Filename, 'a', 1 )
def tube_impulse_callback(channel): # threaded callback -- falling edge detected
global counter # make counter global to be able to increment it
counter+=1
# when a falling edge is detected on pin#12, regardless of whatever
# else is happening in the program, the tube_impulse_callback will be run
GPIO.add_event_detect(12, GPIO.FALLING, callback=tube_impulse_callback)
try:
while True:
currentMinute = datetime.now().minute
while datetime.now().minute == currentMinute: # this minute..
time.sleep(1) # .. wait while add_event_detect detects pulses
tmp = "{},{}\n"
logFile.write( tmp.format(datetime.now().strftime("%d/%m/%y %H:%M"), counter) )
counter=0 # reset counter
#except KeyboardInterrupt:
# GPIO.cleanup() # clean up GPIO on CTRL+C exit
#except:
# GPIO.cleanup() # clean up GPIO on normal exit
finally:
GPIO.cleanup() # clean up GPIO on normal exit
logFile.close()
Last release (6.9.2) the windbarbs were introduced in the ChartsCompiler. There was a difference between Above and Below windbarbs. This was caused by plotting Windbarbs and data to the same xAxis (when using Below). This compressed the data such that the distance between datapoints became the same as for the windbarbs (2 - 3 hours) i.s.o. the required 5 or 10 minutes or even 1 minute. It has been solved by creating separate xAxis for the windbarbs with offset:0 (Below) or opposite: true (Above). This won't be noticed by the user, but if you are interested in highcharts it may be a useful technique.