USB connection: power handling

90 views
Skip to first unread message

Andreas

unread,
Jan 13, 2020, 4:01:00 PM1/13/20
to weewx-user
Hi all,

I am using a TFA Nexus weather station which is know for losing its sensors if connected to USB. The usage of a long USB cable with ferrites on either end made it better, but a real improvement was the deactivation of USB power after every import which is easy to handle on a raspberry pi with uhubctl.

Until now the following line is implemented in crontab and executed every 15 minutes:

sudo uhubctl - a on -p 2 && sudo service weewx start && sleep 10 && sudo wee_reports /etc/weewx/weewx.conf && sleep 5 && sudo service weewx stop && sudo uhubctl -a off -p 2

Because USB power is just switched on for several seconds, connection to the sensors is not lost any more (exceptions possible), but I see disadvantages because of the multiple terminations of weewx. The graphs show missing data entries, the regular archive interval is interrupted and - the worst thing in my eyes - after every start of weewx all report files are recreated, e.g. every jpg file, favicon.ico etc. These files usually only are created once after start, and on further archive periods only the files are recreated which are stated in the skin.conf.

I know I could improve my graphs by using 'line_gap_fraction' or to change the skin.conf to avoid the multiple creation of report files. But instead I would like to start weewx only once and to switch on USB power just for the short period of the data import. Following things would be possible:

- in crontab just switch on/off USB every 15 minutes and in weewx set up archive interval also to 15 minutes, hoping that both events correspond long-lasting.
Disadvantage: I do not know how to harmonize both events so that USB is certainly active if the archive interval starts. Moreover, it could be dangerous if the USB connection was terminated within a data import.

- let weewx execute the switch of USB with uhubctl
Every time before data is imported by weewx from the weather station, weewx should switch on USB, when import is complete it should turn off USB using 'sudo uhubctl - a on/off p 2'. Would this be possible?

Great, but I do not have a clue about implementing this feature in weewx. Any ideas? Could this be solved easily just by inserting a command in a skin or report? The ftp report for example also causes console commands, doesn't it?

Thanks for your help and ideas,
Andreas

mwall

unread,
Jan 13, 2020, 5:14:03 PM1/13/20
to weewx-user
here are a few things to try or to think about:

- do not read historical data from the station.  for the fine offset usb stations, reading historical records requires more usb comm that reading current data.  it is the same for te923 stations.  if your usb is flaky, then minimizing usb comms can help avoid lockups.  so if you set record_generation=software, weewx will read only current conditions.  weewx will still read historical data when it starts up (you can disable that too, if you want).

- do not restart weewx when you power cycle the usb.  if you power up the weather station, start weewx, then power cycle the weather station, weewx *should* recover.  it should re-establish the connection to the station and continue reading data.  so as long as your power cycling happens in less than one archve interval, you won't notice anything.  be sure to use a reasonable archive interval (5 minutes works well).

- if you cannot ensure that the weather station is powered on when weewx starts up, then use the loop_on_init option to force weewx to keep trying.  (normally weewx will stop if it cannot detect the hardware you requested)

a long time ago i tried putting usbcntl logic into the fousb driver.  the intent was to detect the usb lockups in the driver, and make the driver force a power cycling of the usb.  although that worked, it was difficult to maintain - there is too much variability in how power control is done in usb, so putting that logic in the driver made the driver too brittle.

i think a better approach is to do the power cycling somewhere else, then be sure that weewx will re-connect to the station reliably.

as for when to power cycle, you can do that using cron, but another approach is to only do it when you lose the connection.  so write a weewx service that watches for data continuity - have it watch the timestamp on each loop packet.  when it sees that a loop packet is missed (or maybe 5 loop packets), then do the power cycle.  the driver should simply recover and continue capturing data.

m

Andreas

unread,
Jan 13, 2020, 5:21:11 PM1/13/20
to weewx-user
Thanks for your quick reply. Just to make sure: It is not the USB connection that is lost when the weather station is plugged to the raspberry. It is the connection to the temperature and wind sensors.

Andreas

unread,
Jan 22, 2020, 2:14:01 PM1/22/20
to weewx-user
So since a few days the solution with crontab is working fine, except from the many copies and uploads of the files, but I can live with that. But I noticed that every time weewx starts, the first record from TE923 is skipped, so if I start weewx every 15 minutes and the archive period is five minutes, the first record is skipped and only two records every 15 minutes are saved.

Would you please have a look at the attached log file with two cycles (started 16:45 and 17:00)? I do not find the reason for the skipping, just the note in the log file that a record is skipped.

Weewx is running on a raspberry pi, belchertown skin is in use. The pi time is fixed by ntp and a local router which is the local time server, on T923 the radio controlled clock is active.

Thanks,
Andreas
log.txt
Reply all
Reply to author
Forward
0 new messages