Closed createcandle closed 2 years ago
For anyone finding this: polling the printer for its battery level every 30 seconds is keeping it alive so far.
Also, trying the reconnect
method before you try the connect
method as a backup also seems to work well. After a reboot of the Raspberry Pi it seems to reconnect well.
@createcandle
It seems like this printer may go in standby mode after some time, but mostly it can be configured using setTimeout()
.
In other case you may use the solution suggested by @flatsiedatsie and ping printer every 30 seconds by requesting battery status with getDeviceBattery()
.
Do you have an example/suggestion on setTimeout()? Do you know the maximum value the printer will accept? What value do you recommend? Or is this not how I should understand it?
I've mistyped function name.
You can use setPowerTimeout(minutes) to change power timeout on printer. This printer allows setting timeout from 1 to 65520 seconds, which means printer will stay awake for this time. I've set it for 60 minutes when performed tests.
In addition you can set socket connection timeout (time that socket will wait for response until recognizes the printer as unavailable) with setTImeout(seconds), but time limit seems to be implementation dependent in pybluez. I've used 1 second when performed tests.
In case when you need constantly working connection, you can setTimeout to several seconds, setPowerTimeout to 10+ minutes and periodically call getDeviceBattery() to keep socket connected and printer awake.
Ok, thanks, I'm trying it now.
self.printer = ppa6.Printer(self.persistent_data['printer_mac'], ppa6.PrinterType.A6p)
self.printer.setPowerTimeout(300) # minutes
self.printer.setTimeout(8) # seconds
I would suggest to make a test like this:
import time
printer = ppa6.Printer('mac', ppa6.PrinterType.A6p)
printer.connect()
printer.setPowerTimeout(1)
printer.setTimeout(1)
while True:
print(printer.getDeviceBattery())
time.sleep(10)
To check if getDeviceBattery really keeps printer awake. I can not check it right now because my bluetooth support is broken.
Also, remember to call connect() before using setPowerTimeout()
Thanks! I'm was seeing an error:
error setting up printer: 'Printer' object has no attribute 'sock'
Probably because it wasn't connected yet :-D
I know that getDeviceBattery
keeps the device awake, I've tested that.
I noticed that the printer is not marked as 'trusted' after being connected. Marking it as such might make automatic reconnecting easier?
sudo bluetoothctl trust XX:XX:XX:ETC
I'm not sure because my tests were performed on windows and raspberry pi without making printer trusted and reconnection worked similar on each platform
Ah, yes, that would matter. In my experiments the printer seemed to reconnect ok as long as the reboot was fast. It generally lasted a few days, but then would eventually lose connection. I'm hoping these experiments improve it.
I should also explore the USB connection option I guess, but my Raspberry Pi doesn't have that much power or ports to spare. Are you still planning to implement USB support?
Yes, I'm planning to implement usb printing, but not sure when
For now you can give a try for print_service.py. It's not fully tested yet, but worked fine for ASCII & Images until RPI zero W SD died
I'm trying to integrate your fantastic work into a plugin for a privacy friendly smart home system. The idea is that data logs can be printed to paper every hour, and then deleted, so that only a paper trail exists.
I've managed to get everything working. But even though it's permanently plugged into power, after a while the PeriPage printer sometimes doesn't connect.
[Errno 112] Host is down
It probably went into standby mode?
How would you recommend keeping the printer awake/connected so that I can print once every hour/day?