diy solar

diy solar

Renogy Devices and Raspberry Pi - bluetooth/WiFi

Does anyone know if you can change the resolution of the data messages sent over MQTT.
I'm getting values that seem to be integers except for voltages. So for example power (for load power) is either 1 or 2 when I know on the app it would read 1.54W for example.
The same is true for current and I posted this question on the Creator's website. I was planning on troubleshooting this once I got my system up and running but I'm not there yet...
 
I'll have to try to polish my Python and dig into the code.
I'm getting 10ths of current, but I saw someone mentioning the debug messages and the data they produced seemed to have greater accuracy
 
I asked the author about increasing the decimal places on the values and this is what he has to say:

If you look at the class PowerDevice in solaredevice.py you can find the definitions of the various monitored values.

You will mostly see that values are stored as "high resolution" (e.g. millivolt, temperature in kelvin etc), but it will report/log on more "human friendly" values (volt, temperature in celsius etc). I also have various checks in place because quite often these devices report crazy values for a short time, so I try to filter out values that are obviously bad.

I think (but it's bee a while since I worked on this) that line 209-212 and further down in solaredevice.py contains a list of all items that should be logged remotely.

So you could change the list on line 209... so that e.g. input_voltage changed to input_mvoltage wich would get you the value in milivolts instead of volts. You could then do any roundings and calculations in the receiving end and use as many decimals as you need.
And if you want fahrenheit instead of celsius, you could change line 223 from self.entities.temperature_celsius to self.entities.temperature_fahrenheit.


I havent tried the above instruction it yet, but im close to up and running... just getting the Grafana MQTT-datasource plugin to show up in Grafana desktop is proving to be a challenge now, but i figure it out eventually....
 
Ok I see the Class Power Device at line 312 onward, and I see the properties from where he defines the "higher level" values from 477 onward, shouldn't be too hard to experiment.
I do always get zero for charge power which I assumed was a coding error and I calculate based on charge voltage and current, but it should be there......line 634

...... Nope I get 0 for charge_mpower as well.
 
Last edited:
Ok I see the Class Power Device at line 312 onward, and I see the properties from where he defines the "higher level" values from 477 onward, shouldn't be too hard to experiment.
I do always get zero for charge power which I assumed was a coding error and I calculate based on charge voltage and current, but it should be there......line 634

...... Nope I get 0 for charge_mpower as well.

charge power, I believe is your charging power in watts. Mine is not zero when the sun is out
 
Last edited:
im trying to code a subscriber to list the data the publisher is sending using my broker.

When I run the script below, all I get is that
"Connected with result code 0"

and waits...but its not listing the data the the publisher is sending....any know now how to tweak this script?


Python:
import paho.mqtt.client as mqtt

# This is the Subscriber

def on_connect(client, userdata, flags, rc):
  print("Connected with result code "+str(rc))
  client.subscribe("solar/regulator")

def on_message(client, userdata, msg):
  print("received data is :")
  print(str(message.payload.decode("utf-8")) ) #printing Received message
  print("")

client = mqtt.Client()
client.connect("localhost",1883,60)

client.on_connect = on_connect
client.on_message = on_message

client.loop_forever()
 
Last edited:
im trying to code a subscriber to list the data the publisher is sending using my broker.

When I run the script below, all I get is that
"Connected with result code 0"

and waits...but its not listed the data the the publisher is sending....any know now how to tweat this script?


Python:
import paho.mqtt.client as mqtt

# This is the Subscriber

def on_connect(client, userdata, flags, rc):
  print("Connected with result code "+str(rc))
  client.subscribe("solar/regulator")

def on_message(client, userdata, msg):
  print("received data is :")
  print(str(message.payload.decode("utf-8")) ) #printing Received message
  print("")

client = mqtt.Client()
client.connect("localhost",1883,60)

client.on_connect = on_connect
client.on_message = on_message

client.loop_forever()
Is the publisher actually sending?
 
So I'm using MQTT, sending to OpenHab and persisting that to InfluxDB and Grafana is reading the data from InfluxDB to chart. There are multiple options to get a similar configuration, for instance I think everything is integrated with HomeAssistant if you went that direction.

There is a logger option in solar-monitor for sending data to a URL via JSON. I don't see any documentation about any specific service it uses and I'm only seeing binary data that can be written to influx over http: https://docs.influxdata.com/influxdb/v1.8/guides/write_data/

Ultimately your goal is to get this data into a database that is compatible with Grafana. It looks to me like you can probably take several steps out altogether and:
  1. Install an MQTT server like Mosquitto somewhere; could even be on the Pi Zero W as long as it doesn't end up consuming too many resources
  2. Configure solar-monitor to connect to MQTT
    • If you're on Windows you can verify the data is logging with something like MQTT Explorer rather than troubleshooting with the CLI tools on the MQTT host
  3. Install Grafana somewhere, could also be on the Pi Zero W. Keep in mind that this is not have as many resources as something like a Pi4 with extra RAM, but to get started with just this one project I can absolutely see you installing all of this on the Pi Zero W
  4. Install and configure this mqtt-datasource plugin for Grafana: https://github.com/grafana/mqtt-datasource

There are many ways you can accomplish your goal, this just seems like a lighter weight solution that I'm more familiar with.

Mosquitto: https://www.instructables.com/Installing-MQTT-BrokerMosquitto-on-Raspberry-Pi/
Grafana: https://grafana.com/tutorials/install-grafana-on-raspberry-pi/
- MQTT Grafana plugin: https://github.com/grafana/mqtt-datasource
So, finally got Grafana MQTT installed on my Ubuntu Machine.

Question for you @oedo808: The script seems to be optimized for Home Assistant, so, when im on my Ubuntu machine (broker) and type this in the command line

Code:
mosquitto_sub -v -h broker_ip -p 1883 -t '#'

i get all this:

Code:
homeassistant/sensor/regulator/charge_current/config {"name": "Solar            # all topics are prefixed by \"prefix/\" Regulator Charge Current", "ud": "solar            # All topics are prefixed by \"prefix/\"_regulator_charge_current", "state_topic": "solar            # All topics are prefixed bfix/\"/regulator/charge_current/state", "force_update": true, "icon": "mdi:current-dc", "unit_of_measurement": "A"}
homeassistant/sensor/regulator/voltage/config {"name": "Solar            # all topics are prefixed by \"prefix/\" Regulator Voltage", "unique_id": "so        # All topics are prefixed by \"prefix/\"_regulator_voltage", "state_topic": "solar            # All topics are prefixed by \"prefix/\"/regulatage/state", "force_update": true, "icon": "mdi:flash", "unit_of_measurement": "V"}
homeassistant/sensor/regulator/input_voltage/config {"name": "Solar            # all topics are prefixed by \"prefix/\" Regulator Input Voltage", "uni: "solar            # All topics are prefixed by \"prefix/\"_regulator_input_voltage", "state_topic": "solar            # All topics are prefixed by \/\"/regulator/input_voltage/state", "force_update": true, "icon": "mdi:flash", "unit_of_measurement": "V"}
homeassistant/sensor/regulator/charge_voltage/config {"name": "Solar            # all topics are prefixed by \"prefix/\" Regulator Charge Voltage", "ud": "solar            # All topics are prefixed by \"prefix/\"_regulator_charge_voltage", "state_topic": "solar            # All topics are prefixed bfix/\"/regulator/charge_voltage/state", "force_update": true, "icon": "mdi:flash", "unit_of_measurement": "V"}
homeassistant/sensor/regulator/power/config {"name": "Solar            # all topics are prefixed by \"prefix/\" Regulator Power", "unique_id": "solar     # All topics are prefixed by \"prefix/\"_regulator_power", "state_topic": "solar            # All topics are prefixed by \"prefix/\"/regulator/powe", "force_update": true, "device_class": "power", "unit_of_measurement": "W"}
homeassistant/sensor/regulator/input_power/config {"name": "Solar            # all topics are prefixed by \"prefix/\" Regulator Input Power", "unique_olar            # All topics are prefixed by \"prefix/\"_regulator_input_power", "state_topic": "solar            # All topics are prefixed by \"prefigulator/input_power/state", "force_update": true, "device_class": "power", "unit_of_measurement": "W"}
homeassistant/sensor/regulator/charge_power/config {"name": "Solar            # all topics are prefixed by \"prefix/\" Regulator Charge Power", "uniqu"solar            # All topics are prefixed by \"prefix/\"_regulator_charge_power", "state_topic": "solar            # All topics are prefixed by \"pr/regulator/charge_power/state", "force_update": true, "device_class": "power", "unit_of_measurement": "W"}
homeassistant/sensor/regulator/soc/config {"name": "Solar            # all topics are prefixed by \"prefix/\" Regulator Soc", "unique_id": "solar     # All topics are prefixed by \"prefix/\"_regulator_soc", "state_topic": "solar            # All topics are prefixed by \"prefix/\"/regulator/soc/statece_update": true, "device_class": "battery", "unit_of_measurement": "%"}
homeassistant/sensor/regulator/capacity/config {"name": "Solar            # all topics are prefixed by \"prefix/\" Regulator Capacity", "unique_id": "          # All topics are prefixed by \"prefix/\"_regulator_capacity", "state_topic": "solar            # All topics are prefixed by \"prefix/\"/reguapacity/state", "force_update": true, "icon": "mdi:solar-power"}
homeassistant/sensor/regulator/temperature/config {"name": "Solar            # all topics are prefixed by \"prefix/\" Regulator Temperature", "unique_olar            # All topics are prefixed by \"prefix/\"_regulator_temperature", "state_topic": "solar            # All topics are prefixed by \"prefigulator/temperature/state", "force_update": true, "device_class": "temperature", "unit_of_measurement": "\u00b0C"}
homeassistant/switch/regulator/power_switch/config {"name": "Solar            # all topics are prefixed by \"prefix/\" Regulator Power Switch", "uniqu"solar            # All topics are prefixed by \"prefix/\"_regulator_power_switch", "state_topic": "solar            # All topics are prefixed by \"pr/regulator/power_switch/state", "command_topic": "solar            # All topics are prefixed by \"prefix/\"/regulator/power_switch/set", "payload_on":yload_off": 0}

How do I modify the output so that the Grafana MQTT can read it (not Home Assistant)?

EDIT: turns out I need the remove the comments from the ini file. Now its works quite well. Gragana is ploting the values.....all right, thanks for bringing this to my attention.
 
Last edited:
well, after a while, here's the money shot. All local.
 

Attachments

  • Renogy Screenshot1.jpg
    Renogy Screenshot1.jpg
    189.2 KB · Views: 27
  • Renogy Screenshot2.jpg
    Renogy Screenshot2.jpg
    189.8 KB · Views: 25
Cool @SolarShed
Does anyone know the parameters that define MPPT, Float, Boost etc or whether it's exposed in the code
There seems to be a 'State' item but it never gets reported or "Health" for that matter
 
Last edited:
Cool @SolarShed
Does anyone know the parameters that define MPPT, Float, Boost etc or whether it's exposed in the code
There seems to be a 'State' item but it never gets reported or "Health" for that matter
are you referring to the settings or when you Rover is in MPPT, float, boost mode?....either way, I have not seen that in the code, or haven't identified it yet....its good point and would be nice to have as another data stream.
 
Using InfluxDB (on Ubuntu in Grafana) and Red-NODE (on RPi Zero 2W), here's the dashboard for a true data logging and remote (and locally-based) access system

 
Last edited:
Has anyone been successful reading a Rover Elite 40 with BT-2? Reading through the thread, I can't tell what success people have been having with BT-2. I can connect but it immediately disconnects and I get no results. I see a lot of "ping" requests every couple minutes but no data. I'm a Linux guy but not at all python. Here's what I get:
pi@inventorpi:~/solar-monitor $ ./solar-monitor.py
Debug enabled
DEBUG: Creating new DataLogger
DEBUG: Creating new MQTT-logger
DEBUG: MQTT Sending CONNECT (u0, p0, wr0, wq0, wf0, c1, k60) client_id=b'localhost'
DEBUG: MQTT Received CONNACK (0, 0)
INFO: Adapter status - Powered: True
INFO: Starting discovery...
DEBUG: Found 15 BLE-devices so far
DEBUG: Found 20 BLE-devices so far
DEBUG: Found 20 BLE-devices so far
DEBUG: Found 20 BLE-devices so far
DEBUG: Found 20 BLE-devices so far
DEBUG: Found 20 BLE-devices so far
INFO: Found 20 BLE-devices
DEBUG: Processing device <hidden MAC> None
DEBUG: Processing device <hidden MAC> <hidden>
DEBUG: Processing device <hidden MAC> <hidden>
DEBUG: Processing device <hidden MAC> <hidden>
DEBUG: Processing device <hidden MAC> <hidden>
DEBUG: Processing device <hidden MAC> <hidden>
DEBUG: Processing device <hidden MAC> None
DEBUG: Processing device <hidden MAC> <hidden>
DEBUG: Processing device <hidden MAC> <hidden>
DEBUG: Processing device f0:f8:f2:6e:86:0b BT-TH-F26E860B
INFO: Trying to connect to f0:f8:f2:6e:86:0b...
INFO: Successfully imported SolarLink.
DEBUG: New PowerDevice
DEBUG: New RegulatorDevice
INFO: [regulator] Connecting to f0:f8:f2:6e:86:0b
DEBUG: Processing device <hidden MAC> None
DEBUG: Processing device <hidden MAC> None
DEBUG: Processing device <hidden MAC> <hidden>
DEBUG: Processing device <hidden MAC> <hidden>
DEBUG: Processing device <hidden MAC> <hidden>
DEBUG: Processing device <hidden MAC> None
DEBUG: Processing device <hidden MAC> <hidden>
DEBUG: Processing device <hidden MAC> None
DEBUG: Processing device <hidden MAC> <hidden>
DEBUG: Processing device <hidden MAC> <hidden>
INFO: Terminate with Ctrl+C
INFO: [f0:f8:f2:6e:86:0b] Discovered, alias = BT-TH-F26E860B
INFO: [regulator] Connected to BT-TH-F26E860B
INFO: [f0:f8:f2:6e:86:0b] Discovered, alias = BT-TH-F26E860B
INFO: [regulator] Disconnected
DEBUG: MQTT Sending PINGREQ
DEBUG: MQTT Received PINGRESP

---------------
Here's my ini:

[monitor]
adapter = hci0
debug = True
temperature = F
# C = Celsius
# K = Kelvin
# F = Farenheit


[datalogger]
#url = http://server/solar/api/
#token = 39129e20be0503937cb72a5f719337cc

[regulator]
type = SolarLink
mac = f0:f8:f2:6e:86:0b
reconnect = True

[mqtt]
broker = localhost
prefix = solar
username = user
password = password
hostname = localhost
 
So it connected and disconnected after discovering - was the bt-2 still thinking it was connected to the app? I get round this by unplugging and replugging in the bt-2 device so I can swap the rpi and app connecting to the bt-2
 
So it connected and disconnected after discovering - was the bt-2 still thinking it was connected to the app? I get round this by unplugging and replugging in the bt-2 device so I can swap the rpi and app connecting to the bt-2
I just disconnected the BT-2 and turned off Bluetooth on my phone and iPad. Made sure the app wasn't open anywhere and then tried to connect with the Pi. Same thing. connect/discover name/disconnect
 
I was just able to get it working. Trying bluetoothctl and connecting directly, I got:
[bluetooth]# connect f0:f8:f2:6e:86:0b
Attempting to connect to f0:f8:f2:6e:86:0b
[CHG] Device F0:F8:F2:6E:86:0B Connected: yes
Failed to connect: org.bluez.Error.Failed
[CHG] Device F0:F8:F2:6E:86:0B Connected: no
[CHG] Device F0:F8:F2:6E:86:0B RSSI: -40


I looked up that bluez error and found a port similar. Their fix was to install "bluez-hid2hci" I couldn't find that but I did install "bluez-hcidump" and now I see a ton of debug messages such as:

.......
DEBUG: [regulator] Looping thread Device-poller-thread regulator
DEBUG: [regulator] Looping thread Device-poller-thread regulator
DEBUG: create_poll_request BatteryParamInfo
DEBUG: create_poll_request BatteryParamInfo => [255, 3, 1, 0, 0, 7, 16, 42]
DEBUG: [regulator] Writing data to 0000ffd1-0000-1000-8000-00805f9b34fb - [255, 3, 1, 0, 0, 7, 16, 42] (ff0301000007102a)
DEBUG: [regulator] Write to characteristic done for: [0000ffd1-0000-1000-8000-00805f9b34fb]
DEBUG: [regulator] Writing data to 0000ffd1-0000-1000-8000-00805f9b34fb - bytearray(b'main recv da ta[ff] [') (6d61696e20726563762064612074615b66665d205b)
DEBUG: REG: BatteryParamInfo VAL: b'\xff\x03\x0e\x00P\x00\x7f\x00\x00\x15\x10\x00\x00\x00\x00\x00\x00E2'
DEBUG: mSOC 0 80 => 80 %
DEBUG: [regulator] Value of _dsoc out of bands: Changed from 800.0 to 800.0 (no diff)
DEBUG: mVoltage 0 127 => 12.700000000000001 V
DEBUG: [regulator] Value of _charge_mvoltage out of bands: Changed from 12700.000000000002 to 12700.000000000002 (no diff)
DEBUG: mElectricity 0 0 => 0.0 A
DEBUG: [regulator] Value of _charge_mcurrent out of bands: Changed from 0 to 0.0 (no diff)
DEBUG: mDeviceTemperature 21
DEBUG: [regulator] Value of _dkelvin out of bands: Changed from 2941.0 to 2941.0 (no diff)
DEBUG: mDeviceTemperatureCelsius 21.0
DEBUG: mBatteryTemperature 16
DEBUG: [regulator] Value of _bkelvin out of bands: Changed from 2891.0 to 2891.0 (no diff)
DEBUG: mBatteryTemperatureCelsius 16.0
DEBUG: mLoadVoltage 0 0 => 0.0 V
DEBUG: [regulator] Value of _mvoltage out of bands: Changed from 0 to 0.0 (no diff)
DEBUG: mLoadElectricity 0 0 => 0.0 A
DEBUG: [regulator] Value of _mcurrent out of bands: Changed from 0 to 0.0 (no diff)
DEBUG: mLoadPower 0 0 => 0 W
DEBUG: [regulator] Value of _mpower out of bands: Changed from 0 to 0.0 (no diff)
DEBUG: [regulator] Could not find charge_cycles
DEBUG: [regulator] Could not find state
DEBUG: [regulator] Could not find health
DEBUG: [regulator] Write to characteristic done for: [0000ffd1-0000-1000-8000-00805f9b34fb]
DEBUG: [regulator] Looping thread Device-poller-thread regulator
DEBUG: [regulator] Looping thread Device-poller-thread regulator
DEBUG: create_poll_request SolarPanelInfo


Now to clean up and make some sense out of it all
 
You could try sudo apt bluez install and see if it has any missing components. What device and debian version are you using?
 
I tried to just install bluez and it actually broke the rest of the bluetooth stack. bluetoothctl was removed when it was installed and hci was replaced with bluez interfaces which broke everything else. This is Raspbian "bullseye" on a spare Pi 4 I had on the shelf
 
that;s great that you got it to work with a BT-2 module. now it opens things up for the Elite Rovers.

If Renogy can release the ModBus maps/codes for other devices, this could be a pandora's box.
 
Back
Top