Using An Anemometer With Raspberry Pi - Odt

You might also like

Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 2

Using an anemometer with Raspberry Pi

The GPIO Connection is super simple, anemometer has 2 cables, one would
connect to ground and the other to Pin 3 (the GPIO02), no matter what cable
where. We base ourselves we have a Raspberry Pi with Raspbian installed
and enabled GPIO (sudo Raspi-config…).
Now everyone who is interested modify it as you, If you want to spend
the meters per second to kilometers per hour and put the result in a
MySQL database, add the line around 60 Something like:

1 ...
viento_kmph = actual_windspeed_msec * 3.6 # Convertir metros por segundo a
2
kilometros hora

3 print viento_kmph
4 if vuelta == 30: # Así cada 30 segundos lo mete en BD

5 vuelta = 0
db =
6
MySQLdb.connect("DIRECCION_IP_MYSQL","USUARIO","CONTRASEÑA","BASE_DATOS")

7 cursor = db.cursor()
cursor.execute("""INSERT INTO viento (velocidad) VALUES (%s) """,
8
( viento_kmph))

9 db.commit()
10 else:

11 vuelta = vuelta + 1
12 ...

Not forgetting to add at the beginning 'import MySQLdb’ to load


modules Python MySQL (sudo apt-get install python-mysqldb if you do
not have them installed). And every 30 bring us seconds on the wind
speed chart our MySQL DB, is a table goofy 2 fields, one speed and
another date is automatically completed, if you need this would be the
code to create the table in this same example:

1 CREATE TABLE `viento` (


2 `velocidad` FLOAT NOT NULL,

`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE


3
CURRENT_TIMESTAMP
4)

5 COLLATE='latin1_swedish_ci'
6 ENGINE=InnoDB

7 ROW_FORMAT=COMPACT
8;

The en Grafana, a Dashboard, if we create a Panel Type Graph, Data


Source select as our connection to our MySQL database and add a
simple Query to paint us the wind, then either we tuneamos the graph
as more or less like it, if the guides, The Query of this graph:

SELECT velocidad as value, "Velocidad" as metric, UNIX_TIMESTAMP(created_at)


1 as time_sec FROM viento WHERE $__timeFilter(created_at) order by time_sec
asc

Good, I hope you like it, gradually we will be getting more sensors to
our Raspberry Pi to mount a weather station or what pleases us, go!

You might also like