Expected b'battery_v'but got b'battery:...' error communicating with Pisgar3

Asked 2 years ago, Updated 2 years ago, 367 views

The raspberry pie is equipped with a UPS called pisugar3 to obtain voltage and battery capacity from pisugar every 5 seconds.

It works at the beginning of the program, but after about 20 minutes of movement, an error is returned. (See photo) I think there is something wrong with the syntax, but I don't know what's wrong with it.

Error Screen

Reference Scripts

github PiSugar.py

code

from pisugar import*
import datetime
import csv
import time


conn, event_conn = connect_tcp('raspberrypi.local')
s = PiSugarServer(conn, event_conn)

#s.register_single_tap_handler(lambda:print('single'))) What was mentioned in the github of pisgar? I don't understand this sentence.
#s.register_double_tap_handler(lambda:print('double'))) I don't understand this sentence.


#csv Configuration
path=open(r"data/log.csv", 'a', newline=')
f=csv.writer(path)
writer=f


# acquisition time interval
inter=5# Set the interval time in seconds

list = ' '

def writeecsv():

# pisugar_API
    battery=s.get_battery_power_plugged()#Power Supply Method
    battery=s.get_battery_level()#battery remaining
    v=s.get_battery_voltage()#

# time setting
    dt_nowrow=datetime.datetime.now()
    dt_now = dt_nowrow.strftime ('%Y year %m month %d day %H:%M:%S')
    list = [dt_now, battery plug, battery level, v]
    writer.writerow (list)
    print(list)


#csv, writing
writer.writerow ('Time Stamp', 'Power Supply', 'Battery Remaining', 'Voltage')
while True:
    shutdownlevel=s.get_battery_level()# shutdown factor

    writeecsv()
    time.sleep(inter)
    
    if (shutdownlevel<10):
        break

python python3 raspberry-pi

2022-11-11 11:18

2 Answers

It seems that there are few people who have knowledge of the product, so I think it will be difficult to get an answer, so I will answer with my guess.

No problem found with Python syntax.Perhaps the product is actually responding incorrectly. Alternatively, there may be a bug in the program that coordinates communication with the product pisugar-server, or there may be no Python module and version available.

Generally speaking, as an easy workaround for these errors (maybe bugs),

  • Avoid concurrent connections
  • Open communication intervals
  • Regularly reconnect and reboot

and so on.

Also, in the case of a library where communication results in exceptions, as in the case of a question, exception can be handled in the try statement to address errors, etc.


2022-11-11 14:55

Dear @mjy,
Thank you.

I tried a workaround, but it didn't work.Therefore, when I rewritten the try statement to avoid errors and execute it, I was able to retrieve the data successfully.
It's solved. Thank you.


2022-11-11 19:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.