Page 1 of 1

Question on using API

Posted: Thu Sep 14, 2017 9:10 am
by petoz
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 13969 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 13969 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?

Re: Question on using API

Posted: Thu Sep 14, 2017 9:22 am
by Jachym
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

Re: Question on using API

Posted: Thu Sep 14, 2017 11:04 am
by petoz
Thank you for your help,
when I looked to file "meteotemplateLive.txt"
Capture1.PNG
Capture1.PNG (9.82 KiB) Viewed 13960 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 13960 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.

Re: Question on using API

Posted: Thu Sep 14, 2017 12:08 pm
by Jachym
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"

Re: Question on using API

Posted: Thu Sep 14, 2017 4:11 pm
by Luc
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.

Re: Question on using API

Posted: Thu Sep 14, 2017 4:32 pm
by Jachym
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

Re: Question on using API

Posted: Thu Sep 14, 2017 4:39 pm
by Luc
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?

Re: Question on using API

Posted: Thu Sep 14, 2017 5:50 pm
by Jachym
The API should save data when there is:
- timestamp
- at least one valid value

Re: Question on using API

Posted: Sun Feb 09, 2020 1:11 pm
by spd2612
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