get data from external database

66 views
Skip to first unread message

matteo pirazzi

unread,
Apr 22, 2024, 4:22:33 PMApr 22
to weewx-development
dear all, i'm sorry for my poor english, i'm italian and i haven't take a lesson for english in my life ;)
I ask if it's possible to get data not from hardware but from a mariadb database. This because i think that is one the way to make the softwate for many people in the world that not have access to buy a hardware station in list ,... i'm one of this peopole .
I have made my personal weather station by hardware on internet and i have write the code to read data whit one simple raspberry. Now is 5 years that the software register the data every 5 minutes on Mariadb database on local hdd, and i would put the data on internet for read meteo data with my phone (also another data like temperature of my home and level of water tank for my garden).
I haven't problem to read php and html code, but i haven't experience with java code, there someome to helpo me to modify phpo code to realize my project?
thanks in advance and kind regards at all
matteo



Peter Fletcher

unread,
Apr 23, 2024, 3:50:19 PMApr 23
to weewx-development
Mariadb databases are directly supported by weewx (MySQL is one of its standard database types, and Mariadb can, for most purposes, be regarded as a MySQL variant). So, for historical data, the easiest approach would probably be to set up weewx with its simulator driver and MySQL support, and then (within Mariadb) transfer the data from your archives into the appropriate columns of weewx's database. For newly arriving data, the simplest approach might well be to write a text file for each new set of readings and modify the fileparse driver (in the /examples folder) to read each new set in, when it appears.

matteo pirazzi

unread,
Apr 24, 2024, 8:16:00 AMApr 24
to weewx-development
Dear Peter,
thanks for your reply, I have found the correct table name and I have found the columns; my personal approach for inserting the data into the database is simpler: since the data is at my home and MariaDB is online, it is better for me to modify the local data storage script to insert new records into the table of the weewx online database.
In simulation mode the system automatically inserts a record every few seconds but this, for me, is not necessary and I need to stop this but I cannot find where, could you help me?
thanks in advance.
respect
matteo


.

Peter Fletcher

unread,
Apr 24, 2024, 9:49:05 AMApr 24
to weewx-development
I was really only suggesting that you use the simulator driver to allow weewx to create its default MySQL/Mariadb database. It is probably not the best model or basis for your working code. While I am sure that it is easy to modify your local data storage script to use the weewx database, this doesn't (without further coding) give weewx meaningful access to your real-time data, and I am not sure that weewx 'expects' new data to appear in its database in real time other than through its own mechanisms. I would again suggest that you look at the code of the fileparse driver in /examples. It should be fairly easy for you to modify this either to get new data directly from your sensors at your chosen interval or (my original suggestion) to read a text file written at intervals by your data storage script. weewx will then be able to process and store the new data as if it came directly from the sensors.

Cameron D

unread,
Apr 24, 2024, 9:03:33 PMApr 24
to weewx-development
Hello Matteo,
I think it is quite possible to have your own code filling the weewx DB and running weewx simply to create the plots and calculate the long term summaries.

It would be a huge task to have weewx directly read your db format, so maintaining both DBs (your original one and weewx)  side by side would be the best way to go. Simply adjust your php code to update the weewx DB at the same time as it updates your own DB.  Note that weewx records the date/time rounded to exact multiples of the time interval.

Transferring your old data might be something as a simple as a single INSERT ... SELECT  statement run on the server, depending on your DB format. This would depend on aligning the units being used. I presume you would use some form of metric system, so configure weewx to use a non-default unit system.

In my case I just run "weectl report"  via a cron job, however in your case you might need to run the weewx daemon to generate the day summaries - I don't know if the report generator will do that for you.
Reply all
Reply to author
Forward
0 new messages