Skip to content

Commit 86296c0

Browse files
committed
first commit
1 parent 139d345 commit 86296c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3660
-0
lines changed

Dispatcher.py

Lines changed: 529 additions & 0 deletions
Large diffs are not rendered by default.

Sensor.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import time
2+
from my_libs import *
3+
import heapq;
4+
import random;
5+
import Queue;
6+
import json
7+
8+
setup_logging()
9+
log = logging.getLogger("<Sensor>")
10+
11+
12+
class Callable():
13+
def call(sim):
14+
raise Exception('Call of %s is not implemented' % self)
15+
16+
class Sensor(Callable):
17+
18+
def __init__(self, name, readlatency, period, size, gamma):
19+
"""
20+
Construct a new 'Sensor' object.
21+
:param name: The name of Sensor
22+
:param readlatency: read latency
23+
:param period: The period to read
24+
:param size: The size of sensor reading in bytes
25+
:return: returns nothing
26+
"""
27+
self.name = name
28+
self.readlatency = readlatency
29+
self.period = period
30+
self.size = size
31+
self.gamma = gamma
32+
self.flag = False
33+
34+
def __repr__(self):
35+
return 'Sensor::%s' % self.name
36+
37+
def set_period(self, period):
38+
self.period = period
39+
40+
def call(self, sim):
41+
if self.flag:
42+
self.flag = False
43+
print 'Time %f sensor %s reading completed' % (sim.simclock, self)
44+
sim.add_event(sim.simclock + self.period, self)
45+
else:
46+
self.flag = True
47+
sim.read_queue = sim.read_queue + self.size
48+
reading = Reading(self.name, sim.simclock, self.size)
49+
sim.readings_queue.put(reading)
50+
print 'Time %f reading sensor %s current queue %d' % (sim.simclock, self, sim.read_queue)
51+
sim.add_event(sim.simclock + self.readlatency, self)
52+
53+
54+
55+
class Reading:
56+
def __init__(self, sensor_name, sensing_time, size):
57+
self.sensor_name = sensor_name
58+
self.sensing_time = sensing_time
59+
self.size = size
60+
61+
def __repr__(self):
62+
return 'Sensor::%s' % self.sensor_name

Sensor.pyc

3.15 KB
Binary file not shown.

cam.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import time
2+
import picamera
3+
4+
def take_picture(pic_name='image.jpg', delay=0):
5+
#pic_location = '/home/pi/workshop/camera/'
6+
pic_location = 'pictures/'
7+
pic_location = pic_location + pic_name
8+
with picamera.PiCamera() as camera:
9+
camera.start_preview()
10+
time.sleep(delay)
11+
camera.capture(pic_location)
12+
camera.stop_preview()
13+
14+
#pic_location = '/home/pi/workshop/camera/image.jpg'
15+
#take_picture()

cam.pyc

636 Bytes
Binary file not shown.

communicate/__init__.py

Whitespace-only changes.

config/.Rhistory

Whitespace-only changes.

config/calibration.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"MQ6_RAW": 410, "MQ6": 2.943574073499083, "MQ135": 973.5719237041191, "MQ4": 1.574462293197566, "DUST_RAW": 189.98, "DUST": 10204.00390625, "MQ4_RAW": 278, "MQ135_RAW": 324}

config/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"SENSE_INTERVAL": 10, "TX_MEDIUM": "wlan0", "MQTT_BROKER_HOSTNAME": "iot.eclipse.org", "RUNTIME": 86400}

config/logging.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"version": 1,
3+
"disable_existing_loggers": false,
4+
"formatters": {
5+
"simple": {
6+
"format": "%(asctime)s \t %(name)s \t %(levelname)s \t %(message)s"
7+
}
8+
},
9+
10+
"handlers": {
11+
"console": {
12+
"class": "logging.StreamHandler",
13+
"level": "CRITICAL",
14+
"formatter": "simple",
15+
"stream": "ext://sys.stdout"
16+
},
17+
18+
"bytes_file_handler": {
19+
"class": "logging.handlers.RotatingFileHandler",
20+
"level": 45,
21+
"formatter": "simple",
22+
"filename": "logs/bytes.log",
23+
"maxBytes": 512000,
24+
"backupCount": 20,
25+
"encoding": "utf8"
26+
},
27+
28+
"error_file_handler": {
29+
"class": "logging.handlers.RotatingFileHandler",
30+
"level": "INFO",
31+
"formatter": "simple",
32+
"filename": "logs/event_log.log",
33+
"maxBytes": 512000,
34+
"backupCount": 20,
35+
"encoding": "utf8"
36+
}
37+
},
38+
39+
"loggers": {
40+
"my_module": {
41+
"level": "ERROR",
42+
"handlers": ["console"],
43+
"propagate": "no"
44+
}
45+
},
46+
47+
"root": {
48+
"level": "INFO",
49+
"handlers": ["console", "bytes_file_handler", "error_file_handler"]
50+
}
51+
}

0 commit comments

Comments
 (0)