Author Topic: Tutorial: Davis Station with Weewx, Ubuntu, MySQL and SLOWeather Serial Cable  (Read 37624 times)

0 Members and 1 Guest are viewing this topic.

Offline tonyperk

  • Member
  • *
  • Posts: 1
    • Blue Sky Bust
Hello everyone!  I've been using the information here at wxforum.net to get my own setup going, and I have the pleasure of making my first post.  I've created what I hope to be a bare bones, step by step tutorial on getting a Davis Vantage Vue running with:

WeeWX
A non-logging serial cable
Ubuntu Linux
MySQL

Hopefully this can help some other folks out along the way to getting their station on the internet on the cheap.

Here is what will be the most up to date tutorial link:
http://www.blueskybust.com/homewx.html

Here are the copied contents of the tutorial... sorry for the lack of formatting:

Getting your weather station online using a Davis Vantage Vue, a SLOweather serial cable (found here at wxforum), and WeeWX on Ubuntu Linux.
Updated 11/2012

I wanted to get a Davis Vantage Vue on the Internet. Since I already have an Ubuntu Linux PC running 24 hours a day, this is where I chose to send the data from the station. The Davis product to interface with a PC, called WeatherLink, only contains software for Macs or Windows. Essentially, you spend $100+ for a serial cable and software you throw away.

Fortunately, community grown solutions exist to do this for much cheaper. Through Google I found a homebew serial cable to interface between the Davis console and the Ubuntu PC. This cable can be found by googling for SLOweather and Davis serial cable. I got my for around $30. There are two kinds for purchase, a serial cable, and a USB interface. I have read that the serial interface is rock solid compared to the USB interface, and since my PC has a serial port, I went with that.

Steps to set up
Prerequisite steps:

    Your Davis Vantage weather station is operational and the console is displaying the weather data
    You have an Ubuntu Linux PC
    You have MySQL installed and running on Ubuntu


Disclaimer: I found that some things needed to be run as sudo to work on Ubuntu, or that certains files couldn't be edited because I wasn't logged in as 'weewx'. My quick fixes are to change the permissions of those files to 777, and to run a lot of stuff as sudo. It works to get things going. I know it's not the secure way to do things.

Install the serial cable:

    Turn off the console and remove the batteries so the power is completely off to it. I don't know if this is required, but I did it.
    Hook the other end up to the Ubuntu PC with a serial port.
    Turn the console back on. Press 'Done' on it to get out of setup mode.

Test the connection to Ubuntu
Install the program minicom on Ubuntu:
sudo apt-get install minicom

Find your serial port identified in the device list with this command:
dmesg | grep ttyS

For me, this returned the information of:
[ 0.510838] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[ 0.532564] 00:08: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A

The serial port device to use based on this is ttyS0.

Setup minicom for the test
sudo minicom -s

Go to the menu option Serial port setup.
Change setting of "Serial Device" to be what was in the previous step, with /dev/ prepended.
Example: /dev/ttyS0

Change setting of "Bps/Par/Bits" to:
Speed: 19200
Parity: None
Stopbits: 8-N-1

When done, save the config on the first menu with Save setup as dfl.

Test with minicom
Start minicom with:
sudo minicom

When it starts, type TEST in all capitals. You wont be seeing what you are typing. If the word TEST is replied back, then it works.
Next, type LOOP in all caps. You should see gibberish characters come across. This is the weather data being sent. Exit the command with Ctrl-C.

You have now verified that the console is sending data to the Ubuntu PC.

Install WeeWx
WeeWx can decode the data and generate useful graphs and HTML pages with it. It also stores the data in a MySQL database, and can post the data to internet sites.

I downloaded the latest version using wget, which was weewx-2.0.2.tar.gz:
wget http://sourceforge.net/projects/weewx/files/weewx-2.0.2.tar.gz/download

Open the quick guide setup steps here. It's titled for Debian but works on Ubuntu:

http://www.weewx.com/docs/debian.htm

Follow the Prerequisite install steps as is.
Follow the Installing section as is.
For the "Configure" section: Edit the configuration file (I use vi, use what you like):

sudo chmod 777 /home/weewx/weewx.conf
vi /home/weewx/weewx.conf

Here are the changes I made to work with the SLOWeather serial cable and mysql:
Enable debugging. You may need it, so it doesn't hurt. You can turn it back to 0 after everything is working.
debug = 1

