Case example Python code (Picture 6) how to use Edge computing and calculate wind speed, direction and wind gusts. All of these operations are performed in real time on the Edge node. Edge node sends only parameter N (North), NNE (North-northeast) etc. to the datastore (InfluxDB) and by using Grafana dashboard we can see the result on wind direction (Picture 7).
A wind vane works because wind exerts force on its vertical blade, which rotates to find the position of least wind resistance; this position is aligned with the direction of the oncoming wind. Like the rain gauge or anemometer, the wind vane used in the project also has reed switches and a rotating magnet, but it is more complex and works in a completely different way. The wind direction is measured using 8 different reed switches. There are also eight resistors in the wind vane, and as the magnet rotates, different reed switches will open and close and thus switch their corresponding resistor in and out of the circuit.
The wind speed is measured using an anemometer. A typical anemometer has three arms with scoops on the end that catch the wind and cause the arms to spin. This will cause the reed switch located on the bottom to trigger. We used the number of signals from the reed switch to calculate how fast the anemometer spins.
A wind gust is a brief increase in wind speed that can occur whenever the wind is blowing. A typical wind gust lasts less than 20 seconds. We implemented this by constantly taking wind speed measurements for five seconds, and temporarily storing them to be processed every few minutes.
#Function which return ohms-value
def calculate_vout(self, ra, rb, vin): # Ohm's law resistive divider calculation
return (float(rb) / float(ra + rb)) * float(vin)
# Function which return angle-value
def get_dir(self, adc_value):
angle = None
for dir in self.config["directions"]:
if (adc_value > 0 and \
adc_value >= dir["adcmin"] and \
adc_value <= dir["adcmax"] and \
adc_value < self.adc.max):
angle = dir["angle"]
break
return angle
#json-file where are set direction to dir parameter based on what the ohms and angle values are
{
"vin": 3.268,
"vdivider": 75000,
"directions": [
{ "dir": "N", "angle": 0.0, "ohms": 33000 },
{ "dir": "NNE", "angle": 22.5, "ohms": 6570 },
{ "dir": "NE", "angle": 45.0, "ohms": 8200 },
{ "dir": "ENE", "angle": 67.5, "ohms": 891 },
{ "dir": "E", "angle": 90.0, "ohms": 1000 },
{ "dir": "ESE", "angle": 112.5, "ohms": 688 },
{ "dir": "SE", "angle": 135.0, "ohms": 2200 },
{ "dir": "SSE", "angle": 157.5, "ohms": 1410 },
{ "dir": "S", "angle": 180.0, "ohms": 3900 },
{ "dir": "SSW", "angle": 202.5, "ohms": 3140 },
{ "dir": "SW", "angle": 225.0, "ohms": 16000 },
{ "dir": "WSW", "angle": 247.5, "ohms": 14120 },
{ "dir": "W", "angle": 270.0, "ohms": 120000 },
{ "dir": "WNW", "angle": 292.5, "ohms": 42120 },
{ "dir": "NW", "angle": 315.0, "ohms": 64900 },
{ "dir": "NNW", "angle": 337.5, "ohms": 21880 }
]
}
Picture 6. Example code how to use Edge computing near by sensor.
Picture 7. Wind direction Grafana dashboard.