pyobs_weather.weather.stations.MySQL

class MySQL(connect, table, fields, time: str = 'time', time_offset: int = 0, *args, **kwargs)[source]

The MySQL weather station reads current weather information from a MySQL database.

Creates a new Database station.

A typical JSON configuration for this weather station might look like this:

{
“connect”: {
“host”: “database.com”,
“user”: “weather”,
“password”: “weather”,
“db”: “weather”
},
“table”: “weather_table”,
“time”: “sensor_datetime”,
“time_offset”: -7200,
“fields”: {
“temp”: {“code”: “temp”, “name”: “Temperature”, “unit”: “°C”},
“rel_hum”: {“code”: “humid”, “name”: “Relative humidity”, “unit”: “%”},
“temp_dew”: {“code”: “dewpoint”, “name”: “Dew point”, “unit”: “°C”},
“windsp”: {“code”: “windspeed”, “name”: “Wind speed”, “unit”: “km/h”},
“winddir”: {“code”: “winddir”, “name”: “Wind direction”, “unit”: “°E of N”},
“pressure”: {“code”: “press”, “name”: “Pressure”, “unit”: “hPa”}
}
}
Parameters
  • connect – Dictionary with fields required by MySQLd.connect

  • table – Database table.

  • time – Name of column containing time.

  • fields

    Dictionary with field->SensorType data,

    e.g. {column: {code=”temp”, name=”Temperature”, unit=”C”}}

    column: table column code: field code name: field name unit: field unit bool_true: if given, evaluate value to 1 if equal to this, otherwise 0 bool_false: if given, evaluate value to 0 if equal to this, otherwise 1

  • time_offset – Offset in seconds to add to current time to get UTC.

create_sensors()[source]

Entry point for creating sensors for this station.

New sensors are created based on the configuration.

update()[source]

Entry point for updating sensor values for this station.

This method connects to the database and reads the latest values.