Home Assistant with MODBUS - modbus

Integrating a MODBUS installation with Home Assistant
MODBUS controller in the Gavazzi SH2WEB24
Home Assistant Configiguration.yaml:
modbus:
name: SmartHouse
type: tcp
host: <my_ip_addr>
port: 502
# SmartHouse Functions
switch:
platform: modbus
scan_interval: 10
registers:
- name: test1
hub: SmartHouse
slave: 1
register: 352
command_on: 1
command_off: 0
# SmartHouse Convert to light
light:
- platform: switch
name: Light_test1
entity_id: switch.test1
In the Home Assistant startup logs, we see this error:
Logger: pymodbus.client.sync Source:
/usr/local/lib/python3.8/site-packages/pymodbus/client/sync.py:214
First occurred: 10:40:02 (1 occurrences) Last logged: 10:40:02
Connection to (<my_ip_addr>, 502) failed: [Errno 111] Connection
refused
The modbus controller is working fine when used with the Gavazzi (windows) software.
In that software, only IP and port need to be specified, no other credentials.
So why would there be a "connection refused" error addressing it from Home Assistant?

Got it working.
Key is to enable modes in the SHTOOL software: in project settings / communication enable "Modbus TCP/IP"
Also the modes map must be created:
Modbus / Modbus map: click a bulb, expand it and click the 'v' icon to enable the mapping. You can as well do that with all entities to map all of them to modbus.
Note the "use address" field. This is important, and will be used as "register" value below (see **).
This list can be exported to ckv via "Save modbus as CSV"
Go to Home Assistant
Enable the "File Editor" if you didn't do this already.
See this link for more info
Now ediy the config file: Click "File Editor" in the left pane.
Look for /config/configuration.yaml
Then add these entries:
modbus:
name: SmartHouse
type: tcp
host: <your smart house IP>
port: 502
# SmartHouse Functions
switch:
platform: modbus
scan_interval: 10
registers:
- name: light1
hub: SmartHouse
slave: 1
register: <register as noted above **>
command_on: 1
command_off: 0
# SmartHouse Convert to light
light:
- platform: switch
name: light1
entity_id: light1
That's basically it. Now you can use this light e.g. in the dashboard.
Go the dashboard, edit it and add the light.
You can click it to toggle, and see the status as well.

Related

Is it possible to use Traefik to proxy PostgreSQL over SSL?

Motivations
I am a running into an issue when trying to proxy PostgreSQL with Traefik over SSL using Let's Encrypt.
I did some research but it is not well documented and I would like to confirm my observations and leave a record to everyone who faces this situation.
Configuration
I use latest versions of PostgreSQL v12 and Traefik v2. I want to build a pure TCP flow from tcp://example.com:5432 -> tcp://postgresql:5432 over TLS using Let's Encrypt.
Traefik service is configured as follow:
version: "3.6"
services:
traefik:
image: traefik:latest
restart: unless-stopped
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./configuration/traefik.toml:/etc/traefik/traefik.toml:ro"
- "./configuration/dynamic_conf.toml:/etc/traefik/dynamic_conf.toml"
- "./letsencrypt/acme.json:/acme.json"
networks:
- backend
ports:
- "80:80"
- "443:443"
- "5432:5432"
networks:
backend:
external: true
With the static setup:
[entryPoints]
[entryPoints.web]
address = ":80"
[entryPoints.web.http]
[entryPoints.web.http.redirections.entryPoint]
to = "websecure"
scheme = "https"
[entryPoints.websecure]
address = ":443"
[entryPoints.websecure.http]
[entryPoints.websecure.http.tls]
certresolver = "lets"
[entryPoints.postgres]
address = ":5432"
PostgreSQL service is configured as follow:
version: "3.6"
services:
postgresql:
image: postgres:latest
environment:
- POSTGRES_PASSWORD=secret
volumes:
- ./configuration/trial_config.conf:/etc/postgresql/postgresql.conf:ro
- ./configuration/trial_hba.conf:/etc/postgresql/pg_hba.conf:ro
- ./configuration/initdb:/docker-entrypoint-initdb.d
- postgresql-data:/var/lib/postgresql/data
networks:
- backend
#ports:
# - 5432:5432
labels:
- "traefik.enable=true"
- "traefik.docker.network=backend"
- "traefik.tcp.routers.postgres.entrypoints=postgres"
- "traefik.tcp.routers.postgres.rule=HostSNI(`example.com`)"
- "traefic.tcp.routers.postgres.tls=true"
- "traefik.tcp.routers.postgres.tls.certresolver=lets"
- "traefik.tcp.services.postgres.loadBalancer.server.port=5432"
networks:
backend:
external: true
volumes:
postgresql-data:
It seems my Traefik configuration is correct. Everything is OK in the logs and all sections in dashboard are flagged as Success (no Warnings, no Errors). So I am confident with the Traefik configuration above. The complete flow is about:
EntryPoint(':5432') -> HostSNI(`example.com`) -> TcpRouter(`postgres`) -> Service(`postgres#docker`)
But, it may have a limitation at PostgreSQL side.
Debug
The problem is that I cannot connect the PostgreSQL database. I always get a Timeout error.
I have checked PostgreSQL is listening properly (main cause of Timeout error):
# - Connection Settings -
listen_addresses = '*'
port = 5432
And I checked that I can connect PostgreSQL on the host (outside the container):
psql --host 172.19.0.4 -U postgres
Password for user postgres:
psql (12.2 (Ubuntu 12.2-4), server 12.3 (Debian 12.3-1.pgdg100+1))
Type "help" for help.
postgres=#
Thus I know PostgreSQL is listening outside its container, so Traefik should be able to bind the flow.
I also have checked external traefik can reach the server:
sudo tcpdump -i ens3 port 5432
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens3, link-type EN10MB (Ethernet), capture size 262144 bytes
09:02:37.878614 IP x.y-z-w.isp.com.61229 > example.com.postgresql: Flags [S], seq 1027429527, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
09:02:37.879858 IP example.com.postgresql > x.y-z-w.isp.com.61229: Flags [S.], seq 3545496818, ack 1027429528, win 64240, options [mss 1460,nop,nop,sackOK,nop,wscale 7], length 0
09:02:37.922591 IP x.y-z-w.isp.com.61229 > example.com.postgresql: Flags [.], ack 1, win 516, length 0
09:02:37.922718 IP x.y-z-w.isp.com.61229 > example.com.postgresql: Flags [P.], seq 1:9, ack 1, win 516, length 8
09:02:37.922750 IP example.com.postgresql > x.y-z-w.isp.com.61229: Flags [.], ack 9, win 502, length 0
09:02:47.908808 IP x.y-z-w.isp.com.61229 > example.com.postgresql: Flags [F.], seq 9, ack 1, win 516, length 0
09:02:47.909578 IP example.com.postgresql > x.y-z-w.isp.com.61229: Flags [P.], seq 1:104, ack 10, win 502, length 103
09:02:47.909754 IP example.com.postgresql > x.y-z-w.isp.com.61229: Flags [F.], seq 104, ack 10, win 502, length 0
09:02:47.961826 IP x.y-z-w.isp.com.61229 > example.com.postgresql: Flags [R.], seq 10, ack 104, win 0, length 0
So, I am wondering why the connection cannot succeed. Something must be wrong between Traefik and PostgreSQL.
SNI incompatibility?
Even when I remove the TLS configuration, the problem is still there, so I don't expect the TLS to be the origin of this problem.
Then I searched and I found few posts relating similar issue:
Introducing SNI in TLS handshake for SSL connections
Traefik 2.0 TCP routing for multiple DBs;
As far as I understand it, the SSL protocol of PostgreSQL is a custom one and does not support SNI for now and might never support it. If it is correct, it will confirm that Traefik cannot proxy PostgreSQL for now and this is a limitation.
By writing this post I would like to confirm my observations and at the same time leave a visible record on Stack Overflow to anyone who faces the same problem and seek for help. My question is then: Is it possible to use Traefik to proxy PostgreSQL?
Update
Intersting observation, if using HostSNI('*') and Let's Encrypt:
labels:
- "traefik.enable=true"
- "traefik.docker.network=backend"
- "traefik.tcp.routers.postgres.entrypoints=postgres"
- "traefik.tcp.routers.postgres.rule=HostSNI(`*`)"
- "traefik.tcp.routers.postgres.tls=true"
- "traefik.tcp.routers.postgres.tls.certresolver=lets"
- "traefik.tcp.services.postgres.loadBalancer.server.port=5432"
Everything is flagged as success in Dashboard but of course Let's Encrypt cannot perform the DNS Challenge for wildcard *, it complaints in logs:
time="2020-08-12T10:25:22Z" level=error msg="Unable to obtain ACME certificate for domains \"*\": unable to generate a wildcard certificate in ACME provider for domain \"*\" : ACME needs a DNSChallenge" providerName=lets.acme routerName=postgres#docker rule="HostSNI(`*`)"
When I try the following configuration:
labels:
- "traefik.enable=true"
- "traefik.docker.network=backend"
- "traefik.tcp.routers.postgres.entrypoints=postgres"
- "traefik.tcp.routers.postgres.rule=HostSNI(`*`)"
- "traefik.tcp.routers.postgres.tls=true"
- "traefik.tcp.routers.postgres.tls.domains[0].main=example.com"
- "traefik.tcp.routers.postgres.tls.certresolver=lets"
- "traefik.tcp.services.postgres.loadBalancer.server.port=5432"
The error vanishes from logs and in both setups the dashboard seems ok but traffic is not routed to PostgreSQL (time out). Anyway, removing SSL from the configuration makes the flow complete (and unsecure):
labels:
- "traefik.enable=true"
- "traefik.docker.network=backend"
- "traefik.tcp.routers.postgres.entrypoints=postgres"
- "traefik.tcp.routers.postgres.rule=HostSNI(`*`)"
- "traefik.tcp.services.postgres.loadBalancer.server.port=5432"
Then it is possible to connect PostgreSQL database:
time="2020-08-12T10:30:52Z" level=debug msg="Handling connection from x.y.z.w:58389"
I'm using Traefik to proxy PostgreSQL, so answer is yes. But I'm not using TLS, because my setup is a bit different. First of all, if PostgreSQL doesn't support SNI, then I would suggest to try to modify labels, especially HostSNI rule to this:
"traefik.tcp.routers.postgres.rule=HostSNI(`*`)"
That says: ignore SNI and just take any name from specified entrypoint as valid.
SNI routing for postgres with STARTTLS has been added to Traefik in this PR. Now Treafik will listen to the initial bytes sent by postgres and if its going to initiate a TLS handshake (Note that postgres TLS requests are created as non-TLS first and then upgraded to TLS requests), Treafik will handle the handshake and then is able to receive the TLS headers from postgres, which contains the SNI information that it needs to route the request properly. This means that you can use HostSNI("example.com") along with tls to expose postgres databases under different subdomains.
As of writing this answer, I was able to get this working with the v3.0.0-beta2 image (Reference)

ejabberd register from specific ip's

I am trying to setup my ejabberd server to allow user registration from a specific ip adress. So far the only time I can register a user is when I change ip_access value to all. But thats not what I want.
Here is part of my config file:
...
acl:
...
loopback:
ip:
- "127.0.0.0/8"
- "xx.xx.xx.xx"
register_networks:
ip:
- "xx.xx.xx.xx"
...
access:
...
register:
all: allow
trusted_network:
loopback: allow
register_network:
register_networks: allow
...
registration_timeout: infinity
...
modules:
...
mod_register:
ip_access: register_network
access: register
...
Neither trusted_network or register_network work. I always get 403 Forbidden error. I am using ejabberd 16.01
you have defined register_networks: in acl but you referred to register_network as the ip_access value.
It might be the issue there.
Regards,

consul - connect client to server

I'm new at consul and I try to setup a server-client environment. I have started my server with the following command and configuration:
consul.exe agent -ui -config-dir=P:\Consule\config
The config file looks the following ("P:\Consule\config\server.json")
{
"bootstrap": false,
"server": true,
"datacenter": "MyServices",
"data_dir": "P:\\Consule\\data",
"log_level": "INFO"
}
Output when I start consul from commandline with above command:
==> Starting Consul agent...
==> Consul agent running!
Version: 'v0.8.3'
Node ID: '1a244456-e725-44be-0549-33603ea7087d'
Node name: 'MYCOMPUTERNAMEA'
Datacenter: 'myservices'
Server: true (bootstrap: false)
Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600)
Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)
Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false
Atlas: <disabled>
Now, at another computer in my domain I try to run an consul client with follwoing commandline and config-file:
consul.exe agent -config-dir C:\Consul -bind=127.0.0.1
Config file ("C:\Consul\client.json")
{
"server": false,
"datacenter": "MyServices",
"data_dir": "C:\\TEMP",
"log_level": "INFO",
"start_join": ["MYCOMPUTERNAMEA"]
}
But I always get follwing output/error message:
==> Starting Consul agent...
==> Joining cluster...
==> 1 error(s) occurred:
* Failed to join <IP_OF_MYCOMPUTERNAMEA>: dial tcp <IP_OF_MYCOMPUTERNAMEA>:8301: connectex: No connection could be made because the target machine actively refused it.
Does anyone know what I'm doing wrong?
Thanks and best regards
I suppose, the reason is that your server is available only for 127.0.0.1 ip-address, which is localhost ip and available only from the same server. This can be seen here:
Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600)
Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)
You have to configure your server, to make it listening all network interfaces or some specific interface, which have to be available from other server.
Try to run it with the client and advertise options set to 0.0.0.0 (or some specific ip). Read about it here and here.
And you might have to delete -bind=127.0.0.1 from the client configuration, since it might be available from the server too.

how to deploy war file to Glassfish on port 80?

When I deploy my application, I can access to my website at the adress: domain.com:8080 but I want to access with the adress domain.com:80.
When I try to access to domain.com, I found a page "index of" with different folders (my .war) but not website. Can I configure something on glassfish, what I need to do?
help me I'm desesperate
To run your app under 80 port you have just to adjust your listener from 8080 to 80 and make the your app as default web app in the virtual server :
log first on the GF admin panel ( default domain.com:4848 )
then go to left menu :
(change port to 80)
1 - Configuration -> 2 - server-config (default) -> 3 - network Config -> 4 - network Listeners -> 5 -select your listener (http-listener-1 if default) ---> 6 - then change the port to 80 and save .
(make it default app)
same thing but make change in default virtual server :
1 - Configuration -> 2 - server-config (default) -> 3 - virtual servers -> 4 - server (by default) ---> 5 - then select your app in the default web app and save
after those restart the server and try .
here are some image so they can help you (sorry screen shot in french)
Config port 80 :
make your app as default in virtual server :

Problem accessing Eclipse source through proxy.eclipse.org

I'm trying to access the eclipse source code in cvs, but unfortunately, the location I'm at blocks all non-standard tcp/ip ports. I spoke with a sysadmin on the phone, and he recommended that I try to find a way to download the source using the port 80 or port 443 proxy listed at: http://wiki.eclipse.org/CVS_Howto#CVS_and_firewalls
The problem I'm having is that neither of the sites (proxy.eclipse.org:80 and pebbles.eclipse.org:443) do not seem to be available to connect to using either the CVS in eclipse or tortoiseCVS. I've been trying to connect using the following setup:
Host: proxy.eclipse.org
Repository Path: /cvsroot/eclipse
User: Anonymous
Pass: <blank>
Connection Type: pserver
Use Port: 80
I've also tried:
Host: pebbles.eclipse.org
Repository Path: /cvsroot/eclipse
User: Anonymous
Pass: <blank>
Connection Type: pserver
Use Port: 443
Both of these give me the following exception when I try to fetch the module list:
Could not connect to:
I/O exception occurred: No response from server.
Thoughts on this? Perhaps there is a newer server to download the source that I'm missing?
Thanks!
Try contacting webmaster#eclipse.org.