btmon for python 3?

Post any 3rd party software here.
vespaman
Posts: 68
Joined: Sat Oct 08, 2011 2:48 am
Location: Sweden

btmon for python 3?

Post by vespaman » Sun Nov 29, 2020 11:16 am

Has anyone done or seen a updated btmon that works with python 3? I am updating my server, and of course 2.7 is no longer with us..
ben
Site Admin
Posts: 4262
Joined: Fri Jun 04, 2010 9:39 am

Re: btmon for python 3?

Post by ben » Mon Nov 30, 2020 11:36 am

vespaman wrote:
Sun Nov 29, 2020 11:16 am
Has anyone done or seen a updated btmon that works with python 3? I am updating my server, and of course 2.7 is no longer with us..
Try the attached conversion to see if it works. Report back any errors.

EDIT: Attached a new copy.
Attachments
btmon3.zip
(41.43 KiB) Downloaded 532 times
Ben
Brultech Research Inc.
E: ben(at)brultech.com
vespaman
Posts: 68
Joined: Sat Oct 08, 2011 2:48 am
Location: Sweden

Re: btmon for python 3?

Post by vespaman » Mon Dec 28, 2020 2:12 pm

So, finally, I had some time to test btmon3.
It has some issues, that I fixed (configparser issue and I also removed "options.ip_poll_interval > 0" check).

After this, I get no errors, it starts up and prints the same stuff that I get on the 2.7 version on my old server, but it does not work. Not sure why. Only thing I know, is that it never sends anything to the broker.

Is there any prefered way to debug this?
ben
Site Admin
Posts: 4262
Joined: Fri Jun 04, 2010 9:39 am

Re: btmon for python 3?

Post by ben » Tue Dec 29, 2020 12:13 pm

vespaman wrote:
Mon Dec 28, 2020 2:12 pm
So, finally, I had some time to test btmon3.
It has some issues, that I fixed (configparser issue and I also removed "options.ip_poll_interval > 0" check).

After this, I get no errors, it starts up and prints the same stuff that I get on the 2.7 version on my old server, but it does not work. Not sure why. Only thing I know, is that it never sends anything to the broker.

Is there any prefered way to debug this?
Does it show packets being processed?

Does the MQTT settings show up when you start the script?
Ben
Brultech Research Inc.
E: ben(at)brultech.com
vespaman
Posts: 68
Joined: Sat Oct 08, 2011 2:48 am
Location: Sweden

Re: btmon for python 3?

Post by vespaman » Wed Dec 30, 2020 8:14 am

No, I don't think any packets are processed, this is probably where it fails. Here's a sample output:

Code: Select all

oxygen /etc/btmon # /usr/bin/python /etc/btmon/btmon3.py -c /etc/btmon/gem2.cfg
2020/12/30 14:10:38 btmon: 3.3.1
2020/12/30 14:10:38 python: 3.8.7 (default, Dec 25 2020, 16:06:21) 
[GCC 10.2.0]
2020/12/30 14:10:38 platform: linux
2020/12/30 14:10:38 polarity is reversed
2020/12/30 14:10:38 device type: gem
2020/12/30 14:10:38 device list: ['']
2020/12/30 14:10:38 packet format: gem48ptbin
2020/12/30 14:10:38 schema: counters
2020/12/30 14:10:38 SOCKET: timeout: 60
2020/12/30 14:10:38 SOCKET: server host: 10.1.200.11
2020/12/30 14:10:38 SOCKET: server port: 8000
2020/12/30 14:10:38 SOCKET: poll interval: 12
2020/12/30 14:10:38 MQTT: mqtt:localhost:1883?clientid=btmon-gem2
2020/12/30 14:10:38 MQTT: user: <not-specified>
2020/12/30 14:10:38 MQTT: tls: <not-specified>
2020/12/30 14:10:38 MQTT: topic: /house/energy
2020/12/30 14:10:38 MQTT: qos: 0
2020/12/30 14:10:38 MQTT: retain: False
2020/12/30 14:10:38 MQTT: will: <not-specified>
2020/12/30 14:10:38 MQTT: upload period: 12
2020/12/30 14:10:38 MQTT: map: 
2020/12/30 14:10:51 a bytes-like object is required, not 'str'
2020/12/30 14:10:51 a bytes-like object is required, not 'str'
2020/12/30 14:10:51 a bytes-like object is required, not 'str'
2020/12/30 14:10:51 3 requests failed for device 

