|
Forum Index : Microcontroller and PC projects : PC3 - OpenWeather Forecasts
| Author | Message | ||||
| Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 908 |
Hi There, I am trying to use my PC3 to access OpenWeather forecasts. I'm using version 7.000008 HDMIUSB. I've done it before with my PicoW1 which reliably gets 8, 4-hr forecasts (using older firmware versions). In the code below (only a test snippet), by varying the value of CNT, I 'rarely' get 8, 'sometimes' 4, and 'usually' 2 forecast periods. It does vary! When it fails it has omitted some of the lead-in text and text after "ground_lev". I've previously used much smaller buffer for m%() but increasing it here 'appears' to help?? The PAUSEs dont seem to do anything? Any suggestions/better code? Cheers, Andrew 'Get_Forecast Check v2.bas OPTION EXPLICIT OPTION DEFAULT NONE Dim Integer TZone = 10, DST = 1, II DIM string ID$ = "7932628" 'Kew East Dim string APIKEY$ = "****. . ." dim integer CNT = 8 'No of x4 hr time periods requested in forecast. 8 = 24hrs Dim INTEGER m%(2048*3) 'm% should be a multiple of 8 Dim string b$ b$ = "GET /data/2.5/forecast?id="+ID$+"&APPID="+APIKEY$+"&units=metric"+"&cnt="+STR$(CNT)+Chr$(10)+Chr$(13) longstring CLEAR m%() WEB NTP Tzone+DST,"au.pool.ntp.org" pause 1000 WEB OPEN TCP CLIENT "api.openweathermap.org", 80 WEB TCP CLIENT REQUEST b$,m%() pause 1000 LongString print m%() print "Site ";JSON$(m%(),"city.name") print "Sunset ";json$(m%(),"city.sunset") print "CNT ";json$(m%(),"CNT") for II = 0 to 8 print json$(m%(),"list["+str$(II)+"].wind.deg") next II WEB CLOSE TCP CLIENT end Edited 2026-10-25 10:16 by Andrew_G |
||||
TassyJim![]() Guru Joined: 07/08/2011 Location: AustraliaPosts: 6629 |
I get a json string 3534 bytes long. If you take the last 1460 bytes and move them to the beginning of the string, you will have working json data It looks like packets out of order or a ring buffer got lost. Tested with WEBMITE and HDMIWEB V7 RC5 Jim VK7JH MMedit |
||||
| Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 908 |
Hi Jim, Thanks. Are you able to capture a LONGSTRING PRINT of a typical full lot of data. (MMCC can help . . .) I'm using similar hardware with RC8. Cheers, Andrew |
||||
TassyJim![]() Guru Joined: 07/08/2011 Location: AustraliaPosts: 6629 |
Yes , provided you have wordwrap on, MMCC can capture the full longstring. Email sent. First string is with the wrong sequence. second string has it 'fixed' but not tested. Jim VK7JH MMedit |
||||
TassyJim![]() Guru Joined: 07/08/2011 Location: AustraliaPosts: 6629 |
'Get_Forecast Check v2.bas OPTION EXPLICIT OPTION DEFAULT NONE Dim Integer TZone = 10, DST = 1, II DIM string ID$ = "7932628" 'Kew East Dim string APIKEY$ = "xxxxxxxxxxxxxxxxx" dim integer CNT = 8 'No of x4 hr time periods requested in forecast. 8 = 24hrs Dim INTEGER m%(576*8) 'm% should be a multiple of 8 dim integer k%(576*8) Dim string b$ b$ = "GET /data/2.5/forecast?id="+ID$+"&APPID="+APIKEY$+"&units=metric"+"&cnt="+STR$(CNT)+Chr$(10)+Chr$(13) longstring CLEAR m%() WEB NTP Tzone+DST,"au.pool.ntp.org" pause 1000 WEB OPEN TCP CLIENT "api.openweathermap.org", 80 'print b$ WEB TCP CLIENT REQUEST b$,m%() ',3000 pause 1000 print llen(m%()) LongString print m%() longstring right k%(),m%(),1460 longstring concat k%(),m%() print "Site ";JSON$(k%(),"city.name") print "Sunset ";json$(k%(),"city.sunset") print "CNT ";json$(k%(),"CNT") for II = 0 to 8 print json$(k%(),"list["+str$(II)+"].wind.deg") next II WEB CLOSE TCP CLIENT memory end Crude fix to reorder the json string Jim VK7JH MMedit |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |