eifel-tech / ioBroker.syrconnect

Simulates the cloud of https://syrconnect.de for iobroker
MIT License
5 stars 0 forks source link

Webserver with Admin V7.x ? #176

Closed Ilovegym66 closed 1 month ago

Ilovegym66 commented 2 months ago

Hello, so far I know and understand, since Admin V7.x it's possible to use it as an internal webserver for exact this, what the adapter here need... Can you make a try, please? I have a Syrconnect Lex Plus 10 SL (include an Safeconnect) and can test it, too. dnsmasp is running and the Syrconnect Lex is currently implemented with the HA Addon in HA and connected to iobroker with the HASS Adapter.. HA Addon: https://github.com/Richard-Schaller/addon-syrlex2mqtt?tab=readme-ov-file

eifel-tech commented 1 month ago

Do you have further information about this possibility? I didn't find any docu or description about this feature.

Ilovegym66 commented 1 month ago

Hi, here: https://github.com/ioBroker/webserver so far I understand the problem.?

and like a welcomepage: https://github.com/ioBroker/ioBroker.welcome. to provide webpages.

eifel-tech commented 1 month ago

Thank you for the links. Looks good at first appearance. I'll have a try in the near future and let you know ;-)

Ilovegym66 commented 1 month ago

yes, and, if you would like to read https://github.com/Richard-Schaller/syrlex2mqtt/blob/main/doc/syrconnect-protocol.md#leakage-protection. and me conversation and tests at https://github.com/Richard-Schaller/addon-syrlex2mqtt/issues/2. it would be cool, if you can add these topics to your adapter, so that I don't need the HA any more :)

eifel-tech commented 1 month ago

Here are my results:

Ilovegym66 commented 1 month ago

can you provide a example, how to configure the webserver with port forwarding to iobroker? My system is a UDM Pro - there are the dns forwarding works well. Iobroker is installed in a lxc with bookworm debian. have you tried this? or is this only manuelly possible for the iobroker-user (iobroker user in the sudoer group and in visudo added? 'setcap CAP_NET_BIND_SERVICE=+eip $(which node)'

Screenshot 2024-10-29 at 13 04 20 after this command it must be possible to start a web server as iobroker user lower 1024.

eifel-tech commented 1 month ago

That's my config of an Apache-Webserver which works fine for my Lex10:

<Location /WebServices/SyrConnectLimexWebService.asmx/>
        RewriteEngine on
    RewriteCond %{REQUEST_URI} ^\/WebServices\/SyrConnectLimexWebService\.asmx\/(.*)$
        RewriteRule ^(.*)$ http://<IP of iobroker>:<configured port in adapter>/%1 [QSA,P,L]
</Location>

I didn't try your command, it's not a global setting. You have to run on your own system. Feel free to test it and give feedback, so I'll can add it to readme. But for users who don't know what they do it could be dangerous ;-) Configure port 80 at the instance settings and have a try. The adapter only will throw an error if EACCES will occur. So if not, the adapter will start with that port.

Ilovegym66 commented 1 month ago

in which apache config file must this included?

The setcap command works fine on the iobroker, the adapter starts fine with port 80.

Ilovegym66 commented 1 month ago

and.. have you installed the dnsmasp and webserver on the same host as iobroker is installed?

eifel-tech commented 1 month ago

What was the exact command you entered? Then I'll extend the docs ;-)

Well, you have to listen to all incoming requests on port 80 and then handle on that special location from above. I think you'll find a lot of examples how to configure an apache webserver in the internet. By the way you can choose any webserver you want, apache is only one example. Yes, I've installed dnsmasq on the same host as iobroker and apache. But that is only my setup, it's not a must and surely not perfect ;-) Because of everything I won't give you my whole config. Your setup is different and you have to adjust the things on your setup. I'll help as much as I can but it could be you get some security problems if you take my whole config. So please look at your own, sorry.

eifel-tech commented 1 month ago

But do you need an additional webserver like apache if the adapter runs on port 80? In dnsmasq you have only configure the adapters ip for the syr requests. Or am I wrong?