The last four lines are repeated for each call to the gem. (every 12'th second), (for some reason I did not see them the last time I test, maybe I did not wait enougth time). I don't really know where this is done in the code, I have tried to 'breakpoint()' here and there, but without finding the actual place where the gem polling is done.
ben
Site Admin
Posts: 4262
Joined: Fri Jun 04, 2010 9:39 am

Re: btmon for python 3?

Post by ben » Wed Dec 30, 2020 4:06 pm

vespaman wrote:
Wed Dec 30, 2020 8:14 am
No, I don't think any packets are processed, this is probably where it fails. Here's a sample output:

Code: Select all

oxygen /etc/btmon # /usr/bin/python /etc/btmon/btmon3.py -c /etc/btmon/gem2.cfg
2020/12/30 14:10:38 btmon: 3.3.1
2020/12/30 14:10:38 python: 3.8.7 (default, Dec 25 2020, 16:06:21) 
[GCC 10.2.0]
2020/12/30 14:10:38 platform: linux
2020/12/30 14:10:38 polarity is reversed
2020/12/30 14:10:38 device type: gem
2020/12/30 14:10:38 device list: ['']
2020/12/30 14:10:38 packet format: gem48ptbin
2020/12/30 14:10:38 schema: counters
2020/12/30 14:10:38 SOCKET: timeout: 60
2020/12/30 14:10:38 SOCKET: server host: 10.1.200.11
2020/12/30 14:10:38 SOCKET: server port: 8000
2020/12/30 14:10:38 SOCKET: poll interval: 12
2020/12/30 14:10:38 MQTT: mqtt:localhost:1883?clientid=btmon-gem2
2020/12/30 14:10:38 MQTT: user: <not-specified>
2020/12/30 14:10:38 MQTT: tls: <not-specified>
2020/12/30 14:10:38 MQTT: topic: /house/energy
2020/12/30 14:10:38 MQTT: qos: 0
2020/12/30 14:10:38 MQTT: retain: False
2020/12/30 14:10:38 MQTT: will: <not-specified>
2020/12/30 14:10:38 MQTT: upload period: 12
2020/12/30 14:10:38 MQTT: map: 
2020/12/30 14:10:51 a bytes-like object is required, not 'str'
2020/12/30 14:10:51 a bytes-like object is required, not 'str'
2020/12/30 14:10:51 a bytes-like object is required, not 'str'
2020/12/30 14:10:51 3 requests failed for device 

The last four lines are repeated for each call to the gem. (every 12'th second), (for some reason I did not see them the last time I test, maybe I did not wait enougth time). I don't really know where this is done in the code, I have tried to 'breakpoint()' here and there, but without finding the actual place where the gem polling is done.
Line 1501, try changing :

Code: Select all

    def requestpacket(self, com, gemid=''):
        idstr = ''
        if len(gemid) > 0:
            idstr = 'NMB%s' % gemid
        com.send('^^^%sAPISPK' % idstr)
        
to:

Code: Select all

    def requestpacket(self, com, gemid=''):
        idstr = ''
        if len(gemid) > 0:
            idstr = 'NMB%s' % gemid
        output = '^^^%sAPISPK' % idstr
        com.sendall(output.encode('utf-8'))
Ben
Brultech Research Inc.
E: ben(at)brultech.com
vespaman
Posts: 68
Joined: Sat Oct 08, 2011 2:48 am
Location: Sweden

Re: btmon for python 3?

Post by vespaman » Fri Jan 01, 2021 6:36 am

So, after doing that, I get these outputs instead (repeated for each poll);

Code: Select all

2021/01/01 12:33:08 'PollingSocketClientCollector' object has no attribute 'sendall'
2021/01/01 12:33:08 'PollingSocketClientCollector' object has no attribute 'sendall'2021/01/01 12:33:08 'PollingSocketClientCollector' object has no attribute 'sendall'
2021/01/01 12:33:08 'PollingSocketClientCollector' object has no attribute 'sendall'
2021/01/01 12:33:08 'PollingSocketClientCollector' object has no attribute 'sendall'
2021/01/01 12:33:08 3 requests failed for device 

2021/01/01 12:33:08 'PollingSocketClientCollector' object has no attribute 'sendall'
2021/01/01 12:33:08 3 requests failed for device 
ben
Site Admin
Posts: 4262
Joined: Fri Jun 04, 2010 9:39 am

Re: btmon for python 3?

Post by ben » Mon Jan 04, 2021 1:33 pm

vespaman wrote:
Fri Jan 01, 2021 6:36 am
So, after doing that, I get these outputs instead (repeated for each poll);

Code: Select all

2021/01/01 12:33:08 'PollingSocketClientCollector' object has no attribute 'sendall'
2021/01/01 12:33:08 'PollingSocketClientCollector' object has no attribute 'sendall'2021/01/01 12:33:08 'PollingSocketClientCollector' object has no attribute 'sendall'
2021/01/01 12:33:08 'PollingSocketClientCollector' object has no attribute 'sendall'
2021/01/01 12:33:08 'PollingSocketClientCollector' object has no attribute 'sendall'
2021/01/01 12:33:08 3 requests failed for device 

2021/01/01 12:33:08 'PollingSocketClientCollector' object has no attribute 'sendall'
2021/01/01 12:33:08 3 requests failed for device 
Revert it to send. Thought that was a direct reference to a socket but the socket is located within the ClientCollector.
Ben
Brultech Research Inc.
E: ben(at)brultech.com
vespaman
Posts: 68
Joined: Sat Oct 08, 2011 2:48 am
Location: Sweden

Re: btmon for python 3?

Post by vespaman » Thu Jan 07, 2021 11:13 am

OK, so changing into send, gives me;

Code: Select all

2021/01/07 17:01:00 can only concatenate str (not "bytes") to str
2021/01/07 17:01:00 3 requests failed for device 
I don't think this happens at the same place though.

Sorry for being so clueless with python...
ben
Site Admin
Posts: 4262
Joined: Fri Jun 04, 2010 9:39 am

Re: btmon for python 3?

Post by ben » Thu Jan 07, 2021 1:08 pm

vespaman wrote:
Thu Jan 07, 2021 11:13 am
OK, so changing into send, gives me;

Code: Select all

2021/01/07 17:01:00 can only concatenate str (not "bytes") to str
2021/01/07 17:01:00 3 requests failed for device 
I don't think this happens at the same place though.

Sorry for being so clueless with python...
NP, attach your config file (feel free to remove your serial number, etc) and I'll try running it.
Ben
Brultech Research Inc.
E: ben(at)brultech.com
Post Reply