Python Forum
error in python script (for energy meter)
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error in python script (for energy meter)
#1

Hello,

i'm having issues with a script which I found on https://github.com/datenschuft/SMA-EM

It's a script to read out and write away to some file the values of the energy meter which it has been created for.

I tried contacting the creator, but seems he has no clue either, or his instructions were not very complete.

Anyhow, I hope anyone can point me in the right direction regarding the following error:

Error:
/home/SMA-EM $ sudo python3 sma-daemon.py Traceback (most recent call last): File "/usr/local/lib/python3.5/configparser.py", line 1136, in _unify_values sectiondict = self._sections[section] KeyError: 'SMA-EM' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "sma-daemon.py", line 30, in <module> smaemserials=parser.get('SMA-EM', 'serials') File "/usr/local/lib/python3.5/configparser.py", line 779, in get d = self._unify_values(section, vars) File "/usr/local/lib/python3.5/configparser.py", line 1139, in _unify_values raise NoSectionError(section) configparser.NoSectionError: No section: 'SMA-EM'
I get this error after running this script:



#!/usr/bin/env python3
# coding=utf-8
"""
 ....
"""
import sys, time
from daemon3x import daemon3x
from configparser import SafeConfigParser
import smaem

#read configuration
parser = SafeConfigParser()
parser.read('/etc/smaemd/config')

smaemserials=parser.get('SMA-EM', 'serials')
serials=smaemserials.split(' ')
smavalues=parser.get('SMA-EM', 'values')
values=smavalues.split(' ')
pidfile=parser.get('DAEMON', 'pidfile')

class MyDaemon(daemon3x):
def run(self):
emparts = {}
while True:
emparts=smaem.readem()
for serial in serials:
#print(serial)
#print(emparts['serial'])
if serial==format(emparts['serial']):
#print("match")
for value in values:
file = open("/run/shm/em-"+format(serial)+"-"+format(value), "w")
file.write('%.4f' % emparts[value])
file.close()

if __name__ == "__main__":
daemon = MyDaemon(pidfile)
if len(sys.argv) == 2:
if 'start' == sys.argv[1]:
daemon.start()
elif 'stop' == sys.argv[1]:
daemon.stop()
elif 'restart' == sys.argv[1]:
daemon.restart()
else:
print ("Unknown command")
sys.exit(2)
sys.exit(0)
else:
print ("usage: %s start|stop|restart" % sys.argv[0])
print (pidfile)
sys.exit(2)
and it refers to this config file as well (which I needed to create myself given the instructions)

configfile Wrote:[SMA-EM]

*serials of sma-ems the daemon should take notice
*seperated by space
serials=1900254500
*measurement values
values=pregard psurplus qsurplus ssurplus

[DAEMON]
pidfile=/run/smaemd.pid

I tried running python v3 and the base version (2.7...) with sudo ofcourse.

The issue i posted on this github, which gave me no info :

https://github.com/datenschuft/SMA-EM/issues/9


Thanks for anyone who wants to help out here.
Reply


Messages In This Thread
error in python script (for energy meter) - by br0ken - Nov-30-2017, 02:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Modify an Energy Model to account for year dependent interest rate rather than only t giovanniandrean 0 493 Oct-10-2023, 07:00 AM
Last Post: giovanniandrean
  Alicat Flow Meter data acquisition marenr 0 412 Sep-29-2023, 10:59 PM
Last Post: marenr
Sad "PriceSystem" Python Script error to Shopify API Alphetto 0 512 Jul-04-2023, 10:03 AM
Last Post: Alphetto
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,745 Jun-29-2023, 11:57 AM
Last Post: gologica
  No module named '_cffi_backend' error with executable not with python script stephanh 2 5,940 Nov-25-2021, 06:52 AM
Last Post: stephanh
  How to kill a bash script running as root from a python script? jc_lafleur 4 6,170 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,421 May-28-2020, 05:27 PM
Last Post: micseydel
  Python script Server list - if condition error razor04 12 5,507 Jan-27-2020, 09:05 PM
Last Post: razor04
  PYTHON Script ERROR Help Need alex9745 3 2,613 Sep-17-2019, 08:37 AM
Last Post: alex9745
  Using VBA to Call a Python script causes error in pyodbc connector pcarra 1 2,939 Jun-11-2019, 04:14 PM
Last Post: pcarra

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020