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
#7
Well...

First, thank you for the reply as it's appreciated...

Second, the reason is because I'm a complete newbie Python coder and haven't yet reached a level of understanding to even understand the above code...but I'll certainly give it a try, and try and learn from it...I'm diligently reading my O'Reilly Intro to Python book right now (sadly I bought it years ago and it's an older addition). Python is quite different from the other languages I've used so there's a bit of a learning curve for me...

But Thirdly, I'm trying to understand, given the code I posted, why the addition of Print statements or the lack thereof can cause random failures when the code is executed. I'm assuming it's because of how variable scope declarations are handled in Python, but I'm not sure.

I'm trying to build a system that will monitor 4 of my off grid buildings, each with its own solar and battery system. Right now I have to walk to within Bluetooth range of each building (spread over 40 acres) and connect to the BMS' with a phone app, to get readings. All these building are interconnected on my LAN (some wired, some microwave linked). I found a potential solution for bluetooth connectivity using RPis on GitHub (username tgalarneau, project BMS) and have tweaked his code base for my purposes. The idea is to use an existing RPi in each building to attach and read the BMS data every 5 minutes and publish that data to an MQTT broker in the main building. I'll then grab that JSON based MQTT data and push it into my Maria/MySQL DB and then present a unified view of all the systems using Grafana. I'm more familiar with all of that process and less with Python, but heck, I like to learn...and I'm snowed in now anyway...

The borrowed code was writing multiple messages to MQTT and I wanted to unify that into a single message containing the data I want to track, so I pulled the MQTT post process out of the original individual functions (and deleted a couple I didn't need at all to streamline things) and thought I could use a global list to hold the values retrieve by each function that I want to use, and then have a singled MQTT post process. So, I've kind of hacked tgalarneau's code without really understanding its finer points.

Your code dealing with "delegates" is new to me so I guess I need to dig into that a lot more to understand why the "tgalarneau" code was set up the way it was.

So, do you see anything in the code I have that would be causing a seemingly random "works/fails" situation and the "list index out of range" issue?

Again, thanks for the reply...
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  Strange behavior list of list mmhmjanssen 3 1,751 May-09-2024, 11:32 AM
Last Post: mmhmjanssen
  strange behavior of chess library in Python max22 1 1,324 Jan-18-2024, 06:35 PM
Last Post: deanhystad
  running a TensorFlow program Led_Zeppelin 0 1,458 Apr-07-2022, 06:33 PM
Last Post: Led_Zeppelin
  Strange write()/File behavior kaega2 2 2,734 Jan-28-2022, 02:53 AM
Last Post: kaega2
  Python Program running a lot slower after change to Ubuntu hubenhau 1 3,859 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,881 Nov-13-2020, 07:43 AM
Last Post: buran
  Running Python 2.7 program ErnestTBass 2 3,844 Oct-21-2020, 08:06 AM
Last Post: snippsat
  read terminal text from running program AArdvark_UK 2 2,768 Aug-27-2020, 12:43 PM
Last Post: AArdvark_UK
  Modify code from running program ? samuelbachorik 2 3,201 Jun-26-2020, 08:17 PM
Last Post: samuelbachorik
  Upper-Bound Exclusive Meaning Johnny1998 1 4,659 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