spacemanspiff2007 / sml2mqtt

Sml to MQTT Bridge
GNU General Public License v3.0
25 stars 8 forks source link

sml2mqtt does not reconnect to mqtt broker upon los of connection #20

Closed baiti closed 1 year ago

baiti commented 1 year ago

As it seems, and by observation, if I shutdown my remote moquitto for maintenance, even if it is just an instant service mosquitto restart, sml2mqtt loses its connection and never opens it again. To be on the safe side I typically reboot the raspi that runs sml2mqtt in such a situation. It would be much more reliable, however, if sml2mqtt detects the connection loss and performs an automatic reconnect, permanently and periodically, and never gives up on retry. My tasmota based sensors, which also report via MQTT do exactly that, therefore no manual intervention is ever required if one component in the flowgraph goes down for a while and comes back later.

spacemanspiff2007 commented 1 year ago

Could you post the error message from the log please?

baiti commented 1 year ago

Here is the scenario, everything is running since days (or months) I then take mosquitto down via service mosquitto stop (mosquitto is running somewhere else, not on the host where sml2mqtt runs`. When the nex message is due, the log shows:

[2023-01-10 11:40:52,940] [sml.mqtt               ] ERROR    | Error while publishing to sml2mqtt/xxxx/energy: [code:4] The client is not currently connected. (MqttCodeError)
[2023-01-10 11:41:07,945] [sml.mqtt               ] ERROR    | Error while publishing to sml2mqtt/xxxx/power: [code:4] The client is not currently connected. (MqttCodeError)
[2023-01-10 11:42:08,942] [sml.mqtt               ] ERROR    | Error while publishing to sml2mqtt/xxxx/power: [code:4] The client is not currently connected. (MqttCodeError)

This now goes on forever, even though I did a service mosquitto start after I received the second error message listed above.

While I am typing this, I have now received 8 of those messages. moquitto is backup and running and sml2mqtt just never even tries to reconnect. At least that is how it looks like by interpreting the logs. I'd expect to see an INFO log indicating that it is trying to reconnect, however, not seeing such a log does not necessarily mean that it isn't trying, however, the subsequent ERROR logs more or less confirm that it isn't.

If I now do a service sml2mqtt stop followd by service sml2mqtt start everything is back to normal of course.

spacemanspiff2007 commented 1 year ago

Strange - can you set the logging to DEBUG (config.yml -> logging -> level)? I would have expected at least an Error message that the reconnect fails. Reconnect should begin after 15 secs

spacemanspiff2007 commented 1 year ago

Could you try 2.0 and see if the issue is still there?

baiti commented 1 year ago

Could you try 2.0 and see if the issue is still there?

ok, will do, however, might take a while to get back with results. Stay tuned.

baiti commented 1 year ago

can I use the config.yml unchanged?

spacemanspiff2007 commented 1 year ago

yes - should work without modification. The only change was to device id obis and this is a field that's not generated by default and a very advanced option.

baiti commented 1 year ago

I did the upgrade following the steps in the documentation, then ran:

venv/bin/sml2mqtt --config config.yml -a

Then I received:

[2023-03-23 09:09:15,977] [sml.serial0            ] ERROR    | Found none of the following obis ids in the sml frame: 0100000009ff
[2023-03-23 09:09:15,977] [sml.serial0            ] ERROR    | Received Frame
[2023-03-23 09:09:15,978] [sml.serial0            ] ERROR    |  -> b'76050550750262006200726301017601010501c57c560b0a0149534b0005020de27262016501c57c07620163c49700760505507503620062007263070177010b0a0149534b0005020de2070100620affff7262016501c57c07757707010060320101010101010449534b0177070100600100ff010101010b0a0149534b0005020de20177070100010800ff65001c410401621e52ff6501d3c8d80177070100020800ff0101621e52ff650001fe010177070100100700ff0101621b52005300ad010101639e9c007605055075046200620072630201710163b71b00'
[2023-03-23 09:09:15,979] [sml.serial0            ] ERROR    | 
[2023-03-23 09:09:15,979] [sml.serial0.status     ] INFO     | ERROR
[2023-03-23 09:09:15,980] [sml.mqtt.pub           ] INFO     | sml2mqtt//dev/serial0/status: ERROR (QOS: 0, retain: False)
[2023-03-23 09:09:15,981] [sml.serial             ] INFO     | Port /dev/serial0 was closed
[2023-03-23 09:09:15,982] [sml.serial0.status     ] INFO     | PORT_CLOSED
[2023-03-23 09:09:15,982] [sml.mqtt.pub           ] INFO     | sml2mqtt//dev/serial0/status: PORT_CLOSED (QOS: 0, retain: False)
Shutting down ...
[2023-03-23 09:09:15,984] [sml                    ] INFO     | Shutting down ...

I must fallback to the previus version as this system is running in production and I have no sandbox environment for obvious reasons.

spacemanspiff2007 commented 1 year ago

Can't you just buy a second home so you can test this? ;-)

I'll look into it since I'm very surprised that there's a behavior difference.

baiti commented 1 year ago

here is my config for reference:

logging:
  level: INFO                    # Log level
  file: sml2mqtt.log             # Log file path (absolute or relative to config file)

mqtt:
  connection:
    client id: sml2mqtt
    host: xxxxxxxxxxxxxxx
    port: 1883
    user: 'xxxxxxxx'
    password: 'xxxxxxxxx'
    tls: false
    tls insecure: false

  defaults:
    qos: 0
    retain: false

  last will:
    topic: status

general:
  Wh in kWh: true                 # Automatically convert Wh to kWh
  republish after: 7200           # Republish automatically after this time (if no other every filter is configured)

ports:
- url: /dev/serial0
  timeout: 3

devices:
  # Device configuration by OBIS value 0100000009ff or by url if the device does not report OBIS 0100000009ff
  #11111111111111111111:
  /dev/serial0:

    mqtt:
      topic: xxxxxxx

    skip:
      - '010060320101'
      - '0100600100ff'

    values:

      0100100700ff:
        mqtt:
          topic: power
        filters:
          - diff: 300
          - every: 60

      0100010800ff:
        mqtt:
          topic: energy
        filters:
          - diff: 1
          - every: 300

      0100020800ff:
        mqtt:
          topic: grid
        filters:
          - diff: 1
          - every: 300
spacemanspiff2007 commented 1 year ago

Your device seems to report the serial number under 0100600100ff or 1-0:96.1.0*255 This is very unusual and I can't seem to find information about this obis id online. You have to set device id obis: ["0100600100ff"] in general in your config. Then everything will work as expected.

Matching the configuration through the serial path is no longer supported.

baiti commented 1 year ago

Your device seems to report the serial number under 0100600100ff or 1-0:96.1.0*255 This is very unusual and I can't seem to find information about this obis id online. You have to set device id obis: ["0100600100ff"] in general in your config. Then everything will work as expected.

Matching the configuration through the serial path is no longer supported.

Like this? ....

general:
  device id obis: ["0100600100ff"]
  Wh in kWh: true                 # Automatically convert Wh to kWh
  republish after: 7200           # Republish automatically after this time (if no other every filter is configured)

for reasons I don't remember I had this ID in skip:

   skip:
      - '010060320101'
      - '0100600100ff'

Perhaps this is why it failed ? But there must have been a reason why I needed to add that '0100600100ff' to the skip list

spacemanspiff2007 commented 1 year ago

Like this

general:
  device id obis: ["0100600100ff"]

or this:

general:
  device id obis: 
    - "0100600100ff"

Whatever you like better.

Perhaps this is why it failed ? But there must have been a reason why I needed to add that '0100600100ff' to the skip list

It's automatically added to the ignore list, so you don't have to do that manually any more. It prevents sml2mqtt from reporting the serial number through mqtt since it's constant and does never change.

baiti commented 1 year ago

Previously, as reported, it died on start. Now with the changed config it keeps running, however, with a warning:

[2023-03-23 14:15:25,827] [sml                    ] INFO     | Starting V2.0.0
[2023-03-23 14:15:25,854] [sml.serial0.status     ] INFO     | PORT_OPENED
[2023-03-23 14:15:27,062] [sml.serial0            ] WARNING  | No configuration found for 0a0149534b0005020de2
[2023-03-23 14:15:27,063] [sml.serial0.status     ] INFO     | OK
baiti commented 1 year ago

something is broken. The new version, with the update config, sends MQTT messages at a high frequency (once per second) to the mosquitto:

mosquitto_sub -t 'sml2mqtt/#' -v
sml2mqtt/0a0149534b0005020de2/0100010800ff 3067.1661
sml2mqtt/0a0149534b0005020de2/0100100700ff 1155
sml2mqtt/0a0149534b0005020de2/0100010800ff 3067.1664
sml2mqtt/0a0149534b0005020de2/0100100700ff 745
sml2mqtt/0a0149534b0005020de2/0100010800ff 3067.1665
sml2mqtt/0a0149534b0005020de2/0100100700ff 625
sml2mqtt/0a0149534b0005020de2/0100010800ff 3067.1668
sml2mqtt/0a0149534b0005020de2/0100100700ff 728
sml2mqtt/0a0149534b0005020de2/0100010800ff 3067.1669
sml2mqtt/0a0149534b0005020de2/0100100700ff 81

The old version behaved like this, and honoured the time intervals I have in the config:

mosquitto_sub -t 'sml2mqtt/#' -v
sml2mqtt/xxx/power 1130
sml2mqtt/xxx/power 730

where xxx are mnemonic topic fields and not hex values. It seems like my config.yml isn't parsed correctly anymore. The only change in config.yml is that device id under generic as you have outlined it in your first post on the subject:

general:
  device id obis: ["0100600100ff"]

And I have tried it with that id listed in skip and without having it listed in skip, no difference.

baiti commented 1 year ago

Also, in the documentation: image

cd /opt/sml2mqtt seems wrong as there is no bin/activate there.

It seems I must do a: cd /opt/sml2mqtt/venv and run the source bin/activate from there.

spacemanspiff2007 commented 1 year ago

[2023-03-23 14:15:27,062] [sml.serial0 ] WARNING | No configuration found for 0a0149534b0005020de2

You have to configure your config as the config that is assigned to 0a0149534b0005020de2. The warning indicates that it's running with the default configuration.

devices:
  # Device configuration by OBIS value 0100000009ff or by url if the device does not report OBIS 0100000009ff
 "0a0149534b0005020de2":

cd /opt/sml2mqtt seems wrong as there is no bin/activate there.

Thanks for the hint - I'll have to fix the docs!

baiti commented 1 year ago

Unfortunately I am not a yaml expert. I tried:

devices:
  "0a0149534b0005020de2"

and:

devices:
  "0a0149534b0005020de2":

and got:

venv/bin/sml2mqtt --config config.yml -a 1 validation error for Settings devices -> 0a0149534b0005020de2 none is not an allowed value (type=type_error.none.not_allowed)

spacemanspiff2007 commented 1 year ago

You have to set the serial number instead of /dev/serial0


devices:
  # Device configuration by OBIS value 0100000009ff or by url if the device does not report OBIS 0100000009ff
  # instead of /dev/serial0:
  "0a0149534b0005020de2":

    mqtt:
      topic: xxxxxxx
baiti commented 1 year ago

You have to set the serial number instead of /dev/serial0

devices:
  # Device configuration by OBIS value 0100000009ff or by url if the device does not report OBIS 0100000009ff
  # instead of /dev/serial0:
  "0a0149534b0005020de2":

    mqtt:
      topic: xxxxxxx

Still not working with this change made. A few posts ago you wrote:

general:
  device id obis: ["0100600100ff"]

Now I am getting complaints in exactly that area:

venv/bin/sml2mqtt --config config.yml -a
1 validation error for Settings
general -> device id obis
  extra fields not permitted (type=value_error.extra)

Is there any updated documentation with respect to creating a valid config.yml. Obviously my existing config.yml that still works with V1.2.0 is everything but compatible with V2.0.0.

After removing that line under "gerneral" the device id obis: ["0100600100ff"]. The command

venv/bin/sml2mqtt --config config.yml -a now runs without errors. But then, the original error is back, which is what I actually expected as it was the reason in the first place to put that line under "general":

[2023-03-24 19:09:53,745] [sml                    ] INFO     | Starting V2.0.0
[2023-03-24 19:09:53,771] [sml.serial0.status     ] INFO     | PORT_OPENED
[2023-03-24 19:09:54,777] [sml.serial0            ] ERROR    | Found none of the following obis ids in the sml frame: 0100000009ff
[2023-03-24 19:09:54,778] [sml.serial0            ] ERROR    | Received Frame
[2023-03-24 19:09:54,778] [sml.serial0            ] ERROR    |  -> b'760505560fd462006200726301017601010501c75a9c0b0a0149534b0005020de27262016501c75a4d620163965800760505560fd5620062007263070177010b0a0149534b0005020de2070100620affff7262016501c75a4d757707010060320101010101010449534b0177070100600100ff010101010b0a0149534b0005020de20177070100010800ff65001c010401621e52ff6501d543fb0177070100020800ff0101621e52ff65000205230177070100100700ff0101621b520053014701010163332500760505560fd662006200726302017101637fe200'
[2023-03-24 19:09:54,778] [sml.serial0            ] ERROR    | 
[2023-03-24 19:09:54,779] [sml.serial0.status     ] INFO     | ERROR
[2023-03-24 19:09:54,780] [sml.serial             ] INFO     | Port /dev/serial0 was closed
[2023-03-24 19:09:54,781] [sml.serial0.status     ] INFO     | PORT_CLOSED
[2023-03-24 19:09:54,782] [sml                    ] INFO     | Shutting down ...
baiti commented 1 year ago

For completeness, using the alternate syntax you recommended above:

general:
  device id obis:
    - "0100600100ff"

also doesn't work. It creates:

venv/bin/sml2mqtt --config config.yml -a
1 validation error for Settings
general -> device id obis
  extra fields not permitted (type=value_error.extra)
spacemanspiff2007 commented 1 year ago

You wrote above that it's working with the suggested changes and suddenly it doesn't any more. I guess you somehow messed up your configuration file.

But you can always create a new default configuration file but just renaming the original one. If the file with the -c switch does not exist sml2mqtt will create a new default one.

baiti commented 1 year ago

I have a working config.yml vor V1.2.0. And I can't get V2.0.0 to work not matter what I try. Above you say the new version should work without modification but it really doesn't. I don't think I have messed up the config. At that point where I said it's working what that meant was there weren't any syntax error complaints but at runtime it blasted messages at the MQTT Broker at a high frequency and it didn't honour my topic definition which tells me it didn't correctly parse the config.

I have now renamed my config, then ran the program and it created a default config, as you mentioned above. Of course that doesn't work as it complains about a COM1 which is Windows and not Linux. Ok, I deleted these two lines and also renamed the /dev/ttyS0 to /dev/serial0, I also put in the device id in hex and set some topics, then the program ran, but with the error we got from the very beginning. I am adding the config and I am adding the full log below. This is as close to the default config as it can possibly get:

logging:
  level: INFO         # Log level
  file: sml2mqtt.log  # Log file path (absolute or relative to config file)
mqtt:
  connection:
    client id: sml2mqtt
    host: localhost
    port: 1883
    user: ''
    password: ''
    tls: false
    tls insecure: false
  topic prefix: sml2mqtt
  defaults:
    qos: 0         # Default value for QOS if no other QOS value in the config entry is set
    retain: false  # Default value for retain if no other retain value in the config entry is set
  last will:
    topic: status   # Topic fragment for building this topic with the parent topic
general:
  Wh in kWh: true       # Automatically convert Wh to kWh
  republish after: 120  # Republish automatically after this time (if no other filter configured)
ports:
- url: /dev/serial0 # Device path
  timeout: 3        # Seconds after which a timeout will be detected (default=3)
devices:   # Device configuration by ID or url
  "0a0149534b0005020de2":
    mqtt:    # Optional MQTT configuration for this meter.
      topic: 'test1'   # Topic fragment for building this topic with the parent topic
    status:  # Optional MQTT status topic configuration for this meter
      topic: status   # Topic fragment for building this topic with the parent topic
    skip:    # OBIS codes (HEX) of values that will not be published (optional)
    - OBIS
    values:  # Special configurations for each of the values (optional)
      OBIS:
        mqtt:             # Mqtt config for this entry (optional)
          topic: 'test2'   # Topic fragment for building this topic with the parent topic
        workarounds:      # Workarounds for the value (optional)
        - negative on energy meter status: true
        transformations:  # Mathematical transformations for the value (optional)
        - factor: 3
        - offset: 100
        - round: 2
        filters:          # Refresh options for the value (optional)
        - diff: 10
        - perc: 10
        - every: 120

The log:

[2023-03-25 14:22:54,757] [sml                    ] INFO     | Starting V2.0.0
[2023-03-25 14:22:54,763] [sml.serial0.status     ] INFO     | PORT_OPENED
[2023-03-25 14:22:55,368] [sml.serial0            ] INFO     |
[2023-03-25 14:22:55,369] [sml.serial0            ] INFO     | Received Frame
[2023-03-25 14:22:55,369] [sml.serial0            ] INFO     |  -> b'760505593a7f62006200726301017601010501c868d50b0a0149534b0005020de27262016501c86889620163a9d400760505593a80620062007263070177010b0a0149534b0005020de2070100620affff7262016501c86889757707010060320101010101010449534b0177070100600100ff010101010b0a0149534b0005020de20177070100010800ff65001c010401621e52ff6501d621440177070100020800ff0101621e52ff6500020d670177070100100700ff0101621b52005302500101016398d900760505593a816200620072630201710163b97500'
[2023-03-25 14:22:55,370] [sml.serial0            ] INFO     |
[2023-03-25 14:22:55,373] [sml.serial0            ] INFO     | <SmlMessage>
[2023-03-25 14:22:55,373] [sml.serial0            ] INFO     |   transaction_id: 05593a7f
[2023-03-25 14:22:55,374] [sml.serial0            ] INFO     |   group_no      : 0
[2023-03-25 14:22:55,374] [sml.serial0            ] INFO     |   abort_on_error: 0
[2023-03-25 14:22:55,375] [sml.serial0            ] INFO     |   message_body <SmlOpenResponse>
[2023-03-25 14:22:55,376] [sml.serial0            ] INFO     |     codepage   : None
[2023-03-25 14:22:55,376] [sml.serial0            ] INFO     |     client_id  : None
[2023-03-25 14:22:55,377] [sml.serial0            ] INFO     |     req_file_id: 01c868d5
[2023-03-25 14:22:55,377] [sml.serial0            ] INFO     |     server_id  : 0a0149534b0005020de2
[2023-03-25 14:22:55,378] [sml.serial0            ] INFO     |     ref_time   : 29911177
[2023-03-25 14:22:55,378] [sml.serial0            ] INFO     |     sml_version: 1
[2023-03-25 14:22:55,379] [sml.serial0            ] INFO     |   crc16         : 43476
[2023-03-25 14:22:55,380] [sml.serial0            ] INFO     | <SmlMessage>
[2023-03-25 14:22:55,381] [sml.serial0            ] INFO     |   transaction_id: 05593a80
[2023-03-25 14:22:55,381] [sml.serial0            ] INFO     |   group_no      : 0
[2023-03-25 14:22:55,382] [sml.serial0            ] INFO     |   abort_on_error: 0
[2023-03-25 14:22:55,383] [sml.serial0            ] INFO     |   message_body <SmlGetListResponse>
[2023-03-25 14:22:55,383] [sml.serial0            ] INFO     |     client_id       : None
[2023-03-25 14:22:55,384] [sml.serial0            ] INFO     |     server_id       : 0a0149534b0005020de2
[2023-03-25 14:22:55,385] [sml.serial0            ] INFO     |     list_name       : 0100620affff
[2023-03-25 14:22:55,385] [sml.serial0            ] INFO     |     act_sensor_time : 29911177
[2023-03-25 14:22:55,386] [sml.serial0            ] INFO     |     val_list:
[2023-03-25 14:22:55,386] [sml.serial0            ] INFO     |       <SmlListEntry>
[2023-03-25 14:22:55,387] [sml.serial0            ] INFO     |         obis           : 010060320101 (1-0:96.50.1*1)
[2023-03-25 14:22:55,388] [sml.serial0            ] INFO     |         status         : None
[2023-03-25 14:22:55,388] [sml.serial0            ] INFO     |         val_time       : None
[2023-03-25 14:22:55,389] [sml.serial0            ] INFO     |         unit           : None
[2023-03-25 14:22:55,389] [sml.serial0            ] INFO     |         scaler         : None
[2023-03-25 14:22:55,390] [sml.serial0            ] INFO     |         value          : ISK
[2023-03-25 14:22:55,391] [sml.serial0            ] INFO     |         value_signature: None
[2023-03-25 14:22:55,391] [sml.serial0            ] INFO     |       <SmlListEntry>
[2023-03-25 14:22:55,392] [sml.serial0            ] INFO     |         obis           : 0100600100ff (1-0:96.1.0*255)
[2023-03-25 14:22:55,392] [sml.serial0            ] INFO     |         status         : None
[2023-03-25 14:22:55,393] [sml.serial0            ] INFO     |         val_time       : None
[2023-03-25 14:22:55,393] [sml.serial0            ] INFO     |         unit           : None
[2023-03-25 14:22:55,394] [sml.serial0            ] INFO     |         scaler         : None
[2023-03-25 14:22:55,395] [sml.serial0            ] INFO     |         value          : 0a0149534b0005020de2
[2023-03-25 14:22:55,395] [sml.serial0            ] INFO     |         value_signature: None
[2023-03-25 14:22:55,396] [sml.serial0            ] INFO     |       <SmlListEntry>
[2023-03-25 14:22:55,396] [sml.serial0            ] INFO     |         obis           : 0100010800ff (1-0:1.8.0*255)
[2023-03-25 14:22:55,397] [sml.serial0            ] INFO     |         status         : 1835268
[2023-03-25 14:22:55,397] [sml.serial0            ] INFO     |         val_time       : None
[2023-03-25 14:22:55,398] [sml.serial0            ] INFO     |         unit           : 30
[2023-03-25 14:22:55,398] [sml.serial0            ] INFO     |         scaler         : -1
[2023-03-25 14:22:55,399] [sml.serial0            ] INFO     |         value          : 30810436
[2023-03-25 14:22:55,400] [sml.serial0            ] INFO     |         value_signature: None
[2023-03-25 14:22:55,400] [sml.serial0            ] INFO     |         -> 3081043.6Wh (Zählerstand Total)
[2023-03-25 14:22:55,401] [sml.serial0            ] INFO     |       <SmlListEntry>
[2023-03-25 14:22:55,401] [sml.serial0            ] INFO     |         obis           : 0100020800ff (1-0:2.8.0*255)
[2023-03-25 14:22:55,402] [sml.serial0            ] INFO     |         status         : None
[2023-03-25 14:22:55,402] [sml.serial0            ] INFO     |         val_time       : None
[2023-03-25 14:22:55,403] [sml.serial0            ] INFO     |         unit           : 30
[2023-03-25 14:22:55,403] [sml.serial0            ] INFO     |         scaler         : -1
[2023-03-25 14:22:55,404] [sml.serial0            ] INFO     |         value          : 134503
[2023-03-25 14:22:55,405] [sml.serial0            ] INFO     |         value_signature: None
[2023-03-25 14:22:55,405] [sml.serial0            ] INFO     |         -> 13450.3Wh (Wirkenergie Total)
[2023-03-25 14:22:55,406] [sml.serial0            ] INFO     |       <SmlListEntry>
[2023-03-25 14:22:55,406] [sml.serial0            ] INFO     |         obis           : 0100100700ff (1-0:16.7.0*255)
[2023-03-25 14:22:55,407] [sml.serial0            ] INFO     |         status         : None
[2023-03-25 14:22:55,407] [sml.serial0            ] INFO     |         val_time       : None
[2023-03-25 14:22:55,408] [sml.serial0            ] INFO     |         unit           : 27
[2023-03-25 14:22:55,409] [sml.serial0            ] INFO     |         scaler         : 0
[2023-03-25 14:22:55,409] [sml.serial0            ] INFO     |         value          : 592
[2023-03-25 14:22:55,410] [sml.serial0            ] INFO     |         value_signature: None
[2023-03-25 14:22:55,410] [sml.serial0            ] INFO     |         -> 592W (aktuelle Wirkleistung)
[2023-03-25 14:22:55,411] [sml.serial0            ] INFO     |     list_signature  : None
[2023-03-25 14:22:55,411] [sml.serial0            ] INFO     |     act_gateway_time: None
[2023-03-25 14:22:55,412] [sml.serial0            ] INFO     |   crc16         : 39129
[2023-03-25 14:22:55,413] [sml.serial0            ] INFO     | <SmlMessage>
[2023-03-25 14:22:55,413] [sml.serial0            ] INFO     |   transaction_id: 05593a81
[2023-03-25 14:22:55,414] [sml.serial0            ] INFO     |   group_no      : 0
[2023-03-25 14:22:55,414] [sml.serial0            ] INFO     |   abort_on_error: 0
[2023-03-25 14:22:55,415] [sml.serial0            ] INFO     |   message_body <SmlCloseResponse>
[2023-03-25 14:22:55,416] [sml.serial0            ] INFO     |     global_signature: None
[2023-03-25 14:22:55,416] [sml.serial0            ] INFO     |   crc16         : 47477
[2023-03-25 14:22:55,417] [sml.serial0            ] INFO     |
[2023-03-25 14:22:55,418] [sml.serial0            ] ERROR    | Found none of the following obis ids in the sml frame: 0100000009ff
[2023-03-25 14:22:55,419] [sml.serial0            ] ERROR    | Received Frame
[2023-03-25 14:22:55,420] [sml.serial0            ] ERROR    |  -> b'760505593a7f62006200726301017601010501c868d50b0a0149534b0005020de27262016501c86889620163a9d400760505593a80620062007263070177010b0a0149534b0005020de2070100620affff7262016501c86889757707010060320101010101010449534b0177070100600100ff010101010b0a0149534b0005020de20177070100010800ff65001c010401621e52ff6501d621440177070100020800ff0101621e52ff6500020d670177070100100700ff0101621b52005302500101016398d900760505593a816200620072630201710163b97500'
[2023-03-25 14:22:55,420] [sml.serial0            ] ERROR    |
[2023-03-25 14:22:55,421] [sml.serial0.status     ] INFO     | ERROR
[2023-03-25 14:22:55,422] [sml.mqtt.pub           ] INFO     | sml2mqtt//dev/serial0/status: ERROR (QOS: 0, retain: False)
[2023-03-25 14:22:55,423] [sml.serial             ] INFO     | Port /dev/serial0 was closed
[2023-03-25 14:22:55,424] [sml.serial0.status     ] INFO     | PORT_CLOSED
[2023-03-25 14:22:55,424] [sml.mqtt.pub           ] INFO     | sml2mqtt//dev/serial0/status: PORT_CLOSED (QOS: 0, retain: False)
[2023-03-25 14:22:55,426] [sml                    ] INFO     | Shutting down ...
spacemanspiff2007 commented 1 year ago

Looks good so far. Now you still have to add the "device id obis" entry under general as described above.

baiti commented 1 year ago

Looks good so far. Now you still have to add the "device id obis" entry under general as described above.

Now it is indeed running. Not only without syntax errors in config but also with respect to the messages sent to the MQTT. Thanks much. Still no idea why the other config didn't work. Will do some serious vimdiff later. Could whitespace mess up the yaml? Empty lines? Indentation of stanzas as with Python?

Now comes the actual test. The original problem was that once the MQTT Broker is shut down (runs on a different server) and restarted later, sml2mqtt never retried the connection.

Testscenario:

cat sml2mqtt.log 
[2023-03-25 15:34:36,070] [sml                    ] INFO     | Starting V2.0.0
[2023-03-25 15:34:36,096] [sml.serial0.status     ] INFO     | PORT_OPENED
[2023-03-25 15:34:37,306] [sml.serial0.status     ] INFO     | OK
[2023-03-25 15:42:01,399] [sml.mqtt               ] ERROR    | [code:7] The connection was lost. (MqttCodeError)

The results above match expectation. In this case the "code:7" is the result of my stopping MQTT. After I restarted MQTT I immediately got:

mosquitto_sub -t 'sml2mqtt/#' -v
sml2mqtt/status ONLINE

And after a while, and matching my interval settings in sml2mqtt config, the messages came in.

So from my perspective it is now indeed working as expected and I will therefore close the issue.

Again, thx much for your help and of course for developing the very useful tool in the first place.