Exemplo n.º 1
0
def setup():
    print("Setting up...")
    SensorsInterface.setupSensorian()  # Prepare the sensors on the Sensorian Shield
    time.sleep(2)  # Wait 2 seconds or some sensors won't be ready
    (x, y, z) = SensorsInterface.getMagnetometer()  # Get the current force values of the magnetometer
    sensor_string = "X: " + str(x) + " Y: " + str(y) + " Z: " + str(z)  # Add the magnet values to the string
    tft_printer.screen_print_rotated(sensor_string, 1)  # Print the completed string to the landscape display
def setup():
    print("Setting up...")
    SensorsInterface.setupSensorian()  # Prepare the sensors on the Sensorian Shield
    time.sleep(2)  # Wait 2 seconds or some sensors won't be ready
    global desired_lux
    desired_lux = SensorsInterface.getAmbientLight()  # Sets the desired light level to that of when the program ran
    print("Desired Light: " + str(desired_lux))  # Print the desired light level
Exemplo n.º 3
0
def setup():
    print("Setting up...")
    SensorsInterface.setupSensorian(
    )  # Prepare the sensors on the Sensorian Shield
    time.sleep(2)  # Wait 2 seconds or some sensors won't be ready
    global desired_lux
    desired_lux = SensorsInterface.getAmbientLight(
    )  # Sets the desired light level to that of when the program ran
    print("Desired Light: " +
          str(desired_lux))  # Print the desired light level
	def run(self):
		global sensors
		
		#self.flask_input = open('read_pipe','w')
		#self.flask_output = open('write_pipe','r')
		self.mmap_file = open('mmap_ipc','a+b')
		self.mmap_buf = mmap.mmap(self.mmap_file.fileno(),0,access=mmap.ACCESS_WRITE)
		
		self.mmap_altitude_file = open('/home/pi/.sensorian/mmap_altitude','a+b')
		self.mmap_altitude = mmap.mmap(self.mmap_altitude_file.fileno(),0,access=mmap.ACCESS_WRITE)
		
		self.mmap_pressure_file = open('/home/pi/.sensorian/mmap_pressure','a+b')
		self.mmap_pressure = mmap.mmap(self.mmap_pressure_file.fileno(),0,access=mmap.ACCESS_WRITE)
		
		self.mmap_temperature_file = open('/home/pi/.sensorian/mmap_temperature','a+b')
		self.mmap_temperature = mmap.mmap(self.mmap_temperature_file.fileno(),0,access=mmap.ACCESS_WRITE)
		
		self.mmap_ambientlight_file = open('/home/pi/.sensorian/mmap_ambientlight','a+b')
		self.mmap_ambientlight = mmap.mmap(self.mmap_ambientlight_file.fileno(),0,access=mmap.ACCESS_WRITE)
		
		SensorsInterface.setupSensorian()
		
		#Setup a dummy alarm for now
		SensorsInterface.setRTCCtime(2016,3,4,5,33,0)
		SensorsInterface.setRTCCalarm(2018,1,1,1,40,20,1) #MINUTES_MATCH mode
		
		prev_touchpad = SensorsInterface.getTouchpad()
		#prev_magnetometer = SensorsInterface.getMagnetometer()
		prev_magnetometer = mk_bin_tuple(SensorsInterface.getMagnetometer())
		prev_accelerometer = mk_bin_tuple(SensorsInterface.getAccelerometer())
		prev_alarmtrigger = SensorsInterface.pollRTCCalarm()
		while self.alive:
			sensors_lock.acquire()
			sensors = {}
			touchpad = SensorsInterface.getTouchpad()
			if touchpad != prev_touchpad:
				print "Touchpad: " + str(touchpad)
				#sensors_lock.acquire()
				sensors['touchpad'] = touchpad
				#sensors_lock.release()
			prev_touchpad = touchpad
			
			#magnetometer = SensorsInterface.getMagnetometer()
			magnetometer = mk_bin_tuple(SensorsInterface.getMagnetometer())
			if magnetometer != prev_magnetometer:
				print "Magnetometer: " + str(magnetometer)
				#sensors_lock.acquire()
				sensors['magnetometer'] = magnetometer
				#sensors_lock.release()
			prev_magnetometer = magnetometer
			
			accelerometer = mk_bin_tuple(SensorsInterface.getAccelerometer())
			if accelerometer != prev_accelerometer:
				print "Accelerometer: " + str(accelerometer)
				sensors['accelerometer'] = accelerometer
			prev_accelerometer = accelerometer
			
			alarmtrigger = SensorsInterface.pollRTCCalarm()
			if alarmtrigger != prev_alarmtrigger:
				print "Alarm Trigger: " + str(alarmtrigger)
				sensors['alarmtrigger'] = alarmtrigger
			prev_alarmtrigger = alarmtrigger
			
			#Poll flask_rtcc_interface.py for new updates to RTCC
			#print "polling flask_rtcc_interface.py"
			#self.flask_input.write("reqUpdate\n")
			#self.flask_input.flush()
			if self.mmap_buf[0] == '1':
				#Update the time
				new_time_tuple = get_time_from_mmap(self.mmap_buf,2)
				SensorsInterface.setRTCCtime(new_time_tuple[0],new_time_tuple[1],new_time_tuple[2],new_time_tuple[3],new_time_tuple[4],new_time_tuple[5])
				print "done setting the time"
				self.mmap_buf[0] = '0' #Clear NEW_TIME
			
			if self.mmap_buf[1] == '1':
				#Update the alarm
				new_alarm_tuple = get_alarm_from_mmap(self.mmap_buf,16)
				SensorsInterface.setRTCCalarm(new_alarm_tuple[0],new_alarm_tuple[1],new_alarm_tuple[2],new_alarm_tuple[3],new_alarm_tuple[4],new_alarm_tuple[5],new_alarm_tuple[6])
				print "done setting the alarm"
				self.mmap_buf[1] = '0' #Clear NEW_ALARM
			
			#Altitude
			if self.mmap_altitude[0] == '1':
				#Send altitude data... but first set the BUSY byte
				self.mmap_altitude[1] = '1'
				#Get the Altitude data
				print "Getting altitude data"
				sensors['altitude'] = str(SensorsInterface.getAltitude())
				self.mmap_altitude[0] = '0' #The request has been completed
				self.mmap_altitude[1] = '0' #...and we are no longer busy
			
			#Pressure
			if self.mmap_pressure[0] == '1':
				#Send pressure data... but first set the BUSY byte
				self.mmap_pressure[1] = '1'
				#Get the Pressure data
				print "Getting pressure data"
				sensors['pressure'] = str(SensorsInterface.getBarometricPressure())
				self.mmap_pressure[0] = '0' #The request has been completed
				self.mmap_pressure[1] = '0' #...and we are no longer busy
			
			#Temperature
			if self.mmap_temperature[0] == '1':
				#Send temperature data... but first set the BUSY byte
				self.mmap_temperature[1] = '1'
				#Get the Temperature data
				print "Getting temperature data"
				sensors['temperature'] = str(SensorsInterface.getTemperature())
				self.mmap_temperature[0] = '0' #The request has been completed
				self.mmap_temperature[1] = '0' #...and we are no longer busy
			
			#AmbientLight
			if self.mmap_ambientlight[0] == '1':
				#Send temperature data... but first set the BUSY byte
				self.mmap_ambientlight[1] = '1'
				#Get the Ambient Light data
				print "Getting ambient light data"
				sensors['ambientlight'] = str(SensorsInterface.getAmbientLight())
				self.mmap_ambientlight[0] = '0' #The request has been completed
				self.mmap_ambientlight[1] = '0' #...and we are no longer busy
			
			sensors_lock.release()
			
			"""If there is new data stored in sensors --> sensors != {},
			then we should make this thread wait until it is sent to the
			socket. """
			if sensors != {}:
				data_ready_event.clear()
				data_ready_event.wait()
