How does one download data now for real time


#1

Title says it all really, fed up of seeing 0 on home page

How does one download data now for real time display on website, was working when opensensors but not now


#2

Hi @smokie, probably the easiest way to get what you’re looking for is to go to https://airqualityegg.wickeddevice.com/download and fill out the form to get emailed with CSV data. You can then either plot that in your own tools, or you can drop the CSV file into the web tool we put up here at https://airqualityegg.wickeddevice.com/multiplot.

If you want to see real-time data plotted in the browser with a bit less flexibility, you should use https:// airqualityegg.wickeddevice.com/portal, log into that using Google Chrome (only browser supported right now, but we’re working on changing that).

If you haven’t already, you’ll need to Claim Your Egg. Under the side menu ‘hamburger’ in the upper left, click Explore Eggs, then click on the “My Eggs” segment in the middle top of the page, and then click on the big green plus sign in the lower right corner and enter the serial number and claim code. If it doesn’t show up under my Eggs, you may need to restart the browser and/or log out and back in (again we are working on fixes). Once it’s listed under “My Eggs” you can click on the Egg’s icon, and in the upper right hand corner of the page you can find an icon that looks like a heartbeat. Click it and you’ll see real-time graphs for that Egg. Clicking on “Change Duration” in the upper right hand corner on that page will let you change the time scale from 15 minutes to a week.

We’re hard at work making this whole experience a bit more streamlined, but one of those two methods should get you where you want to be.

If you want to integrate data onto your own website, currently I have created a lightweight API, and access to it is basically by request. You can read the docs at https://airqualityegg.wickeddevice.com/api-docs, and just let me know by emailing support at wickeddevice dot com if you are interested in that.


#3

OK, had a quick look baffled by this jwt Authorization vicatcu


#4

Would like to explore with you how to make it more accessible. Do you have any suggestions?


#5

An easy set up guide or perhaps a widget we could put on web site would be great


#6

Sorry for the long cycle in replying. You can think of JWT as a way to get an new “API key” (called a token in this context) on request using your username and password, and once you get one it’s good for a period of time. If you get an “Unauthorized” response from an API request, it generally means it’s time to request a fresh token. I want to lower the barrier to entry for this stuff, but it’s a balancing act of not compromising security and resiliency goals in the process.

Perhaps you can point me to an example of some other service that does what you want well so I can take a look at emulating / taking inspiration from a good approach rather than trying to invent it from soup to nuts?


#7

Do you have any sample php code to retrieve data using JWT, I’m stuck

3rd attempt email keeps bounced back


#8

Sure, I have some PHP experience and can try and help with that. Will have to wait till later today or tomorrow though. I can also just private message you your JWT token to get you started.


#9

Vicatcu, Made some progress today, got JWT working and data out using start and end dates, is it possible to just get last uploaded MQTT rather than a whole day or am I missing something


#10

Ya, I think I can probably come up with a way to do that… stay tuned.


#11

OK, cool … so I think I should be able to provide a specialized route for this relatively easily. I’ve made some adjustments to the data flows on the back end so that for each Egg I always have a representation of the last data that was sent by it for any particular sensor key. So the object you’ll get back is something like:

 { 
    "serial-number": "egg0080...",
    "temperature": { 
       "date": "ISO-8601 formatted timestamp like 2018-04-19T18:34:23Z"
       // ... normal temperature payload ... 
    },
    // ... etc. keys and payloads for any other sensors being reported by the egg ...
 }

And for the route, I was thinking something like
GET https://airqualityegg.wickeddevice.com/api/v1/most-recent/messages/device/:serial-number

Sound OK to you @smokie? I suspect I could have that running quite soon. I’ll report back.


#12

@smokie OK I think that’s actually working, let me know if it “answers the mail” or if you have ideas on how to make it more useful / usable. Cheers!


#13

Note, in case it impacts / impacted you, I just fixed it so it names the key “date” rather than “timestamp.”


#14

Yes, it works fine, just what i wanted, got to do some scripting to put readings online at the weekend.

When i first tried it kept coming back, not found, but is working now


#15

Done it, Online , check out my website, CO still shows zero

Which should I use “converted-value” or “compensated-value”, using converted-value

This might be a more difficult question, is it possible to include graphs on website to ?

Included link back to you as well


#16

Awesome, well done! Recommend using compensated-value generally. “Converted” value is mostly of diagnostic interest. I can certainly work on a graph image delivering API call, but that’s going to some work. Let me get back to you next week.

Zero may mean need to recalibrate / adjust baseline tables. You can use command “co_negz 0” (then “exit” and wait for Egg to connect to server before resetting) in Config Mode to allow the Egg to report negative values to get any idea how far its drifted negative. I want to update desktop application to let you adjust ppb of gas sensors, but knowing how much to adjust by is a pre-requisite. Topic for a different thread.

Also link to your website here so others can see?


#17

Website Link,

http://www.newquayweather.com/

Have changed to compensated-value

For others, just to get you started here’s my php code to get last message and save, then display code. I am only a novice so I’m sure it can be done better

 $cacheName="/home/xxxx/public_html/xxx/egg-cache.json"; // set to your website
 $jwt='your jwt token here';
 
// egg api call
 $url = 'https://airqualityegg.wickeddevice.com/api/v1/most-recent/messages/device/your  egg number '; // *** most recent mqtt upload

 $result=jwt_request($jwt, $url); // call function

// save for display
 file_put_contents($cacheName, $result);	


 function jwt_request($token, $ur) {

	$numberOfSeconds="5";
	$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $ur);                         // connect to provided URL

    curl_setopt($ch, CURLOPT_USERAGENT,  'Mozilla/5.0 (egg-fetch.php - newquayweather.com)');
       $authorization = "Authorization: Bearer ".$token; // **Prepare Autorisation Token**

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization )); // **Inject Token into Header**
    curl_setopt( $ch, CURLOPT_COOKIEFILE, 'cookiefile' );
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $numberOfSeconds);  //  connection timeout
    curl_setopt($ch, CURLOPT_TIMEOUT, $numberOfSeconds);         //  data timeout
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);              // return the data transfer

    curl_setopt($ch, CURLOPT_HEADER, 0);      // No headers returned with result
    $result = curl_exec($ch);
    //  $response = curl_getinfo( $ch );
    curl_close($ch);
    return $result;
 }

 // fetch is called by cron

 // display is done by loading file

 $jsondata = file_get_contents($eggfile);
 $data = json_decode($jsondata, true);

 echo $data['no2']['compensated-value'];