Ilovegym66 commented 1 month ago
exactly, I don't need an additional webserver, if the local webserver of the adapter is running. My quesiton is, because in the HomeAssistant plugin it looks like it hears on port 80 and 443, if this is enough? Here I have this in the logfile, why secure connection not enabled?: ` syrconnect.0 2024-10-29 16:46:54.526 info Webserver started listening on 0.0.0.0:80
syrconnect.0 2024-10-29 16:46:54.523 debug Secure connection not enabled - using http createServer
syrconnect.0 2024-10-29 16:46:54.510 info starting. Version 1.0.1 (non-npm: eifel-tech/ioBroker.syrconnect#c05b6c8d955dc4f361c35aeedbfe5d6f996e4778) in /opt/iobroker/node_modules/iobroker.syrconnect, node: v20.18.0, js-controller: 7.0.2
syrconnect.0 2024-10-29 16:46:54.205 debug States connected to redis: 10.1.1.6:6379
syrconnect.0 2024-10-29 16:46:54.200 debug States create User PubSub Client
syrconnect.0 2024-10-29 16:46:54.200 debug States create System PubSub Client
syrconnect.0 2024-10-29 16:46:54.197 debug Redis States: Use Redis connection: 10.1.1.6:6379
syrconnect.0 2024-10-29 16:46:54.188 debug Objects connected to redis: 10.1.1.6:6379
syrconnect.0 2024-10-29 16:46:54.184 debug Objects client initialize lua scripts
syrconnect.0 2024-10-29 16:46:54.012 debug Objects create User PubSub Client
syrconnect.0 2024-10-29 16:46:54.012 debug Objects create System PubSub Client
syrconnect.0 2024-10-29 16:46:54.011 debug Objects client ready ... initialize now
syrconnect.0 2024-10-29 16:46:53.990 debug Redis Objects: Use Redis connection: 10.1.1.6:6379

`

the command was this: setcap CAP_NET_BIND_SERVICE=+eip $(which node)'

eifel-tech commented 1 month ago

You have to configure that port, that your device sends on. That's only one port either 80 or 443. By the way I would configure a specific ip too, to that what is configured in dnsmasq - to where the traffic will be redirected (your iobroker ip?!). Now with 0.0.0.0 it listens to all IPs, but you want only requests of your device, right? ;-) The secure connection output comes from the iobroker webserver. We don't have any certificates here so it creates the server in an other way. That's all.

Ilovegym66 commented 1 month ago

I make another test: new vm debian bookworm, iobroker fresh installed, your adapter installed from git, configured as ip of the vm, and port 80, it works and adapter say connected to server and is green. But no data comes... the dnsmasq is on the same vm and point with the syrconnec domains to itself. So with a new installation it's possible to start a server on port 80 or 443, but it can be, that are no data comes? I want to install wireshark and look on the traffic...

Ilovegym66 commented 1 month ago

thats the debug from the HA plugin: ` [2024-10-29T16:32:51.837Z] Connected to MQTT server [2024-10-29T16:32:51.923Z] Webserver started listening [2024-10-29T16:32:58.195Z] Request for syrconnect.de/WebServices/SyrConnectLimexWebService.asmx/GetAllCommands <?xml version="1.0" encoding="utf-8"?>

[2024-10-29T16:32:58.228Z] New MQTTDevice 'lexplus10sl232657019' at http://0.0.0.0 [2024-10-29T16:32:58.271Z] Publishing state message: {"48":"","71":"0","current_water_flow":"0","salt_remaining":"10","remaining_resin_capacity":"100","remaining_water_capacity":"1378","total_water_consumption":"16414","number_of_regenerations":"27","last_regeneration":"2024-10-29T16:43:56+01:00","status_message":" ","salt_in_stock":"21","regeneration_interval":"3","regeneration_week_days":"(None)","regeneration_time":"15:00","regeneration_running":"OFF","SRN":"232657019","VER":"1.9","UNI":"","LNG":"","BLT":"","DMA":"1","PRS":"46","CNO":"","CEL":"182","BSI":"","AVO":"0mL","VOL":"","BSA":"0","FLL":"","EXI":"","AWY":"","SRV":"","CEO":"","DBD":"10","DBT":"15","DST":"180","DCM":"3","DOM":"60","DPL":"10","DTC":"3","DPH":"","MEX":"","TPA":"","BOX":"","FLG":"","INT":"","HUM":"","BUP":"","GLE":"","GUL":"","DSW":"","DRP":"1","AEF":"","UL":"0","TC":"","NPS":"6510","FLO":"0","TO":"","TYP":"80","VLV":"20","ALA":"0","ALM":"","EN":"","KW":"","CTR":"","LE":"44","REL":"","T1":"","BAT":"","TMP":"0","BRI":"","TN":"20","AB":"1","BAR":"","BUZ":"","T2":"1","NET":"poł�czono","water_temperature":18.2,"valve":"open"} [2024-10-29T16:32:58.289Z] Response to allCommands: <?xml version="1.0" encoding="utf-8"?> `

eifel-tech commented 1 month ago

Please try the newest version from github. I had a bug by searching for the names of the devices, so your device possibly sends data to the adapter but it didn't knew your devicename and didn't answer, so nothing happens. Sorry for that. Now it should run, I tested it by calling adapter with your posted request at https://github.com/Richard-Schaller/addon-syrlex2mqtt/issues/2#issuecomment-2395438129

Ilovegym66 commented 1 month ago

Hello good news! I installed your new version from git, but now it don't start with a lower port any more. My tries with apache are fine, but it looks like something with the rewrite dont work, so I look for another solution.. and I found it: iptables are, what we need! With iptables it's possible to route the ports to a higher one, without a webserver. My config on syrconnect Adapter is the ip of the vm, and port 8090. With this commands I map all incoming from port 80 and 443 to 8090: sudo iptables -A PREROUTING -t nat -i ens18 -p tcp --dport 80 -j REDIRECT --to-port 8090 sudo iptables -A PREROUTING -t nat -i ens18 -p tcp --dport 443 -j REDIRECT --to-port 8090

Now the adapter gets the informations from the device! Great! Only two missing PRS (water pressure in bar) and NPS (leckage in ml) :)

eifel-tech commented 1 month ago

Are you sure? The device description in the code contains NPS. But it's the count of micro leckage isn't it? The datapoint should be created, if the device sends getNPS. PRS added. New try please :-)

Ilovegym66 commented 1 month ago

Super, geht, ich schreib mal in Deutsch, damits keine Missverstaendnisse gibt.. :) Druck passt, sind 4,7 Bar hier. NPS ist nicht die Anzahl an Leckagen, sondern die entwichene Wassermenge, ich hab hier was tropfendes und da steigt die Menge immer, bis ein Ventil richtig oeffnet. Der Wert NPS ist in milliliter, der Wert selbst stimmt. Auch kommen jetzt noch mehr Werte, sehr gut.

Ilovegym66 commented 1 month ago

Korrektur: NPS Wert muss ich durch 10 teilen, dann ist das wohl die Leckage-Menge. Sonst keine Fehlermeldungen oder auswirkungen wegen iptables routing auf meinen iobroker. (bin jetzt auf das Produktivsystem umgezogen, klappt. Denke das Issue hier kann zu gemacht werden, hat zwar nicht ganz so geklappt, wie gedacht, aber wir haben wieder ein System weg von HA ( da ist jetzt nur noch bluetooth aktiv.. das move ich auch noch zu iobroker). Danke vielmals! TOP! Vielleicht kann man eine Version jetzt releasen, zumindest damit der Adapter ins Latest kommt..?

eifel-tech commented 1 month ago

Ok, dann ändere ich NPS noch ab in "Leckagemenge". Ist das dann in l oder ml? Und der Wert muss durch 10 geteilt werden, damit er stimmt? Ist das richtig? Das baue ich gleich noch ein und mache dann ein Release.

Ilovegym66 commented 1 month ago

Screenshot 2024-10-30 at 11 23 00 Hier der Alias dazu: Screenshot 2024-10-30 at 11 24 24 also durch 10 Teilen ergibt dann die ml. Super!

eifel-tech commented 1 month ago

Ist implementiert in 1.1.0. Bitte dann den DP getNPS löschen, damit er dann mit dem neuen Namen, Einheit und Umrechnungen neu angelegt wird.

Ilovegym66 commented 1 month ago

Hat alles geklappt, danke!