ebaauw / homebridge-p1

Homebridge plugin for DSMR end-consumer (P1) interface
Apache License 2.0
53 stars 11 forks source link

Support for `ser2net` connection to smart meter #55

Closed hemant5400z closed 3 years ago

hemant5400z commented 3 years ago

In have a p1 exposes using ser2net http which is connected to domoticz. I want to use the same connection to expose it to homekit so insteas of serial use http. Would that be possible. As my p1 smartmeter is on a remote system not close to domoticz nor to homebridge hencd tty is not an option.

Cheers

ebaauw commented 3 years ago

I don’t understand your setup. Afaik, ser2net doesn’t talk http. Also using http for the P1 telegrams makes no sense to me, as the smart meter pushes these. Homebridge P1 doesn’t request (get) telegrams; instead it expects to receive notifications.

hemant5400z commented 3 years ago

Hi,

Setup is as follwos i have a mini pc which serves as p1 server. The p1 is connected to its ttyusb port. Ser2net converts this to ip:port. I use this to connect to my domoticz which has a p1 over land connection type. I want to do similar which homebridge instead of serial go over the lan connection

image

Like this.

ebaauw commented 3 years ago

What is your ser2net config?

ebaauw commented 3 years ago

I have Homebridge P1 beta v1.2.10-0 working with ser2net. Could you please try that version? Set serialPort to hostname:port of the server running ser2net. In ser2net.conf, you need to setup a raw connection (in my case connecting port 2000 to /dev/ttyUSB0):

2000:raw:600:/dev/ttyUSB0:115200 8DATABITS NONE 1STOPBIT

I find the connection considerably less reliable than using a direct connection. Not sure if that's ser2net or my WiFi. I had to add checksum validation, discarding telegrams with a CRC error. I never had a need for that using the serial port directly.

Note that DSMR 2.2 probably won't work with ser2net. Not only does it use 9600 7E1 instead of 115200 8N1, it also doesn't provide checksums, so I cannot check wether a telegram is valid. You'll get all sorts of errors when Homebridge P1 tries to parse an invalid telegram.

hemant5400z commented 3 years ago

Hi ebauuw,

Let me test that i have the dsmr 5 version. Also in domoticz i use crc running this setup for 8 months now without a problem. I gues need to uninstall current version? How do i pull the beta as it is not showing in the search box

ebaauw commented 3 years ago

Let me test that i have the dsmr 5 version

The version is usually mentioned on a label on the meter. Also if you receive a telegram every second, it's DSMR 5 alright. Otherwise, Homebridge P1 logs the version on startup (after the meter's serial number).

How do i pull the beta as it is not showing in the search box

Use the Install Previous Version option from the UI, under the wrench symbol in the Plugins screen.

I find the connection considerably less reliable than using a direct connection. Not sure if that's ser2net or my WiFi.

Left two instances running overnight: one on the Pi with the USB P1 cable (pi4), using /dev/ttyUSB0 and one on a remote Pi, using pi4:2000. The local Pi showed shy of 300 CRC errors, the remote Pi almost nine times as many. I had configured ser2net months ago already and haven't seen any errors due to parsing invalid telegrams. I would theorise the issues are caused by multiple concurrent connections to the serial port.

I now reverted to connecting the remote Pi over Homebridge P1's websocket relay to see if the local Pi will still be reporting CRC errors. Next step will be connecting the local Pi over ser2net (using the loopback interface). And after that, connecting both local and remote Pi over ser2net (hoping it would share a single connection to the serial port between multiple TCP clients).

hemant5400z commented 3 years ago

Hi just installed.

I can see the messages but seems strange device in homekit.

No actual numbers but a programmable switch?

image

hemant5400z commented 3 years ago

image image

ebaauw commented 3 years ago

Use a decent HomeKit app, see #40. The button is so you can un-favourite the otherwise not supported accessory in Home, see #41.

ebaauw commented 3 years ago

Some further analysis: also seeing "invalid telegram" and "no data received" warnings in the log of the local Pi and remote Pi. Total warnings (incl. CRC errors) about 1100 on the local Pi, and 3100 on the remote Pi. The warnings on the two Pi are independent (each individual warning only shows on one of the Pi-s). I haven't seen any warnings on for over half an hour, after reverting to the serial connection. Will be trying a local ser2net connection next.

hemant5400z commented 3 years ago

Ok installed eve and indeed working as expected. In my mind i thought it would be exposed in homekit.

I connot detect errors in the log not sure why you get them. Min is going over cable connection. I have 4 simultanous connections and all work fine.

hemant5400z commented 3 years ago

Also i'm not running on a pi. I have ubuntu lts 20.04 running on a virtual machine. The usb is passed on to the vm with passthrough.

hemant5400z commented 3 years ago

Just to be more specific:

Server Ubuntu LTS 20.04 running on ESXI. P1: connection to Meter about 10 meters from it using USB2serial (home made :) ) Ser2net captures ttyUSB0 to ip:port max 10 connections Connection 1 Docker : DSMR Connection 2 Docker : Domoticz Connection 3 Azure cloud VM : DSMR cloud instance Connection 4 Docker : Homebridge

Why? for fun :)

ebaauw commented 3 years ago

In my mind i thought it would be exposed in homekit.

It is. Apple's Home app does not equal HomeKit.

Ser2net captures ttyUSB0 to ip:port max 10 connections

Where/how do you specify the max connections? I tried to open the ser2net port from two clients, but it closes the second connection on me. From the ser2net man page: "If another user is already using the connection or serial port, the connection is refused with an error message."

ebaauw commented 3 years ago

Google is my friend. Changed ser2net.conf to read:

2000:raw:600:/dev/ttyUSB0:115200 8DATABITS NONE 1STOPBIT max-connections=3

Now the second client stays connected, and both clients receive data. No warnings, so far...

hemant5400z commented 3 years ago

Mine is slight different also max-num only works with v3.x not supported in V2.

ipv4,tcp,5000:raw:0:/dev/ttyUSB-P1:115200 NONE 1STOPBIT 8DATABITS max-connections=10

you are using 600 which drops connection in 10min i think, domoticz did not like that.

ebaauw commented 3 years ago

you are using 600 which drops connection in 10min i think, domoticz did not like that.

Only when it doesn't see any telegrams for 10 minutes, in my experience. This would only happen when the cable has been disconnected from the smart meter. Homebridge P1 re-connects automatically some time after a connection has been closed.

ebaauw commented 3 years ago

Now going 40 minutes without warnings, using two concurrent ser2net connections. I'm concluding that the instability was caused by two concurrent connections (Homebridge P1 and ser2net) to the serial port.

@hemant5400z, if you see no other issues, I want to publish a proper version.

ebaauw commented 3 years ago

Has been running stable for over a week. Published v1.2.10.

hemant5400z commented 3 years ago

That is very cool!

Verstuurd vanaf mijn iPhone

Op 17 sep. 2021 om 10:33 heeft Erik Baauw @.***> het volgende geschreven:



Has been running stable for over a week. Published v1.2.10.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/ebaauw/homebridge-p1/issues/55#issuecomment-921612911, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEA6CKRJKT3SMXOITG62HX3UCL4M7ANCNFSM5DWPNDMA.