ok I give you the scripts
in attach file
The main script is weather_station_BYO_10.py
thank you
patrick
On Saturday, December 8, 2018 at 3:40:43 PM UTC+1, Patrick Tranchant wrote:
>
> hello I am a newbie from France ( sorry for my english )
>
> I want to use weewx on a raspberry with a weather station built by myself
> (view on Magpi)
> I don't see my station on your website to configure :
>
> Weather Station Hardware Comparison: I don't found my weather station.
> Do you have a solution or how to configure Weewx
>
> thank you for your help
>
> Patrick
>
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
import math
from gpiozero import MCP3008
import time
adc = MCP3008(channel=0)
count = 0
values = []
volts = {0.4: 0.0,
1.4: 22.5,
1.2: 45.0,
2.8: 67.5,
2.7: 90.0,
2.9: 112.5,
2.2: 135.0,
2.5: 157.5,
1.8: 180.0,
2.0: 202.5,
0.7: 225.0,
0.8: 247.5,
0.1: 270.0,
0.3: 292.5,
0.2: 315.0,
0.6: 337.5}
def get_average(angles):
sin_sum = 0.0
cos_sum = 0.0
for angle in angles:
r = math.radians(angle)
sin_sum += math.sin(r)
cos_sum += math.cos(r)
flen = float(len(angles))
s = sin_sum / flen
c = cos_sum / flen
arc = math.degrees(math.atan(s / c))
average = 0.0
if s > 0 and c > 0:
average = arc
elif c < 0:
average = arc + 180
elif s < 0 and c > 0:
average = arc + 360
return 0.0 if average == 360 else average
def get_value(length=5):
data = []
print("Measuring wind direction for %d seconds..." % length)
start_time = time.time()
while time.time() - start_time <= length:
wind =round(adc.value*3.3,1)
if not wind in volts: # keep only good measurements
print('unknown value ' + str(wind))
else:
data.append(volts[wind])
return get_average(data)
#while True:
# wind =round(adc.value*3.3,1)
# if not wind in volts:
# print('unknown value' + str(wind) + ' ' + str(volts[wind]))
# else:
# print('found ' + str(wind) + ' ' + str(volts[wind]))
import bme280
import smbus2
from time import sleep
port = 1
address = 0x76
bus = smbus2.SMBus(port)
bme280.load_calibration_params(bus,address)
def read_all():
bme280_data = bme280.sample(bus,address)
return bme280_data.humidity, bme280_data.pressure, bme280_data.temperature
from gpiozero import Button
import time
import math
import bme280_sensor_2
import wind_direction_byo_5
import statistics
import ds18b20_therm
import datetime
import database
wind_count = 0 # Counts how many half-rotations
radius_cm = 9.0 # Radius of your anemometer
wind_interval = 5 # Hox often (secs) to sample speed
interval = 300 # measurements recorded every 5 minutes
CM_IN_A_KM = 100000.0
SECS_IN_AN_HOUR = 3600
ADJUSTMENT = 1.18
BUCKET_SIZE = 0.2794
rain_count = 0
gust = 0
store_speeds = []
store_directions = []
# Every half-rotations, add 1 to count
def spin():
global wind_count
wind_count = wind_count + 1
#print("spin" + str(wind_count))
def calculate_speed(time_sec):
global wind_count
global gust
circumference_cm = (2 * math.pi) * radius_cm
rotations = wind_count / 2.0
# Calculate distance travelled by a cup in km
dist_km = (circumference_cm * rotations) / CM_IN_A_KM
# Speed = distance / time
km_per_sec = dist_km / time_sec
km_per_hour = km_per_sec * SECS_IN_AN_HOUR
# Calculate Speed
final_speed = km_per_hour * ADJUSTMENT
return final_speed
def bucket_tipped():
global rain_count
rain_count = rain_count + 1
#print (rain_count * BUCKET_SIZE)
def reset_rainfall():
global rain_count
rain_count = 0
def reset_wind():
global wind_count
wind_count = 0
def reset_gust():
global gust
gust = 0
wind_speed_sensor = Button(5)
wind_speed_sensor.when_pressed = spin
temp_probe = ds18b20_therm.DS18B20()
rain_sensor = Button(6)
rain_sensor.when_pressed = bucket_tipped
db = database.weather_database()
while True:
start_time = time.time()
while time.time() - start_time <= interval:
wind_start_time = time.time()
reset_wind()
while time.time() - wind_start_time <= wind_interval:
store_directions.append(wind_direction_byo_5.get_value())
final_speed = calculate_speed(wind_interval)# Add this speed to the list
store_speeds.append(final_speed)
wind_average = wind_direction_byo_5.get_average(store_directions)
wind_gust = max(store_speeds)
wind_speed = statistics.mean(store_speeds)
rainfall = rain_count * BUCKET_SIZE
reset_rainfall()
store_speeds = []
store_directions = []
ground_temp = temp_probe.read_temp()
# ground_temp =45
humidity, pressure, ambient_temp = bme280_sensor_2.read_all()
# db.insert(ambient_temp, ground_temp, 0, pressure, humidity, wind_average, wind_speed, wind_gust, rainfall)
db.insert(ambient_temp, ground_temp, 0, pressure, humidity, wind_average, wind_speed, wind_gust, rainfall, datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
print()
print('Wind direction: ' + str(wind_average) +' /', 'Wind speed: ' + str(wind_speed) +' /', 'Wind gust: ' + str(wind_gust) +' /', 'Rainfall: ' + str(rainfall) +' /', 'Humidity: ' + str(humidity) +' /', 'Pressure: ' + str(pressure) +' /', 'Ambient Temperature: ' + str(ambient_temp) +' /', 'Ground Temperature: ' +str(ground_temp) +';')
print()