Welcome to our

Cyber Security News Aggregator

.

Cyber Tzar

provide a

cyber security risk management

platform; including automated penetration tests and risk assesments culminating in a "cyber risk score" out of 1,000, just like a credit score.

Interfacing With A Cheap Geiger Counter

published on 2024-11-22 00:00:00 UTC by Didier Stevens
Content:

I got a cheap Geiger counter from Aliexpress:

This picture was taken on an airplane: you have more radiation (cosmic rays) at high altitude.

I figured out how to interface with this counter in Python to log real time data:

#!/usr/bin/env python

from __future__ import print_function

__description__ = "Program for geiger meter"
__author__ = 'Didier Stevens'
__version__ = '0.0.1'
__date__ = '2024/05/11'

"""

Source code put in the public domain by Didier Stevens, no Copyright
https://DidierStevens.com
Use at your own risk

History:
  2024/05/11: start

Todo:
"""

import optparse
import serial
import time

def FormatTime(epoch=None):
    if epoch == None:
        epoch = time.time()
    return '%04d%02d%02d-%02d%02d%02d' % time.localtime(epoch)[0:6]

def FindCOMPorts():
    ports = []
    for number in range(1, 10):
        try:
            comport = 'COM%d' % number
            with serial.Serial(comport) as oSerial:
                ports.append(comport)
        except serial.serialutil.SerialException as e:
            if 'PermissionError' in e.args[0]:
                ports.append(comport)
    return ports

def LogToCSV(comport):
    ser = serial.Serial(comport, 115200, timeout=0, write_timeout=0)
    ser.write(b'\xAA\x05\x0E\x01\xBE\x55\x00')
    alldata = b''
    fOut = open('geiger.csv', 'a')
    while True:
        data = ser.read(1000)
        if data != b'':
            alldata += data
            lines = alldata.split(b'\xaaU\x0e')
            alldata = lines[-1]
            lines = lines[:-1]
            for line in lines:
                if line != b'':
                    out = FormatTime() + ';' + line.decode('latin')
                    print(out)
                    fOut.write(out + '\n')
            if alldata.endswith(b'U') and not alldata.endswith(b'\xaaU'):
                out = FormatTime() + ';' + alldata.decode('latin')
                print(out)
                fOut.write(out + '\n')
                alldata = b''
            time.sleep(0.40)

def Main():
    oParser = optparse.OptionParser(usage='usage: %prog [options]\n' + __description__ , version='%prog ' + __version__)
    oParser.add_option('-l', '--listports', action='store_true', default=False, help='List ports')
    (options, args) = oParser.parse_args()

    comports = FindCOMPorts()
    if options.listports:
        print('Available ports:')
        for comport in comports:
            print(' %s' % comport)
        return

    if len(args) == 1:
        LogToCSV(args[0])
    elif len(comports) == 1:
        print('Using %s' % comports[0])
        LogToCSV(comports[0])
    else:
        print('Provide the COM port as argument')
        print('Available ports:')
        for comport in comports:
            print(' %s' % comport)

if __name__ == '__main__':
    Main()

Article: Interfacing With A Cheap Geiger Counter - published about 13 hours ago.

https://blog.didierstevens.com/2024/11/22/interfacing-with-a-cheap-geiger-counter/   
Published: 2024 11 22 00:00:00
Received: 2024 11 22 00:19:24
Feed: Didier Stevens
Source: Didier Stevens
Category: Cyber Security
Topic: Cyber Security
Views: 0

Custom HTML Block

Click to Open Code Editor