Local safe autonomy #22

Merged
senaduka merged 15 commits from local_safe_autonomy into master 2016-06-08 11:23:44 +02:00
5 changed files with 86 additions and 3 deletions
Showing only changes of commit f1d7232c10 - Show all commits

View File

@@ -3,7 +3,7 @@
## Installation ## Installation
1. Go to every subdirectory in drivers directory and follow instructions about installation of drivers 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: 3. configure cron to run controller.py every 15 minutes as a superuser:
``` ```
@@ -12,3 +12,10 @@ crontab -e -u root
*/15 * * * * /usr/bin/python /home/pi/projects/tfm/controller/sensors.py "Automatski, Senad Uka" 120 */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 */1 * * * * /usr/bin/python /home/pi/projects/tfm/controller/sync_state.py "Automatski, Senad Uka" 120
``` ```
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
```

View File

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

View File

@@ -9,6 +9,14 @@ def safely_panic():
changer = Changer(safe_state,safe_state) changer = Changer(safe_state,safe_state)
changer.stop_everything() 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(): def sync():
try: try:
@@ -35,5 +43,3 @@ def sync():
except: except:
print " panicking safely ! " print " panicking safely ! "
safely_panic() safely_panic()
print " rebooting "
commands.getoutput('/sbin/shutdown -r +3')

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.');
});
});