In the [Station] section:
location = (enter any text you want to describe your location)
latitude = (your stations latitude)
longitude = (your stations longitude)
altitude = (your stations altitude, foot) ( Example: altitude=654,foot )
station_type = Vantage (I think this was the default, but it's important to verify)

In the [Vantage] section:
port = (Use the /dev/ttyS0 entry you found when testing with mini com)
Ex: port = /dev/ttyS0

In the [StdReport] section:
HTML_ROOT = public_html
(Since I run a web server on the same Ubuntu box, I changed this from public_html to a path like /var/www/myserver/myweather. You can just keep it at public_html for initial testing and change it later if it needs to go to another directory.)

In the [StdArchive] section:
Change the entries so it uses mysql:

archive_database = archive_mysql
stats_database = stats_mysql
record_generation = software

I needed to change record_generation to software in order for it to work with the SLOweather serial cable. I think it's because the cable doesn't store records itself.

Nothing else needs to change in the config file. I used the default username and password listed in the [[archive_mysql]] and [[stats_mysql]] sections of weewx / weewx.

Create the public_html directory
This didn't exist on my installation, so create it:

sudo mkdir /home/weewx/public_html
sudo chmod 777 /home/weewx/public_html

Create the MySQL database user of weewx
Start the mysql client:

mysql -u root -p
(Enter your root password for mysql. Can't help you here)

CREATE USER 'weewx'@'localhost' IDENTIFIED BY 'weewx.;
GRANT select, update, create, insert, delete on weewx.* to weewx@localhost;
GRANT select, update, create, insert, delete on stats.* to weewx@localhost;
quit
Start up weewx
sudo /home/weewx/bin/weewxd.py /home/weewx/weewx.conf

If things are working, you'll see data being printed to your window.
If nothing shows after 15 seconds or so, exit using Ctrl-C and then check the weewx debug output in the syslog:
grep weewx /var/log/syslog | more

If it's working ok too, do Ctrl-C to stop weewx.

Verify that mysql is logging data
Run this command again, but as the weewx user instead of root:

mysql -u weewx -p
(Enter password of weewx, which you probably created above as 'weewx')
use stats;
select * from outTemp;

You should see a record or two in the tables here, like this:
+------------+------+------------+------+------------+------------------+-------+
| dateTime | min | mintime | max | maxtime | sum | count |
+------------+------+------------+------+------------+------------------+-------+
| 1353736800 | 27.2 | 1353819100 | 28.8 | 1353822986 | 986.258918640156 | 35 |
| 1353823200 | 27.5 | 1353862112 | 30.6 | 1353830478 | 4726.0591897815 | 164 |
+------------+------+------------+------+------------+------------------+-------+

2 rows in set (0.00 sec)

If you don't see aything, then something isn't set up right with the mysql logging. Type quit and check the weewx syslog with:
grep weewx /var/log/syslog | more

If you saw a record, chances are the archive database is working too. From still in mysql:

use weewx;
select * from archive;

You should see one or more records listed. If you don.t, it may just be that weewx wasn.t running for 5 minutes before we stopped the initial test. If weewx is running later for 15+ minutes and you still see nothing in here, check the weewx debug syslog:
grep weewx /var/log/syslog | more

type quit to exit mysql

You should also be seeing files generated in the public_html directory. Open a few of the .html files with your web browser to check.

Add weewx as a service that starts up automatically
Now that it.s all working, let.s set it up so weewx starts on system startup, and that it uses the familiar init.d start and stop functions.

sudo cp /home/weewx/start_scripts/Debian/weewx /etc/init.d/
sudo chmod +x /etc/init.d/weewx
sudo update-rc.d weewx defaults 98

Now you can start and stop weewx with:

sudo /etc/init.d/weewx start
sudo /etc/init.d/weewx stop
sudo /etc/init.d/weewx restart

Remember to turn off debugging with debug=0 in the weewx.conf file if you want, and then restart weewx.

That's it. Questions, comments, or improvements, send me an email at the permanent link at the top.

« Last Edit: November 29, 2012, 10:33:50 PM by tonyperk »

Offline Bushman

  • Forecaster
  • *****
  • Posts: 7549
    • Eagle Bay Weather
Nice work!! 
Need low cost IP monitoring?  http://wirelesstag.net/wta.aspx?link=NisJxz6FhUa4V67/cwCRWA or PM me for 50% off Wirelesstags!!

Offline pvw

  • Member
  • *
  • Posts: 46
    • http://www.palominovalleyweather.com
Having just gone through this last week, I can say it really is just that easy! (Except I used a davis logger).

Great job!
Better living and lower productivity through the use of technology.

Offline Jeff

  • Senior Member
  • **
  • Posts: 92
    • MansfieldWeather
Welcome to the forum Tony!

Nice tutorial and great work, thanks for posting this for others to follow!

Have fun here on the forum!

J

Offline HandyGeek

  • KD4E
  • Senior Member
  • **
  • Posts: 58
My experience, is - of course - atypical.  Sigh.

I had to replace this step ...

Quote
mysql -u root -p
(Enter your root password for mysql. Can't help you here)

With ...

Code: [Select]
cd /opt/lampp/bin && ./mysql -u root -p
Then I entered the following ...

Quote
CREATE USER 'weewx'@'localhost' IDENTIFIED BY 'weewx.;
GRANT select, update, create, insert, delete on weewx.* to weewx@localhost;
GRANT select, update, create, insert, delete on stats.* to weewx@localhost;
quit

But MySQL refused to recognize "quit" or "quit;" or "QUIT".

I had to Ctrl-C to break out but that resulted in an "Aborted" message, which
I take to mean that the CREATE USER & GRANT lines were lost.

Why would MySQL refuse the "quit" command and how might I solve that, please?

Thanks!

Offline DeKay

  • Forecaster
  • *****
  • Posts: 399
    • Mad Scientist Labs
But MySQL refused to recognize "quit" or "quit;" or "QUIT".

I had to Ctrl-C to break out but that resulted in an "Aborted" message, which
I take to mean that the CREATE USER & GRANT lines were lost.

Why would MySQL refuse the "quit" command and how might I solve that, please?

Thanks!

I'm no SQL guru but

CREATE USER 'weewx'@'localhost' IDENTIFIED BY 'weewx.;

is almost certainly wrong.  The period just before the semicolon should be an apostrophe instead to match the opening apostrophe before weewx.  Likely a cut and paste error in the original post.

Plain out "quit" should have worked.  Don't add  semicolons as those are for MySQL commands only and not internal commands.  I think the error in that one line screwed up the stuff that followed.  I'd run the MySQL commands over again, fixing that typo.

Offline HandyGeek

  • KD4E
  • Senior Member
  • **
  • Posts: 58
That was it, thanks!

Curiously someone elsewhere shared the story of a 2 week hunt for a bug in FORTRAN that turned out to be one "." at the beginning of a line.

Offline vpweather

  • Member
  • *
  • Posts: 8
Great write-up. I'd like to get Weewx up and running on a Linux-box failing that a RaspberryPi. My Linux-skills are not great (practically non-existent) however I'd like to give the installation a try (following the tutorial as closely as possible that is). Currently running Cumulus-Weather software and think that in all fairness this is great compared to Weather-Link. Does Weewx allow for posts onto Twitter though? - At a guess it does. Thank you in advance for any help/suggestions. Excellent forum.
@VPWeather

Offline Bushman

  • Forecaster
  • *****
  • Posts: 7549
    • Eagle Bay Weather
Run your fave flavour of Linux in a virtual box like VBox.  I run Ubuntu on my Win 7 system that way.  No need for separate hardware.
Need low cost IP monitoring?  http://wirelesstag.net/wta.aspx?link=NisJxz6FhUa4V67/cwCRWA or PM me for 50% off Wirelesstags!!

Offline vpweather

  • Member
  • *
  • Posts: 8
Run your fave flavour of Linux in a virtual box like VBox.  I run Ubuntu on my Win 7 system that way.  No need for separate hardware.

Hi Bushman,
Thank you for your reply. That sounds like a good idea. Am running Cumulus-Weather on a Virtual Machine on a Mac Mini therefore running a Linux distro shouldn't be a problem.
Think that I'd prefer to opt for Ubuntu as you have done too.
Best Regards.
@VPWeather

Offline froggy2684

  • Member
  • *
  • Posts: 5
Is the cable still available?

Offline ChuckM

  • Member
  • *
  • Posts: 1
Thanks for the very detailed instructions. They work eight years later in 2020. I'm using a Vantage Vue weather station feeding data to a Raspberry Pi 4 via a Davis WeatherLink USB Data Logger (#6510USB). The diagnostics with minicom was a big help. These days, there's another utility called cutecom, which has a nice GUI.

I've played with MySQL and MariaDB before just because databases are neat. In the case of weewx running on a dedicated machine, I followed the kiss rule and left weewx using sqlite.

The Raspberry Pi 4 is running Apache2 server so I can access the web-based reports from other machines. Weewx conveniently generates the reports in /var/www/html/weewx, so I just have to navigate to <the local ip>/weewx.