Question on using API

Post Reply
petoz
Newbie
Newbie
Posts: 5
Joined: Thu Aug 31, 2017 12:55 pm
Location: Zilina, Slovakia
Station model: Own arduino + raspberry
Software: Own (Python;C++)
Contact:

Question on using API

Post by petoz » Thu Sep 14, 2017 9:10 am

Hi,
I have my own program (python) to send data to API. When I want to use more sensors, how can I give each value from diffrent sensors different time (time in which value was measured)?
I send this URL to my template:

Code: Select all

http://coffee.onmypc.net/meteotemplate/api.php?U=1505378730&TTime=1505378724&T=20.60&H=58.20&HTime=1505378724&TBATTime=1505378724&TBAT=79.08&T1Time=1505378716&T1=21.70&H1=45.50&H1Time=1505378716&T1BATTime=1505378716&T1BAT=76.83&P=1008.96&W=0.0&G=0.0&B=0&R=0.0&RR=0.0&S=0.0&TIN=24.25&HIN=50.20&PASS=
Capture.PNG
Capture.PNG (6.4 KiB) Viewed 6816 times
The result from server side is: Success, but on server side meteotemplateLive.txt is:

Code: Select all

{"U":1505378730,"TTime":1505378733,"T":20.6,"H":58.2,"HTime":1505378733,"TBATTime":1505378733,"TBAT":79.08,"T1Time":1505378733,"T1":21.7,"H1":45.5,"H1Time":1505378733,"T1BATTime":1505378733,"T1BAT":76.83,"P":1008.96,"W":0,"G":0,"B":0,"R":0,"RR":0,"S":0,"TIN":24.25,"HIN":50.2,"UTime":1505378733,"TTimeTime":1505378733,"HTimeTime":1505378733,"TBATTimeTime":1505378733,"T1TimeTime":1505378733,"H1TimeTime":1505378733,"T1BATTimeTime":1505378733,"PTime":1505378733,"WTime":1505378733,"GTime":1505378733,"BTime":1505378733,"RTime":1505378733,"RRTime":1505378733,"STime":1505378733,"TINTime":1505378733,"HINTime":1505378733,"D":12.1,"DTime":1505378733,"A":21.2,"ATime":1505378733}
Capture1.PNG
Capture1.PNG (9.17 KiB) Viewed 6816 times
I have problem also when some sensor is not working, all template is not updated and is going to offline.
Do you have any suggestions hove to use API correctly?
Must I use for every sensor own URL update?
Image

User avatar
Jachym
Site Admin
Site Admin
Posts: 1686
Joined: Fri Aug 18, 2017 10:12 pm
Location: Brno, Czech Republic
Station model: WH1080
Software: Meteobridge
Contact:

Re: Question on using API

Post by Jachym » Thu Sep 14, 2017 9:22 am

Hi,
you cannot update the database with two different timestamps at the same time. This means that you cannot send data from different intervals at the same time.

If you wanted to do that they would have to be separate calls to the API, at the time when it was measured.

The API will save the data to the db even if not all info is available, it only requires that there is timestamp and the correct update password and at least one other value. But this is likely to make a mess in the API caching mechanism.

Im afraid updating several sensors at different times is not really supported because it will result in very inconsistent database entries, statistics and confuse many pages because it assumes that the data is in regular intervals

petoz
Newbie
Newbie
Posts: 5
Joined: Thu Aug 31, 2017 12:55 pm
Location: Zilina, Slovakia
Station model: Own arduino + raspberry
Software: Own (Python;C++)
Contact:

Re: Question on using API

Post by petoz » Thu Sep 14, 2017 11:04 am

Thank you for your help,
when I looked to file "meteotemplateLive.txt"
Capture1.PNG
Capture1.PNG (9.82 KiB) Viewed 6807 times
I supposed that when for each value is "valueTime:timestamp" I can use it in updates the same way.
Now I adjusted the URL to this:
Capture.PNG
Capture.PNG (4.66 KiB) Viewed 6807 times
So now when some sensor will fail, there will be updated to meteotemplate with unactual (same) values. So I have to use different way to control if all sensors are sending actual data. Or I can send one URL request for each sensor with own timestamp.
Image

User avatar
Jachym
Site Admin
Site Admin
Posts: 1686
Joined: Fri Aug 18, 2017 10:12 pm
Location: Brno, Czech Republic
Station model: WH1080
Software: Meteobridge
Contact:

Re: Question on using API

Post by Jachym » Thu Sep 14, 2017 12:08 pm

The general rule is:
if a sensor is not sending data then the value has to be either blank or not in the API call at all. In such case the value in db will be "null", which is ignored by all statistics etc.
Timestamp in the API call is labeled as "U"

User avatar
Luc
Developer
Developer
Posts: 168
Joined: Mon Aug 21, 2017 6:40 am
Location: Paramaribo, Suriname
Station model: Davis Pro 2 (2x)
Software: WeeWX
Contact:

Re: Question on using API

Post by Luc » Thu Sep 14, 2017 4:11 pm

You can send data for each sensor with its own time stamp to the api as often as the sensor has new data. Once per five minutes the api will aggregate all received data to one database value per sensor.
Image

User avatar
Jachym
Site Admin
Site Admin
Posts: 1686
Joined: Fri Aug 18, 2017 10:12 pm
Location: Brno, Czech Republic
Station model: WH1080
Software: Meteobridge
Contact:

Re: Question on using API

Post by Jachym » Thu Sep 14, 2017 4:32 pm

Yes, but I think what he meant was this db time because in db there will always be just one set of data every 5 mins

User avatar
Luc
Developer
Developer
Posts: 168
Joined: Mon Aug 21, 2017 6:40 am
Location: Paramaribo, Suriname
Station model: Davis Pro 2 (2x)
Software: WeeWX
Contact:

Re: Question on using API

Post by Luc » Thu Sep 14, 2017 4:39 pm

Jachym, the problem seems to be the station is flagged 'offline' when one sensor stops sending data.
I think when each sensor sends its data independently with its own timestamp the station won't go offline, right?
Image

User avatar
Jachym
Site Admin
Site Admin
Posts: 1686
Joined: Fri Aug 18, 2017 10:12 pm
Location: Brno, Czech Republic
Station model: WH1080
Software: Meteobridge
Contact:

Re: Question on using API

Post by Jachym » Thu Sep 14, 2017 5:50 pm

The API should save data when there is:
- timestamp
- at least one valid value

spd2612
Forecaster
Forecaster
Posts: 165
Joined: Thu Jan 23, 2020 4:00 pm
Location: Fort Myers
Station model: WS-5000/GW1100
Software: ECOWITT Plugin
Contact:

Re: Question on using API

Post by spd2612 » Sun Feb 09, 2020 1:11 pm

I know this is a old post but i am trying to learn the flow that meteotemplate uses
Im trying to use ambient weather api on the template
Reason is i have a 2902A which transmits wirelessly to AW and my console every 16 seconds not minutes
I have written some code that pulls AW data and posts it to that page
So if that data was put in the data base would Meteotemplate use it
If I stopped getting data from WU took out the keys in main template or just changed it to API in main template
Image

Ambient Weather WS-5000
Ultrasonic Anemometer
Thermo-Hygrometer Sensor WH31E
Soil Moisture Sensor WH31SM
Lightning Detection WH31L

Post Reply