Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 21:10 20 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : What am I doing wrong

     Page 2 of 2    
Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 02:02pm 26 Nov 2020
Copy link to clipboard 
Print this post

I have this to parse
I can see I have one "list" so it needs to be something like
 Dim As integer d(9000)
 DIM STRING q=Chr$(34) '" symbol
DIM d$,icon$

system "wget -q -O- "+q$+"https://api.weather.com/v2/pws/observations/current?stationId=IMANCH7&format=json&units=m&apiKey=8320530003ba490ba0530003bae90b4e"+q$,d()
precip1$=JSON$(d(),"list[1].pop")'precipitation forecast


There is one list which is why I used list[1]
It doesn't work
so I tried
icon$=JSON$(c%(),"list[1].weather[1].icon")

That should have worked because there is one list and I wanted the first icon which is part of weather[1] but it doesn't work
I'm stumped
I don't actually want the icon, only the pop but the icon should have parsed using that code

  Quote  {"cod":"200","message":0,"cnt":40,"list":[{"dt":1606402800,"main":{"temp":281.03,"feels_like":278.53,"temp_min":280.31,"temp_max":281.03,"pressure":1021,"sea_level":1021,"grnd_level":1007,"humidity":81,"temp_kf":0.72},
"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":81},"wind":{"speed":1.92,"deg":225},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2020-11-26 15:00:00"},{"dt":1606413600,"main":{"temp":279.84,"feels_like":277.54,"temp_min":279.32,"temp_max":279.84,"pressure":1021,"sea_level":1021,"grnd_level":1007,"humidity":84,"temp_kf":0.52},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":84},"wind":{"speed":1.45,"deg":204},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-26 18:00:00"},{"dt":1606424400,"main":{"temp":278.34,"feels_like":276.07,"temp_min":278.11,"temp_max":278.34,"pressure":1022,"sea_level":1022,"grnd_level":1008,"humidity":89,"temp_kf":0.23},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":45},"wind":{"speed":1.23,"deg":204},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-26 21:00:00"},{"dt":1606435200,"main":{"temp":277.4,"feels_like":275.37,"temp_min":277.37,"temp_max":277.4,"pressure":1022,"sea_level":1022,"grnd_level":1008,"humidity":91,"temp_kf":0.03},"weather":[{"id":802,"main":"Clouds","description":"scattered

Edited 2020-11-27 00:03 by lew247
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3010
Posted: 02:18pm 26 Nov 2020
Copy link to clipboard 
Print this post

Do you have OPTION BASE 1 so that the first array item is list[1]?

Otherwise the first array item is list[0].

(If I have understood correctly.)
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 03:23pm 26 Nov 2020
Copy link to clipboard 
Print this post

No I don't have any Option Base set
I've tried these one by one, commenting one line at a time till I've tried all 4 versions
Dim As integer d(1000)
DIM STRING q=Chr$(34) '" symbol
DIM icon$,icon1$,icon2$,icon3$

system "wget -q -O- "+q$+"https://api.weather.com/v2/pws/observations/current?stationId=IMANCH7&format=json&units=m&apiKey=8320530003ba490ba0530003bae90b4e"+q$,d()
'icon$=JSON$(d%(),"list[0].weather[0].icon")'precipitation forecast
'icon1$=JSON$(c%(),"list[0].weather[1].icon")
'icon2$=JSON$(c%(),"list[1].weather[0].icon")
icon3$=JSON$(c%(),"list[1].weather[1].icon")
print icon$
print icon1$
print icon2$
print icon3$

This is the result of each

Editing - I can see I made a mistake
going to try again
Edited 2020-11-27 01:24 by lew247
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 03:32pm 26 Nov 2020
Copy link to clipboard 
Print this post

Dim As integer d(1000)
DIM STRING q=Chr$(34) '" symbol
DIM icon$,icon1$,icon2$,icon3$

