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 KingdomPosts: 1676 |
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 Edited 2020-11-27 00:03 by lew247 |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3010 |
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 KingdomPosts: 1676 |
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 KingdomPosts: 1676 |
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 StatesPosts: 3010 |
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 KingdomPosts: 1676 |
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 |
||||
lew247 Guru Joined: 23/12/2015 Location: United KingdomPosts: 1676 |
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 KingdomPosts: 1676 |
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() 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 KingdomPosts: 3649 |
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 KingdomPosts: 1676 |
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: AustraliaPosts: 5886 |
Yes 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 KingdomPosts: 1676 |
Thanks |
||||
lew247 Guru Joined: 23/12/2015 Location: United KingdomPosts: 1676 |
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 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 KingdomPosts: 1676 |
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 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. 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 KingdomPosts: 1676 |
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 KingdomPosts: 1676 |
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 StatesPosts: 3010 |
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 KingdomPosts: 1676 |
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: AustraliaPosts: 843 |
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 |