This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I see wind speed (& direction) with digital (& analogic)wind sensor in OP&SK?
#3
Thanks for your reply.
The sensors actually work, or rather, the anemometer currently works. I have a program in pyton that, as a function of impulses in time, calculates the distance traveled, so I have speed. The step I miss is how to extract data from the program in python (better traduceing it in NMEA0183 sentence?) and send it via UDP (or better TCP?) so that it is displayed in the dashboard.
I know, I'm so noob, but stubborn .. I will try

Anyway this is "my" code, how could I send calc_speed ?


Code:
from gpiozero import Button
from time import sleep
import math

count = 0       # Counts how many half-rotations
radius_cm = 7.0 # Radius of your anemometer
interval = 3    # How often (secs) to report speed
ADJUSTMENT = 1.18
CM_IN_A_ML = 185200.0
SECS_IN_AN_HOUR = 3600
store_speeds = [] # Define a list to store last 4 wind speeds

# Every half-rotation, add 1 to count
def spin():
   global count
   count = count + 1
   print( count )

# Calculate the wind speed given the time interval
def calc_speed(time_sec):
       global count
       global store_speeds
       circumference_cm = (2 * math.pi) * radius_cm        
       rotations = count / 2.0

       # Calculate distance travelled by a cup in km
       dist_km = (circumference_cm * rotations) / CM_IN_A_ML

       # 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

       # Add this speed to the list
       store_speeds.append(final_speed)

       # If that takes the list over 4 items, chop off the first
       if len(store_speeds) > 4:
               store_speeds = store_speeds[1:]
     
       # Show what is in the store_speeds list
       print( str(store_speeds) )
       
       return final_speed

# Check whether the last 20 seconds of readings had any gusts
def check_for_gusts():
       highest = max(store_speeds)
       lowest = min(store_speeds)
       GUST_ABOVE = 1      
       GUST_RANGE = 2
       if highest > GUST_ABOVE and highest - lowest > GUST_RANGE:
           return highest
       else:
           return 0      

wind_speed_sensor = Button(5)
wind_speed_sensor.when_activated = spin


# Loop to measure wind speed and report at 5-second intervals
while True:
       count = 0
       sleep(interval)
       print( calc_speed(interval), "kph")
       print("Gust speed " + str(check_for_gusts()) + "kph")
Reply


Messages In This Thread
RE: How can I see wind speed (& direction) with digital (& analogic)wind sensor in OP&SK? - by pol.bob - 2019-10-15, 05:09 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)