Skip to content

Commit

Permalink
Converting soil moisture to be a percentage out of 1023
Browse files Browse the repository at this point in the history
  • Loading branch information
mtlynch committed Jun 12, 2017
1 parent 81e6179 commit f7d5442
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions app/app.js
Expand Up @@ -25,9 +25,16 @@ greenPiThumbApp.controller('DashboardCtrl', function($scope, $http) {
lightHistory[lightHistory.length - 1].light;
});
$http.get('/soilMoistureHistory.json').success(function(moistureHistory) {
$scope.soilMoisture = moistureHistory;
// Convert raw soil moisture readings into a percentage (out of 1023).
$scope.soilMoisture = [];
moistureHistory.forEach(function(record) {
$scope.soilMoisture.push({
moisture: (record.soil_moisture / 1023.0) * 100.0,
timestamp: record.timestamp
});
});
$scope.latestSoilMoisture =
moistureHistory[moistureHistory.length - 1].soil_moisture;
$scope.soilMoisture[$scope.soilMoisture.length - 1].moisture;
});
$http.get('/images.json').success(function(images) {
$scope.images = [];
Expand Down
2 changes: 1 addition & 1 deletion app/app_test.js
Expand Up @@ -58,7 +58,7 @@ describe('greenPiThumbApp controller', function() {
expect(mockScope.latestTemperature).toEqual(25.0);
expect(mockScope.latestHumidity).toEqual(53.0);
expect(mockScope.latestLightLevel).toEqual(66.3);
expect(mockScope.latestSoilMoisture).toEqual(888.2);
expect(mockScope.latestSoilMoisture).toBeCloseTo(86.8, 1);
});

it('Creates full history variables', function() {
Expand Down
4 changes: 2 additions & 2 deletions app/index.html
Expand Up @@ -52,7 +52,7 @@ <h1>Current Readings</h1>
</tr>
<tr>
<td>Soil Moisture</td>
<td>{{ latestSoilMoisture | number:0 }}</td>
<td>{{ latestSoilMoisture | number:1 }}%</td>
</tr>
</table>
<div class="row cameraImage" id="camera">
Expand Down Expand Up @@ -89,7 +89,7 @@ <h3>Ambient Humidity</h3>
<h3>Ambient Light</h3>
<line-graph chart-data="lightLevel" value-property="light"></line-graph>
<h3>Soil Moisture</h3>
<line-graph chart-data="soilMoisture" value-property="soil_moisture"></line-graph>
<line-graph chart-data="soilMoisture" value-property="moisture"></line-graph>
</div>
<div class="row" id="about">
<h1>About</h1>
Expand Down

0 comments on commit f7d5442

Please sign in to comment.