I was bored and wrote the is horrible ugly program to do it, 98% compete and working... looking to beautify it.. any pointers? I removed my api key but feel free to use your own station ID and key to test .. lemme know what you think .. I have thick skin. Lol
'CR6 Datalogger 'The datalogger type listed on line 1 determines the default instruction set, 'compiler, and help files used for a program that uses the .DLD or .CRB program 'Date:10-16-21 'Program author:ty fairchild 'Public Variables Public PTemp As Float Public Batt_volt As Float Public acurite_api As String * 500 Public country As String * 10 'Country Code Public epoch As Float 'Time in UNIX seconds Public humidity As Float 'The relative humidity of the air. Public lat As Float 'Latitude of PWS Public lon As Float 'Longitude of PWS Public neighborhood As String * 24 'Neighborhood associated with the PWS location Public obsTimeLocal As String * 24 'Time observation is valid in local apparent time by timezone - tz Public obsTimeUtc As String * 24 'GMT(UTC) time Public qcStatus As Float 'Quality control indicator: '-1: No quality control check performed ' 0: This observation was marked As possibly incorrect by our quality control algorithm ' 1: This observation passed quality control checks Public realtimeFrequency As Float 'Frequency of data report updates in minutes Public softwareType As String * 24 'Software type of the PWS Public solarRadiation As Float 'Solar Radiation Public stationID As String * 24 'ID as registered by wunderground.com Public uv As Float 'UV reading of the intensity of solar radiation Public winddir As Float 'Wind Direction Public imperial As String * 24 'Object containing fields that use a defined unit of measure. The object label is dependent on the units parameter assigned in the request. '"imperial", "metric", "metric_si", "uk_hybrid" see API docs Public metric As String * 24 ' see imperial notes above Public metric_si As String * 24 ' see imperial notes above Public uk_hybrid As String * 24 ' see imperial notes above Public dewpt As Float 'The temperature which air must be cooled at constant pressure to reach saturation. The Dew Point is also an indirect measure of the humidity of the air. The Dew Point will never exceed the Temperature. When the Dew Point and Temperature are equal, clouds or fog will typically form. The closer the values of Temperature and Dew Point, the higher the relative humidity. Public elev As Float 'Elevation Public heatIndex As Float 'Heat Index - An apparent temperature. It represents what the air temperature “feels like” on exposed human skin due to the combined effect of warm temperatures and high humidity. 'When the temperature is 70°F or higher, the Feels Like value represents the computed Heat Index. Public precipRate As Float 'Rate of precipitation - instantaneous precipitation rate. How much rain would fall if the precipitation intensity did not change for one hour Public precipTotal As Float 'Accumulated precipitation for today from midnight to present. Public pressure As Long 'Mean Sea Level Pressure, the equivalent pressure reading at sea level recorded at this station Public temp As Float 'Temperature in defined unit of measure. Public windChill As Float 'Wind Chill - An apparent temperature. It represents what the air temperature “feels like” on exposed human skin due to the combined effect of the cold temperatures and wind speed. 'When the temperature is 61°F or lower the Feels Like value represents the computed Wind Chill so display the Wind Chill value. Public windGust As Float 'Wind Gust - sudden and temporary variations of the average Wind Speed. The report always shows the maximum wind gust speed recorded during the observation period. It is a required display field if Wind Speed is shown. Public windSpeed As Float 'Wind Speed - The wind is treated as a vector; hence, winds must have direction and magnitude (speed). The wind information reported in the hourly current conditions corresponds to a 10-minute average called the sustained wind speed. Sudden or brief variations in the wind speed are known as “wind gusts” and are reported in a separate data field. 'Wind directions are always expressed as ""from whence the wind blows"" meaning that a North wind blows from North to South. If you face North in a North wind the wind is at your face. Face southward and the North wind is at your back. 'defining of object start points, an appended number "1" indicates position from beginning of the api call probably in JSON format Public country1 As String * 10 Public epoch1 As String * 24 Public humidity1 As String * 24 Public lat1 As Float Public lon1 As Float Public neighborhood1 As String * 24 Public obsTimeLocal1 As String * 24 Public obsTimeUtc1 As String * 24 Public qcStatus1 As String * 24 Public realtimeFrequency1 As String * 24 Public softwareType1 As String * 24 Public solarRadiation1 As String * 24 Public stationID1 As String * 24 Public uv1 As String * 24 Public winddir1 As String * 24 Public imperial1 As String * 24 Public metric1 As String * 24 Public metric_si1 As String * 24 Public uk_hybrid1 As String * 24 Public dewpt1 As String * 24 Public elev1 As String * 24 Public heatIndex1 As String * 24 Public precipRate1 As String * 24 Public precipTotal1 As String * 24 Public pressure1 As String * 24 Public temp1 As String * 24 Public windChill1 As String * 24 Public windGust1 As String * 24 Public windSpeed1 As String * 24 'defining of object values 'actual starting positions of objects, an appended number "2" indicates position from beginning of the api call probably in JSON format Public country2 As Float Public epoch2 As Float Public humidity2 As Float Public lat2 As Float Public lon2 As Float Public neighborhood2 As Float Public obsTimeLocal2 as FLOAT Public obsTimeUtc2 As String * 24 Public qcStatus2 As String * 24 Public realtimeFrequency2 As String * 24 Public softwareType2 As String * 24 Public solarRadiation2 As String * 24 Public stationID2 As String * 24 Public uv2 As String * 24 Public winddir2 As String * 24 Public imperial2 As String * 24 Public metric2 As String * 24 Public metric_si2 As String * 24 Public uk_hybrid2 As String * 24 Public dewpt2 As String * 24 Public elev2 As String * 24 Public heatIndex2 As String * 24 Public precipRate2 As String * 24 Public precipTotal2 As String * 24 Public pressure2 As String * 24 Public temp2 As String * 24 Public windChill2 As String * 24 Public windGust2 As String * 24 Public windSpeed2 As String * 24 'units define here Units PTemp=c 'deg celcius Units Batt_volt=v 'vdc Units epoch=sec 'UNIX seconds Units rh=% 'in percent Units AT=c 'deg c -40 - +50 Units ws=m/s 'in meters per sec Units wd=deg 'degrees 0-359 Units solar=w/m2 'watt meter squared Units baro=mb 'millibar 'Alias Alias acurite_api = api Alias humidity = rh Alias temp = AT Alias windSpeed = ws Alias winddir = wd Alias pressure = baro Alias precipRate = rain_rate Alias precipTotal = rain_total Alias solarRadiation = solar 'Data Tables 'logger status table DataTable (logger_status,1,-1) DataInterval (0,15,Sec,10) Sample (1,PTemp,FP2) Sample (1,Batt_volt,FP2) EndTable 'api table DataTable (api_table,1,-1) DataInterval (0,15,Sec,10) Sample (1,acurite_api,String) EndTable 'Full station info table DataTable (full_Observations,1,-1) 'set table size to # of records, or -1 to autoallocate. DataInterval (0,15,Sec,10) Sample 1,country,String Sample 1,epoch,IEEE8 Sample 1,humidity,FP2 Sample 1,lat,FP2 Sample 1,lon,FP2 Sample 1,neighborhood,String Sample 1,obsTimeLocal,String Sample 1,obsTimeUtc,String Sample 1,qcStatus,FP2 Sample 1,realtimeFrequency,FP2 Sample 1,softwareType,String Sample 1,solarRadiation,FP2 Sample 1,stationID,String Sample 1,uv,FP2 Sample 1,winddir,FP2 Sample 1,imperial,String Sample 1,metric,String Sample 1,metric_si,String Sample 1,uk_hybrid,String Sample 1,dewpt,IEEE4 Sample 1,elev,FP2 Sample 1,heatIndex,FP2 Sample 1,precipRate,FP2 Sample 1,precipTotal,FP2 Sample 1,pressure,IEEE4 Sample 1,temp,FP2 Sample 1,windChill,FP2 Sample 1,windGust,FP2 Sample 1,windSpeed,FP2 EndTable 'Location info table DataTable (Location_info,1,-1) 'Set table size to # of records, or -1 to autoallocate. DataInterval (0,15,Sec,10) Sample 1,stationID,String Sample 1,country,String Sample 1,neighborhood,String Sample 1,lon,FP2 Sample 1,lat,FP2 Sample 1,obsTimeUtc,String EndTable 'MET for SAFER output table DataTable (SAFER_modbus_out,1,-1) 'Set table size to # of records, or -1 to autoallocate. DataInterval (0,15,Sec,10) Sample 1,windSpeed,FP2 Sample 1,winddir,FP2 Sample 1,temp,FP2 Sample 1,humidity,FP2 Sample 1,solarRadiation,FP2 Sample 1,pressure,IEEE4 Sample 1,precipRate,FP2 Sample 1,precipTotal,FP2 EndTable 'Main Program BeginProg PanelTemp (PTemp,15000) Battery (Batt_volt) Scan (15,Sec,0,0) 'calling the api HTTPGet ("https://api.weather.com/v2/pws/observations/current?stationId=ststionID&format=json&units=e&apiKey=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",acurite_api,"Accept-Encoding: gzip",30) 'defining object filter values country1 = "country" epoch1 = "epoch" humidity1 = "humidity" lat1 = "lat" lon1 = "lon" neighborhood1 = "neighborhood" obsTimeLocal1 = "obsTimeLocal" obsTimeUtc1 = "obsTimeUtc" qcStatus1 = "qcStatus" realtimeFrequency1 = "realtimeFrequency" softwareType1 = "softwareType" solarRadiation1 = "solarRadiation" stationID1 = "stationID" uv1 = "uv" winddir1 = "winddir" imperial1 = "imperial" metric1 = "metric" metric_si1 = "metric_si" uk_hybrid1 = "uk_hybrid" dewpt1 = "dewpt" elev1 = "elev" heatIndex1 = "heatIndex" precipRate1 = "precipRate" precipTotal1 = "precipTotal" pressure1 = "pressure" temp1 = "temp" windChill1 = "windChill" windGust1 = "windGust" windSpeed1 = "windspeed" 'parsing the api json to find start point for objects and extracting country2 = InStr (1,acurite_api,country1,2)+10 country = Mid (acurite_api,country2,2) epoch2 = InStr (1,acurite_api,epoch1,2)+8 epoch = Mid (acurite_api,epoch2,10) humidity2 =InStr (1,acurite_api,humidity1,2)+11 humidity = Mid (acurite_api,humidity2,2) lat2 = InStr (1,acurite_api,lat1,2)+6 lat = Mid (acurite_api,lat2,8) lon2 = InStr (1,acurite_api,lon1,2)+6 lon = Mid (acurite_api,lon2,8) neighborhood2 = InStr (1,acurite_api,neighborhood1,2)+16 neighborhood = Mid (acurite_api,neighborhood2,24) obsTimeLocal2 = InStr (1,acurite_api,obsTimeLocal1,2)+16 obsTimeLocal = Mid (acurite_api,obsTimeLocal2,24) obsTimeUtc2 = InStr (1,acurite_api,obsTimeUtc1,2)+14 obsTimeUtc = Mid (acurite_api,obsTimeUtc2,23) qcStatus2 = InStr (1,acurite_api,qcStatus1,2)+11 qcStatus = Mid (acurite_api,qcStatus2,2) realtimeFrequency2 = InStr (1,acurite_api,realtimeFrequency1,2)+20 realtimeFrequency = Mid (acurite_api,realtimeFrequency2,4) softwareType2 = InStr (1,acurite_api,softwareType1,2)+16 softwareType = Mid (acurite_api,softwareType2,14) solarRadiation2 = InStr (1,acurite_api,solarRadiation1,2)+17 solarRadiation = Mid (acurite_api,solarRadiation2,4) stationID2 = InStr (1,acurite_api,stationID1,2)+12 stationID = Mid (acurite_api,stationID2,12) uv2 = InStr (1,acurite_api,uv1,2)+4 uv = Mid (acurite_api,uv2,3) winddir2 = InStr (1,acurite_api,winddir1,2)+10 winddir = Mid (acurite_api,winddir2,3) imperial2 = InStr (1,acurite_api,imperial1,2)+11 imperial = Mid (acurite_api,imperial2,20) metric2 = InStr (1,acurite_api,metric1,2) metric = Mid (acurite_api,metric2,20) metric_si2 = InStr (1,acurite_api,metric_si1,2) metric_si = Mid (acurite_api,metric_si2,20) uk_hybrid2 = InStr (1,acurite_api,uk_hybrid1,2) uk_hybrid = Mid (acurite_api,uk_hybrid2,20) dewpt2 = InStr (1,acurite_api,dewpt1,2)+8 dewpt = Mid (Batt_volt,dewpt2,2) elev2 = InStr (1,acurite_api,elev1,2)+7 elev = Mid (acurite_api,elev2,4) heatIndex2 = InStr (1,acurite_api,heatIndex1,2)+12 heatIndex = Mid (acurite_api,heatIndex2,2) precipRate2 = InStr (1,acurite_api,precipRate1,2)+13 precipRate = Mid (acurite_api,precipRate2,4) precipTotal2 = InStr (1,acurite_api,precipTotal1,2)+14 precipTotal = Mid (Batt_volt,precipTotal2,4) pressure2 = InStr (1,acurite_api,pressure1,2)+11 pressure = Mid (pressure1,pressure2,5) temp2 = InStr (1,acurite_api,temp1,2)+7 temp = Mid (acurite_api,temp2,3) windChill2 = InStr (1,acurite_api,windChill1,2)+12 windChill = Mid (acurite_api,windChill2,3) windGust2 = InStr (1,acurite_api,windGust1,2)+11 windGust = Mid (acurite_api,windGust2,2) windSpeed2 = InStr (1,acurite_api,windSpeed1,2)+12 windSpeed = Mid (acurite_api,windSpeed2,3) CallTable SAFER_modbus_out CallTable Location_info CallTable full_Observations CallTable api_table CallTable logger_status NextScan EndProg
Hi,
Your program looks nice. Try tested, it doesn't work for me. Error come outs as api = "Http comms Error". All parameters got NAN. The code works on web brawser. Here it is
{"observations":[{"stationID":"IJOHORBA4","obsTimeUtc":"2021-12-01T11:10:39Z","obsTimeLocal":"2021-12-01 19:10:39","neighborhood":"AME Senai Airport City","softwareType":null,"country":"MY","solarRadiation":null,"lon":103.680107,"realtimeFrequency":null,"epoch":1638357039,"lat":1.59889,"uv":null,"winddir":157,"humidity":70,"qcStatus":-1,"imperial":{"temp":89,"heatIndex":103,"dewpt":78,"windChill":89,"windSpeed":5,"windGust":null,"pressure":29.66,"precipRate":null,"precipTotal":0.00,"elev":131}}]}
Do I need to do something with the datalogger communication settings?
Rgds,
Thein