uRADMonitor API Charts

An example on how to use the uRADMonitor API calls

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dygraph/1.1.1/dygraph-combined.js"></script>
<body style="padding:10px;">

<!-- DEFINE SOME SIMPLE HTML CODE -->
<h3>uRADMonitor API example</h3>
<hr>
<div style="width:800px; padding: 10px;">
1. Select your unit<br>
<select class="form-control" id="units"></select><br>
2. Select your unit's sensor<br>
<select class="form-control" id="sensors"></select><br>
Status: <span id="status">Idle</span>
</div>
<br>
<div style='width:800px;height:400px;border-style: solid; border-width: 2px;' id="area"><span id="title"></span><div id="graphdiv" style='width:100%;height:350px;'></div>
</body>
</html>

JavaScript

// CONFIGURE HERE 
// Open the dashboard, www.uradmonitor.com/dashboard , to retrieve your user id and key 
var userid = "204"; // set a valid user id from the uRADMonitor Dashboard!
var userkey= "8cc846e55e322e4dc69aaa36522e188f";
var time = 24 * 3600; // last 24 hours of data

// HELPER FUNCTIONS FOR URADMONITOR API

	function getUnit(sensor) {
		switch (sensor) {
			case "temperature": return "°C";
			case "cpm": return "CPM";
			case "voltage": return "Volts";
			case "duty": return "‰";
			case "pressure": return "Pa";
			case "humidity": return "% RH";
			case "gas1": return "ppm";
			case "gas2": return "ppm";
			case "gas3": return "ppm";
			case "gas4": return "ppm";
			case "dust": return "mg/m³";
			case "co2" : return "ppm";
			case "ch2o" : return "ppm";
			case "pm25" : return "µg/m³";
			case "pm10" : return "µg/m³";
			case "noise" : return "dBA";
			case "voc" : return "voc";
		}
	}
	
	function downloadUnits(u) {
		$("#status").html('loading').css('color', 'magenta');
		$.ajax({
	    		type: 'GET',
    			url: "https://data.uradmonitor.com/api/v1/devices/userid/" + u ,
	    		dataType: 'json',
			success: function(data) { 
			    // status
			    if (Object.keys(data)[0] == 'error') 
			    	$("#status").html(data['error']).css('color', 'red');
				else 
					$("#status").html('Units ok').css('color', 'green');
			    // populate select
				$.each(data, function(key, value) {
					$('#units').append($("<option />").val(value['id']).text(value['id']));
				});
				// first trigger
				if (data.length > 0)
					$('#units').trigger('change');
			},
			async: true
		});
	}


	// populate sensors
	function downloadCapabilities(id, u, k) {
		$("#status").html('loading').css('color', 'magenta');
		$.ajax({
	    		type: 'GET',
    			url: "https://data.uradmonitor.com/api/v1/devices/" + id ,
	    		dataType: 'json',
	    		headers: { 'Content-Type' : 'text/plain', 'X-User-id': u, 'X-User-hash': k },
			success: function(data) {...