Exemplo n.º 5
0
    def run(self):
        global sensors

        #self.flask_input = open('read_pipe','w')
        #self.flask_output = open('write_pipe','r')
        self.mmap_file = open('mmap_ipc', 'a+b')
        self.mmap_buf = mmap.mmap(self.mmap_file.fileno(),
                                  0,
                                  access=mmap.ACCESS_WRITE)

        self.mmap_altitude_file = open('/home/pi/.sensorian/mmap_altitude',
                                       'a+b')
        self.mmap_altitude = mmap.mmap(self.mmap_altitude_file.fileno(),
                                       0,
                                       access=mmap.ACCESS_WRITE)

        self.mmap_pressure_file = open('/home/pi/.sensorian/mmap_pressure',
                                       'a+b')
        self.mmap_pressure = mmap.mmap(self.mmap_pressure_file.fileno(),
                                       0,
                                       access=mmap.ACCESS_WRITE)

        self.mmap_temperature_file = open(
            '/home/pi/.sensorian/mmap_temperature', 'a+b')
        self.mmap_temperature = mmap.mmap(self.mmap_temperature_file.fileno(),
                                          0,
                                          access=mmap.ACCESS_WRITE)

        self.mmap_ambientlight_file = open(
            '/home/pi/.sensorian/mmap_ambientlight', 'a+b')
        self.mmap_ambientlight = mmap.mmap(
            self.mmap_ambientlight_file.fileno(), 0, access=mmap.ACCESS_WRITE)

        SensorsInterface.setupSensorian()

        #Setup a dummy alarm for now
        SensorsInterface.setRTCCtime(2016, 3, 4, 5, 33, 0)
        SensorsInterface.setRTCCalarm(2018, 1, 1, 1, 40, 20,
                                      1)  #MINUTES_MATCH mode

        prev_touchpad = SensorsInterface.getTouchpad()
        #prev_magnetometer = SensorsInterface.getMagnetometer()
        prev_magnetometer = mk_bin_tuple(SensorsInterface.getMagnetometer())
        prev_accelerometer = mk_bin_tuple(SensorsInterface.getAccelerometer())
        prev_alarmtrigger = SensorsInterface.pollRTCCalarm()
        while self.alive:
            sensors_lock.acquire()
            sensors = {}
            touchpad = SensorsInterface.getTouchpad()
            if touchpad != prev_touchpad:
                print "Touchpad: " + str(touchpad)
                #sensors_lock.acquire()
                sensors['touchpad'] = touchpad
                #sensors_lock.release()
            prev_touchpad = touchpad

            #magnetometer = SensorsInterface.getMagnetometer()
            magnetometer = mk_bin_tuple(SensorsInterface.getMagnetometer())
            if magnetometer != prev_magnetometer:
                print "Magnetometer: " + str(magnetometer)
                #sensors_lock.acquire()
                sensors['magnetometer'] = magnetometer
                #sensors_lock.release()
            prev_magnetometer = magnetometer

            accelerometer = mk_bin_tuple(SensorsInterface.getAccelerometer())
            if accelerometer != prev_accelerometer:
                print "Accelerometer: " + str(accelerometer)
                sensors['accelerometer'] = accelerometer
            prev_accelerometer = accelerometer

            alarmtrigger = SensorsInterface.pollRTCCalarm()
            if alarmtrigger != prev_alarmtrigger:
                print "Alarm Trigger: " + str(alarmtrigger)
                sensors['alarmtrigger'] = alarmtrigger
            prev_alarmtrigger = alarmtrigger

            #Poll flask_rtcc_interface.py for new updates to RTCC
            #print "polling flask_rtcc_interface.py"
            #self.flask_input.write("reqUpdate\n")
            #self.flask_input.flush()
            if self.mmap_buf[0] == '1':
                #Update the time
                new_time_tuple = get_time_from_mmap(self.mmap_buf, 2)
                SensorsInterface.setRTCCtime(
                    new_time_tuple[0], new_time_tuple[1], new_time_tuple[2],
                    new_time_tuple[3], new_time_tuple[4], new_time_tuple[5])
                print "done setting the time"
                self.mmap_buf[0] = '0'  #Clear NEW_TIME

            if self.mmap_buf[1] == '1':
                #Update the alarm
                new_alarm_tuple = get_alarm_from_mmap(self.mmap_buf, 16)
                SensorsInterface.setRTCCalarm(
                    new_alarm_tuple[0], new_alarm_tuple[1], new_alarm_tuple[2],
                    new_alarm_tuple[3], new_alarm_tuple[4], new_alarm_tuple[5],
                    new_alarm_tuple[6])
                print "done setting the alarm"
                self.mmap_buf[1] = '0'  #Clear NEW_ALARM

            #Altitude
            if self.mmap_altitude[0] == '1':
                #Send altitude data... but first set the BUSY byte
                self.mmap_altitude[1] = '1'
                #Get the Altitude data
                print "Getting altitude data"
                sensors['altitude'] = str(SensorsInterface.getAltitude())
                self.mmap_altitude[0] = '0'  #The request has been completed
                self.mmap_altitude[1] = '0'  #...and we are no longer busy

            #Pressure
            if self.mmap_pressure[0] == '1':
                #Send pressure data... but first set the BUSY byte
                self.mmap_pressure[1] = '1'
                #Get the Pressure data
                print "Getting pressure data"
                sensors['pressure'] = str(
                    SensorsInterface.getBarometricPressure())
                self.mmap_pressure[0] = '0'  #The request has been completed
                self.mmap_pressure[1] = '0'  #...and we are no longer busy

            #Temperature
            if self.mmap_temperature[0] == '1':
                #Send temperature data... but first set the BUSY byte
                self.mmap_temperature[1] = '1'
                #Get the Temperature data
                print "Getting temperature data"
                sensors['temperature'] = str(SensorsInterface.getTemperature())
                self.mmap_temperature[0] = '0'  #The request has been completed
                self.mmap_temperature[1] = '0'  #...and we are no longer busy

            #AmbientLight
            if self.mmap_ambientlight[0] == '1':
                #Send temperature data... but first set the BUSY byte
                self.mmap_ambientlight[1] = '1'
                #Get the Ambient Light data
                print "Getting ambient light data"
                sensors['ambientlight'] = str(
                    SensorsInterface.getAmbientLight())
                self.mmap_ambientlight[
                    0] = '0'  #The request has been completed
                self.mmap_ambientlight[1] = '0'  #...and we are no longer busy

            sensors_lock.release()
            """If there is new data stored in sensors --> sensors != {},
			then we should make this thread wait until it is sent to the
			socket. """
            if sensors != {}:
                data_ready_event.clear()
                data_ready_event.wait()
