Page 1 of 1

Raspberry e Openweathermap

Posted: Sun 05 Jun 2016 6:01 pm
by nicmarco
Hello everyone, I just installed cumulusMx on a raspberry Pi3 , and I would like to send the station on openweathermap , someone can help me ? Thank you

Re: Raspberry e Openweathermap

Posted: Sun 05 Jun 2016 8:26 pm
by water01
Sorry but I don't think Cumulus MX has an interface to OpenWeatherMap.

Re: Raspberry e Openweathermap

Posted: Sun 05 Jun 2016 10:00 pm
by philpugh
You can do it reasonably simply using a bit of Python code. I attach a modified version of the one I use - which pulls data from the MySQL databases I use. You could use other methods to generate the required info though. Something along the lines of the realtimegaugesMXT.txt for instance. Sorry about the code insert - couldn't get the file upload to work for some reason

Code: Select all

#!/usr/bin/python
import MySQLdb
import subprocess
# To read databases and submit info to OpenWeatherMap
# Should be run via crontab every 15 mins (suggested)
# some constants

mphtms = 0.447 		# convert mph to m/s

db1 = MySQLdb.connect(host="localhost", user="xxx", passwd="yyy", db="ws3083")
db2 = MySQLdb.connect(host="localhost", user="mmm", passwd="nnn", db="weather")

# create Cursor objects. 
cur1 = db1.cursor()
cur2 = db2.cursor()

# Use all the SQL you like
cur1.execute("SELECT Windspeed, Windbearing, UVindex, SolarRad FROM Monthly ORDER BY LogDateTime DESC LIMIT 1")
cur2.execute("SELECT LogDateTime, Temp, Humidity, TodayRainSoFar, Pressure FROM Monthly ORDER BY LogDateTime DESC LIMIT 1")

# process result - should only be one record - the last record entered
for row in cur1.fetchall():
    ws = row
for row in cur2.fetchall():
    dv = row
db1.close()
db2.close()

# now generate the command to send

endstr = " --user 'user:password' -H 'x-api-key:apikey'  http://openweathermap.org/data/post"
posstr = "&lat=nn.nn&long=-nn.nn&alt=mmm&name=MyStation" + "'"
val1 = "'"+"temp="+str(dv[1])+"&wind_speed="+str("%1.1f"%(float(ws[0])*mphtms))+"&wind_dir="+str(ws[1])+"&pressure="+str(dv[4])
val2 = "&rain_today="+str(dv[3])+"&uv="+str(ws[2])+"&radiation="+str(ws[3])
cmd = "curl -d "+val1+val2+posstr+endstr
#print cmd
subprocess.call(cmd, shell=True)
NB endstr should contain your openweathermap access info (username, password, API key)
posstr contains lat, long and name of your weather station

Re: Raspberry e Openweathermap

Posted: Mon 06 Jun 2016 9:15 am
by philpugh
Sorry - edited code above as I had left in a debug comment in front of the first database close.

The commented out "print cmd" is there for testing - you can see the string you are going to send.

Re: Raspberry e Openweathermap

Posted: Mon 06 Jun 2016 9:21 pm
by mcrossley
Could you use the custom http options in MX?

Re: Raspberry e Openweathermap

Posted: Tue 07 Jun 2016 9:15 am
by philpugh
Can't see why not Mark - I should have investigated this first.

Having said that the OpenWeatherMap.com site is pretty much useless and I guess they 'sell' the information we provide to app developers that want cheap access to weather information - e.g. smart watch developers. I was having difficulty recovering the data I was sending and the tech support provided a link that returned JSON style info - it was my data but I was thrown by the temp value until it dawned on me they seem to display the value in degrees Kelvin - useful for certain weather calculations I guess, but not a common thing to display.