mweinelt / sml-exporter

Smartmeter Prometheus Exporter using the Smartmeter Message Language (SML)
MIT License
0 stars 1 forks source link

exporter show no smartmeter_ metrics only the python default ones #4

Open databus23 opened 2 years ago

databus23 commented 2 years ago

I tried running this exporter to collect data from an EMH mMe 4.0.

I can confirm that the smart meter is sending out sml frames which I can see using the example sml_server from the libsml project:

> ./sml_server /dev/ttyUSB0
1-0:96.50.1*1#EMH#
1-0:96.1.0*255#XX XX XX XX XX #
1-0:1.8.0*255#616.4#Wh
1-0:16.7.0*255#-7#W
1-0:96.50.1*1#EMH#
1-0:96.1.0*255#XX XX XX XX XX #
1-0:1.8.0*255#616.4#Wh
1-0:16.7.0*255#-33#W
1-0:96.50.1*1#EMH#
1-0:96.1.0*255#XX XX XX XX XX #
1-0:1.8.0*255#616.4#Wh
1-0:16.7.0*255#-38#W
...

Unfortunately the exporter is not showing any smart meter metrics but a single exception when its starting up:

Task exception was never retrieved
future: <Task finished name='Task-3' coro=<SmlProtocol._reconnect() done, defined at /usr/local/lib/python3.9/site-packages/sml/asyncio.py:107> exception=AttributeError("'NoneType' object has no attribute 'call_soon'")>
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/sml/asyncio.py", line 109, in _reconnect
    await self._disconnect()
  File "/usr/local/lib/python3.9/site-packages/sml/asyncio.py", line 140, in _disconnect
    self._transport.abort()
  File "/usr/local/lib/python3.9/site-packages/serial_asyncio/__init__.py", line 192, in abort
    self._abort(None)
  File "/usr/local/lib/python3.9/site-packages/serial_asyncio/__init__.py", line 396, in _abort
    self._loop.call_soon(self._call_connection_lost, exc)
AttributeError: 'NoneType' object has no attribute 'call_soon'

I was building the python package myself because I had to remove the vendor and device_id thing because my smart meter is not sending those apparently.

I'm not a python export so I'm pretty clueless about what is going wrong here. Help would be appreciated.

UPDATE: Looking at the output from sml_server it seems like my smart meter is sending out vendor and device_id. But with the unmodified 0.1.4 version I get zero output, no exception but also no metrics. Looking at the code I figured it was still waiting for the vendor or device_id but maybe I was wrong there.

UPDATE 2: Looking at it again the obis number for vendor on device_id seem to be different for my smart meter. So I think I do have the problem with the upstream version that the exporter waits for those indefinitely.

mweinelt commented 2 years ago

I have only ever tested this against one model of smart meters, also an EMH, so I think it's fair to say that I may have introduced assumptions, that don't work for your smart meter.

Does yours actually spew out a binary format that you're decoding using sml_server? Can you try an example of pysml, the SML library used in this project?

I think this one should help us: https://github.com/mtdcr/pysml/blob/master/examples/test_asyncio.py

mweinelt commented 1 year ago

With #10 there is an example where you need to add the proper OBIS IDs to identify the device. Only when vendor/model have been detected will SML frames be accepted.

The PR also adds more log messages that should help debug this scenario, if you are still interested.