Exemplo n.º 6
0
                print "Connected with MQTT Broker: " + str(MQTT_Broker)

def on_publish(client, userdata, mid):
        pass

def on_disconnect(client, userdata, rc):
        if rc !=0:
                pass

mqttc = mqtt.Client()
mqttc.on_connect = on_connect
mqttc.on_disconnect = on_disconnect
mqttc.on_publish = on_publish
mqttc.connect(MQTT_Broker, int(MQTT_Port), int(Keep_Alive_Interval))

sensor.setupSensorian()

time.sleep(2)

while True:
        temp = str(sensor.getTemperature())
        light = str(sensor.getAmbientLight())
        press = str(sensor.getBarometricPressure())
        alt = str(sensor.getAltitude())

        mqttc.publish(topic_temp, temp)
        time.sleep(2)
        print temp
        mqttc.publish(topic_light, light)
        time.sleep(2)
        print light
Exemplo n.º 7
0
#!/usr/bin/env python

"""test.py: Tests the functionality of tft_printer, SensorsInterface and NetworkingTools"""

import time
import tft_printer
import SensorsInterface
import PiTools
import CloudTools

__author__ = "Dylan Kauling"
__maintainer__ = "Dylan Kauling"
__status__ = "Development"

SensorsInterface.setupSensorian()  # Prepare the sensors on the Sensorian Shield

SensorsInterface.ledOn()  # Turn on the Sensorian Orange LED

# Print White Hello World to the display in Portrait mode
tft_printer.screen_print_rotated("Hello world!", 0)

time.sleep(2)  # Wait for 2 seconds before continuing.

# Print a longer black string on a white background to the display in Landscape mode
tft_printer.screen_print_rotated("This is a longer string to demonstrate the wrapping and text background", 1,
                                 colour=(0, 0, 0, 0), background=(255, 255, 255))

time.sleep(2)  # Wait for 2 seconds before continuing.

sensor_string = ""  # Prepare an empty string to be printed to the screen 
Exemplo n.º 8
0
        selected_sensor_numbers.append(6)
        selected_sensor_numbers.append(7)
    if var_args["magnetometer"]:
        selected_sensor_numbers.append(8)
        selected_sensor_numbers.append(9)
        selected_sensor_numbers.append(10)
    if var_args["rtcc"]:
        selected_sensor_numbers.append(11)
        selected_sensor_numbers.append(12)
        selected_sensor_numbers.append(13)
        selected_sensor_numbers.append(14)
        selected_sensor_numbers.append(15)
        selected_sensor_numbers.append(16)
        selected_sensor_numbers.append(17)

SensorsInterface.setupSensorian()

# Ensure all alarms are off
SensorsInterface.resetRTCCalarm()

sensormonitor = SensorMonitor(selected_sensor_numbers)
sensormonitor.start()

if var_args["connect"]:
    remote_host = var_args["connect"][0]
    client = ScratchHandler(selected_sensor_numbers, host=remote_host)
else:
    client = ScratchHandler(selected_sensor_numbers)

asyncore.loop()
Exemplo n.º 9
0
#!/usr/bin/env python
"""test.py: Tests the functionality of tft_printer, SensorsInterface and NetworkingTools"""

import time
import tft_printer
import SensorsInterface
import PiTools
import CloudTools

__author__ = "Dylan Kauling"
__maintainer__ = "Dylan Kauling"
__status__ = "Development"

SensorsInterface.setupSensorian(
)  # Prepare the sensors on the Sensorian Shield

SensorsInterface.ledOn()  # Turn on the Sensorian Orange LED

# Print White Hello World to the display in Portrait mode
tft_printer.screen_print_rotated("Hello world!", 0)

time.sleep(2)  # Wait for 2 seconds before continuing.

# Print a longer black string on a white background to the display in Landscape mode
tft_printer.screen_print_rotated(
    "This is a longer string to demonstrate the wrapping and text background",
    1,
    colour=(0, 0, 0, 0),
    background=(255, 255, 255))

time.sleep(2)  # Wait for 2 seconds before continuing.
import json
import math
import time

import tornado.websocket
import tornado.web
import tornado.ioloop
import tornado.httpserver

import SensorsInterface

VECT_X = 0.00
VECT_Y = 0.00
VECT_Z = 0.00

SensorsInterface.setupSensorian() #Initialize Sensorian

clients = []

class RotationDataSocket(tornado.websocket.WebSocketHandler):
	def open(self):
		print "Websocket has been opened"
		clients.append(self)
	
	def on_message(self,message):
		print "I have received a message"
	
	def on_close(self):
		print "Websocket closed"
	
	def update(self):
Exemplo n.º 11
0
        selected_sensor_numbers.append(6)
        selected_sensor_numbers.append(7)
    if var_args['magnetometer']:
        selected_sensor_numbers.append(8)
        selected_sensor_numbers.append(9)
        selected_sensor_numbers.append(10)
    if var_args['rtcc']:
        selected_sensor_numbers.append(11)
        selected_sensor_numbers.append(12)
        selected_sensor_numbers.append(13)
        selected_sensor_numbers.append(14)
        selected_sensor_numbers.append(15)
        selected_sensor_numbers.append(16)
        selected_sensor_numbers.append(17)

SensorsInterface.setupSensorian()

#Ensure all alarms are off
SensorsInterface.resetRTCCalarm()

sensormonitor = SensorMonitor(selected_sensor_numbers)
sensormonitor.start()

if var_args['connect']:
    remote_host = var_args['connect'][0]
    client = ScratchHandler(selected_sensor_numbers, host=remote_host)
else:
    client = ScratchHandler(selected_sensor_numbers)

asyncore.loop()