WavePlus_Bridge icon indicating copy to clipboard operation
WavePlus_Bridge copied to clipboard

Connection failed most of the time

Open AndreaPro opened this issue 4 years ago • 9 comments

Hello, I am testing the software and I've noticed that most of the time I get this error in the logs: Failed to communicate with device <serial_number> / basement : Failed to connect to peripheral <MAC_Address>, addr type: public sometimes the values are read and sometimes this error is displayed. What can be the cause?

AndreaPro avatar Jan 10 '22 13:01 AndreaPro

Hi @AndreaPro, There was a very similar issue reported by 'ulrischa' in September 2021 [https://github.com/Drolla/WavePlus_Bridge/issues/4]. The reason for the failure was simply that the WavePlus devices were too far away from the Raspberry. So maybe you can move the WavePlus device and Raspberry closer together, at least for debugging purposes to see if this changes the connection quality. If this does not work, could you please add the full log to this case? And could you please also send the information from your configuration file (waveplus_bridge.yaml) that is relevant for the connection (period, sn, port). Please don't send eventual private data (email, password, etc). Then, could you also answer the following questions:

  • What is the platform (which Raspberry Pi version)?
  • Have you enabled Bluetooth?
  • Were you already able to connect to the WavePlus device from your Raspberry Pi (with another application)?
  • Are you running the application as admin/root, or as normal user?
  • What Python and BluePy versions are you using?
  • How far away is your Raspberry Pi from your WavePlus device?

Thanks!

Drolla avatar Jan 15 '22 16:01 Drolla

I will post the relevant informations as soon as I can but in the meantime I can say that this happens even at 1m of distance.

Another error that appears almost randomly is this one:

Failed to communicate with device 2930061548 / basement : non-hexadecimal number found
 in fromhex() arg at position 0

AndreaPro avatar Jan 15 '22 20:01 AndreaPro

OK, too bad that the distance is not the problem. So I will wait on your additional information.

Drolla avatar Jan 16 '22 09:01 Drolla

Hi @AndreaPro, There was a very similar issue reported by 'ulrischa' in September 2021 [https://github.com//issues/4]. The reason for the failure was simply that the WavePlus devices were too far away from the Raspberry. So maybe you can move the WavePlus device and Raspberry closer together, at least for debugging purposes to see if this changes the connection quality. If this does not work, could you please add the full log to this case? And could you please also send the information from your configuration file (waveplus_bridge.yaml) that is relevant for the connection (period, sn, port). Please don't send eventual private data (email, password, etc). Then, could you also answer the following questions:

  • What is the platform (which Raspberry Pi version)?
  • Have you enabled Bluetooth?
  • Were you already able to connect to the WavePlus device from your Raspberry Pi (with another application)?
  • Are you running the application as admin/root, or as normal user?
  • What Python and BluePy versions are you using?
  • How far away is your Raspberry Pi from your WavePlus device?

Thanks!

To answer to your questions:

  • I have a Pi4 running RaspiOS_lite_arm64-2021-11-08 image
  • I have the internal bluetooth disabled due to the short range inside the Argon One metal case and I am using an extender with a TP-Link UB-400 connected with an active extender. I have the same issues with and without extender
  • I have not tried with other applications
  • From my home folder I am using the following command: sudo ./waveplus_bridge.py --config waveplus_bridge.yaml --log ""
  • I am running Python 3.9.2and BluePy1.2.0
  • Normally 5 or 6 meters, but the same errors happens even at 1 meter These are the relevant connection informations from my configuration file, everything else is commented because I would use it only with mqtt to transmit data to Home Assistant:
period: 30
sn:
   - 2930061548, basement
mqtt:
    host: <myip>
    port: 1883
    auth:
         username: <myusername>
         password: <mypassword>
    topic: /waveplus_bridge
    sensors:
        basement: '*'
    publish:
        basement: '*'

AndreaPro avatar Jan 17 '22 12:01 AndreaPro

@Drolla, were you able to troubleshoot this problem? I am also getting it and distance doesn't seem to be it.

I read online for IanHarvey's bluepy, and apparently the problem can easily be fixed if we can pass the addrtype Public to bluepy.btle. Reference: https://github.com/IanHarvey/bluepy/issues/83

I think the problem is on line 265 where the addrtype is not defined. HEre is the documentation for the bluepy Peripheral() function: https://ianharvey.github.io/bluepy-doc/peripheral.html. My limited programming knowledge got me so far as changing line 265 to self.periph = Peripheral(self.mac_addr, addrType='public') but it doesn't seem to fix it still.

Thank you!

nasdim avatar May 08 '22 07:05 nasdim

Hi @nasdim and @AndreaPro, I am going to provide you shortly an update that allows debugging the issue.

Drolla avatar May 15 '22 16:05 Drolla

@AndreaPro , the new section 'Debugging' has been added to the README.md file that provides instructions how connection issues can be debugged. Could you run the test application embedded in the newly created Wave Plus communication module, libs/waveplus.py. It does not any complex YAML configuration, but you can just provide the refresh period (e.g. 60), followed by one or multiple serial numbers of your Wave Plus devices:

sudo python waveplus.py <period> <serial_number_1> [serial_number_2] ..

Let me know what output you get. The improvement made by @nasdim (add retries in case of communication issues) has been added to the latest available tool version. Maybe this helps ...

Drolla avatar Jun 24 '22 04:06 Drolla

Thank you for the updates, @Drolla! I confirm it works now.

However, I am still not able to set it up as a service and isntead opted for running it using the .bashrc file. Here is a reference of how I did it: https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/#amzn_assoc_ad_div_adunit_3

nasdim avatar Jul 16 '22 20:07 nasdim

OK, it is great that this works now for you, @nasdim. @AndreaPro , it would be great if you could recheck on you side to see if it works also for you. Thanks!

Regarding the other concern to setup the waveplus bridge as service, I will open another ticket to separate topics.

Drolla avatar Jul 17 '22 14:07 Drolla

Closing since it is resolved for AndreasPro. No feedback received from nasdim.

Drolla avatar Mar 11 '23 15:03 Drolla