Group Abstract Group Abstract

Message Boards Message Boards

Reading high resolution weather data from Netatmo

POSTED BY: Marco Thiel
9 Replies
Posted 4 years ago

Hi, have you by chance updated the data preparation aka formula behind tab....it seems they have completely reworked the results. I managed to get the data but I'm not able to use the date because the tab gives me an empty list. Thank you...nice work.

POSTED BY: Andreas Nold

Apparently I missed this post, great work! Lots of data to play with!

POSTED BY: Sander Huisman
Posted 8 years ago

Is that grant _type rather than granttype? curl -X POST -d "granttype=password&clientid=AAAAAAAAAAAAAAAAAAAA&clientsecret=BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB &username=XXXXXXXXXXXXXXXX&password=YYYYYYYYYYYYYYY&scope=readstation" http://api.netatmo.net/oauth2/token ~/Desktop/request-token.txt

I'm getting invalid client responses, any thoughts as to what could be wrong ?

Thanks Ian

POSTED BY: Ian Neild

Dear Ian,

yes you are right. They changed the oauth protocol. You might want to try this:

This generates the key should you need one.

Run["~/Desktop/getNetatmokeyblog.sh > ~/Desktop/keys.txt"];
keysfile = Import["~/Desktop/keys.txt"];
accesstoken = StringSplit[StringSplit[keysfile, "\":\""][[2]], "\""][[1]];

Note that you need a terminal script. Here it is:

curl -X POST -d "grant_type=password&client_id=<clientidhere>&client_secret=<secrethere>&username=<usernamehere>&password=<passwordhere>scope=read_station" https://api.netatmo.com/oauth2/token

This needs to go into a script file - do not forget to substitute the respective parts including the "< >". I use OSX so it goes in an sh file and I need to make that executable. I changed to a script version, because I use this in public lectures and was not too happy to put my password and id directly on the slides. Of course you can execute that command "by hand" and use the accesstoken in the following. Here's how to get the data:

data = Import[
   "https://api.netatmo.com/api/getpublicdata?access_token=" <> 
    accesstoken <> 
    "&lat_ne=59.91&lon_ne=13.75&lat_sw=40.42&lon_sw=-20.0&filter=\
True", "Text"];
tab = Quiet[
   Select[Select[
     Table[ToExpression /@ 
       Flatten[StringSplit[#, "]"] & /@ StringSplit[#, "["] & /@ 
          If[Length[
             StringSplit[StringSplit[data, "place"][[k]], ","]] > 12, 
           Drop[StringSplit[StringSplit[data, "place"][[k]], 
             ","], {5}], 
           StringSplit[StringSplit[data, "place"][[k]], ","]]
         ][[{2, 3, 7, 8, 15}]], {k, 2, 
       Length[StringSplit[data, "place"]]}], 
     Length[Cases[Flatten[#], $Failed]] == 0 &  ], Length[#] == 5 &]];

This is how to plot it.

scaled = Rescale[tab[[All, 3]]]; GeoGraphics[
 Table[{GeoStyling[Opacity[0.99], 
    RGBColor[scaled[[k]], 1 - scaled[[k]], 0]], 
   GeoDisk[{tab[[k, 2]], tab[[k, 1]]}, 
    Quantity[20, "Kilometers"] ]}, {k, 1, Length[tab]}], 
 GeoBackground -> "Satellite", ImageSize -> Large]

enter image description here

This should work with their new system.

Cheers,

Marco

POSTED BY: Marco Thiel
Posted 8 years ago

Thanks Marco, so I tried again, NB you need a & before that scope so

curl -X POST -d "granttype=password&clientid=<clientidhere>&clientsecret=<secrethere>&username=<usernamehere>&password=<passwordhere>&scope=readstation" https://api.netatmo.com/oauth2/token

but I get "invalid_grant"

my post is like curl -X POST -d "granttype=password&clientid=AAAAAA&clientsecret=BBBBBB&username=user+extra@ISP.com&password=XXXX&scope=readstation" https://api.netatmo.com/oauth2/token

could it be the + I use in my email address

POSTED BY: Ian Neild

Great example! How would the initial setup with credentials look if you used the new functions in 11? That is HTTPRequest and URLRead? I want to read the data from a cloud process and I am getting stuck with how to set up this part only using Wolfram

POSTED BY: Fredrik Doberl

Dear Frederik,

yes, I can use the build in functionality to get the access key too. It's quite straight forward to sent a POST command. I will try to update this later.

Best wishes, Marco

POSTED BY: Marco Thiel

enter image description here - another post of yours has been selected for the Staff Picks group, congratulations !

We are happy to see you at the tops of the "Featured Contributor" board. Thank you for your wonderful contributions, and please keep them coming!

POSTED BY: EDITORIAL BOARD

I think this would make a perfect data source for the Data Drop. I wish I could put my hands on this device. Relevant: Build Your Own Weather Station in a Snap with the Wolfram Cloud! Great post Marco!

POSTED BY: Sam Carrettie
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard