ESP32 Classic MQTT Publisher & Home Assistant

Started by Graham, February 13, 2020, 05:58:57 PM

Previous topic - Next topic

daklein


This would be very helpful for anyone using classicMQTT with an IOTstack RPi, me for one!  Big thanks to Paraphraser from IOTstack discord!

https://gist.github.com/Paraphraser/378d17e759901d4871e5be4327e3f3c8

ClassicCrazy

Thanks daklein
I will give the node red flow  a try next time I get a chance .
Your other post about how to make Iot container  from github is interesting too.

Larry
system 1
Classic 150 , 5s3p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system 2
 5s 135w Kyocero , 3s3p 270w Kyocera  to Classic 150 ,   8s Kyocera 225w to Hawkes Bay Jakiper 48v 15kwh LiFePO4 , Outback VFX 3648 inverter
system 3
KID / Brat portable

Graham

Quote from: ForeverHomestead on January 25, 2021, 07:37:31 PM
So I had some spacing issues in the above.  I ran it through a validator and got that fixed, now the error has changed to:

ERROR: The Compose file './classic_mqtt_compose.yml' is invalid because:
'classic_mqtt2', 'classic_mqtt3' do not match any of the regexes: '^x-'

You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/


Any ideas?

is that your whole .yml file in your previous post? or do you have the following at the top before the comment block?


version: "3"
services:
  classic_mqtt:
    image: classic_mqtt
    restart: always
    build: .
    environment:
      - LOGLEVEL=DEBUG
    depends_on:
      - mosquitto
    networks:
      - localnet
Off-Grid Island cottage, Lac Simon QC Canada
370 Ahrs @ 24V (4 8L16 batteries)
4 x 250watt panels on dual axis trackers http://tinyurl.com/hfpkgr5
Classic 150, Whizbang Jr.
Android Monitor: http://tinyurl.com/lomzq3s

ForeverHomestead

Yes that is at the top.  Looks like it did not copy the whole thing over.  Here is the complete:

version: "3"
services:
  mosquitto:
    hostname: mosquitto
    image: eclipse-mosquitto:latest
    restart: always
    volumes:
      - ./mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
      - ./mosquitto/mosquitto.passwd:/mosquitto/config/mosquitto.passwd
    networks:
      - localnet
    ports:
      - "1883:1883"
  classic_mqtt:
    image: classic_mqtt
    restart: always
    build: .
    environment:
      - LOGLEVEL=DEBUG
    depends_on:
      - mosquitto
    networks:
      - localnet

    # Note you need to create your own .env file in the same directory as this yml file.
    # In it add ALL of the ${VARIABLES} used below. In windows, VS Code lets you create ".env" easily,
    # but in file explorer you cannot. On Linux, no issue. 
    # Note, in the mosquitto.passwd file in the repo there are 2 users or you can create your own:
    # ClassicPublisher password = ClassicPub123
    # ClassicClient password= ClassicClient123
    #
    # The file should look like the following.
    #
    # CLASSIC=<IP address or URL>
    # CLASSIC_PORT=<Port usually 502>
    # CLASSIC_NAME=<Name of you Classic usually "classic" - the name used in Android App>
    # MQTT_ROOT=<The MQTT Root, usually ClassicMQTT>
    # MQTT_USER=ClassicPublisher
    # MQTT_PASS=ClassicPub123
    #
    # After you have created the .env file issue the following command to build and run it:
    # docker-compose -f classic_mqtt_compose.yml up
    #
    # Note, if you change the .env file after you run this command the first time, you need to issue
    # the following command to re-build it before running it again.
    # docker-compose -f classic_mqtt_compose.yml build
    #
    command: "--classic_name ${CLASSIC_NAME} --classic ${CLASSIC} --classic_port ${CLASSIC_PORT} --mqtt mosquitto --mqtt_root ${MQTT_ROOT} --mqtt_user ${MQTT_USER} --mqtt_pass ${MQTT_PASS}"
classic_mqtt2:
  image: classic_mqtt
  restart: always
  build: .
  environment:
    - LOGLEVEL=DEBUG
  depends_on:
    - mosquitto
  networks:
    - localnet
  command: "--classic_name ${CLASSIC_NAME2}  --classic ${CLASSIC2} --classic_port ${CLASSIC_PORT2} --mqtt mosquitto --mqtt_root ${MQTT_ROOT} --mqtt_user ${MQTT_USER} --mqtt_pass ${MQTT_PASS}"
classic_mqtt3:
  image: classic_mqtt
  restart: always
  build: .
  environment:
    - LOGLEVEL=DEBUG
  depends_on:
    - mosquitto
  networks:
    - localnet
  command: "--classic_name ${CLASSIC_NAME3}  --classic ${CLASSIC3} --classic_port ${CLASSIC_PORT3} --mqtt mosquitto --mqtt_root ${MQTT_ROOT} --mqtt_user ${MQTT_USER} --mqtt_pass ${MQTT_PASS}"
networks:
  localnet:

Graham

Quote from: ForeverHomestead on January 26, 2021, 08:43:48 AM
Yes that is at the top.  Looks like it did not copy the whole thing over.  Here is the complete:

version: "3"
services:
  mosquitto:
    hostname: mosquitto
    image: eclipse-mosquitto:latest
    restart: always
    volumes:
      - ./mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
      - ./mosquitto/mosquitto.passwd:/mosquitto/config/mosquitto.passwd
    networks:
      - localnet
    ports:
      - "1883:1883"
  classic_mqtt:
    image: classic_mqtt
    restart: always
    build: .
    environment:
      - LOGLEVEL=DEBUG
    depends_on:
      - mosquitto
    networks:
      - localnet

    # Note you need to create your own .env file in the same directory as this yml file.
    # In it add ALL of the ${VARIABLES} used below. In windows, VS Code lets you create ".env" easily,
    # but in file explorer you cannot. On Linux, no issue. 
    # Note, in the mosquitto.passwd file in the repo there are 2 users or you can create your own:
    # ClassicPublisher password = ClassicPub123
    # ClassicClient password= ClassicClient123
    #
    # The file should look like the following.
    #
    # CLASSIC=<IP address or URL>
    # CLASSIC_PORT=<Port usually 502>
    # CLASSIC_NAME=<Name of you Classic usually "classic" - the name used in Android App>
    # MQTT_ROOT=<The MQTT Root, usually ClassicMQTT>
    # MQTT_USER=ClassicPublisher
    # MQTT_PASS=ClassicPub123
    #
    # After you have created the .env file issue the following command to build and run it:
    # docker-compose -f classic_mqtt_compose.yml up
    #
    # Note, if you change the .env file after you run this command the first time, you need to issue
    # the following command to re-build it before running it again.
    # docker-compose -f classic_mqtt_compose.yml build
    #
    command: "--classic_name ${CLASSIC_NAME} --classic ${CLASSIC} --classic_port ${CLASSIC_PORT} --mqtt mosquitto --mqtt_root ${MQTT_ROOT} --mqtt_user ${MQTT_USER} --mqtt_pass ${MQTT_PASS}"
classic_mqtt2:
  image: classic_mqtt
  restart: always
  build: .
  environment:
    - LOGLEVEL=DEBUG
  depends_on:
    - mosquitto
  networks:
    - localnet
  command: "--classic_name ${CLASSIC_NAME2}  --classic ${CLASSIC2} --classic_port ${CLASSIC_PORT2} --mqtt mosquitto --mqtt_root ${MQTT_ROOT} --mqtt_user ${MQTT_USER} --mqtt_pass ${MQTT_PASS}"
classic_mqtt3:
  image: classic_mqtt
  restart: always
  build: .
  environment:
    - LOGLEVEL=DEBUG
  depends_on:
    - mosquitto
  networks:
    - localnet
  command: "--classic_name ${CLASSIC_NAME3}  --classic ${CLASSIC3} --classic_port ${CLASSIC_PORT3} --mqtt mosquitto --mqtt_root ${MQTT_ROOT} --mqtt_user ${MQTT_USER} --mqtt_pass ${MQTT_PASS}"
networks:
  localnet:


you need to add 2 spaces before each line starting at classic_mqtt2: to the last command:
the indentation has to match the first classic_mqtt
Off-Grid Island cottage, Lac Simon QC Canada
370 Ahrs @ 24V (4 8L16 batteries)
4 x 250watt panels on dual axis trackers http://tinyurl.com/hfpkgr5
Classic 150, Whizbang Jr.
Android Monitor: http://tinyurl.com/lomzq3s

ForeverHomestead

hmmm.  Replaced with this error:

ERROR: The Compose file './classic_mqtt_compose.yml' is invalid because:
Unsupported config option for services.networks: 'localnet'

version: "3"
services:
  mosquitto:
    hostname: mosquitto
    image: eclipse-mosquitto:latest
    restart: always
    volumes:
      - ./mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
      - ./mosquitto/mosquitto.passwd:/mosquitto/config/mosquitto.passwd
    networks:
      - localnet
    ports:
      - "1883:1883"
  classic_mqtt:
    image: classic_mqtt
    restart: always
    build: .
    environment:
      - LOGLEVEL=DEBUG
    depends_on:
      - mosquitto
    networks:
      - localnet

    # Note you need to create your own .env file in the same directory as this yml file.
    # In it add ALL of the ${VARIABLES} used below. In windows, VS Code lets you create ".env" easily,
    # but in file explorer you cannot. On Linux, no issue. 
    # Note, in the mosquitto.passwd file in the repo there are 2 users or you can create your own:
    # ClassicPublisher password = ClassicPub123
    # ClassicClient password= ClassicClient123
    #
    # The file should look like the following.
    #
    # CLASSIC=<IP address or URL>
    # CLASSIC_PORT=<Port usually 502>
    # CLASSIC_NAME=<Name of you Classic usually "classic" - the name used in Android App>
    # MQTT_ROOT=<The MQTT Root, usually ClassicMQTT>
    # MQTT_USER=ClassicPublisher
    # MQTT_PASS=ClassicPub123
    #
    # After you have created the .env file issue the following command to build and run it:
    # docker-compose -f classic_mqtt_compose.yml up
    #
    # Note, if you change the .env file after you run this command the first time, you need to issue
    # the following command to re-build it before running it again.
    # docker-compose -f classic_mqtt_compose.yml build
    #
    command: "--classic_name ${CLASSIC_NAME} --classic ${CLASSIC} --classic_port ${CLASSIC_PORT} --mqtt mosquitto --mqtt_root ${MQTT_ROOT} --mqtt_user ${MQTT_USER} --mqtt_pass ${MQTT_PASS}"
  classic_mqtt2:
    image: classic_mqtt
    restart: always
    build: .
    environment:
      - LOGLEVEL=DEBUG
    depends_on:
      - mosquitto
    networks:
      - localnet
    command: "--classic_name ${CLASSIC_NAME2}  --classic ${CLASSIC2} --classic_port ${CLASSIC_PORT2} --mqtt mosquitto --mqtt_root ${MQTT_ROOT} --mqtt_user ${MQTT_USER} --mqtt_pass ${MQTT_PASS}"
  classic_mqtt3:
    image: classic_mqtt
    restart: always
    build: .
    environment:
      - LOGLEVEL=DEBUG
    depends_on:
      - mosquitto
    networks:
      - localnet
    command: "--classic_name ${CLASSIC_NAME3}  --classic ${CLASSIC3} --classic_port ${CLASSIC_PORT3} --mqtt mosquitto --mqtt_root ${MQTT_ROOT} --mqtt_user ${MQTT_USER} --mqtt_pass ${MQTT_PASS}"
  networks:
    localnet:


Graham

Quote from: ForeverHomestead on January 26, 2021, 09:45:30 AM
hmmm.  Replaced with this error:

ERROR: The Compose file './classic_mqtt_compose.yml' is invalid because:
Unsupported config option for services.networks: 'localnet'

version: "3"
services:
  mosquitto:
    hostname: mosquitto
    image: eclipse-mosquitto:latest
    restart: always
    volumes:
      - ./mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
      - ./mosquitto/mosquitto.passwd:/mosquitto/config/mosquitto.passwd
    networks:
      - localnet
    ports:
      - "1883:1883"
  classic_mqtt:
    image: classic_mqtt
    restart: always
    build: .
    environment:
      - LOGLEVEL=DEBUG
    depends_on:
      - mosquitto
    networks:
      - localnet

    # Note you need to create your own .env file in the same directory as this yml file.
    # In it add ALL of the ${VARIABLES} used below. In windows, VS Code lets you create ".env" easily,
    # but in file explorer you cannot. On Linux, no issue. 
    # Note, in the mosquitto.passwd file in the repo there are 2 users or you can create your own:
    # ClassicPublisher password = ClassicPub123
    # ClassicClient password= ClassicClient123
    #
    # The file should look like the following.
    #
    # CLASSIC=<IP address or URL>
    # CLASSIC_PORT=<Port usually 502>
    # CLASSIC_NAME=<Name of you Classic usually "classic" - the name used in Android App>
    # MQTT_ROOT=<The MQTT Root, usually ClassicMQTT>
    # MQTT_USER=ClassicPublisher
    # MQTT_PASS=ClassicPub123
    #
    # After you have created the .env file issue the following command to build and run it:
    # docker-compose -f classic_mqtt_compose.yml up
    #
    # Note, if you change the .env file after you run this command the first time, you need to issue
    # the following command to re-build it before running it again.
    # docker-compose -f classic_mqtt_compose.yml build
    #
    command: "--classic_name ${CLASSIC_NAME} --classic ${CLASSIC} --classic_port ${CLASSIC_PORT} --mqtt mosquitto --mqtt_root ${MQTT_ROOT} --mqtt_user ${MQTT_USER} --mqtt_pass ${MQTT_PASS}"
  classic_mqtt2:
    image: classic_mqtt
    restart: always
    build: .
    environment:
      - LOGLEVEL=DEBUG
    depends_on:
      - mosquitto
    networks:
      - localnet
    command: "--classic_name ${CLASSIC_NAME2}  --classic ${CLASSIC2} --classic_port ${CLASSIC_PORT2} --mqtt mosquitto --mqtt_root ${MQTT_ROOT} --mqtt_user ${MQTT_USER} --mqtt_pass ${MQTT_PASS}"
  classic_mqtt3:
    image: classic_mqtt
    restart: always
    build: .
    environment:
      - LOGLEVEL=DEBUG
    depends_on:
      - mosquitto
    networks:
      - localnet
    command: "--classic_name ${CLASSIC_NAME3}  --classic ${CLASSIC3} --classic_port ${CLASSIC_PORT3} --mqtt mosquitto --mqtt_root ${MQTT_ROOT} --mqtt_user ${MQTT_USER} --mqtt_pass ${MQTT_PASS}"
  networks:
    localnet:


don't add spaces to the last two lines, just to the command: ...


  classic_mqtt3:
    image: classic_mqtt
    restart: always
    build: .
    environment:
      - LOGLEVEL=DEBUG
    depends_on:
      - mosquitto
    networks:
      - localnet
    command: "--classic_name ${CLASSIC_NAME3}  --classic ${CLASSIC3} --classic_port ${CLASSIC_PORT3} --mqtt mosquitto --mqtt_root ${MQTT_ROOT} --mqtt_user ${MQTT_USER} --mqtt_pass ${MQTT_PASS}"
networks:
  localnet:
Off-Grid Island cottage, Lac Simon QC Canada
370 Ahrs @ 24V (4 8L16 batteries)
4 x 250watt panels on dual axis trackers http://tinyurl.com/hfpkgr5
Classic 150, Whizbang Jr.
Android Monitor: http://tinyurl.com/lomzq3s

ForeverHomestead

Oh shoot, ok I was going to ask that.  That did it.  Looks like it is building now.  Thanks for the help through this. 

Graham

#158
Quote from: ForeverHomestead on January 26, 2021, 09:54:16 AM
Oh shoot, ok I was going to ask that.  That did it.  Looks like it is building now.  Thanks for the help through this.

Just tested it with three classics (one real one and two simulators using ModbusTool)
Here are my configuration files


I then used MQTTfx to connect to the mosquito instance using the pi's IP address and port 1883 and the default user/pw
Username: ClassicClient
Password: ClassicClient123

Published {"Wake"} to the "ClassicMQTT/workshop/cmnd" and "ClassicMQTT/dev/cmnd" topics to get it to send the readings...

Off-Grid Island cottage, Lac Simon QC Canada
370 Ahrs @ 24V (4 8L16 batteries)
4 x 250watt panels on dual axis trackers http://tinyurl.com/hfpkgr5
Classic 150, Whizbang Jr.
Android Monitor: http://tinyurl.com/lomzq3s

ForeverHomestead

Thanks.

If I reboot my PI do I need to start Portainer again somehow?  I had it working, then rebooted and not I cannot pull it up.  Does it run as a service?

I am using a plugin for my  Homeseer automation server called MCSmqtt.  I works really slick.  Easy to get the data I want into automation. 

Graham

#160
Quote from: ForeverHomestead on January 26, 2021, 10:45:18 AM
Thanks.

If I reboot my PI do I need to start Portainer again somehow?  I had it working, then rebooted and not I cannot pull it up.  Does it run as a service?

I am using a plugin for my  Homeseer automation server called MCSmqtt.  I works really slick.  Easy to get the data I want into automation.

It runs as a docker image. Use the command

docker ps

to list all the running containers, if it's not there, use the following to start

docker start portainer-ce


that plugin does look really slick
Off-Grid Island cottage, Lac Simon QC Canada
370 Ahrs @ 24V (4 8L16 batteries)
4 x 250watt panels on dual axis trackers http://tinyurl.com/hfpkgr5
Classic 150, Whizbang Jr.
Android Monitor: http://tinyurl.com/lomzq3s

ClassicCrazy

Quote from: daklein on January 26, 2021, 01:01:14 AM

This would be very helpful for anyone using classicMQTT with an IOTstack RPi, me for one!  Big thanks to Paraphraser from IOTstack discord!

https://gist.github.com/Paraphraser/378d17e759901d4871e5be4327e3f3c8

I have been trying to follow this and do the build.
I get an error though when I try to do the final build ( and I am using all his latest revisions) .
Did you get it working using this method  ?
I mainly want to just use the IOTstack mosquitto and not the other one installed by ClassicMQTT for pi .

Larry
system 1
Classic 150 , 5s3p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system 2
 5s 135w Kyocero , 3s3p 270w Kyocera  to Classic 150 ,   8s Kyocera 225w to Hawkes Bay Jakiper 48v 15kwh LiFePO4 , Outback VFX 3648 inverter
system 3
KID / Brat portable

daklein

Larry,    Mine is working,  but I didn't yet go through the remaining tweaks in the writeup to clean up a couple things better.    Mainly the environment variables instead of hardcoding the command line args.

What error do you get?  Post the error in the gist comments and Paraphraser will probably pipe in, especially if you link a copy of your docker-compose.yml file in pastebin or comments.

mcsarge

Well, I just read the comments Paraphraser and I am not excited. I put alot of work into that code and the snarky comments were not good. I am considering removing the python version from the public.
Off Grid Island in Ontario Canada (Beaverstone Bay)
Primary: Classic 150 + wbjr; 3s2p HES 270watt
Winter: SolarBoost 50 MPPT (into wbjr); 2 x Sharp NE-80EJEA 80watt
Pack: 4s2p ROLLS S6-460AGM 6V for 24V pack
Inverter/Charger: Trace DR2424
Call Sign: KG4EUF

ForeverHomestead

When MQTT publishes info like this

{"BatTemperature":0.8,
  "NetAmpHours":4,
  "ChargeState":0,
  "InfoFlagsBits":-1308610300,
  "ReasonForResting":4,
  "NegativeAmpHours":-9369,
  "BatVoltage":25.9,
  "PVVoltage":10.5,
  "VbattRegSetPTmpComp":27.4,
  "TotalAmpHours":704,
  "WhizbangBatCurrent":-0.5,
  "BatCurrent":0.0,
  "PVCurrent":0.0,
  "ConnectionState":0,
  "EnergyToday":0.5,
  "EqualizeTime":10800,
  "SOC":100,
  "Aux1":false,
  "Aux2":false,
  "Power":0.0,
  "FETTemperature":14.0,
  "PositiveAmpHours":17138,
  "TotalEnergy":616.1,
  "FloatTimeTodaySeconds":29689,
  "RemainingAmpHours":704,
  "AbsorbTime":18000,
  "ShuntTemperature":4.0,
  "PCBTemperature":21.3}


What format is the "AbsorbTime":18000, in.

I am trying to figure out how to get it into useful format in my .net script.