system "wget -q -O- "+q$+"https://api.weather.com/v2/pws/observations/current?stationId=IMANCH7&format=json&units=m&apiKey=8320530003ba490ba0530003bae90b4e"+q$,d()
icon$=JSON$(d%(),"list[0].weather[0].icon")
icon1$=JSON$(d%(),"list[0].weather[1].icon")
icon2$=JSON$(d%(),"list[1].weather[0].icon")
icon3$=JSON$(d%(),"list[1].weather[1].icon")
print icon$,",","Test1"
print icon1$,",","Test2"
print icon2$,",","Test3"
print icon3$,",","Test4"




I really don't get why it isn't working
I've left the API key in there in case anyone wants to see if it's working their end
Edited 2020-11-27 01:43 by lew247
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3010
Posted: 04:51pm 26 Nov 2020
Copy link to clipboard 
Print this post

What is actually returned by your wget? Which I'm guessing is put into the integer array d() (which I suppose is actually a LONGSTRING)? This is, if you do
LONGSTRING PRINT d%()
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 05:33pm 26 Nov 2020
Copy link to clipboard 
Print this post

  lizby said  What is actually returned by your wget? Which I'm guessing is put into the integer array d() (which I suppose is actually a LONGSTRING)? This is, if you do
LONGSTRING PRINT d%()

I'm an idiot I had the wrong page I was calling
But I tried it again with the correct api address and got this
ERROR: Invalid JSON data

