![]() |
Forum Index : Microcontroller and PC projects : Mind gone blank
Author | Message | ||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
So I've come back to MM after a break in hospital again and I've bought a Weatherflow Weather station This has a really nice display for my phone and computer but I want to incorporate the results into my Pi-Cromite weather display I made previously I cannot figure out how to get the parsing that I need from it. There are 2 modules both giving readings This is the output from one {"status":{"status_code":0,"status_message":"SUCCESS"},"device_id":35102,"type":"obs_air","source":"cache","summary":{"pressure_trend":"falling","strike_count_3h":0,"strike_last_dist":63,"strike_last_epoch":1570638805,"feels_like":21.5,"heat_index":21.5,"wind_chill":21.5},"obs":[[1580039238,991.1,21.5,55,0,0,2.75,1]]} This is the meanings Air (type="obs_air") Observation Layout 0 - Epoch (seconds UTC) 1 - Station Pressure (MB) 2 - Air Temperature (C) 3 - Relative Humidity (%) 4 - Lightning Strike Count 5 - Lightning Strike Average Distance (km) 6 - Battery (volts) 7 - Report Interval (minutes) What I actually need to use is the Pressure, Temp, Humidity, and Battery Volts 1,2,3 and 6 in the list Any ideas how I can get them from the readout? Also the 2nd module gives this readout {"status":{"status_code":0,"status_message":"SUCCESS"},"device_id":35103,"type":"obs_sky","source":"cache","summary":{"precip_total_1h":0.319429,"precip_accum_local_yesterday":0.0,"precip_analysis_type_yesterday":0},"obs":[[1580039179,2981,0.16,0,0,1.12,2.5,233,3.24,1,24,0.903418,0,15,null,null,0]]} The meanings are this Sky (type="obs_sky") Observation Layout 0 - Epoch (seconds UTC) 1 - Illuminance (lux) 2 - UV (index) 3 - Rain Accumulation (mm) 4 - Wind Lull (m/s) 5 - Wind Avg (m/s) 6 - Wind Gust (m/s) 7 - Wind Direction (degrees) 8 - Battery (volts) 9 - Report Interval (minutes) 10 - Solar Radiation (W/m^2) 11 - Local Day Rain Accumulation (mm) 12 - Precipitation Type (0 = none, 1 = rain, 2 = hail) 13 - Wind Sample Interval (seconds) 14 - Rain Accumulation Final (Rain Check) (mm) 15 - Local Day Rain Accumulation Final (Rain Check) (mm) 16 - Precipitation Analysis Type (0 = none, 1 = Rain Check with user display on, 2 = Rain Check with user display off) What I'd lik,e to use is 1, 2, 5, 6, 7, 8, 11 Lux,UV,Wind average, Wind Gust, Wind direction, battery, and rain accumulation This is my code to get the information system "wget -q -O- "+p$+"https://swd.weatherflow.com/swd/rest/observations/device/35103?api_key=insertkeyhere"+p$,e() (and device 35102) and the above printouts are whats shown when I do longstring PRINT e() Normally I would use something like prob$=JSON$(a(),"currently.precipProbability")'Chance of Rain/Snow 'prob$ = str$(val(prob$)*100) hum1$=JSON$(a(),"currently.humidity")'humidity hum1$ = str$(val(hum1$)*100) press1$=JSON$(a(),"currently.pressure")'pressure prs1tmp = val(press1$) uv2$=JSON$(a(),"currently.uvIndex")'uv index uv=Val(uv2$) uv2$=Str$(uv) vis$=JSON$(a(),"currently.visibility")'visibility but in this case I have no idea how to specify which part of the readout means what Any clues suggestions or ideas? Edited 2020-01-26 22:09 by lew247 |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
I don't have anything to test the json part but you should be able to get the obs data and then extract each individual part as required. The PI might have a more elegant way of retrieving the individual fields but this works OK Jim VK7JH MMedit |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Unfortunately that didn't work I tried it many different ways I think the issue may be that where you have getObs "1580039179,2981,0.16,0,0,1.12,2.5,233,3.24,1,24,0.903418,0,15,null,null,0" and getObs "1580039238,991.1,21.5,55,0,0,2.75,1" That won't exist the first set of numbers are the epoch settings when the reading is taken and all the other numbers change as well What I ideally need to do is to be able to comma seperated values after the word "obs":[[ |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
What do you get from obs$=JSON$(e(),"obs") That should get the required data with the enclosing square braces. If you don't need the first and last values, you can ignore the braces or you may have to remove them. Start by seeing if you can use json to get the complete string of data. Jim VK7JH MMedit |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
This is the section of code that calls the information system "wget -q -O- "+p$+"https://swd.weatherflow.com/swd/rest/observations/device/35103?api_key=20c70eae-e62f-4d3b-b3a4-8586e90f3ac8"+p$,e() 'longstring PRINT e() ' print weather to test it works* obs$=JSON$(e(),"obs") print obs$ This is the result ![]() If I uncomment out the longstring print e() and comment out the print obs$ I get this ![]() |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
I can't help with the correct JSON code so this is a way to do it without JSON. It assumes that there is only one field with '[[' in it and that is the last field. DIM e%(100) DIM f%(100) DIM allObs$(16) j1$ ="{"+CHR$(34)+"status"+CHR$(34)+":{"+CHR$(34)+"status_code"+CHR$(34)+":0,"+CHR$(34)+"status_message"+CHR$(34)+":"+CHR$(34)+"SUCCESS"+CHR$(34) j2$ ="},"+CHR$(34)+"device_id"+CHR$(34)+":35102,"+CHR$(34)+"type"+CHR$(34)+":"+CHR$(34)+"obs_air"+CHR$(34)+","+CHR$(34)+"source"+CHR$(34)+":" j3$ =CHR$(34)+"cache"+CHR$(34)+","+CHR$(34)+"summary"+CHR$(34)+":{"+CHR$(34)+"pressure_trend"+CHR$(34)+":"+CHR$(34)+"falling"+CHR$(34)+"," j4$ =CHR$(34)+"strike_count_3h"+CHR$(34)+":0,"+CHR$(34)+"strike_last_dist"+CHR$(34)+":63,"+CHR$(34)+"strike_last_epoch"+CHR$(34)+":1570638805," j5$ =CHR$(34)+"feels_like"+CHR$(34)+":21.5,"+CHR$(34)+"heat_index"+CHR$(34)+":21.5,"+CHR$(34)+"wind_chill"+CHR$(34)+":21.5},"+CHR$(34)+"obs" j6$ =CHR$(34)+":[[1580039238,991.1,21.5,55,0,0,2.75,1]]}" ' ' k1$ ="{"+CHR$(34)+"status"+CHR$(34)+":{"+CHR$(34)+"status_code"+CHR$(34)+":0,"+CHR$(34)+"status_message"+CHR$(34)+":"+CHR$(34)+"SUCCESS" k2$ =CHR$(34)+"},"+CHR$(34)+"device_id"+CHR$(34)+":35103,"+CHR$(34)+"type"+CHR$(34)+":"+CHR$(34)+"obs_sky"+CHR$(34)+","+CHR$(34)+"source" k3$ =CHR$(34)+":"+CHR$(34)+"cache"+CHR$(34)+","+CHR$(34)+"summary"+CHR$(34)+":{"+CHR$(34)+"precip_total_1h"+CHR$(34)+":0.319429," k4$ =CHR$(34)+"precip_accum_local_yesterday"+CHR$(34)+":0.0,"+CHR$(34)+"precip_analysis_type_yesterday"+CHR$(34)+":0},"+CHR$(34)+"obs" k5$ =CHR$(34)+":[[1580039179,2981,0.16,0,0,1.12,2.5,233,3.24,1,24,0.903418,0,15,null,null,0]]}" LONGSTRING APPEND e%(),j1$ LONGSTRING APPEND e%(),j2$ LONGSTRING APPEND e%(),j3$ LONGSTRING APPEND e%(),j4$ LONGSTRING APPEND e%(),j5$ LONGSTRING APPEND e%(),j6$ LONGSTRING APPEND f%(),k1$ LONGSTRING APPEND f%(),k2$ LONGSTRING APPEND f%(),k3$ LONGSTRING APPEND f%(),k4$ LONGSTRING APPEND f%(),k5$ LONGSTRING PRINT e%() ' just to check that we have a valid longstring LONGSTRING PRINT f%() p = LINSTR(e%(),"[[")+2 ' find just past the square braces obs$ = lgetstr$(e%(),p,100) ' extract the rest of the longstring into a normal string obs$ = LEFT$(obs$,LEN(obs$)-3) ' and trim the last 3 characters PRINT obs$ getObs obs$ FOR p = 0 TO 16 PRINT p," ",allobs$(p) NEXT p p = LINSTR(f%(),"[[")+2 obs$ = lgetstr$(f%(),p,100) obs$ = LEFT$(obs$,LEN(obs$)-3) PRINT obs$ getObs obs$ FOR p = 0 TO 16 PRINT p," ",allobs$(p) NEXT p SUB getObs obs$ FOR p = 0 TO 16 ' clear any old readings allObs$(p) = "" NEXT p p = 1 k = 0 DO c= INSTR(p,obs$,",") IF c = 0 THEN c = LEN(obs$) ' last field allObs$(k) = MID$(obs$,p,c-p) p = c+1 k = k+1 LOOP UNTIL c = LEN(obs$) END SUB I can't use wget to fill the array so I did that by joining normal data. Jim VK7JH MMedit |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Getting a lot further ![]() ![]() EDIT: It's not reading the data received - it's only showing J1$ to k5$ I tested this by removing the get data line and it's showing the same results This is the readings once I put the get data line in again and I told it to longprint e() ![]() Edited 2020-01-29 20:40 by lew247 |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Not sure if this will help or not but this is the help page for the API https://weatherflow.github.io/SmartWeather/api/ Edited 2020-01-29 20:44 by lew247 |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
You mention longprint e() Is it e() or e%() Based on your initial post, I used e%() but you may have to change it to e() in your code. VK7JH MMedit |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |