45 Commits

Author SHA1 Message Date
66442bf4de fixed a bug in rendering the correct picture, due to changes of multiple levels 2016-06-19 00:59:25 +02:00
78f052a664 - failed temp and humidity reading wont prevent data sending
- printing of water level
2016-06-12 12:03:19 +02:00
Senad Uka
8fc028aaab fixed duplicate controller folder 2016-06-11 18:56:47 +02:00
Senad Uka
cc7aebc6f9 Merge pull request #23 from senaduka/config_pumping_levels_and_draining_period
Config pumping levels and draining period
2016-06-10 10:01:39 +02:00
e5d4c820d6 set both start and stop pumping levels by default to full 2016-06-09 21:56:26 +02:00
cfd7d677dd deleted draining period and amount from config file as this does not work like i thought it would 2016-06-09 20:56:42 +02:00
4872f4a910 expanded the water levels to be used to configure pumping levels and moved the water draining period to config file 2016-06-09 20:07:38 +02:00
Senad Uka
5c1f1629e7 Update __init__.py
removing canceling shutdown
2016-06-08 18:50:32 +02:00
46af39c7af Update README.md
changed the crontab info in means of changing
*/15 * * * * /usr/bin/python /home/pi/projects/tfm/controller/sensors.py "Automatski, Senad Uka" 120
*/1 * * * * /usr/bin/python /home/pi/projects/tfm/controller/sync_state.py "Automatski, Senad Uka" 120
to 
*/5 * * * * cd /home/pi/projects/tfm/controller && sh activity.sh
2016-06-08 13:18:08 +02:00
bcb84e4400 Update copy__init__.py.example 2016-06-08 13:12:36 +02:00
79651cb6af Merge pull request #22 from senaduka/local_safe_autonomy
Local safe autonomy
2016-06-08 11:15:04 +02:00
Senad Uka
bffab2bf26 Merge pull request #17 from senaduka/shell_script_to_unify_activities
created activity.sh to unify all activities in a specific order
2016-06-08 11:14:33 +02:00
Senad Uka
718968f57d readme 2016-06-08 10:45:32 +02:00
Senad Uka
f1d7232c10 network check script 2016-06-08 10:34:05 +02:00
Senad Uka
fec689a5bc dweet fix again 2016-06-08 10:03:17 +02:00
Senad Uka
533135013b dweet fix again 2016-06-08 10:01:55 +02:00
Senad Uka
e0e0f0d24c dweet fix 2016-06-08 09:48:36 +02:00
Senad Uka
b30af162a1 reboot time 2016-06-08 09:38:54 +02:00
Senad Uka
c11e6b29b1 dweet exception 2016-06-08 09:31:51 +02:00
Senad Uka
d2a2fae936 dweet source code 2016-06-08 09:30:06 +02:00
Senad Uka
a12a218e85 reboot canceling 2016-06-08 09:28:42 +02:00
Senad Uka
f8a8284944 added dweet and reboot 2016-06-08 09:16:44 +02:00
Senad Uka
f9defb8e2a fixed syntax error 4 2016-06-08 08:39:31 +02:00
Senad Uka
5ae36641a2 fixed syntax error 3 2016-06-08 08:31:58 +02:00
Senad Uka
62f9cabb83 fixed syntax error 2 2016-06-08 08:31:42 +02:00
Senad Uka
91027c5330 fixed syntax error 2016-06-08 08:28:48 +02:00
Senad Uka
7d434625ca Local autonomy test 1 2016-06-08 08:24:43 +02:00
Senad Uka
61bb6d0d4b Merge pull request #21 from senaduka/multipleWaterLevelSensors
Multiple level sensors added
2016-06-05 11:14:25 +02:00
1ae13f6fb1 Multiple level sensors added 2016-06-02 23:13:42 +02:00
db843163f2 Merge pull request #20 from senaduka/last_fill_time
Disabled temperature graph
2016-05-17 16:12:53 +02:00
Senad Uka
d2db89ffc0 Disabled temperature graph 2016-05-17 07:05:54 +02:00
336b82be3f Merge pull request #19 from senaduka/last_fill_time
Added last valve open time
2016-05-08 06:06:31 +02:00
Senad Uka
ac76654e2a Added last valve open time 2016-05-08 05:17:12 +02:00
2772baafbc Merge pull request #18 from senaduka/add_low_temperature
Lower temperature forecast
2016-05-02 18:13:22 +02:00
Senad Uka
3e0733bf3d Lower temperature forecast 2016-05-02 18:10:54 +02:00
Senad Uka
d9fa0bf2f5 Calculator done 2016-05-02 15:18:02 +02:00
Senad Uka
abff71ac06 Calculator done 2016-05-02 14:09:09 +02:00
90e43b8bd2 created activity.sh to unify all activities in a specific order 2016-04-23 14:32:31 +00:00
Senad Uka
5a4fdbbd00 reversed logic 2016-04-10 12:11:54 +02:00
Senad Uka
96c67a6d00 gitignore 2016-04-10 11:58:18 +02:00
Senad Uka
3b8fb3dce4 fixed bug with rpio 2016-04-10 11:57:13 +02:00
0b4a886de6 Merge pull request #16 from senaduka/add_weather_again
weather works
2016-04-10 10:56:23 +02:00
Senad Uka
79df9d05b4 weather works 2016-04-10 10:47:11 +02:00
4df30c3523 Merge pull request #15 from senaduka/graph_fixing
FIxed graphs / inverted the tankFull bit!
2016-04-09 09:48:02 +02:00
Senad Uka
f886530f5f upgraded mongo and packages 2016-04-09 07:51:11 +02:00
32 changed files with 567 additions and 147 deletions

3
.gitignore vendored
View File

@@ -58,3 +58,6 @@ docs/_build/
# PyBuilder
target/
# meteor
app.tar.gz

View File

@@ -10,3 +10,4 @@ notices-for-facebook-graph-api-2
1.2.0-meteor-platform-split
1.2.0-cordova-changes
1.2.0-breaking-changes
1.3.0-split-minifiers-package

View File

@@ -12,7 +12,6 @@ session # Client-side reactive dictionary for your app
jquery # Helpful client-side library
tracker # Meteor's client-side reactive programming library
standard-minifiers # JS/CSS minifiers run for production mode
es5-shim # ECMAScript 5 compatibility for older browsers.
ecmascript # Enable ECMAScript2015+ syntax in app code
@@ -27,3 +26,5 @@ rzymek:moment-locale-bs
peppelg:bootstrap-3-modal
fortawesome:fontawesome
mfpierre:chartist-js
standard-minifier-css
standard-minifier-js

View File

@@ -1 +1 @@
METEOR@1.2.1
METEOR@1.3.1

View File

@@ -1,92 +1,95 @@
accounts-base@1.2.2
accounts-password@1.1.4
accounts-base@1.2.5
accounts-password@1.1.7
allow-deny@1.0.3
amplify@1.0.0
autoupdate@1.2.4
babel-compiler@5.8.24_1
babel-runtime@0.1.4
base64@1.0.4
binary-heap@1.0.4
blaze@2.1.3
blaze-html-templates@1.0.1
blaze-tools@1.0.4
boilerplate-generator@1.0.4
caching-compiler@1.0.0
caching-html-compiler@1.0.2
callback-hook@1.0.4
check@1.1.0
coffeescript@1.0.11
ddp@1.2.2
ddp-client@1.2.1
ddp-common@1.2.2
ddp-rate-limiter@1.0.0
ddp-server@1.2.2
deps@1.0.9
diff-sequence@1.0.1
ecmascript@0.1.6
ecmascript-runtime@0.2.6
ejson@1.0.7
email@1.0.8
es5-shim@4.1.14
fastclick@1.0.7
autoupdate@1.2.7
babel-compiler@6.6.1
babel-runtime@0.1.7
base64@1.0.7
binary-heap@1.0.7
blaze@2.1.6
blaze-html-templates@1.0.3
blaze-tools@1.0.7
boilerplate-generator@1.0.7
caching-compiler@1.0.3
caching-html-compiler@1.0.5
callback-hook@1.0.7
check@1.1.3
coffeescript@1.0.16
ddp@1.2.4
ddp-client@1.2.4
ddp-common@1.2.4
ddp-rate-limiter@1.0.3
ddp-server@1.2.5
deps@1.0.11
diff-sequence@1.0.4
ecmascript@0.4.2
ecmascript-runtime@0.2.9
ejson@1.0.10
email@1.0.11
es5-shim@4.5.9
fastclick@1.0.10
fortawesome:fontawesome@4.5.0
fourseven:scss@3.4.1
geojson-utils@1.0.4
handlebars@1.0.4
hot-code-push@1.0.0
html-tools@1.0.5
htmljs@1.0.5
http@1.1.1
huttonr:bootstrap3@3.3.6_6
huttonr:bootstrap3-assets@3.3.6_2
id-map@1.0.4
jquery@1.11.4
json@1.0.3
launch-screen@1.0.4
less@2.5.1
livedata@1.0.15
localstorage@1.0.5
logging@1.0.8
meteor@1.1.10
meteor-base@1.0.1
geojson-utils@1.0.7
hot-code-push@1.0.3
html-tools@1.0.8
htmljs@1.0.8
http@1.1.4
huttonr:bootstrap3@3.3.6_10
huttonr:bootstrap3-assets@3.3.6_3
id-map@1.0.6
jquery@1.11.7
launch-screen@1.0.10
less@2.5.7
livedata@1.0.17
localstorage@1.0.8
logging@1.0.11
meteor@1.1.13
meteor-base@1.0.3
mfpierre:chartist-js@1.6.1
minifiers@1.1.7
minimongo@1.0.10
mobile-experience@1.0.1
mobile-status-bar@1.0.6
momentjs:moment@2.11.2
mongo@1.1.3
mongo-id@1.0.1
nimble:restivus@0.8.7
minifier-css@1.1.10
minifier-js@1.1.10
minimongo@1.0.13
mobile-experience@1.0.3
mobile-status-bar@1.0.11
modules@0.5.2
modules-runtime@0.6.2
momentjs:moment@2.12.0
mongo@1.1.6
mongo-id@1.0.3
nimble:restivus@0.8.10
npm-bcrypt@0.7.8_2
npm-mongo@1.4.39_1
observe-sequence@1.0.7
ordered-dict@1.0.4
npm-mongo@1.4.42
observe-sequence@1.0.10
ordered-dict@1.0.6
peppelg:bootstrap-3-modal@1.0.4
percolate:synced-cron@1.3.0
promise@0.5.1
random@1.0.5
rate-limit@1.0.0
reactive-dict@1.1.3
reactive-var@1.0.6
reload@1.1.4
retry@1.0.4
routepolicy@1.0.6
percolate:synced-cron@1.3.2
promise@0.6.6
random@1.0.8
rate-limit@1.0.3
reactive-dict@1.1.6
reactive-var@1.0.8
reload@1.1.7
retry@1.0.6
routepolicy@1.0.9
rzymek:moment-locale-bs@2.9.0
selaias:meteor-simpleweather@0.6.8
service-configuration@1.0.5
session@1.1.1
sha@1.0.4
simple:json-routes@2.0.1
spacebars@1.0.7
spacebars-compiler@1.0.7
srp@1.0.4
standard-minifiers@1.0.2
templating@1.1.5
templating-tools@1.0.0
tracker@1.0.9
selaias:meteor-simpleweather@0.7.0
service-configuration@1.0.8
session@1.1.4
sha@1.0.6
simple:json-routes@2.1.0
spacebars@1.0.10
spacebars-compiler@1.0.10
srp@1.0.7
standard-minifier-css@1.0.5
standard-minifier-js@1.0.5
templating@1.1.8
templating-tools@1.0.3
tracker@1.0.12
u2622:persistent-session@0.4.4
ui@1.0.8
underscore@1.0.4
url@1.0.5
webapp@1.2.3
webapp-hashing@1.0.5
ui@1.0.10
underscore@1.0.7
url@1.0.8
webapp@1.2.7
webapp-hashing@1.0.8

Binary file not shown.

View File

@@ -1,3 +1,3 @@
<template name="sensorData">
<li>{{owner}} / <strong>{{temperatureValue}}°C</strong> / <strong>{{humidityValue}}%</strong> / Bačva puna: <strong>{{tankFull}}</strong> / {{created_at_formatted}}</li>
<li>{{owner}} / <strong>{{temperatureValue}}°C</strong> / <strong>{{humidityValue}}%</strong> / Bačva puna: <strong>{{tankFull}}</strong> (L0:{{tankLevel0}}-L1:{{tankLevel1}}-L2:{{tankLevel2}}-L3:{{tankLevel3}}-L4:{{tankLevel4}}-full:{{tankFull}}) / {{created_at_formatted}}</li>
</template>

View File

@@ -1,17 +0,0 @@
var options = {
location: 40.7127+','+ 74.0059, // New York
unit: 'c',
success: function(weather) {
html = '<h2><i class="sw icon-'+weather.code+'"></i> '
html += weather.temp+'&deg;'+weather.units.temp+'</h2>';
html += '<ul><li>'+weather.city+', '+weather.region +'</li>';
html += '<li class="currently">'+weather.currently+'</li>';
$("#weather").html(html);
},
error: function(error) {
$("#weather").html('<p>'+error+'</p>');
}
}
Weather.options = options

View File