When I do LONGSTRING PRINT d%() I get this - but with no linefeeds
I can't copy and past from Pi-Crommite
  Quote  {"cod":"200","message":0,"cnt":40,"list":[{"dt":1606413600,"main":{"temp":279.93,"feels_like":277.68,"temp_min":279.32,"temp_max":279.93,"pressure":1021,"sea_level":1021,"grnd_level":1007,"humidity":85,"temp_kf":0.61},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":80},"wind":{"speed":1.45,"deg":204},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-26 18:00:00"},{"dt":1606424400,"main":{"temp":278.63,"feels_like":276.42,"temp_min":278.11,"temp_max":278.63,"pressure":1022,"sea_level":1022,"grnd_level":1008,"humidity":89,"temp_kf":0.52},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":50},"wind":{"speed":1.23,"deg":204},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-26 21:00:00"},{"dt":1606435200,"main":{"temp":277.57,"feels_like":275.57,"temp_min":277.37,"temp_max":277.57,"pressure":1022,"sea_level":1022,"grnd_level":1008,"humidity":91,"temp_kf":0.2},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":38},"wind":{"speed":0.73,"deg":252},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-27 00:00:00"},{"dt":1606446000,"main":{"temp":277.22,"feels_like":275.3,"temp_min":277.19,"temp_max":277.22,"pressure":1021,"sea_level":1021,"grnd_level":1008,"humidity":90,"temp_kf":0.03},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":49},"wind":{"speed":0.49,"deg":33},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-27 03:00:00"},{"dt":1606456800,"main":{"temp":276.55,"feels_like":274.19,"temp_min":276.55,"temp_max":276.55,"pressure":1021,"sea_level":1021,"grnd_level":1007,"humidity":88,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":32},"wind":{"speed":0.89,"deg":82},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-27 06:00:00"},{"dt":1606467600,"main":{"temp":276.7,"feels_like":274.44,"temp_min":276.7,"temp_max":276.7,"pressure":1020,"sea_level":1020,"grnd_level":1007,"humidity":83,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":5},"wind":{"speed":0.59,"deg":104},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2020-11-27 09:00:00"},{"dt":1606478400,"main":{"temp":279.3,"feels_like":277.06,"temp_min":279.3,"temp_max":279.3,"pressure":1019,"sea_level":1019,"grnd_level":1006,"humidity":70,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":2},"wind":{"speed":0.6,"deg":244},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2020-11-27 12:00:00"},{"dt":1606489200,"main":{"temp":278.7,"feels_like":276.48,"temp_min":278.7,"temp_max":278.7,"pressure":1018,"sea_level":1018,"grnd_level":1004,"humidity":74,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":5},"wind":{"speed":0.61,"deg":168},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2020-11-27 15:00:00"},{"dt":1606500000,"main":{"temp":277.17,"feels_like":274.62,"temp_min":277.17,"temp_max":277.17,"pressure":1018,"sea_level":1018,"grnd_level":1004,"humidity":81,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":42},"wind":{"speed":1.03,"deg":102},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-27 18:00:00"},{"dt":1606510800,"main":{"temp":276.58,"feels_like":273.81,"temp_min":276.58,"temp_max":276.58,"pressure":1018,"sea_level":1018,"grnd_level":1004,"humidity":83,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":100},"wind":{"speed":1.3,"deg":99},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-27 21:00:00"},{"dt":1606521600,"main":{"temp":276.07,"feels_like":272.98,"temp_min":276.07,"temp_max":276.07,"pressure":1018,"sea_level":1018,"grnd_level":1004,"humidity":82,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":62},"wind":{"speed":1.61,"deg":90},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-28 00:00:00"},{"dt":1606532400,"main":{"temp":277.75,"feels_like":274.5,"temp_min":277.75,"temp_max":277.75,"pressure":1018,"sea_level":1018,"grnd_level":1004,"humidity":83,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":93},"wind":{"speed":2.25,"deg":75},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-28 03:00:00"},{"dt":1606543200,"main":{"temp":277.09,"feels_like":274.17,"temp_min":277.09,"temp_max":277.09,"pressure":1018,"sea_level":1018,"grnd_level":1005,"humidity":92,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":70},"wind":{"speed":1.97,"deg":73},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-28 06:00:00"},{"dt":1606554000,"main":{"temp":278.18,"feels_like":275.43,"temp_min":278.18,"temp_max":278.18,"pressure":1020,"sea_level":1020,"grnd_level":1006,"humidity":91,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":55},"wind":{"speed":1.96,"deg":80},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2020-11-28 09:00:00"},{"dt":1606564800,"main":{"temp":280.67,"feels_like":278,"temp_min":280.67,"temp_max":280.67,"pressure":1020,"sea_level":1020,"grnd_level":1007,"humidity":86,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":72},"wind":{"speed":2.31,"deg":97},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2020-11-28 12:00:00"},{"dt":1606575600,"main":{"temp":280.76,"feels_like":278.33,"temp_min":280.76,"temp_max":280.76,"pressure":1020,"sea_level":1020,"grnd_level":1007,"humidity":87,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":{"all":100},"wind":{"speed":2.03,"deg":82},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2020-11-28 15:00:00"},{"dt":1606586400,"main":{"temp":280.04,"feels_like":277.29,"temp_min":280.04,"temp_max":280.04,"pressure":1022,"sea_level":1022,"grnd_level":1008,"humidity":91,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":90},"wind":{"speed":2.47,"deg":83},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-28 18:00:00"},{"dt":1606597200,"main":{"temp":279.79,"feels_like":277.48,"temp_min":279.79,"temp_max":279.79,"pressure":1023,"sea_level":1023,"grnd_level":1009,"humidity":93,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":38},"wind":{"speed":1.86,"deg":85},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-28 21:00:00"},{"dt":1606608000,"main":{"temp":278.98,"feels_like":276.82,"temp_min":278.98,"temp_max":278.98,"pressure":1024,"sea_level":1024,"grnd_level":1010,"humidity":93,"temp_kf":0},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"clouds":{"all":23},"wind":{"speed":1.42,"deg":85},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-29 00:00:00"},{"dt":1606618800,"main":{"temp":278.59,"feels_like":276.43,"temp_min":278.59,"temp_max":278.59,"pressure":1024,"sea_level":1024,"grnd_level":1011,"humidity":90,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":2},"wind":{"speed":1.18,"deg":77},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-29 03:00:00"},{"dt":1606629600,"main":{"temp":278.38,"feels_like":275.95,"temp_min":278.38,"temp_max":278.38,"pressure":1025,"sea_level":1025,"grnd_level":1011,"humidity":87,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":1},"wind":{"speed":1.39,"deg":79},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-29 06:00:00"},{"dt":1606640400,"main":{"temp":278.59,"feels_like":276.39,"temp_min":278.59,"temp_max":278.59,"pressure":1026,"sea_level":1026,"grnd_level":1012,"humidity":86,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":1.07,"deg":83},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2020-11-29 09:00:00"},{"dt":1606651200,"main":{"temp":281.48,"feels_like":279.83,"temp_min":281.48,"temp_max":281.48,"pressure":1026,"sea_level":1026,"grnd_level":1012,"humidity":74,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":0.47,"deg":118},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2020-11-29 12:00:00"},{"dt":1606662000,"main":{"temp":280.75,"feels_like":279.2,"temp_min":280.75,"temp_max":280.75,"pressure":1026,"sea_level":1026,"grnd_level":1012,"humidity":78,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":0.34,"deg":231},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2020-11-29 15:00:00"},{"dt":1606672800,"main":{"temp":279.32,"feels_like":277.31,"temp_min":279.32,"temp_max":279.32,"pressure":1027,"sea_level":1027,"grnd_level":1013,"humidity":82,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":0.81,"deg":155},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-29 18:00:00"},{"dt":1606683600,"main":{"temp":278.6,"feels_like":276.73,"temp_min":278.6,"temp_max":278.6,"pressure":1027,"sea_level":1027,"grnd_level":1014,"humidity":85,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":5},"wind":{"speed":0.56,"deg":209},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-29 21:00:00"},{"dt":1606694400,"main":{"temp":278,"feels_like":276.04,"temp_min":278,"temp_max":278,"pressure":1028,"sea_level":1028,"grnd_level":1014,"humidity":88,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":2},"wind":{"speed":0.67,"deg":212},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-30 00:00:00"},{"dt":1606705200,"main":{"temp":277.61,"feels_like":275.42,"temp_min":277.61,"temp_max":277.61,"pressure":1027,"sea_level":1027,"grnd_level":1014,"humidity":88,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":1},"wind":{"speed":0.9,"deg":213},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-30 03:00:00"},{"dt":1606716000,"main":{"temp":277.36,"feels_like":275.23,"temp_min":277.36,"temp_max":277.36,"pressure":1028,"sea_level":1028,"grnd_level":1014,"humidity":89,"temp_kf":0},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"clouds":{"all":15},"wind":{"speed":0.79,"deg":232},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-30 06:00:00"},{"dt":1606726800,"main":{"temp":277.72,"feels_like":275.63,"temp_min":277.72,"temp_max":277.72,"pressure":1029,"sea_level":1029,"grnd_level":1015,"humidity":92,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":48},"wind":{"speed":0.94,"deg":194},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2020-11-30 09:00:00"},{"dt":1606737600,"main":{"temp":279.71,"feels_like":277.9,"temp_min":279.71,"temp_max":279.71,"pressure":1029,"sea_level":1029,"grnd_level":1015,"humidity":89,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":71},"wind":{"speed":0.94,"deg":225},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2020-11-30 12:00:00"},{"dt":1606748400,"main":{"temp":279.91,"feels_like":278.03,"temp_min":279.91,"temp_max":279.91,"pressure":1028,"sea_level":1028,"grnd_level":1014,"humidity":91,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":{"all":93},"wind":{"speed":1.19,"deg":234},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2020-11-30 15:00:00"},{"dt":1606759200,"main":{"temp":279.59,"feels_like":277.68,"temp_min":279.59,"temp_max":279.59,"pressure":1028,"sea_level":1028,"grnd_level":1015,"humidity":93,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":94},"wind":{"speed":1.23,"deg":271},"visibility":6135,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-30 18:00:00"},{"dt":1606770000,"main":{"temp":278.98,"feels_like":277.04,"temp_min":278.98,"temp_max":278.98,"pressure":1028,"sea_level":1028,"grnd_level":1015,"humidity":93,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":99},"wind":{"speed":1.1,"deg":235},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-11-30 21:00:00"},{"dt":1606780800,"main":{"temp":278.63,"feels_like":276.4,"temp_min":278.63,"temp_max":278.63,"pressure":1028,"sea_level":1028,"grnd_level":1014,"humidity":93,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":97},"wind":{"speed":1.42,"deg":235},"visibility":6816,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-12-01 00:00:00"},{"dt":1606791600,"main":{"temp":279.16,"feels_like":277.04,"temp_min":279.16,"temp_max":279.16,"pressure":1027,"sea_level":1027,"grnd_level":1014,"humidity":93,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":99},"wind":{"speed":1.41,"deg":226},"visibility":6748,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-12-01 03:00:00"},{"dt":1606802400,"main":{"temp":278.75,"feels_like":276.44,"temp_min":278.75,"temp_max":278.75,"pressure":1027,"sea_level":1027,"grnd_level":1013,"humidity":92,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":100},"wind":{"speed":1.52,"deg":225},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2020-12-01 06:00:00"},{"dt":1606813200,"main":{"temp":278.41,"feels_like":275.9,"temp_min":278.41,"temp_max":278.41,"pressure":1026,"sea_level":1026,"grnd_level":1013,"humidity":89,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":{"all":91},"wind":{"speed":1.6,"deg":187},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2020-12-01 09:00:00"},{"dt":1606824000,"main":{"temp":280.37,"feels_like":277.64,"temp_min":280.37,"temp_max":280.37,"pressure":1026,"sea_level":1026,"grnd_level":1012,"humidity":81,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":71},"wind":{"speed":2.07,"deg":208},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2020-12-01 12:00:00"},{"dt":1606834800,"main":{"temp":280,"feels_like":277.63,"temp_min":280,"temp_max":280,"pressure":1025,"sea_level":1025,"grnd_level":1011,"humidity":85,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":64},"wind":{"speed":1.64,"deg":201},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2020-12-01 15:00:00"}],"city":{"id":6691255,"name":"Haughton Green","coord":{"lat":53.4412,"lon":-2.0983},"country":"GB","population":9000,"timezone":0,"sunrise":1606377237,"sunset":1606406283}}
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 08:48pm 26 Nov 2020
Copy link to clipboard 
Print this post

I've wiped the SD card and started again with an older version of Stretch that I know works and Pi-Cromite 5.4.25 that I know works with this version of Stretch.

nothing I do works - it's driving me potty


Dim As integer d(1000)
DIM STRING q=Chr$(34) '" symbol
DIM icon$,icon1$,icon2$,icon3$
system "wget -q -O- "+q$+"https://api.openweathermap.org/data/2.5/forecast?q=Haughton%20Green,%20GB&appid=0e661c0eb78b1f4b28419346ab6159db"+q$,d()
'icon$=JSON$(d(),"list[0].weather[0].icon")
'icon1$=JSON$(d(),"list[0].weather[1].icon")
'icon2$=JSON$(d(),"list[1].weather[0].icon")
'icon3$=JSON$(d(),"list[1].weather[1].icon")
icon$=JSON$(d%(),"list[1].main.temp")'test to try
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 09:55am 27 Nov 2020
Copy link to clipboard 
Print this post

I got nowhere with the above so I tried something new again

Can anyone tell me why is returns an INTEGER and not a STRING? AND if the result what it's showing is correct

You can see where I tried it as a STRING and the result is below
Dim As integer d(1000)
DIM STRING q=Chr$(34) '" symbol
'prec$ = "9"
'print prec$
prec = 8
print prec
system "wget -q -O- "+q$+"https://api.openweathermap.org/data/2.5/onecall?lat=53.43&lon=-2.10&units=metric&exclude=current,hourly,daily&appid=0e661c0eb78b1f4b28419346ab6159db"+q$,d()
'prec$=val(JSON$(d(),"list[1].minutely[1].precipitation"))
prec=val(JSON$(d(),"list[1].minutely[1].precipitation"))
'longstring print d()
'if prec$ = "0" then icond$ = "null"
'print prec$
print prec



I need to know why it's doing it so I can have some hope of getting the other one to parse

This is longstring print d()
  Quote  {"lat":53.43,"lon":-2.1,"timezone":"Europe/London","timezone_offset":0,"minutely":[{"dt":1606469220,"precipitation":0},{"dt":1606469280,"precipitation":0},{"dt":1606469340,"precipitation":0},{"dt":1606469400,"precipitation":0},{"dt":1606469460,"precipitation":0},{"dt":1606469520,"precipitation":0},{"dt":1606469580,"precipitation":0},{"dt":1606469640,"precipitation":0},{"dt":1606469700,"precipitation":0},{"dt":1606469760,"precipitation":0},{"dt":1606469820,"precipitation":0},{"dt":1606469880,"precipitation":0},{"dt":1606469940,"precipitation":0},{"dt":1606470000,"precipitation":0},{"dt":1606470060,"precipitation":0},{"dt":1606470120,"precipitation":0},{"dt":1606470180,"precipitation":0},{"dt":1606470240,"precipitation":0},{"dt":1606470300,"precipitation":0},{"dt":1606470360,"precipitation":0},{"dt":1606470420,"precipitation":0},{"dt":1606470480,"precipitation":0},{"dt":1606470540,"precipitation":0},{"dt":1606470600,"precipitation":0},{"dt":1606470660,"precipitation":0},{"dt":1606470720,"precipitation":0},{"dt":1606470780,"precipitation":0},{"dt":1606470840,"precipitation":0},{"dt":1606470900,"precipitation":0},{"dt":1606470960,"precipitation":0},{"dt":1606471020,"precipitation":0},{"dt":1606471080,"precipitation":0},{"dt":1606471140,"precipitation":0},{"dt":1606471200,"precipitation":0},{"dt":1606471260,"precipitation":0},{"dt":1606471320,"precipitation":0},{"dt":1606471380,"precipitation":0},{"dt":1606471440,"precipitation":0},{"dt":1606471500,"precipitation":0},{"dt":1606471560,"precipitation":0},{"dt":1606471620,"precipitation":0},{"dt":1606471680,"precipitation":0},{"dt":1606471740,"precipitation":0},{"dt":1606471800,"precipitation":0},{"dt":1606471860,"precipitation":0},{"dt":1606471920,"precipitation":0},{"dt":1606471980,"precipitation":0},{"dt":1606472040,"precipitation":0},{"dt":1606472100,"precipitation":0},{"dt":1606472160,"precipitation":0},{"dt":1606472220,"precipitation":0},{"dt":1606472280,"precipitation":0},{"dt":1606472340,"precipitation":0},{"dt":1606472400,"precipitation":0},{"dt":1606472460,"precipitation":0},{"dt":1606472520,"precipitation":0},{"dt":1606472580,"precipitation":0},{"dt":1606472640,"precipitation":0},{"dt":1606472700,"precipitation":0},{"dt":1606472760,"precipitation":0},{"dt":1606472820,"precipitation":0}],"alerts":[{"sender_name":"Go to UK Met Office","event":"Yellow Fog Warning","start":1606420800,"end":1606478400,"description":"ches may lead to some travel disruption. Slower journey times with delays to bus and train services possible. There is a chance of delays or cancellations to flights"}]}


EDIT:

I also tried  prec=val(JSON$(d(),"minutely[1].precipitation")) and
prec$=val(JSON$(d(),"minutely[1].precipitation"))
Edited 2020-11-27 20:01 by lew247
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3649
Posted: 10:34am 27 Nov 2020
Copy link to clipboard 
Print this post

Instead of using VAL() what happens if you
PRINT JSON$(d(),"list[1].minutely[1].precipitation")

It may be (*) it's not a string, in which case VAL() would give the error it does.

* i.e. almost certainly

John
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 08:55pm 28 Nov 2020
Copy link to clipboard 
Print this post

It was something really stupid
I had to change one of the returned values from Integer to Float

This one (Hopefully) should be a lot easier

I need to get the first PROB value

I could use MID$ but I'm not certain that the length of the report will stay the same every day
It would be better if I could use FIELD$ or something similar but there are no commas

Is it possible to use spaces instead of commas using field$?

{"results":1,"data":["TAF AMD EGCC 282001Z 2820/2924 05003KT 8000 SCT010 TEMPO 2820/2918 3000 BR BKN008 PROB30 TEMPO 2903/2910 0300 FG BKN001 PROB30 TEMPO 2918/2924 0300 FG BKN001"]}

Edited 2020-11-29 06:56 by lew247
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5886
Posted: 09:45pm 28 Nov 2020
Copy link to clipboard 
Print this post

  Quote  Is it possible to use spaces instead of commas using field$?


Yes
  Quote  FIELD$( string1, nbr, string2 [, string3] )

Description:
Returns a particular field in a string with the fields separated by delimiters.
'nbr' is the field to return (the first is nbr 1). 'string1' is the string to search and 'string2' is a string holding the delimiters (more than one can be used).



I am not sure about on the RPi but I assume it's the same.

Jim
VK7JH
MMedit   MMBasic Help
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 08:26am 29 Nov 2020
Copy link to clipboard 
Print this post

Thanks  
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 04:54pm 29 Nov 2020
Copy link to clipboard 
Print this post

After that stupid one that I actually saw when I read the manual (twice) but it never registered
This final one has me really stumped
it should be dead simple
This is the json output
{"results":1,"data":[{"wind":{"degrees":0,"speed_kts":3,"speed_mph":3,"speed_mps":2,"speed_kph":6},"temperature":{"celsius":8,"fahrenheit":46},"dewpoint":{"celsius":8,"fahrenheit":46},"humidity":{"percent":100},"barometer":{"hg":30.3,"hpa":1026,"kpa":102.59,"mb":1025.92},"visibility":{"miles":"2 2.11","miles_float":2.11,"meters":"3,000","meters_float":3000},"ceiling":{"code":"OVC","text":"Overcast","feet":300,"meters":91,"base_feet_agl":300,"base_meters_agl":91},"elevation":{"feet":256,"meters":78},"location":{"coordinates":[-2.27495,53.353699],"type":"Point"},"icao":"EGCC","station":{"name":"Manchester Airport"},"raw_text":"EGCC 291620Z AUTO VRB03KT 3400 BR OVC003 08/08 Q1026","observed":"2020-11-29T16:20:00.000Z","flight_category":"LIFR","clouds":[{"code":"OVC","text":"Overcast","feet":300,"meters":91,"base_feet_agl":300,"base_meters_agl":91}],"conditions":[{"code":"BR","text":"Mist"}]}]}


Put in an easier to read format it's
  Quote  {"results":1,
"data":[{
"wind":{"degrees":0,"speed_kts":2,"speed_mph":2,"speed_mps":1,"speed_kph":4},
"temperature":{"celsius":8,"fahrenheit":46},
"dewpoint":{"celsius":8,"fahrenheit":46},
"humidity":{"percent":100},
"barometer":{"hg":30.3,"hpa":1026,"kpa":102.59,"mb":1025.92},
"visibility":{"miles":"2 2.67","miles_float":2.67,"meters":"4,000","meters_float":4000},
"ceiling":{"code":"OVC","text":"Overcast","feet":300,"meters":91,"base_feet_agl":300,"base_meters_agl":91},
"elevation":{"feet":256,"meters":78},
"location":{"coordinates":[-2.27495,53.353699],"type":"Point"},
"icao":"EGCC","station":{"name":"Manchester Airport"},
"raw_text":"EGCC 291550Z AUTO VRB02KT 4300 BR OVC003 08/08 Q1026","observed":"2020-11-29T15:50:00.000Z","flight_category":"LIFR","clouds":[{"code":"OVC","text":"Overcast","feet":300,"meters":91,"base_feet_agl":300,"base_meters_agl":91}],"conditions":[{"code":"BR","text":"Mist"}]}]}


I ONLY need the BAROMETER.MB field

ONE of these should have worked but they throw a fit and give this result
mb$=JSON$(c(),"data.barometer.mb")
mb$=JSON$(c(),"data[1]barometer.mb")
mb$=JSON$(c(),"data.barometer[1]mb")
mb$=JSON$(c(),"data[1]barometer[1]mb")
print mb$

Edited 2020-11-30 02:56 by lew247
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 05:17pm 29 Nov 2020
Copy link to clipboard 
Print this post

I really have been trying to understand why this won't work
I've even gone back to the manual in the hope it might help
  Quote  FIELD$( str$, field)or
FIELD$( str$, field, delim$)or
FIELD$( str$, field, delim$, quote$

PRINT FIELD$("aaa,bbb,ccc", 2, ",")Will print the string: bbb
PRINT FIELD$("text1, 'quoted, text', text3", 2, ",", "'")will print the string: 'quoted, text'


I really don't understand why they would print those strings from the examples given
Could anyone explain it to me in a simpler way that might help me figure out if I can use field$ to get the field I need?

json should have worked I really don't know why it isnt.
  Quote  JSON$(a%(), “name”)
JSON$(a%(), “coord.lat”)
JSON$(a%(), “weather[0].description”)
JSON$(a%(),”list[4].weather[0].description


IF I understand it right then mb$=JSON$(c%(),"list[1].barometer[0].mb") "SHOULD" work?
Edited 2020-11-30 03:25 by lew247
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 06:21pm 29 Nov 2020
Copy link to clipboard 
Print this post

This should even have worked
m=LINSTR(c(),q$+"barometer"+q$+":")+3
W1$=LGETSTR$(c(),m,255)
press$ = FIELD$(W1$,4)
print "press$"

barometer is the section it starts at
adds 4 fields starting with 0
FIELD$(Q1$,4) is the mb section?
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 09:09pm 30 Nov 2020
Copy link to clipboard 
Print this post

Does ANYONE know if there is a way to do this?

The code below works perfectly getting the high and low temperatures for today

I'd like to be able to get the next 10 days by using the "day_start_local" FIELD

Is there a way to do this or not?

It won't work with my code because it only stores the first 255 and I cannot get it do work the way I'd like to

Dim As integer c(15000)
DIM STRING q=Chr$(34) '" symbol
system "wget -q -O- "+q$+"https://swd.weatherflow.com/swd/rest/better_forecast?api_key=API-KEY&station_id=35102&lat=53.439&lon=-2.106"+q$,e()
 n=LINSTR(e(),q$+"daily"+q$+":[")+8  'ie skip over "daily":["
 forecastdeg$=LGETSTR$(e(),n,255)
 t1$ = FIELD$(forecastdeg$, 8)
 t2$ = FIELD$(forecastdeg$, 9)
 tl1$ = MID$(t2$, 16) 'Temp high Today
 th1$ = MID$(t1$, 17) 'Temp High Today


If you want to see what the full API call returns just click HERE
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3010
Posted: 09:28pm 30 Nov 2020
Copy link to clipboard 
Print this post

Why are you using e() when c() is defined? And why are you using FIELD which only allows for 255-character string input instead of JSON, which takes longstring?
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 09:50pm 30 Nov 2020
Copy link to clipboard 
Print this post

Sorry I copied the relevent bits out of the full program so it wouldn't fill this page with rubbish
I do have Dim As integer e(15000)

I had to use FIELD because I couldn't get JSON working no matter how much I tried
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 843
Posted: 10:17pm 30 Nov 2020
Copy link to clipboard 
Print this post

Hi Lewis,

The LINSTR command allows a third parameter, the start position of the search.
So you can start your search where you want.

So look for string "day_start_local" instead of "daily", do this repeatedly in a loop, but each time start the search a bit further on so you don't find the same one again.

lastn=1

n=LINSTR(e(),"day_start_local",lastn)+8  '
lastn=n+10    'just add enough to get past this one so you dont find it again.

Just loop around the last two commands  10 times to get the next ten day.
You need to adjust the offset as its no longer 8, more like 17 or something now.

regards
Gerry
Latest F4 Latest H7
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024