pywws.WeatherStation

Ottenere i dati da stazioni meteo compatibili con WH1080/WH3080.

Derivato da wwsr.c by Michael Pendec (michael.pendec@gmail.com), wwsrdump.c by Svend Skafte (svend@skafte.net), modificato da Dave Wells, e altre fonti.

Introduzione

Questo è il modulo che in realtà comunica con l’unità di base della stazione meteo. Non ho molta comprensione dell” USB, quindi copiato molto dal programma in C wwsr di Michael Pendec’s

La memoria della stazione meteo è divisa in due parti: «fixed block» di 256 byte e un buffer circolare di 65280 byte. Siccome ogni stringa prende 16 byte la stazione può immagazzinare 4080 letture, o 14 giorni di letture di intervallo di 5 minuti. (Le stazioni tipo 3080 memorizzano 20 byte per la stringa, quindi memorizzano un massimo di 3264). Siccome lettura dei dati è in blocchi di 32 byte, ma ogni lettura meteo è 16 o 20 byte, una piccola cache viene utilizzata per ridurre il traffico USB. Il comportamento di memorizzazione nella cache può essere esclusa con il parametro unbuffered in get_data e get_raw_data.

Decoding the data is controlled by the static dictionaries _reading_format, lo_fix_format and fixed_format. The keys are names of data items and the values can be an (offset, type, multiplier) tuple or another dictionary. So, for example, the _reading_format dictionary entry 'rain' : (13, 'us', 0.3) means that the rain value is an unsigned short (two bytes), 13 bytes from the start of the block, and should be multiplied by 0.3 to get a useful value.

L’uso di dizionari annidati nel dizionario fixed_format permette utili sottoinsiemi di dati per essere decodificati. Ad esempio, per decodificare l’intero blocco get_fixed_block viene chiamato senza parametri

ws = WeatherStation.weather_station()
print ws.get_fixed_block()

Per ottenere la temperatura esterna minima memorizzata, è chiamato get_fixed_block con una sequenza di comandi:

ws = WeatherStation.weather_station()
print ws.get_fixed_block(['min', 'temp_out', 'val'])

Spesso non non c’è nessun obbligo di leggere e decodificare l’intero blocco, siccome i primi 64 byte contengono i dati più utili: l’intervallo dei valori memorizzati, l’indirizzo del buffer dove è memorizzata la lettura corrente e l’ora della data corrente. Il metodo get_lo_fix_block fornisce facile accesso a questi dati.

Per ulteriori esempi di utilizzo del modulo WeatherStation, consultare il programma TestWeatherStation.

Dettagli API

Funzioni

decode_status(status)

Classi

CUSBDrive() Interfaccia di basso livello della stazione meteo tramite USB.
DriftingClock(logger, name, status, period, …)
weather_station([ws_type, status, avoid]) Classe che rappresenta la stazione meteorologica nel programma utente.
pywws.WeatherStation.decode_status(status)[sorgente]
class pywws.WeatherStation.CUSBDrive[sorgente]

Interfaccia di basso livello della stazione meteo tramite USB.

Liberamente ispirato su una classe C++ ottenuta da http://site.ambientweatherstore.com/easyweather/ws_1080_2080_protocol.zip.Non so la provenienza di questo, ma sembra che siano venuti dal produttore.

EndMark = 32
ReadCommand = 161
WriteCommand = 160
WriteCommandWord = 162
read_block(address)[sorgente]

Legge 32 byte dalla stazione meteo.

Se la lettura non riesce per qualche motivo, None viene restituito.

Parametri:address (int) – Indirizzo di lettura da.
Ritorna:I dati della stazione meteo.
Tipo di ritorno:
 list(int)
write_byte(address, data)[sorgente]

Scrive un singolo byte sulla stazione meteo.

Parametri:
  • address (int) – Indirizzo di scrittura su.
  • data (int) – il valore da scrivere.
Ritorna:

eseguito con successo.

Tipo di ritorno:
 

bool

class pywws.WeatherStation.DriftingClock(logger, name, status, period, margin)[sorgente]
before(now)[sorgente]
avoid()[sorgente]
set_clock(now)[sorgente]
invalidate()[sorgente]
class pywws.WeatherStation.weather_station(ws_type='1080', status=None, avoid=3.0)[sorgente]

Classe che rappresenta la stazione meteorologica nel programma utente.

Connettersi alla stazione metereologica e preparare per la lettura dei dati.

min_pause = 0.5
margin = 0.9
live_data(logged_only=False)[sorgente]
inc_ptr(ptr)[sorgente]

Ottenere il puntatore ai dati successivi del buffer circolare.

dec_ptr(ptr)[sorgente]

Ottenere il puntatore ai dati precedenti nel buffer circolare.

get_raw_data(ptr, unbuffered=False)[sorgente]

Ottiene i dati grezzi (raw) dal buffer circolare.

Se “unbuffered” è false, potrebbe essere restituito un valore memorizzato nella cache, che è stato ottenuto in precedenza.

get_data(ptr, unbuffered=False)[sorgente]

Ottiene i dati decodificati dal buffer circolare.

Se “unbuffered” è false, potrebbe essere restituito un valore memorizzato nella cache, che è stato ottenuto in precedenza.

current_pos()[sorgente]

Ottiene la posizione del buffer circolare dove sono scritti dati correnti.

get_raw_fixed_block(unbuffered=False)[sorgente]

Ottiene il grezzo (raw) «fixed block» di impostazioni e dati di min/max.

get_fixed_block(keys=[], unbuffered=False)[sorgente]

Ottiene decodificato «fixed block» di impostazioni e dati di min/max.

Per selezionare un sottoinsieme di tutto il blocco tasti.

write_data(data)[sorgente]

Scrive una serie di byte singoli sulla stazione meteo. Dati devono essere una matrice di coppie (ptr, value).

lo_fix_format = {'alarm_1': (21, 'bf', ('bit0', 'time', 'wind_dir', 'bit3', 'hum_in_lo', 'hum_in_hi', 'hum_out_lo', 'hum_out_hi')), 'alarm_2': (22, 'bf', ('wind_ave', 'wind_gust', 'rain_hour', 'rain_day', 'pressure_abs_lo', 'pressure_abs_hi', 'pressure_rel_lo', 'pressure_rel_hi')), 'alarm_3': (23, 'bf', ('temp_in_lo', 'temp_in_hi', 'temp_out_lo', 'temp_out_hi', 'wind_chill_lo', 'wind_chill_hi', 'dew_point_lo', 'dew_point_hi')), 'current_pos': (30, 'us', None), 'data_changed': (26, 'ub', None), 'data_count': (27, 'us', None), 'display_1': (19, 'bf', ('pressure_rel', 'wind_gust', 'clock_12hr', 'date_mdy', 'time_scale_24', 'show_year', 'show_day_name', 'alarm_time')), 'display_2': (20, 'bf', ('temp_out_temp', 'temp_out_chill', 'temp_out_dew', 'rain_hour', 'rain_day', 'rain_week', 'rain_month', 'rain_total')), 'display_3': (29, 'bf', ('illuminance_fc', 'bit1', 'bit2', 'bit3', 'bit4', 'bit5', 'bit6', 'bit7')), 'read_period': (16, 'ub', None), 'settings_1': (17, 'bf', ('temp_in_F', 'temp_out_F', 'rain_in', 'bit3', 'bit4', 'pressure_hPa', 'pressure_inHg', 'pressure_mmHg')), 'settings_2': (18, 'bf', ('wind_mps', 'wind_kmph', 'wind_knot', 'wind_mph', 'wind_bft', 'bit5', 'bit6', 'bit7')), 'timezone': (24, 'sb', None), 'unknown_01': (25, 'pb', None)}
fixed_format = {'abs_pressure': (34, 'us', 0.1), 'alarm': {'windchill': {'lo': (62, 'ss', 0.1), 'hi': (60, 'ss', 0.1)}, 'dewpoint': {'lo': (66, 'ss', 0.1), 'hi': (64, 'ss', 0.1)}, 'wind_ave': {'ms': (77, 'ub', 0.1), 'bft': (76, 'ub', None)}, 'rain': {'day': (85, 'us', 0.3), 'hour': (83, 'us', 0.3)}, 'rel_pressure': {'lo': (74, 'us', 0.1), 'hi': (72, 'us', 0.1)}, 'hum_in': {'lo': (49, 'ub', None), 'hi': (48, 'ub', None)}, 'temp_out': {'lo': (58, 'ss', 0.1), 'hi': (56, 'ss', 0.1)}, 'wind_dir': (82, 'ub', None), 'hum_out': {'lo': (55, 'ub', None), 'hi': (54, 'ub', None)}, 'wind_gust': {'ms': (80, 'ub', 0.1), 'bft': (79, 'ub', None)}, 'uv': (92, 'ub', None), 'temp_in': {'lo': (52, 'ss', 0.1), 'hi': (50, 'ss', 0.1)}, 'illuminance': (89, 'u3', 0.1), 'abs_pressure': {'lo': (70, 'us', 0.1), 'hi': (68, 'us', 0.1)}, 'time': (87, 'tt', None)}, 'alarm_1': (21, 'bf', ('bit0', 'time', 'wind_dir', 'bit3', 'hum_in_lo', 'hum_in_hi', 'hum_out_lo', 'hum_out_hi')), 'alarm_2': (22, 'bf', ('wind_ave', 'wind_gust', 'rain_hour', 'rain_day', 'pressure_abs_lo', 'pressure_abs_hi', 'pressure_rel_lo', 'pressure_rel_hi')), 'alarm_3': (23, 'bf', ('temp_in_lo', 'temp_in_hi', 'temp_out_lo', 'temp_out_hi', 'wind_chill_lo', 'wind_chill_hi', 'dew_point_lo', 'dew_point_hi')), 'current_pos': (30, 'us', None), 'data_changed': (26, 'ub', None), 'data_count': (27, 'us', None), 'date_time': (43, 'dt', None), 'display_1': (19, 'bf', ('pressure_rel', 'wind_gust', 'clock_12hr', 'date_mdy', 'time_scale_24', 'show_year', 'show_day_name', 'alarm_time')), 'display_2': (20, 'bf', ('temp_out_temp', 'temp_out_chill', 'temp_out_dew', 'rain_hour', 'rain_day', 'rain_week', 'rain_month', 'rain_total')), 'display_3': (29, 'bf', ('illuminance_fc', 'bit1', 'bit2', 'bit3', 'bit4', 'bit5', 'bit6', 'bit7')), 'lux_wm2_coeff': (36, 'us', 0.1), 'magic_0': (0, 'pb', None), 'magic_1': (1, 'pb', None), 'max': {'windchill': {'date': (181, 'dt', None), 'val': (110, 'ss', 0.1)}, 'dewpoint': {'date': (191, 'dt', None), 'val': (114, 'ss', 0.1)}, 'wind_ave': {'date': (221, 'dt', None), 'val': (126, 'us', 0.1)}, 'rain': {'week': {'date': (241, 'dt', None), 'val': (134, 'us', 0.3)}, 'total': {'date': (251, 'dt', None), 'val': (138, 'us', 0.3)}, 'day': {'date': (236, 'dt', None), 'val': (132, 'us', 0.3)}, 'hour': {'date': (231, 'dt', None), 'val': (130, 'us', 0.3)}, 'month': {'date': (246, 'dt', None), 'val': (136, 'us', 0.3)}}, 'rel_pressure': {'date': (211, 'dt', None), 'val': (122, 'us', 0.1)}, 'hum_in': {'date': (141, 'dt', None), 'val': (98, 'ub', None)}, 'temp_out': {'date': (171, 'dt', None), 'val': (106, 'ss', 0.1)}, 'hum_out': {'date': (151, 'dt', None), 'val': (100, 'ub', None)}, 'wind_gust': {'date': (226, 'dt', None), 'val': (128, 'us', 0.1)}, 'uv': {'val': (93, 'ub', None)}, 'temp_in': {'date': (161, 'dt', None), 'val': (102, 'ss', 0.1)}, 'illuminance': {'val': (94, 'u3', 0.1)}, 'abs_pressure': {'date': (201, 'dt', None), 'val': (118, 'us', 0.1)}}, 'min': {'hum_out': {'date': (156, 'dt', None), 'val': (101, 'ub', None)}, 'dewpoint': {'date': (196, 'dt', None), 'val': (116, 'ss', 0.1)}, 'abs_pressure': {'date': (206, 'dt', None), 'val': (120, 'us', 0.1)}, 'windchill': {'date': (186, 'dt', None), 'val': (112, 'ss', 0.1)}, 'hum_in': {'date': (146, 'dt', None), 'val': (99, 'ub', None)}, 'temp_out': {'date': (176, 'dt', None), 'val': (108, 'ss', 0.1)}, 'rel_pressure': {'date': (216, 'dt', None), 'val': (124, 'us', 0.1)}, 'temp_in': {'date': (166, 'dt', None), 'val': (104, 'ss', 0.1)}}, 'read_period': (16, 'ub', None), 'rel_pressure': (32, 'us', 0.1), 'settings_1': (17, 'bf', ('temp_in_F', 'temp_out_F', 'rain_in', 'bit3', 'bit4', 'pressure_hPa', 'pressure_inHg', 'pressure_mmHg')), 'settings_2': (18, 'bf', ('wind_mps', 'wind_kmph', 'wind_knot', 'wind_mph', 'wind_bft', 'bit5', 'bit6', 'bit7')), 'timezone': (24, 'sb', None), 'unknown_01': (25, 'pb', None), 'unknown_18': (97, 'pb', None)}
data_start = 256
reading_len = {'1080': 16, '3080': 20}

Comments or questions? Please subscribe to the pywws mailing list http://groups.google.com/group/pywws and let us know.