@@ -1,10 +1,11 @@
<template name="state">
<div>&nbsp;</div>
<div class="col-md-12">
{{#with controller_state}}
<img src="{{ bucket_image }}" class="img-responsive center-block" id="bucket_image" />
<div class="text-center">
{{controller_id}}:
{{#with last_sensor_reading}} <strong> {{ temperatureValue }} °C, {{ humidityValue }} % </strong> {{/with}}
{{#with last_sensor_reading}} <strong> temp: {{ temperatureValue }} °C, vlaga: {{ humidityValue }} % <br/>nivo vode: {{water_level}} </strong> {{/with}}
</div>
<div class="text-center">
Automatsko zalijevanje:<br /> <strong>{{ pretty_days config.automaticDaysOfWeek }} {{ pretty_time config.automaticDaysOfWeek config.automaticTimeOfDay }}</strong> <button id="run_settings" class="btn btn-default"> <i class="fa fa-wrench"></i> </button>

View File

@@ -61,6 +61,18 @@ Template.state.helpers({
last_sensor_reading: last_sensor_reading,
water_level: function() {
var sensor = last_sensor_reading();
if (sensor) {
if (parseInt(sensor.tankFull) === 1) return '100 %';
else if (parseInt(sensor.tankLevel4) === 1) return '80 %';
else if (parseInt(sensor.tankLevel3) === 1) return '60 %';
else if (parseInt(sensor.tankLevel2) === 1) return '40 %';
else if (parseInt(sensor.tankLevel1) === 1) return '20 %';
else '0 %'
}
},
water_now_button_class: function() {
var stateObject = controller_state();
if (stateObject.state && (stateObject.state.out_valve === 'open' || stateObject.state.out_valve === 'opening')) {
@@ -100,6 +112,8 @@ Template.state.helpers({
}
});
Template.state.events({
'click #water_now': function() {
var controller_id = Session.get('controller_id');

View File

@@ -14,9 +14,13 @@
<div><strong>Ulazni ventil/pumpa:</strong> {{pretty_valve state.in_valve }}</div>
<div><strong>Zadnja komunikacija: {{ last_communication_time }}</strong>
</div>
<div><strong>Zadnje zaljevanje: {{ last_out_valve_open }}</strong>
</div>
<div><strong>Zadnje punjenje: {{ last_in_valve_open }}</strong>
</div>
</div>
</div>
<div class="row">
<div class="row hidden">
<div class="col-md-12 chart">
<h3>Temperatura:</h3>
<div id="temperature_graph">
@@ -24,7 +28,7 @@
</div>
</div>
<div class="row">
<div class="row hidden">
<div class="col-md-12 chart">
<h3>Vlažnost:</h3>
<div id="humidity_graph">

View File

@@ -7,6 +7,12 @@ Template.state_details.helpers({
},
last_communication_time: function() {
return moment(this.time).fromNow();
},
last_out_valve_open: function() {
return moment(this.significantEvents.lastOutValveOpen).fromNow();
},
last_in_valve_open: function() {
return moment(this.significantEvents.lastInValveOpen).fromNow();
}
});
@@ -44,8 +50,8 @@ Template.state_details.rendered = function() {
self.autorun(function() {
sensor_data_collection().observe({
added: function(reading) {
buildTemperatureGraph();
buildHumidityGraph()
// buildTemperatureGraph();
// buildHumidityGraph()
}
});
});
@@ -90,7 +96,7 @@ function buildTemperatureGraph() {
function buildHumidityGraph() {
var unfilteredReadings = sensor_data_collection();
// we want to show only 11 points from all data - filtering will add
// the last one so 10 + 1 = 11
// the last one so 10 + 1 = 11
var breakingPoint = Math.floor(countValues(unfilteredReadings) / 10);
var sensorReadings = filterDataPoints(unfilteredReadings, breakingPoint);

9
app/client/weather.html Normal file
View File

@@ -0,0 +1,9 @@
<template name="weather">
<div>&nbsp;</div>
<div class="col-md-12">
<div class="text-center">
{{>simpleWeather}}
</div>
</div>
</template>

38
app/client/weather.js Normal file
View File

@@ -0,0 +1,38 @@
var options = {
location: 44.0123 + ',' + 18.19455, // New Visoko
unit: 'c',
success: function(weather) {
html = "<h2><i class='sw icon-" + weather.code + "'></i>";
html += weather.temp + '&deg;' + weather.units.temp + '</h2>';
html += '<ul><li>' + weather.city + ', ' + weather.region + '</li>';
html += "<li class='currently'>" + weather.currently + '</li>';
html += '<hr />';
for (var i = 0; i < 5; i++) {
var forecast = weather.forecast[i];
html += '<div>';
html += "<h2><i class='sw icon-" + forecast.code + "'></i>";
html += forecast.high + '&deg;' + weather.units.temp + '</h2>';
html += "<li class='currently'> Najniža dnevna: "+ forecast.low + ' &deg; ' + weather.units.temp + "<br />" + daysInBosnian[forecast.day] + ': ' + forecast.text + '</li>';
html += "</div>";
}
$('#weather').html(html);
},
error: function(error) {
$('#weather').html('<p>' + error + '</p>');
}
}
var daysInBosnian = {
'Sun': 'Nedjelja',
'Mon': 'Ponedjeljak',
'Tue': 'Utorak',
'Wed': 'Srijeda',
'Thu': 'Četvrtak',
'Fri': 'Petak',
'Sat': 'Subota'
};
Weather.options = options

View File

@@ -13,7 +13,14 @@ Api.addRoute('sensorData', {
SensorData.insert({
temperatureValue: parseFloat(this.bodyParams.temperatureValue),
humidityValue: parseFloat(this.bodyParams.humidityValue),
tankLevel0: this.bodyParams.tankLevel0,
tankLevel1: this.bodyParams.tankLevel1,
tankLevel2: this.bodyParams.tankLevel2,
tankLevel3: this.bodyParams.tankLevel3,
tankLevel4: this.bodyParams.tankLevel4,
tankFull: this.bodyParams.tankFull,
startPumpingAt: this.bodyParams.startPumpingAt,
stopPumpingAt: this.bodyParams.stopPumpingAt,
owner: this.bodyParams.owner,
controllerId: this.bodyParams.controllerId,
created_at: new Date()
@@ -24,12 +31,19 @@ Api.addRoute('sensorData', {
function reactToSensorData(nextSensorReading) {
console.log("reacting to sensor");
var controllerId = nextSensorReading.controllerId;
var state = stateOrDefault(controllerId).state;
console.log(nextSensorReading , state);
var shouldStartPumping = (!state.in_valve || state.in_valve === 'closed' || state.in_valve === 'closing') && ((parseInt(nextSensorReading.tankFull) === 0) && (state.out_valve === 'closed' || state.out_valve === 'closing'));
var shouldStopPumping = (state.in_valve === 'open' || state.in_valve === 'opening') && (parseInt(nextSensorReading.tankFull) === 1 || state.out_valve === 'open' || state.out_valve === 'opening');
var startPumpingLevelReached;
if (nextSensorReading.startPumpingAt == 'TANKLEVEL0') startPumpingLevelReached = (parseInt(nextSensorReading.tankLevel0) === 0)
else if (nextSensorReading.startPumpingAt == 'TANKLEVEL1') startPumpingLevelReached = (parseInt(nextSensorReading.tankLevel1) === 0)
else if (nextSensorReading.startPumpingAt == 'TANKLEVEL2') startPumpingLevelReached = (parseInt(nextSensorReading.tankLevel2) === 0)
else if (nextSensorReading.startPumpingAt == 'TANKLEVEL3') startPumpingLevelReached = (parseInt(nextSensorReading.tankLevel3) === 0)
else if (nextSensorReading.startPumpingAt == 'TANKLEVEL4') startPumpingLevelReached = (parseInt(nextSensorReading.tankLevel4) === 0)
else startPumpingLevelReached = true;
var shouldStartPumping = (!state.in_valve || state.in_valve === 'closed') && ((parseInt(nextSensorReading.tankFull) === 0) && startPumpingLevelReached && (state.out_valve === 'closed' || state.out_valve === 'closing'));
if (shouldStartPumping) {
ControllerState.update({
@@ -41,7 +55,19 @@ function reactToSensorData(nextSensorReading) {
'set_by': 'server'
}
});
} else if (shouldStopPumping) {
}
var stopPumpingLevelReached;
if (nextSensorReading.stopPumpingAt == 'TANKLEVEL0') stopPumpingLevelReached = (parseInt(nextSensorReading.tankLevel0) === 1)
else if (nextSensorReading.stopPumpingAt == 'TANKLEVEL1') stopPumpingLevelReached = (parseInt(nextSensorReading.tankLevel1) === 1)
else if (nextSensorReading.stopPumpingAt == 'TANKLEVEL2') stopPumpingLevelReached = (parseInt(nextSensorReading.tankLevel2) === 1)
else if (nextSensorReading.stopPumpingAt == 'TANKLEVEL3') stopPumpingLevelReached = (parseInt(nextSensorReading.tankLevel3) === 1)
else if (nextSensorReading.stopPumpingAt == 'TANKLEVEL4') stopPumpingLevelReached = (parseInt(nextSensorReading.tankLevel4) === 1)
else stopPumpingLevelReached = false;
var shouldStopPumping = (state.in_valve === 'open' || state.in_valve === 'opening') && (parseInt(nextSensorReading.tankFull) === 1 || stopPumpingLevelReached || state.out_valve === 'open' || state.out_valve === 'opening');
if (shouldStopPumping) {
ControllerState.update({
controller_id: controllerId
}, {
@@ -90,7 +116,7 @@ function stateOrDefault(id) {
},
time: new Date(),
config: {
draining_period_amount: 60,
draining_period_amount: 40,
draining_period_unit: 'minutes'
},
set_by: 'server'
@@ -101,6 +127,3 @@ function stateOrDefault(id) {
});
return stateEntry;
}
Meteor.sharedFunctions = Meteor.sharedFunctions || {};
Meteor.sharedFunctions.reactToSensorData = reactToSensorData;

View File

@@ -21,6 +21,15 @@ function setOutValveTo(controller_id, nextState) {
'set_by': 'server'
}
});
if(nextState === "open") {
ControllerState.update(state._id, {
'$set': {
'significantEvents.lastOutValveOpen': new Date(),
}
});
}
}
function openOutValve(controller_id) {

View File

@@ -4,10 +4,34 @@ if (Meteor.isServer) {
SyncedCron.start();
});
// Global API configuration
var Api = new Restivus({
useDefaultAuth: true,
prettyJson: true
});
Api.addRoute('sensorData', {
authRequired: false
}, {
post: function() {
SensorData.insert({
temperatureValue: parseFloat(this.bodyParams.temperatureValue),
humidityValue: parseFloat(this.bodyParams.humidityValue),
tankLevel0: this.bodyParams.tankLevel0,
tankLevel1: this.bodyParams.tankLevel1,
tankLevel2: this.bodyParams.tankLevel2,
tankLevel3: this.bodyParams.tankLevel3,
tankLevel4: this.bodyParams.tankLevel4,
tankFull: this.bodyParams.tankFull,
startPumpingAt: this.bodyParams.startPumpingAt,
stopPumpingAt: this.bodyParams.stopPumpingAt,
owner: this.bodyParams.owner,
created_at: new Date()
});
return [];
}
});
}

View File

@@ -3,12 +3,19 @@
## Installation
1. Go to every subdirectory in drivers directory and follow instructions about installation of drivers
2. edit controller/config/__init__.py and set your controller ID to unique number
2. edit controller/config/__init__.py and set your controller ID to unique number
3. configure cron to run controller.py every 15 minutes as a superuser:
```
crontab -e -u root
#enter these lines
*/15 * * * * /usr/bin/python /home/pi/projects/tfm/controller/sensors.py "Automatski, Senad Uka" 120
*/1 * * * * /usr/bin/python /home/pi/projects/tfm/controller/sync_state.py "Automatski, Senad Uka" 120
*/5 * * * * cd /home/pi/projects/tfm/controller && sh activity.sh
*/30 * * * * /usr/bin/python /home/pi/projects/tfm/controller/network_check.py
```
4. add following lines at the end of /etc/rc.local
```
python /home/pi/projects/tfm/controller/lockdown.py
python /home/pi/projects/tfm/controller/dweet.py
```

3
controller/activity.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
sudo /usr/bin/python /home/pi/projects/tfm/controller/sensors.py
sudo /usr/bin/python /home/pi/projects/tfm/controller/sync_state.py

View File

@@ -1,10 +1,17 @@
GPIO_PIN_DHT = 4 # BCM
SENSORDATA_URL = 'http://tfm.meteor.com/api/v1.0/sensorData'
SENSORDATA_URL = 'http://agrar.zoblak.com/api/v1.0/sensorData'
GPIO_PIN_TANKLEVEL0 = 5 # BCM
GPIO_PIN_TANKLEVEL1 = 6 # BCM
GPIO_PIN_TANKLEVEL2 = 13 # BCM
GPIO_PIN_TANKLEVEL3 = 19 # BCM
GPIO_PIN_TANKLEVEL4 = 26 # BCM
GPIO_PIN_TANKFULL = 20 # BCM
GPIO_PIN_OUT_VALVE = 21 # BCM
GPIO_PIN_IN_VALVE = 18 # BCM
API_BASE_URL = 'http://tfm.meteor.com/api/v1.0'
START_PUMPING_AT = 'TANKFULL' # start pumping when this level = 0
STOP_PUMPING_AT = 'TANKFULL' # stop pumping when this level = 1
API_BASE_URL = 'http://agrar.zoblak.com/api/v1.0'
CONTROLLER_ID = '120' # every controller must have a different one
STATE_FILE = '/var/run/controller_state'

6
controller/dweet.py Normal file
View File

@@ -0,0 +1,6 @@
import config
import commands
command = """curl -H "Content-Type: application/json" -X POST -d '{"message": "I am aliveeee (again!)", "controller_id": %s}' https://dweet.io:443/dweet/quietly/for/5410ab1e-319c-4f14-a2e4-04725df69121""" % config.CONTROLLER_ID
print commands.getoutput(command)

3
controller/lockdown.py Normal file
View File

@@ -0,0 +1,3 @@
import state
state.safely_panic()

View File

@@ -0,0 +1,3 @@
import state
state.reboot_if_network_down()

View File

@@ -5,20 +5,38 @@ import Adafruit_DHT
import config
import RPi.GPIO as GPIO
# Try to read the state of GPIO_PIN_TANKFULL
# Try to read the state of GPIO_PIN_TANKLEVELx and GPIO_PIN_TANKFULL
GPIO.setmode(GPIO.BCM)
GPIO.setup(config.GPIO_PIN_TANKLEVEL0, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(config.GPIO_PIN_TANKLEVEL1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(config.GPIO_PIN_TANKLEVEL2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(config.GPIO_PIN_TANKLEVEL3, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(config.GPIO_PIN_TANKLEVEL4, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(config.GPIO_PIN_TANKFULL, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
# tank sensor has inverse logic - 0 when it is full 1 when it is not
# so we are inverting its value here
tankFull = (not GPIO.input(config.GPIO_PIN_TANKFULL))
tankLevel0 = (GPIO.input(config.GPIO_PIN_TANKLEVEL0) == GPIO.LOW)
tankLevel1 = (GPIO.input(config.GPIO_PIN_TANKLEVEL1) == GPIO.LOW)
tankLevel2 = (GPIO.input(config.GPIO_PIN_TANKLEVEL2) == GPIO.LOW)
tankLevel3 = (GPIO.input(config.GPIO_PIN_TANKLEVEL3) == GPIO.LOW)
tankLevel4 = (GPIO.input(config.GPIO_PIN_TANKLEVEL4) == GPIO.LOW)
tankFull = (GPIO.input(config.GPIO_PIN_TANKFULL) == GPIO.LOW)
GPIO.cleanup()
print 'Bacva Level0: {}'.format(tankLevel0)
print 'Bacva Level1: {}'.format(tankLevel1)
print 'Bacva Level2: {}'.format(tankLevel2)
print 'Bacva Level3: {}'.format(tankLevel3)
print 'Bacva Level4: {}'.format(tankLevel4)
print 'Bacva puna: {}'.format(tankFull)
# Go on to DHT
SENSOR_TYPE = Adafruit_DHT.DHT11
controller_id = config.CONTROLLER_ID
owner = "Controller: %s" % controller_id
startPumpingAt = config.START_PUMPING_AT
stopPumpingAt = config.STOP_PUMPING_AT
# Try to grab a sensor reading. Use the read_retry method which will retry up
# to 15 times to get a sensor reading (waiting 2 seconds between each retry).
@@ -31,9 +49,9 @@ humidity, temperature = Adafruit_DHT.read_retry(SENSOR_TYPE, config.GPIO_PIN_DHT
# the results will be null (because Linux can't
# guarantee the timing of calls to read the sensor).
# If this happens try again!
if temperature is not None and humidity is not None:
response = requests.post(config.SENSORDATA_URL, json={"owner": owner, "temperatureValue": temperature, "humidityValue":humidity, "tankFull":tankFull,
"controllerId": controller_id
if tankFull is not None:
response = requests.post(config.SENSORDATA_URL, json={"owner": owner, "temperatureValue": temperature, "humidityValue":humidity, "tankLevel0": "1" if tankLevel0 else "0","tankLevel1": "1" if tankLevel1 else "0","tankLevel2": "1" if tankLevel2 else "0","tankLevel3": "1" if tankLevel3 else "0", "tankLevel4": "1" if tankLevel4 else "0", "tankFull": "1" if tankFull else "0",
"startPumpingAt": startPumpingAt,"stopPumpingAt": stopPumpingAt,"controllerId": controller_id
})
print 'Temp={0:0.1f}*C'.format(temperature)
print 'Humidity={0:0.1f}%'.format(humidity)

View File

@@ -2,26 +2,42 @@ import config
from state.server import Server
from state.changer import Changer
from state.file import File
import commands
def safely_panic():
safe_state = {}
changer = Changer(safe_state,safe_state)
changer.stop_everything()
def reboot_if_network_down():
try:
server = Server(config.API_BASE_URL, config.CONTROLLER_ID)
server_state = server.get_state()
print "Got state from server: " + repr(server_state)
except:
print "Problem with the network!"
commands.getoutput('/sbin/shutdown -r +3')
def sync():
server = Server(config.API_BASE_URL, config.CONTROLLER_ID)
local = File(config.STATE_FILE)
server_state = server.get_state()
try:
server = Server(config.API_BASE_URL, config.CONTROLLER_ID)
local = File(config.STATE_FILE)
server_state = server.get_state()
if local.present():
local.load()
print "local present: " + repr(local.data)
else:
local.data = server_state
print "local not present, server: " + repr(local.data)
local.save()
local_state = local.data
if local.present():
local.load()
print "local present: " + repr(local.data)
else:
local.data = server_state
print "local not present, server: " + repr(local.data)
local.save()
changer = Changer(local_state, server_state)
current_state = changer.process_change()
local_state = local.data
changer = Changer(local_state, server_state)
current_state = changer.process_change()
server.post_state(current_state)
server.post_state(current_state)
except:
print " panicking safely ! "
safely_panic()

View File

@@ -24,6 +24,10 @@ class Changer(object):
'closed': self.close_in_valve
}
def stop_everything(self):
self.close_in_valve()
self.close_out_valve()
def safe_remote_state(self, key):
if key in ['out_valve', 'in_valve']:
return self.remote_state.get(key, 'closed')

View File

@@ -0,0 +1,33 @@
import json
import requests
DWEET_UID = "5410ab1e-319c-4f14-a2e4-04725df69121"
class DweetServer(object):
"Gets state from server and sends it to the server after change"
def __init__(self, controller_id=None):
self.url_base = "https://dweet.io:443/dweet/quietly/for/%s" % DWEET_UID
self.controller_id = controller_id
def send_message(self, message):
result = requests.post(self.full_url(),
json=json.dumps({
'controller_id': self.controller_id,
'message': message
}))
return handle_response(result)
def full_url(self):
if self.controller_id is None:
raise ClassNotReadyException("Controller id not set!")
if self.url_base is None:
raise ClassNotReadyException("URL base not set!")
return self.url_base
def handle_response(response):
if response.status_code != 200 or response.status_code != 204:
raise Exception("Response not 200 or 204!")
else:
return response.json()

View File

@@ -16,8 +16,6 @@ class Server(object):
result = requests.post(self.full_url('state/%s') % self.controller_id, local_state)
return handle_response(result)
def full_url(self, action):
if self.controller_id is None:
raise ClassNotReadyException("Controller id not set!")

136
misc/calculator.html Normal file
View File

@@ -0,0 +1,136 @@
<html>
<head>
<meta charset="UTF-8">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</head>
<body>
<div class="jumbotron">
<div class="lead text-center">
<img src="./zoblak.png" width="30%" />
<br /> Zoblak Agrar Plus se isplati za <span id="vrijemeZaBreakEven" class="bg-success"></span> mjeseci. U periodu od <span id="brojSezona"></span> godine ostvaruje uštedu u novcu od <span id="iznosUstede" class="bg-success"></span> KM, te uštedu u vremenu od <span id="satiUProjekciji" class="bg-success"></span> sati za podešeni slučaj.
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<p>Na troškove goriva mjesečno trošite <span id="iznosGoriva"></span> KM. Na rad potreban za zalijevanje trošite mjesečno <span id="satiMjesecno"></span> sati što uz zadanu satnicu iznosi <span id="plata"></span> KM. Zajedno to je <span id="ukupnoTroskovaMjesecno"></span> KM troška na zalijevanje. </p>
<p>Okvirna cijena Zoblak Agrar Plus iznosi <span id="bazaCijeneZoblaka"></span> KM + sistem navodnjavanja</p>
<p class="bg-primary">NAPOMENA: finalna cijena može biti niža ili viša i poznata je nakon izrade projekta).</p>
</div>
<div class="col-md-6 col-sm-6">
<form method="post">
<div class="form-group ">
<label class="control-label " for="number">
Vaša udaljenost od polja u km
</label>
<input class="form-control ulazni-parametar" id="pudaljenost" type="number" min="1" max="200" step="0.1" value="5" />
</div>
<div class="form-group ">
<label class="control-label " for="number1">
Prosjecna potro&scaron;nja automobila na 100 km
</label>
<input class="form-control ulazni-parametar" id="ppotrosnja" type="number" min="2" max="15" value="7" step="0.1" />
</div>
<div class="form-group ">
<label class="control-label " for="select">
Koliko često treba zaljevati kulturu?
</label>
<select class="select form-control" id="pfrekvencija_zalijevanja">
<option value="1">
Svaki dan
</option>
<option value="2">
Jednom u dva dana
</option>
<option value="3">
Jednom u tri dana
</option>
<option value="4">
Jednom u četiri dana
</option>
</select>
</div>
<div class="form-group ">
<label class="control-label " for="number2">
Koliko vremena traje put prema polju (u oba smijera) i jedan ciklus zalijevanja? U satima.
</label>
<input class="form-control ulazni-parametar" id="pvrijeme" type="number" min="2" max="10" value="1.5" step="0.5" />
</div>
<div class="form-group ">
<label class="control-label " for="number3">
Satnica osobe koja zalijeva u KM
</label>
<input class="form-control ulazni-parametar" id="psatnica" type="number" min="1" max="100" value="20" step="1" />
</div>
<div class="form-group ">
<label class="control-label " for="number3">
Trajanje sezone u mjesecima
</label>
<input class="form-control ulazni-parametar" id="psezona" type="number" min="1" max="12" value="4" step="1" />
</div>
<div class="form-group ">
<label class="control-label " for="number3">
Na koliko godina/sezona se kalkulacija vrši
</label>
<input class="form-control ulazni-parametar" id="pbroj_sezona" type="number" min="1" max="10" value="3" step="1" />
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript">
function iskalkulisi() {
var udaljenost = parseFloat($('#pudaljenost').val()) || 10;
var potrosnja = parseFloat($('#ppotrosnja').val()) || 7;
var frekvencija = parseInt($('#pfrekvencija_zalijevanja').val()) || 2;
var vrijeme = parseFloat($('#pvrijeme').val()) || 1.5;
var satnica = parseFloat($('#psatnica').val()) || 20;
var sezona = parseInt($('#psezona').val()) || 4;
var brojSezona = parseInt($('#pbroj_sezona').val()) || 3;
var bazaCijeneZoblaka = 1000;
var bazaCijeneVentila = 0;
var bazaCijeneGoriva = 1.70;
var godisnjeOdrzavanjeZoblaka = 200;
// rezultati
var zalijevanjaMjesecno = Math.ceil(30 / frekvencija);
var satiMjesecno = Math.ceil(vrijeme) * zalijevanjaMjesecno;
var plata = satiMjesecno * satnica;
var iznosGoriva = Math.ceil((potrosnja / 100) * bazaCijeneGoriva * (udaljenost * 2) * zalijevanjaMjesecno);
var ukupnoTroskovaMjesecno = iznosGoriva + plata;
var trosakZoblaka = bazaCijeneZoblaka + godisnjeOdrzavanjeZoblaka * (brojSezona - 1);
var satiUProjekciji = satiMjesecno * sezona * brojSezona;
var novcaUProjekciji = ukupnoTroskovaMjesecno * sezona * brojSezona;
var iznosUstede = novcaUProjekciji - trosakZoblaka
var vrijemeZaBreakEven = Math.ceil(bazaCijeneZoblaka / ukupnoTroskovaMjesecno);
$('#vrijemeZaBreakEven').html(vrijemeZaBreakEven);
$('#brojSezona').html(brojSezona);
$('#iznosUstede').html(iznosUstede);
$('#satiUProjekciji').html(satiUProjekciji);
$('#iznosGoriva').html(iznosGoriva);
$('#satiMjesecno').html(satiMjesecno);
$('#plata').html(plata);
$('#ukupnoTroskovaMjesecno').html(ukupnoTroskovaMjesecno);
$('#bazaCijeneZoblaka').html(bazaCijeneZoblaka);
};
$(document).ready(function() {
iskalkulisi();
$(".ulazni-parametar").keyup(iskalkulisi);
$(".ulazni-parametar").change(iskalkulisi);
});
</script>
</body>
</html>

43
misc/latest_dweets.html Normal file
View File

@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<style>
body {
background: #F9F9FA;
}
</style>
</head>
<body>
<a href="#" id="get-data">Get JSON data</a>
<div id="show-data"></div>
<script>
$(document).ready(function() {
$('#get-data').click(function() {
var showData = $('#show-data');
$.getJSON('https://dweet.io:443/get/dweets/for/5410ab1e-319c-4f14-a2e4-04725df69121', function(data) {
console.log(data);
var items = data.with.map(function(item) {
return item.created + ': ' + item.content.controller_id + ' (' + item.content.message + ')';
});
showData.empty();
if (items.length) {
var content = '<li>' + items.join('</li><li>') + '</li>';
var list = $('<ul />').html(content);
showData.append(list);
}
});
showData.text('Loading the JSON file.');
});
});
</script>
</body>
</html>

24
misc/latest_dweets.js Normal file
View File

@@ -0,0 +1,24 @@
$(document).ready(function () {
$('#get-data').click(function () {
var showData = $('#show-data');
$.getJSON('https://dweet.io:443/get/dweets/for/5410ab1e-319c-4f14-a2e4-04725df69121', function (data) {
console.log(data);
var items = data.items.map(function (item) {
return item.key + ': ' + item.value;
});
showData.empty();
if (items.length) {
var content = '<li>' + items.join('</li><li>') + '</li>';
var list = $('<ul />').html(content);
showData.append(list);
}
});
showData.text('Loading the JSON file.');
});
});

BIN
misc/zoblak.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB