Hi all
Emoncms is running local on a Pi 3B, version is emonSD-20Nov23
I noticed comming back from Christmas holidays that Mysolarbattery Dashboard was extremly slow.
Using top, I was surpised that the emonhub service uses 70 to 80% of the CPU.
Emonhub is used only to get the data from my SMA inverter via bluetooth
After a reboot, it drops to normal 3-5%, but we see it increasing with the on time.
I implemented a workaround by rebooting automatically at 2 in the night each day. Now after around 10h up, I see: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 561 pi 20 0 89432 26780 8788 S 18.5 2.8 66:55.78 python3 /usr/local/bin/emonhub/emonhub.py --config-file=/etc
The last modification I made to the setup in end of november was adding an other python service using asyncio, that execute each 2 minutes (with a auto restart after completion), get the feeds by http and generates a plot with matplotlib, converts the jpg into base64 and send it to an external mqtt broker so I can see the basic graph with Solar, SOC and Load on my phone when not at home.
I have also 2 other python services running, one each 5 minutes to get the values from the cloud for a second inverter and push it on the emonpi mqtt broker, and a second one that execute at midnight to get the Solcast forecasts and push it also on the emonpi mqtt broker. These 2 scripts are also using asyncio in order to avoid blocking.
Any idea how to understand root cause and improve the situation ?
Hi.
The only mod I made to emoncms is the slight modification of the kW digits I made and discussed here MySolarBattery kW digits settings
I made some tests yesterday disabling the added services:
it seems that the CPU usage of emonhub does not increase.
then I added my ExternalMqtt service which was the latest added and CPU usage does not increase either. But this script do not push data to the emonpi mqtt broker, only to an external broker.
Do you think the problem is related to the fact that the 2 other python script services are publishing data to the emonpi mqtt broker like emonhub does (even if I do not know) ? I use aiomqtt module to do it with asyncio.
What could be the workaround ? pushing data with http requests ?
Thanks for your support !
Looking at it, this wouldnât make any difference.
It sounded like there was some retry mechanism being blocked, and that removing the other publishers fixed it goes someway to confirming that. There might be something in the log. If you run journalctl -u emonhub that should give you the emonHub log.
2025-01-10 15:31:49,272 ERROR SMASolar [Errno 104] Connection reset by peer
2025-01-10 15:31:49,273 ERROR SMASolar Bluetooth error while connecting to 00:80:25:27:B1:99
2025-01-10 15:31:49,274 ERROR SMASolar âBluetoothErrorâ object is not subscriptable
2025-01-10 15:31:49,276 ERROR SMASolar [âTraceback (most recent call last):\nâ, â File ââ, line 3, in connect\nâ, â_bluetooth.error: (104, âConnection reset by peerâ)\nâ, â\nDuring handling of the above exception, another exception occurred:\n\nâ, âTraceback (most recent call last):\nâ, â File â/opt/openenergymonitor/emonhub/src/interfacers/EmonHubSMASolarInterfacer.pyâ, line 132, in _open_bluetooth\n btSocket.connect((inverteraddress, port))\nâ, â File ââ, line 5, in connect\nâ, âbluetooth.btcommon.BluetoothError: [Errno 104] Connection reset by peer\nâ, â\nDuring handling of the above exception, another exception occurred:\n\nâ, âTraceback (most recent call last):\nâ, â File â/opt/openenergymonitor/emonhub/src/interfacers/EmonHubSMASolarInterfacer.pyâ, line 223, in read\n self._login_inverter()\nâ, â File â/opt/openenergymonitor/emonhub/src/interfacers/EmonHubSMASolarInterfacer.pyâ, line 64, in _login_inverter\n self._btSocket = self._open_bluetooth(self._inverteraddress, self._port)\nâ, â File â/opt/openenergymonitor/emonhub/src/interfacers/EmonHubSMASolarInterfacer.pyâ, line 140, in _open_bluetooth\n errCode = eval(err[0])[0]\nâ, âTypeError: âBluetoothErrorâ object is not subscriptable\nâ]
2025-01-10 15:32:00,038 ERROR SMASolar Bluetooth Error
2025-01-10 15:32:00,039 ERROR SMASolar timed out
But it is the same without my other mqtt services running
What is the mqtt client used in emonhub?
I use an async version of paho.
But this situation is perhaps better linked to the SMAsolar Bluetooth interfacer?
I was loathe to suggest it as it doesnât seem to fit with load increasing over time, but it is in the logs so letâs deal with it. Additionally, the error is in a retry section which does fit the available data
Easy check - assuming youâre not using the SMA Solar system, try temporarily moving ./src/interfacers/EmonHubSMASolarInterfacer.py somewhere else and restart EmonHub. It loads all the interfacers in the src/interfacers folder at start up, so if itâs not in there it wonât be loaded.
I havenât looked in detail at the bluetooth Python module, but the error is being caused by the error being accessed as an array (âobject is not subscriptableâ).
OK. I got it!!
Not a matter of mqtt, not a matter of bluetoothâŚ
Looking at emonhub I found in the doc that serial is enabled by default in emonhub.conf.
And what I forgot is that in december I tried to spy which registers my battery inverter access on the gridmeter with a modbus sniffer script. It works well with my laptop but not with the pi and now I understand why.
The USB converter was still attached to the pi and connected to the modbus so receiving datas.
So it is the EmonOEMinterfacer that increase CPU usage when receiving wrong datas. I disabled it.
Now the problem is solved, CPU usage flat at 3% during the night!