ESP32 Classic MQTT Publisher & Home Assistant

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

Previous topic - Next topic

ForeverHomestead

Hey Guys,

So my pi came today and I am working on setting things up.  I am a complete newbie when it comes to Pi.  I am confused about the step that says:

QuoteCreate the .env file and specify the 5 items listed below in this format. They correspond to the parameters for the classic_mqtt.py program. Notice that since we are bringing up our own MQTT Broker, we can skip specifying the MQTT host. The last 3 parameters will work with the included MQTT broker, so there is no need to change those. To create this file on the Raspberry Pi, I like nano.
CLASSIC=<IP address or URL> 
CLASSIC_PORT=<Port usually 502>
CLASSIC_NAME=MyClassic
MQTT_ROOT=ClassicMQTT
MQTT_USER=ClassicPublisher
MQTT_PASS=ClassicPub123

I am not sure what/how I create this file or where it should be saved.  What am I missing

ClassicCrazy

#121
Quote from: ForeverHomestead on January 22, 2021, 05:05:46 PM
Hey Guys,

So my pi came today and I am working on setting things up.  I am a complete newbie when it comes to Pi.  I am confused about the step that says:

QuoteCreate the .env file and specify the 5 items listed below in this format. They correspond to the parameters for the classic_mqtt.py program. Notice that since we are bringing up our own MQTT Broker, we can skip specifying the MQTT host. The last 3 parameters will work with the included MQTT broker, so there is no need to change those. To create this file on the Raspberry Pi, I like nano.
CLASSIC=<IP address or URL> 
CLASSIC_PORT=<Port usually 502>
CLASSIC_NAME=MyClassic
MQTT_ROOT=ClassicMQTT
MQTT_USER=ClassicPublisher
MQTT_PASS=ClassicPub123

I am not sure what/how I create this file or where it should be saved.  What am I missing

go to your folder where Classic MQTT-Master files are
Go to the Code folder
Go to Python folder
then do
sudo nano .env
It should open up a file with nothing in it - copy and past the stuff above in it with your changes for your system
then do
Control X
yes to save changes
yes to save in the file name
If you want to check it after it closes you can do
sudo nano .env 
do control x to close it and it will just close if you don't make any changes
The .env might not show up in the files after you make it but you can tell if it is there if you do the nano .env
I told you how to do this using terminal program - but you can probably do same thing using desktop file manager

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

ForeverHomestead

#122
that is perfect.  I did some searching and was only missing a step.  Thanks.

If I have multiple Classics, what is the process of adding them into this as well?  Do I just add more lines to the file with the ip address and names?

Looks like I am getting an error trying to read the data from the classic:

classic_mqtt_1  | 2021-01-23 13:37:41,819:DEBUG:classic_mqtt:Opening the modbus Connection
classic_mqtt_1  | 2021-01-23 13:37:47,830:ERROR:classic_mqtt:MODBUS Error H:192.168.2.238 P:502 e:<class 'pymodbus.exceptions.ConnectionException'>
classic_mqtt_1  | 2021-01-23 13:37:47,831:ERROR:classic_mqtt:MODBUS data not good, skipping publish
classic_mqtt_1  | 2021-01-23 13:37:47,831:DEBUG:classic_mqtt:Adjusting next interval to account for cycle taking too long: -1.0118117332458496
classic_mqtt_1  | 2021-01-23 13:37:47,832:DEBUG:classic_mqtt:Adjusted interval: 3.9881882667541504





Graham

Quote from: ForeverHomestead on January 23, 2021, 07:18:54 AM
that is perfect.  I did some searching and was only missing a step.  Thanks.

If I have multiple Classics, what is the process of adding them into this as well?  Do I just add more lines to the file with the ip address and names?

Looks like I am getting an error trying to read the data from the classic:

classic_mqtt_1  | 2021-01-23 13:37:41,819:DEBUG:classic_mqtt:Opening the modbus Connection
classic_mqtt_1  | 2021-01-23 13:37:47,830:ERROR:classic_mqtt:MODBUS Error H:192.168.2.238 P:502 e:<class 'pymodbus.exceptions.ConnectionException'>
classic_mqtt_1  | 2021-01-23 13:37:47,831:ERROR:classic_mqtt:MODBUS data not good, skipping publish
classic_mqtt_1  | 2021-01-23 13:37:47,831:DEBUG:classic_mqtt:Adjusting next interval to account for cycle taking too long: -1.0118117332458496
classic_mqtt_1  | 2021-01-23 13:37:47,832:DEBUG:classic_mqtt:Adjusted interval: 3.9881882667541504

Looking at the python code doesn't give any further detail... (see attachment)
try pinging your classic from the pi
ping 192.168.2.238
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

#124
ping is fine.  I dont need to change anything on the classic itself do I?  Not much to set in there really.  I am set as DHCP, am I better to set as static?  Right now I have my router set to always give it the same address.

I dont see any error in the startup.

/usr/local/lib/python3.5/dist-packages/paramiko/transport.py:33: CryptographyDeprecationWarning: Python 3.5 support will be dropped in the next release of cryptography. Please upgrade your Python.
  from cryptography.hazmat.backends import default_backend
Building with native build. Learn about native build in Compose here: https://docs.docker.com/go/compose-native-build/
Starting python_mosquitto_1 ... done
Starting python_classic_mqtt_1 ... done
Attaching to python_mosquitto_1, python_classic_mqtt_1
mosquitto_1     | chown: /mosquitto/config/mosquitto.conf: Read-only file system
mosquitto_1     | 1611418640: mosquitto version 1.6.12 starting
classic_mqtt_1  | 2021-01-23 16:17:23,690:INFO:classic_mqtt:classic_mqtt starting up...
classic_mqtt_1  | 2021-01-23 16:17:23,706:INFO:classic_mqtt:classicHost = 192.168.2.238
classic_mqtt_1  | 2021-01-23 16:17:23,707:INFO:classic_mqtt:classicPort = 502
classic_mqtt_1  | 2021-01-23 16:17:23,707:INFO:classic_mqtt:classicName = Classic_1
classic_mqtt_1  | 2021-01-23 16:17:23,708:INFO:classic_mqtt:mqttHost = mosquitto
classic_mqtt_1  | 2021-01-23 16:17:23,709:INFO:classic_mqtt:mqttPort = 1883
classic_mqtt_1  | 2021-01-23 16:17:23,709:INFO:classic_mqtt:mqttRoot = ClassicMQTT
classic_mqtt_1  | 2021-01-23 16:17:23,709:INFO:classic_mqtt:mqttUser = ClassicPublisher
classic_mqtt_1  | 2021-01-23 16:17:23,710:INFO:classic_mqtt:mqttPassword = **********
classic_mqtt_1  | 2021-01-23 16:17:23,711:INFO:classic_mqtt:awakePublishRate = 5
classic_mqtt_1  | 2021-01-23 16:17:23,711:INFO:classic_mqtt:snoozePublishRate = 300
classic_mqtt_1  | 2021-01-23 16:17:23,711:INFO:classic_mqtt:awakePublishLimit = 60
classic_mqtt_1  | 2021-01-23 16:17:23,712:DEBUG:classic_mqtt:snoozeCycleLimit: 60
classic_mqtt_1  | 2021-01-23 16:17:23,712:INFO:classic_mqtt:Connecting with clientId=ClassicPublisher_mqttclient_245
classic_mqtt_1  | 2021-01-23 16:17:23,714:INFO:classic_mqtt:Connecting to MQTT mosquitto:1883
classic_mqtt_1  | 2021-01-23 16:17:23,750:DEBUG:classic_mqtt:MQTT connected OK Returned code=0
classic_mqtt_1  | 2021-01-23 16:17:23,752:DEBUG:classic_mqtt:Starting main loop...
classic_mqtt_1  | 2021-01-23 16:17:23,754:DEBUG:classic_mqtt:Subscribed to ClassicMQTT/Classic_1/cmnd/#

Graham

Quote from: ForeverHomestead on January 23, 2021, 11:16:20 AM
ping is fine.  I dont need to change anything on the classic itself do I?  Not much to set in there really.  I am set as DHCP, am I better to set as static?  Right now I have my router set to always give it the same address.
...

can you access your classic from a pc running the midnite local app?
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: ForeverHomestead on January 23, 2021, 07:18:54 AM
that is perfect.  I did some searching and was only missing a step.  Thanks.

If I have multiple Classics, what is the process of adding them into this as well?  Do I just add more lines to the file with the ip address and names?

Looks like I am getting an error trying to read the data from the classic:

classic_mqtt_1  | 2021-01-23 13:37:41,819:DEBUG:classic_mqtt:Opening the modbus Connection
classic_mqtt_1  | 2021-01-23 13:37:47,830:ERROR:classic_mqtt:MODBUS Error H:192.168.2.238 P:502 e:<class 'pymodbus.exceptions.ConnectionException'>
classic_mqtt_1  | 2021-01-23 13:37:47,831:ERROR:classic_mqtt:MODBUS data not good, skipping publish
classic_mqtt_1  | 2021-01-23 13:37:47,831:DEBUG:classic_mqtt:Adjusting next interval to account for cycle taking too long: -1.0118117332458496
classic_mqtt_1  | 2021-01-23 13:37:47,832:DEBUG:classic_mqtt:Adjusted interval: 3.9881882667541504

The .env file I showed in screen shot for mine is how you set it up for two Classics
But you also need to make the second python file like you did for the first one according to the directions ( but put in the info for second Classic )

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

ForeverHomestead

Yes I can access it with the local app.

I think it may just be an occasional error.  I think maybe it is dropping the connection.  I may move it out into my power house and connect via lan in the same switch as the classics.

Can I view the data that it collects via a data stream or folder?  I see the log talking about that, I do not see a folder on the pie though. 

ClassicCrazy

Getting Portainer running is a big help to see if the docker files are running .

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

ClassicCrazy

This is what portainer looks like .
As you can see I have two versions of Mosquitto installed by Docker.
One is not running.
Using  IOT Stack to install Portainer CE is the easiest way .

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

You could use MQTT.fx and subscribe to the root topic ClassicMQTT/# to see if the python code is publishing the classics data to your broker

https://mqttfx.jensd.de/index.php/download
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

I see you have a CLASSIC_NAME1, CLASSIC_NAME2 but no CLASSIC_NAME.... without a number.  I set mine like that and is complains about not having the one without CLASSIC_NAME.  Did you have that issue as well?

ClassicCrazy

Quote from: ForeverHomestead on January 23, 2021, 04:00:53 PM
I see you have a CLASSIC_NAME1, CLASSIC_NAME2 but no CLASSIC_NAME.... without a number.  I set mine like that and is complains about not having the one without CLASSIC_NAME.  Did you have that issue as well?

You should set yours up with just one Classic at first to make sure you have everything working.
Follow the instructions. Use the .env file in the instructions for just one Classic.
If you get it working on just one Classic then you can try to get both of them working.
I think some of the names might be case sensitive so make sure .env file matches the other places you might put in Classic names.

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

ClassicCrazy

This is my classic-compose yaml file .
Mat helped me set this all up to work with two classics .
That is why I thought  you should try to just get one classic working as is documented .
It could be that is why you are getting errors because one of your other files isn't supporting two Classics
I probably shouldn't  have posted my .env file since it is sort of customized.
Anyway this is the yaml file that goes with it which may have been modified 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

daklein

#134
Graham/Larry/Matt,   Thanks for setting up this Classic to MQTT tool, and for the great packaged setup.  It works!

Installed on a Pi with crossover cable to the Classic, and the Pi is set up as bridge/router from home wifi.  The Pi is set up using IOTstack with MQTT to NodeRed to influxdb to grafana.  The Pi collects data from 2 Enphase Envoys, a bridge to the utility main meter, a pair of SMA inverters, and now the Classic!  Woohoo!

I've been trying to figure out the SMA CAN messages enough to be useful for controlling (haven't found battery voltage & current signals correctly yet).  It's been on my list to connect up to the Classic, but it dawned on me that it has battery voltage.   It didn't take long to plug in and get it working.