Get values from a database on another machine?

136 views
Skip to first unread message

Mikael Fredriksson

unread,
Sep 19, 2019, 4:20:29 PM9/19/19
to weewx-user
Hi!

I've added a tempsensor to another Raspberry that I will place in my "underground storehouse" to keep track of the temperature there.
I got a script to work and add timestamp and tempvalue to a sqlite db.
Now I want to import these values to weewx and post to my weather web page.
The Raspberry in the storehouse is on the same local network.
Is there some way to make this work?


Thanks
Micael

Greg Troxel

unread,
Sep 19, 2019, 7:56:19 PM9/19/19
to Mikael Fredriksson, weewx-user
There are many; it depends on how much code you want to write and how
you want to approach it.

I would say the easy way is to set up an MQTT broker. I'd suggest on
the weewx machine. Then on the "underground storehouse" RPI, use the
mosquitto publish program, or write a few lines of python with the paho
library. On weewx, use:
https://github.com/bellrichm/WeeWX-MQTTSubscribe

Note that I have been sending weewx data via MQTT to home assistant, but
not the other way around. However, many have written about
MQTTSubscribe on the list, and it seems clear that it works.

With this approach, you could use an esp8266 instead of an RPI. I'm
using this for temp/humidity ina few places, but I'm not currently
ingesting the data into weewx.


The problem with the above approach is that it fails to record data when
the network is broken. That might be ok with you, and it might not.
You are currently storing data on the RPI, which means you have data
when the RPI has power. So, you could do something which runs on the
weewx machine, connects to both the weewx and the remote database (wave
hands), and then populate the weewx database with the remote records.
Perhaps first extend the schema or declare e.g. extraTemp3 to be what
matters, and then set that column from the remote database when it's
NULL. This way you'll get the records in arrears after a network
outage, sort of like how the Davis driver grabs archive records not yet
in the database.

I don't know of any existing code for this kind of syncing. It's
obviously possible to write, and obviously not trivial to debug.
Probably enough to convince you that just getting live data over MQTT is
good enough :-)


The first thing I'd suggest is to synchronize the data gathering with
the archive period on your weewx setup. I'm using Davis and 5 minutes,
which has a 15 second post-sample guard time and I'd sample right on
time, so the record is in sync and will be in the archive record. I'd
recommend this for either MQTT or filling in archive records.

Greg


p q

unread,
Sep 19, 2019, 8:34:35 PM9/19/19
to weewx...@googlegroups.com, Mikael Fredriksson

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/rmiy2yjalib.fsf%40s1.lexort.com.


--
Peter Quinn
(415)794-2264

Thomas Keffer

unread,
Sep 19, 2019, 8:35:28 PM9/19/19
to weewx-user
See the section Using multiple database bindings in the Customizing Guide.

-tk

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.

Mikael Fredriksson

unread,
Sep 24, 2019, 11:16:58 AM9/24/19
to weewx-user
Hi!

Thanks for your answers.

I will try to get tk's option to work first.

But there are some questions!
I need to get the database to be setup as intended first before I try to get the settings in weewx right.

Must the new database have datetime, unUnits and interval fields? I started with fields timestamp and temp and those worked but they was not in epoch. Now I got it to log in epoch time format ( after changing datetime('now', 'localtime' to strftime('%s','now', 'localtime'); but when I create a new database with those three fields (datetime, unUnits,interval and temp) it doesn't log anything. I will attach the script I'm using (monitor.py). I've got the datebase to populate when only using fields datetime and temp.
How schould I setup the database to work with weewx?
I did setup the database like this:

Table: temps

Fields:
datetime INTEGER unique not null primary
unUnits INTEGER not null
interval INTERGER not null
temp NUMRIC

And it don't write to it.

Only when I setup like this:

Table : temps

Fields:
datetime INTERGER unique not null primary
temp NUMRIC


Here I found the monitor.py script I use.
I've also added "import datetime"


Haven't worked with database before so there's much trail and error!

Thanks /Mikael

Mikael Fredriksson

unread,
Sep 24, 2019, 11:18:58 AM9/24/19
to weewx-user

Thomas Keffer

unread,
Sep 24, 2019, 8:52:37 PM9/24/19
to weewx-user
Must the new database have datetime, unUnits and interval fields?

Yes.

The answers to most of your other questions are in the section The database, in the Customizing Guide. Take a look there.

Perhaps someone will look at your monitor.py, but that's well outside the scope of WeeWX.

-tk
Reply all
Reply to author
Forward
0 new messages