Drolla / WavePlus_Bridge

Airthings Wave Plus Bridge to Wifi/LAN and MQTT
MIT License
21 stars 9 forks source link

Connection failed most of the time #9

Closed AndreaPro closed 1 year ago

AndreaPro commented 2 years ago

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?

Drolla commented 2 years ago

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:

Thanks!

AndreaPro commented 2 years ago

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
Drolla commented 2 years ago

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

AndreaPro commented 2 years ago

Hi @AndreaPro, There was a very similar issue reported by 'ulrischa' in September 2021 [https://github.com/[/issues/4](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!

To answer to your questions:

period: 30
sn:
   - 2930061548, basement
mqtt:
    host: <myip>
    port: 1883
    auth:
         username: <myusername>
         password: <mypassword>
    topic: /waveplus_bridge
    sensors:
        basement: '*'
    publish:
        basement: '*'
nasdim commented 2 years ago

@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!

Drolla commented 2 years ago

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

Drolla commented 2 years ago

@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 ...

nasdim commented 1 year ago

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

Drolla commented 1 year ago

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 commented 1 year ago

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