johanmeijer / grott

Growatt inverter monitor
https://github.com/johanmeijer/grott/wiki
395 stars 109 forks source link

Docker compose mqtt ip etc #309

Open tonbor opened 1 year ago

tonbor commented 1 year ago

Docker compose containers in the same docker have NO default static ip address. Localhost of the host Ubuntu computer does not work, to point to each other. So containers just are connected by container name, at least in my case see [Reference containers by name, not IP, whenever possible. Otherwise you’ll need to constantly update the IP address you use].

That does not work with Grott. - gmqttip=mosquitto in the yaml file Grott still uses localhost. gmqttip=172.18.0.5, does work but the ip address of mosquitto is not static. Please solve this issue.

My Growatt inverter has a lan connection with a static ip number, no wifi . Cannot find where to put this static ip number in the compose yaml. Mosquitto cannot handle message from Grot 1678452725: Client disconnected due to malformed packet.

grott log, last part Grott proxy mode started Hostname : 3a6a1958a08f IP : 172.18.0.7 , port : 5279 #

docker-compose file grott: image: ledidobe/grott container_name: grott restart: unless-stopped ports:

tonbor commented 1 year ago

Well I have a temporary workaround for MQTT with the changing ip address, please adjust your implementation. But there is no output to Mosquitto. WHERE did I go wrong? _grott_logs (3).txt

johanmeijer commented 1 year ago

Ok. I have not done a lot with docker networks. Until now I always externalised the ports per container (mosquitto and grott) and then pointed to the server server ip address as the mqtt ip address.

uhavin commented 8 months ago

Turns out you can set a fixed IP on a container. The way I got this working was to first create a docker network with a specific subnet, e.g.: sudo docker network create --subnet 10.0.8.0/24 mqtt-net

Then, in your docker compose yaml file, configure the network itself and configure the mosquitto service to use that network and give it the fixed ip. Both home assistant and grott will need to be connected to mqtt-net as well

services:
  home-assistant:
    hostname: home-assistant
    # ...
    networks:
      - "other-networks"  # if your home assistant also connects on another network, add it here.  
      - "mqtt-net"

  mosquitto:
    image: eclipse-mosquitto:2
    # ...
    networks:  # use a fixed ip on mqtt-net
      mqtt-net:
        ipv4_address: "10.0.8.100"
        aliases:
          - "mosquitto"
  grott:
    image: ledidobe/grott
    # ...
    env:
      - "gmqttip=10.0.8.100"
      # ...
    networks:
      - "mqtt-net"

networks:
  mqtt-net:
    name: mqtt-net
    external: true