Raspberry Pi Code

X entfernen

sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get autoremove -y && sudo reboot
sudo apt-get purge xserver-common xserver-xorg x11-common
sudo apt-get autoremove

Easymeter einbinden
https://github.com/jschanz/easymeter

http://forum.fhem.de/index.php/topic,14117.135.html


sudo git clone git://github.com/jschanz/easymeter.git
sudo nano /etc/cron.d/easymeter

*/1 * * * * root /opt/easymeter/bin/easymeter.pl > /var/log/easymeter.log 2>&1
	# write csv stream to filehandle
	print FILEHANDLE "$datetime;$ownershipNumber;$importCounter;$exportCounter;$powerL1;$powerL2;$powerL3;$powerOverall;$state;$serialNumber;$consumption;$generation;$export\n";
# write csv stream to filehandle
print FILEHANDLE qq({ "billingData:" : { "assignment" :[ { "obis":"0100000000FF","value":"$serialNumber"}, { "obis":"010000090B00","value":"$datetime"}], "values" : [ {"obis":"0101010800FF","value":$importCounter,"unit":"kWh" }, {"obis":"0100010700FF","value":$powerOverall,"unit":"W"}, {"obis":"0100150700FF","value":$powerL1,"unit":"W"}, {"obis":"0100290700FF","value":$powerL2,"unit":"W"}, {"obis":"01003D0700FF","value":$powerL3,"unit":"W"}, ] }}\n);

	# open filehandle for writing
	open (FILEHANDLE, ">>$csv_file") or

 

# open filehandle for writing
	open (FILEHANDLE, ">$csv_file") or

Ausführung in Kommandozeile:

sudo /opt/easymeter/bin/easymeter.pl

Cronjob anlegen:

sudo crontab -e

und dies eintragen:

*/1 * * * * /opt/easymeter/bin/easymeter.pl

Python

import serial, io
from datetime import datetime,date
from subprocess import PIPE, Popen

def get_cpu_temperature():
process = Popen([‘vcgencmd’, ‘measure_temp’], stdout=PIPE)
output, _error = process.communicate()
return (output[output.index(‘=’) + 1:output.rindex(“‘”)])

def get_cpu_volts():
process = Popen([‘vcgencmd’, ‘measure_volts’], stdout=PIPE)
output, _error = process.communicate()
return (output[output.index(‘=’) + 1:output.rindex(“V”)])

def get_cpu_clock():
process = Popen([‘vcgencmd’, ‘measure_clock’, ‘arm’], stdout=PIPE)
output, _error = process.communicate()
return (output[output.index(‘=’) + 1:output.rindex(“”)])

while True:
datafile=open(‘CPU%s.txt’ % date.today(),’a’)
datafile.writelines(str(datetime.now()))
datafile.write(‘\r\n’)
cpu_temperature = get_cpu_temperature()
datafile.write(cpu_temperature)
datafile.write(‘\r\n’)
cpu_volts = get_cpu_volts()
datafile.write(cpu_volts)
datafile.write(‘\r\n’)
cpu_clock = get_cpu_clock()
datafile.write(cpu_clock)
datafile.write(‘\r\n’)
datafile.close()

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>