Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConnectionRefusedError: [Errno 111] Connection refused #48

Closed
spetter1337 opened this issue Nov 9, 2021 · 14 comments
Closed

ConnectionRefusedError: [Errno 111] Connection refused #48

spetter1337 opened this issue Nov 9, 2021 · 14 comments
Labels
bug Something isn't working

Comments

@spetter1337
Copy link

spetter1337 commented Nov 9, 2021

Describe the bug
pi@goforit:~ $ bash /home/pi/scaleish/wrapper.sh


2021-11-10 00:46:37 - Starting Xiaomi mi Scale...
2021-11-10 00:46:37 - Loading Config From Options.json...
2021-11-10 00:46:37 - Config Loaded...
Traceback (most recent call last):
File "/home/pi/scaleish/Xiaomi_Scale.py", line 298, in
main()
File "/home/pi/scaleish/Xiaomi_Scale.py", line 264, in main
discovery()
File "/home/pi/scaleish/Xiaomi_Scale.py", line 156, in discovery
tls=MQTT_TLS
File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/publish.py", line 241, in single
protocol, transport, proxy_args)
File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/publish.py", line 176, in multiple
client.connect(hostname, port, keepalive)
File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/client.py", line 914, in connect
return self.reconnect()
File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/client.py", line 1044, in reconnect
sock = self._create_socket_connection()
File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/client.py", line 3685, in _create_socket_connection
return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source)
File "/usr/lib/python3.7/socket.py", line 727, in create_connection
raise err
File "/usr/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

Expected behaviour
Expected the scripts to run successfully.

Scale (please complete the following information):

  • Model: Xiaomi Smart Scale 2

Desktop/Server (please complete the following information):

  • Docker or manually ran after a Git Clone? Docker
  • Device used to run the Script/Container [e.g. Raspberry Pi, NUC] Raspberry Pi 4
  • Bluetooth device used [e.g. Built-in, USB Dongle] Built-in
@spetter1337 spetter1337 added the bug Something isn't working label Nov 9, 2021
@lolouk44
Copy link
Owner

lolouk44 commented Nov 10, 2021 via email

@spetter1337
Copy link
Author

For some reason, the MQTT module didnt get installed. I now completed that and also ran the bash with sudo and it worked! Only config of Home Assistant left :D

2021-11-10 21:37:32 - Starting Xiaomi mi Scale...
2021-11-10 21:37:32 - Loading Config From Options.json...
2021-11-10 21:37:32 - Config Loaded...
2021-11-10 21:37:32 - Discovery Completed...
2021-11-10 21:37:32 - Publishing data to topic miscale/Simon/weight: {"weight":80.00,"weight_unit":"kg","bmi":24.42,"basal_metabolism":1706.20,"visceral_fat":12.50,"timestamp":"2021-11-10 21:37:32.497355"}
2021-11-10 21:37:32 - Data Published ...
2021-11-10 21:39:21 - Publishing data to topic miscale/Simon/weight: {"weight":80.15,"weight_unit":"kg","bmi":24.47,"basal_metabolism":1708.44,"visceral_fat":12.57,"timestamp":"2021-11-10 21:39:21.775211"}
2021-11-10 21:39:21 - Data Published ...
2021-11-10 21:41:40 - Publishing data to topic miscale/Simon/weight: {"weight":80.30,"weight_unit":"kg","bmi":24.51,"basal_metabolism":1710.67,"visceral_fat":12.65,"timestamp":"2021-11-10 21:41:40.207222"}
2021-11-10 21:41:40 - Data Published ...

@spetter1337 spetter1337 reopened this Nov 10, 2021
@spetter1337
Copy link
Author

When I do "docker container ls" in the terminal, it says that the container is restarting. Is that suppose to be the case?

d5621dcd3f2b
lolouk44/xiaomi-mi-scale:latest
"/entrypoint.sh /cmd…"
23 hours ago
Restarting (1) 17 seconds ago

@lolouk44
Copy link
Owner

no it should not restart. You should see things in the logs if it doesn't work correctly.
Is there anything else than what you already posted?
Alternatively if you use docker-compose, run it without the -d so you see all the logs in the terminal

@spetter1337
Copy link
Author

Hm... I have successfully managed to get the data streaming into Home Assistant now - i.e. when get on the scale, new data pops up in HA will the correct metrics. Did the HA MQTT integration

@spetter1337
Copy link
Author

Getting the following errors in the logs though:

2021-11-10 21:30:16 - Starting Xiaomi mi Scale...
Traceback (most recent call last):
File "/opt/miscale/Xiaomi_Scale.py", line 39, in
with open('/data/options.json') as json_file:
FileNotFoundError: [Errno 2] No such file or directory: '/data/options.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/opt/miscale/Xiaomi_Scale.py", line 139, in
sys.stderr.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - options.json file missing... {error}\n")
NameError: name 'error' is not defined

@spetter1337
Copy link
Author

My options.json path is: /home/pi/scaleish/options.json. Guess that's why the issue occurs? However, where am I suppose to do the replacement?

@lolouk44
Copy link
Owner

So you found a bug in my code. Thanks 👍
However it's just a cosmetic bug that has nothing to do with your issue 😶
The issue is indeed where you've saved your file
Check your docker-compose file
You should have something that looks like this:


      volumes:
        - /home/pi/scaleish:/data

Provided there is just options.json in that folder (just in case)
If unsure, create a sub folder (e.g. data) and move options.json in it, then map it in your docker-compose file

@spetter1337
Copy link
Author

Thank you! I had the default volume that you had in your file here at github, so that makes sense.

Just one newbie question: I have now edited the docker-compose.yml file - what command do I need to write into the terminal in order for the container to be updated? Tried restarting the container but didn't change anything.

@lolouk44
Copy link
Owner

go where the docker-compose.yml is located and type docker-compose down && docker-compose up -d
This will stop any existing container and restart

@spetter1337
Copy link
Author

spetter1337 commented Nov 10, 2021

Thanks, much appreciated. Looooove this, gonna push everything into Splunk later.

Now I get it, the container is used as a mean to execute the scripts and initiate MQTT between the scale and the raspberry. But because I used bash before - i.e "Running script directly on your host system" - I was still able to get the MQTT up and running, however, using the container seems more convenient as it won't require having the CLI open etc.

@lolouk44
Copy link
Owner

docker is the way to go. No need to worry about dependencies or about having to install additional apps.
Glad I could help.

@spetter1337
Copy link
Author

spetter1337 commented Nov 11, 2021

A question with regards to the volume in the docker-compose file.

volumes:
- /home/pi/scaleish:/data

I have tried to do some googling to understand the logic behind it, but I still don't quite get it. Is my idea of it (stated below) correct to some extent?

  • /home/pi/scaleish = defines the path on the host where the necessary resources are stored (xiaomi python scripts, options.json etc)
  • /data = the directory in the container that will be mapped to the /home/pi/scaleish, completing the resource integration enabling the container to retrieve the resources from the host and run successfully

Also, this is (if I'm correct) classified as an "absolut path mapping", but there seems to be other ways to define volumes (e.g. named volume). In this specific case, would it be possible to define the volume in another way and achieve the same result? Or is the current definition the only way to go?

Thanks!

@lolouk44
Copy link
Owner

lolouk44 commented Nov 11, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants