Importing weewx readings into a Python script

145 views
Skip to first unread message

Jan Hoogendoorn

unread,
Sep 21, 2024, 3:50:09 PM9/21/24
to weewx-user
I have successfully weewx running with a Davis Ventage Pro2 on a Raspberry Pi 3. I want to the weewx readings in a Python script. I scrolled through the documentation, however, it is not clear to me how to get de weather station readings imported in my own Python program. As far as I could find relevant information in the documentation, it is not clear to me how to use it. Is is possible to give some examples of how to get weewx readings from a weather station imported into a Python program?

Kind regards,
Jan.

p q

unread,
Sep 21, 2024, 4:03:17 PM9/21/24
to weewx...@googlegroups.com
I think the easiest way is to have your python program read the database.

import sqlite3
from sqlite3 import Error
import datetime
import time
import json

Connected = False

database = r"C:\users\peter\weewx.sdb"

try:
    conn = sqlite3.connect(database)
except Error as e:
    pass

querystring = "SELECT dateTime, barometer,inTemp,extraTemp2,outTemp,pm2_5,pm10_0 from archive where dateTime>?"
lasttime = 1644172560

while True:
    cur = conn.cursor()
    column_name=[col[0] for col in cur]
    cur.execute(querystring,(str(lasttime),))
    try:
       row = [ dict(line) for line in [zip([ column[0] for column in cur.description], row) for row in cur.fetchall()] ]
       print ("------")
       <<do something here>>
       lasttime = (row[len(row)-1]["dateTime"])
       print (lasttime)
    except:
       print ("error")
    time.sleep(10
)


--
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/e97592df-38f5-401c-9318-142eff4ce674n%40googlegroups.com.


--
Peter Quinn
(415)794-2264

vince

unread,
Sep 21, 2024, 5:42:15 PM9/21/24
to weewx-user
Create a cheetah .tmpl template and write an intermediate file in whatever format you want. with whatever data you want. Really depends on which data you want to process.

Jan Hoogendoorn

unread,
Sep 22, 2024, 8:24:19 AM9/22/24
to weewx-user
Thanks for your response vince, I will try this later. First I will follow the method of Peter Quin.

Jan Hoogendoorn

unread,
Sep 22, 2024, 8:32:13 AM9/22/24
to weewx-user
Ok, that works Peter, thanks. However, there is a difference in what I see when running weewxd and what I get from the database, see attached file. Is the a way to match the data in REC and the database?
Comparison readings and output.txt

Jan Hoogendoorn

unread,
Sep 22, 2024, 11:30:35 AM9/22/24
to weewx-user
I have now found out that adjusting the archive table is done with data binding. That is going well, but there are still some questions left. I will come back to it later, I am running out of time now.

vince

unread,
Sep 22, 2024, 2:01:54 PM9/22/24
to weewx-user
What readings exactly are you trying to read into your python program ?   LOOP packets ?  archive REC events ?   Something else ?

Jan Hoogendoorn

unread,
Sep 22, 2024, 2:48:58 PM9/22/24
to weewx-user
Well, until now I am only able to import REC events, but I would also like to import LOOP packets.

vince

unread,
Sep 22, 2024, 2:53:21 PM9/22/24
to weewx-user
Reply all
Reply to author
Forward
0 new messages