Python Forum
Program running on RPi 3b+ Very Strange Behavior - Out of Bound Index
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Program running on RPi 3b+ Very Strange Behavior - Out of Bound Index
#6
Maybe your writes/notify fails. If you only get one data back, the info array is only 4 long, and info[4] is out of range.

Why aren't you saving your data in your delegate? Something like this:

class MyDelegate(DefaultDelegate):
    def __init__(self):
        super().__init__()
        self.dd03_updates = 0
        self.dd04_updates = 0
        # If you need data as a dictionary, may as well save it as a dictionary.
        self.data = {
            "volts": None,
            "amps": None,
            "capacity": None,
            "remain": None,
            "cell1": None,
            "cell2": None,
            "cell3": None,
            "cell4": None,
        }
 
    def handleNotification(self, cHandle, data):
        hex_data = binascii.hexlify(data)
        if b'dd04' in hex_data:
            self.dd04_messages += 1
            self.data.update(zip(
                ("volts", "amps", "capacity", "remain"),
                struct.unpack_from('>HHHH', data, 4)
            ))
        elif b'dd03' in hex_data:
            self.dd03_messages += 1
            self.data.update(zip(
                ("cell1", "cell2", "cell3", "cell4"),
                struct.unpack_from('>HHHH', data, 4)
            ))
 
    def __str__(self):
        return "\n\t".join((
            f'Messages  dd03:{self.dd03_messages}, dd04{self.dd04_messages}',
            *[f'{key:10} = {value}' for key, value in self.data.items()]
        ))
 
delegate = MyDelegate()
bms.setDelegate(delegate)  # setup bt delegate for notifications
 
. . .

while True:
    bms.writeCharacteristic(0x15, b'\xdd\xa5\x03\x00\xff\xfd\x77', False)
    bms.waitForNotifications(5)
    bms.writeCharacteristic(0x15, b'\xdd\xa5\x04\x00\xff\xfc\x77', False)
    bms.waitForNotifications(5)
    print(delegate)


    ret = mqtt.publish(topic, payload=json.dumps(delegate.data), qos=0, retain=False)
Reply


Messages In This Thread
RE: Program running on RPi 3b+ Very Strange Behavior - Out of Bound Index - by deanhystad - Mar-05-2023, 10:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Strange behavior list of list mmhmjanssen 3 1,744 May-09-2024, 11:32 AM
Last Post: mmhmjanssen
  strange behavior of chess library in Python max22 1 1,317 Jan-18-2024, 06:35 PM
Last Post: deanhystad
  running a TensorFlow program Led_Zeppelin 0 1,454 Apr-07-2022, 06:33 PM
Last Post: Led_Zeppelin
  Strange write()/File behavior kaega2 2 2,729 Jan-28-2022, 02:53 AM
Last Post: kaega2
  Python Program running a lot slower after change to Ubuntu hubenhau 1 3,848 Mar-02-2021, 05:01 PM
Last Post: Serafim
  I have an index error inline 76 but I write the program in a way that cant reach tha abbaszandi 2 2,875 Nov-13-2020, 07:43 AM
Last Post: buran
  Running Python 2.7 program ErnestTBass 2 3,833 Oct-21-2020, 08:06 AM
Last Post: snippsat
  read terminal text from running program AArdvark_UK 2 2,761 Aug-27-2020, 12:43 PM
Last Post: AArdvark_UK
  Modify code from running program ? samuelbachorik 2 3,197 Jun-26-2020, 08:17 PM
Last Post: samuelbachorik
  Upper-Bound Exclusive Meaning Johnny1998 1 4,653 Aug-02-2019, 08:32 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020