def parse(var):
    full = "".join(var)
    full = full.replace("\n", "")
    full = re.sub(" +", " ", full)
    full = full.rstrip()
    utils.info(full)
    print len(full)
    major = int(full[-17:-11].replace(" ", ""), 16)
    minor = int(full[-11:-6].replace(" ", ""), 16)
    temp = minor / 10.0
    utils.info("Major: " + str(major))
    utils.info("Minor: " + str(minor))
    utils.send_to_cloud(1, minor, major)  # 1 represents key for temperature in temp * 100 format
Beispiel #2
0
#!/usr/bin/python

import time
import lib.utils as utils
import subprocess
import sys
from tendo import singleton
import argparse

me = singleton.SingleInstance() # will sys.exit(-1) if other instance is running

parser = argparse.ArgumentParser(description='Sends heartbeat to server.')

parser.add_argument('-s', '--send',    action="store_true", help='Send to server, otherwise just test reading the sensors.')
parser.add_argument('-v', '--verbose', action="store_true", help='Print out more info.')

utils.args = parser.parse_args()

utils.send_to_cloud("beat", time.time())
Beispiel #3
0
utils.args = parser.parse_args()

# Listen on port 2947 (gpsd) of localhost
session = gps.gps('localhost', 2947)
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)

utils.info("Starting gps poller")

while True:
    try:
        utils.info("Starting try...")
        report = session.next()
        utils.info(report);
        if report['class'] == 'TPV':
            utils.info(report)
            if hasattr(report, 'time'):
                error = 0.0
                if hasattr(report, 'epx'):
                    error = (report.epx + report.epy) / 2.0
                location = str(report.lat) + ',' + str(report.lon) + ',' + str(error)
                utils.send_to_cloud("location", location)
                time.sleep(60) # sleep 60 seconds after reporting location
        time.sleep(3); # only try to get data every THIS seconds if unsuccessfull
    except KeyError:
        pass
    except KeyboardInterrupt:
        quit()
    except StopIteration:
        session = None
        utils.info("GPSD has terminated")
Beispiel #4
0
utils.args = parser.parse_args()

#serial_dev = '/dev/ttyACM0'
#serial_dev = '/dev/tty.usbserial-A9007KLg'
serial_dev = '/dev/ttyAMA0'

ser = serial.Serial(serial_dev, 9600)

utils.info(serial_dev + " initialized. Getting data...")
time.sleep(3)

ser.write("2")
out = ser.readline()
light = 100.0 / 1023.0 * float(re.split(':|\\n', out)[2])
utils.info(light)
utils.send_to_cloud("light", light)

sleep = 12
ser.write("0")
time.sleep(sleep)
ser.write("1")
out = ser.readline()
count = re.split(':|\\n', out)[2]
freq = float(count) / float(sleep) / 2.0
mps = float(freq) / 0.777  # 0.777Hz per m/s nominal - from vectorinstruments web site
utils.send_to_cloud("wind_speed", mps)

ser.write("4")
out = ser.readline()
wv = re.split(':|\\n', out)[2]
utils.send_to_cloud("wind_direction", wv)
Beispiel #5
0
me = singleton.SingleInstance() # will sys.exit(-1) if other instance is running

parser = argparse.ArgumentParser(description='Gets temperature data from DS18B20 and sends to server.')

parser.add_argument('-s', '--send',    action="store_true", help='Send to server, otherwise just test reading the sensors.')
parser.add_argument('-v', '--verbose', action="store_true", help='Print out more info.')

utils.args = parser.parse_args()

def read_temperature(onewire):
    file  = '/sys/bus/w1/devices/' + onewire + '/w1_slave'
    tfile = open(file)
    text  = tfile.read()
    tfile.close()

    # split the two lines
    lines = text.split("\n")

    # make sure the crc is valid
    if lines[0].find("YES") > 0:
        # get the 9th (10th) chunk of text and lose the t= bit
        temp = float((lines[1].split(" ")[9])[2:])
        # add a decimal point
        temp /= 1000
        return temp

onewire = '28-0000019d3e23' # marcel
#onewire = '28-000001e3f96c' # hacklab
current_temp = read_temperature(onewire)
utils.send_to_cloud("temp", current_temp)
Beispiel #6
0
# this script is used to read i2c slave information from arduino
# it is defigned to read two bytes of info - in this case number
# of revolutions from anemometer and calculate that to frequency
#
# make sure address variable matchies the one on arduino

import smbus
import time
import lib.utils as utils

sleep = 12
address = 0x04

bus = smbus.SMBus(1)


def readData():
    data1 = bus.read_word_data(address, 0)
    return data1


print "Sampling delay: " + str(sleep) + " seconds."

readData()  # this also resets the counter on arduino
time.sleep(sleep)
count = readData()

freq = float(count) / float(sleep) / 2.0
utils.send_to_cloud("wind_freq", freq)
Beispiel #7
0
#!/usr/bin/env python

# Example for RC timing reading for Raspberry Pi
# Must be used with GPIO 0.3.1a or later - earlier verions
# are not fast enough!

# phoocell is connected directly to RPI via GPIO port 18 through
# a 1uF polarized capacitor as RPI does not have ADC converter

import RPi.GPIO as GPIO, time, os
import lib.utils as utils

DEBUG = 1
GPIO.setmode(GPIO.BCM)

def RCtime (RCpin):
    reading = 0
    GPIO.setup(RCpin, GPIO.OUT)
    GPIO.output(RCpin, GPIO.LOW)
    time.sleep(0.1)

    GPIO.setup(RCpin, GPIO.IN)
    # This takes about 1 millisecond per loop cycle
    while (GPIO.input(RCpin) == GPIO.LOW):
        reading += 1
    return reading

val = RCtime(18) # Read RC timing using pin #18

utils.send_to_cloud("light", val)