コード例 #1
0
 def get(self):
     try:
         reading = 0
         GPIO.setmode(GPIO.BCM)
         GPIO.setup(self.pin, GPIO.OUT)
         GPIO.output(self.pin, GPIO.LOW)
         time.sleep(0.1)
         GPIO.setup(self.pin, GPIO.IN)
         returnValue = 0
         while True:
             if (GPIO.input(self.pin) == GPIO.LOW):
                 reading += 1
             if reading >= 1000:
                 returnValue = 0
                 print 'MoistureDetector with pin %d : %d' % (self.pin,
                                                              returnValue)
                 return 0
             if (GPIO.input(self.pin) != GPIO.LOW):
                 returnValue = 1
                 print 'MoistureDetector with pin %d : %d' % (self.pin,
                                                              returnValue)
                 return 1
     except Exception, e:
         utils.log("MoistureDetector Error: " + str(e))
         print("MoistureDetector Error: " + str(e))
コード例 #2
0
    def get(self):
        GPIO.setmode(GPIO.BCM)
        print "Distance Measurement In Progress"
        utils.log("Distance Measurement In Progress")
        
        GPIO.setup(self.trig,GPIO.OUT)
        GPIO.output(self.trig, GPIO.LOW)
        GPIO.setup(self.echo,GPIO.IN)
        GPIO.output(self.trig, False)

        print "Waiting For Sensor To Settle"
        utils.log("Waiting For Sensor To Settle")
        time.sleep(2)

        GPIO.output(self.trig, True)
        time.sleep(0.00001)
        GPIO.output(self.trig, False)

        while GPIO.input(self.echo)==0:
            pulse_start = time.time()

        while GPIO.input(self.echo)==1:
            pulse_end = time.time()

        pulse_duration = pulse_end - pulse_start
        distance = pulse_duration * 17150
        distance = round(distance, 2)

        print "Distance:",distance,"cm"
        utils.log("Distance: "+str(distance)+"cm")

        GPIO.cleanup()
        return distance
コード例 #3
0
                print(self.name + " Config Key: " + str(e))

    def get(self):
        try:
            reading = 0
            GPIO.setmode(GPIO.BCM)
            GPIO.setup(self.pin, GPIO.OUT)
            GPIO.output(self.pin, GPIO.LOW)
            time.sleep(0.1)
            GPIO.setup(self.pin, GPIO.IN)
            returnValue = 0
            while True:
                if (GPIO.input(self.pin) == GPIO.LOW):
                    reading += 1
                if reading >= 1000:
                    returnValue = 0
                    print 'MoistureDetector with pin %d : %d' % (self.pin,
                                                                 returnValue)
                    return 0
                if (GPIO.input(self.pin) != GPIO.LOW):
                    returnValue = 1
                    print 'MoistureDetector with pin %d : %d' % (self.pin,
                                                                 returnValue)
                    return 1
        except Exception, e:
            utils.log("MoistureDetector Error: " + str(e))
            print("MoistureDetector Error: " + str(e))
        except:
            utils.log("MoistureDetector: Error")
            print("MoistureDetector: Error")
コード例 #4
0
x_microchip = True
x_read_server_json = True
x_read_server_file = False
x_read_server_insta = True

### Sensors and Controllers

if x_microchip:
    print("- - - - - - - - - - - - - - - - - - - - ")
    try:
        microchip = microchipRef.Microchip()
        serialNumber = microchip.getSerialNumber()
        print("Microchip Serial Number : " + serialNumber)
    except Exception, e:
        utils.log("Microchip: ")
        utils.log(str(e))
    except:
        utils.log("Microchip: Unknown Error")

###-------------------------------------
### Read Configurations from Server
###-------------------------------------

### JSON request method

if x_read_server_json:
    print("- - - - - - - - - - - - - - - - - - - - ")
    print("Reading Configuration Data from Server JSON Request...")
    isDataValid = False
    data = {}
コード例 #5
0
new_data_file_path = '/home/pi/iotchip/data/new_data2send.json'
old_data_file_path = '/home/pi/iotchip/data/old_data2send.json'

# rename new file to old file

os.rename(new_data_file_path, old_data_file_path)

# generate random Gaussian values
from random import seed
from random import gauss
#seed(1)

try:
    serialNumber = utils.getSerialNumber()
except Exception, e:
    utils.log("Microchip: ")
    utils.log(str(e))
except:
    utils.log("Microchip: Unknown Error")

timestamp = int(time.time()) * 1000.0
now = datetime.datetime.now()

data = {
    'serial': serialNumber[:16],
    'timeHours': now.hour,
    'timeMinutes': now.minute,
    'temperature': round(gauss(22, 0.5)),
    'humidity': round(gauss(75, 0.5)),
    'moistures': round(gauss(75, 0.5)),
    'waterTemperature': round(gauss(22, 0.5)),
コード例 #6
0
#baseUrl = "http://192.168.0.101/boxbeta"

### Control Variables

x_microchip = True
x_execute = True

### Sensors and Controllers 

if x_microchip :
    try:
        microchip = microchipRef.Microchip()
        serialNumber = microchip.getSerialNumber()
        print("Microchip Serial Number : " + serialNumber)
    except Exception,e: 
        utils.log("Microchip: ")
        utils.log(str(e))
    except:
        utils.log("Microchip: Unknown Error")

### Read from local configuration file

try :
    dataConfiguration = {}
    print("Reading Configuration from File...")
    confPath = utils.getContextPath()+"/conf/fetched_data.json"
    with open(confPath) as data_file:    
        dataConfiguration = json.load(data_file)
    print json.dumps(dataConfiguration, indent=4, sort_keys=True)
except Exception,e: 
    utils.log("File Read Failed :")
コード例 #7
0
### Call Sensors and Controllers
###----------------------

# Power on GPIO
print("- - - - - - - - - - - - - - - - - - - - ")
gpio = gpioRef.GpioController(False)
gpio.powerOn()

if x_microchip:
    print("- - - - - - - - - - - - - - - - - - - - ")
    try:
        microchip = microchipRef.Microchip()
        serialNumber = microchip.getSerialNumber()
        print("Microchip Serial Number : " + serialNumber)
    except Exception, e:
        utils.log("Microchip :")
        utils.log(str(e))
    except:
        utils.log("Microchip : Unknown Error")

if x_thermometer:
    print("- - - - - - - - - - - - - - - - - - - - ")
    try:
        thermometer = thermometerRef.Thermometer()
        print("Getting Air Temperature...")
        temperature = thermometer.get()
        print(temperature)
    except Exception, e:
        utils.log("Thermometer :")
        utils.log(str(e))
    except:
コード例 #8
0
### Control

x_microchip = True # always true as serial number is needed
x_camera = True # if this one if off, no request will be sent
x_send_server_photo = True # x_camera must be True

### Sensors and Controllers 

if x_microchip :
    try:
        microchip = microchipRef.Microchip()
        serialNumber = microchip.getSerialNumber()
        print("Microchip Serial Number: " + serialNumber)
    except Exception,e: 
        utils.log("Microchip :")
        utils.log(str(e))
    except:
        utils.log("Microchip : Unknown Error")


if x_camera:
    try:
        camera = cameraUSBRef.CameraUSB()
        time.sleep(1); utils.log("."); time.sleep(1); utils.log(".");
        print("Trying to Snapshot...")
        photo = camera.capture()
        camera.cleanUpRepository(True)
        print(photo)
    except Exception,e: 
        utils.log("CameraUSB :")
コード例 #9
0
ファイル: send_data.py プロジェクト: fedlucchetti/iotchip
import logging
from beans import utils
from beans import Microchip as microchipRef
frequency = 60  # every X sec a request is sent

x_send_server_data = True

baseUrl = " https://planthive-uat.appspot.com"

new_data_file_path = '/home/pi/iotchip/data/new_data2send.json'
old_data_file_path = '/home/pi/iotchip/data/old_data2send.json'

try:
    serialNumber = utils.getSerialNumber()
except Exception, e:
    utils.log("Microchip: ")
    utils.log(str(e))
except:
    utils.log("Microchip: Unknown Error")

#serialNumber = '0000000000000002'
#serialNumber = 0000000000000001

while True:

    try:
        with open(old_data_file_path) as f:
            olddata = json.load(f)
    except Exception, e:
        utils.log("Error opening Json data file " + str(e))
コード例 #10
0
ファイル: get_data.py プロジェクト: fedlucchetti/iotchip
ledsObj = GrowLED.GrowLED()
fanObj = FanController.FanController()
pwm = ExecutePWM.ExecutePWM()
frontled = FrontLED.FrontLED()

###-------------------------------------
### Read Configurations from Server
###-------------------------------------

### JSON request method

try:
    serialNumber = utils.getSerialNumber()
except Exception, e:
    utils.log("Microchip: ")
    utils.log(str(e))
except:
    utils.log("Microchip: Unknown Error")
#serialNumber = '0000000000000002'

url = baseUrl + "/api/v1/en/planthive/get-device-command/" + serialNumber

print('request data from  ' + url)

while True:
    time.sleep(frequency)
    if x_read_server_json:
        #print("- - - - - - - - - - - - - - - - - - - - ")
        #print("Reading Configuration Data from Server JSON Request...")
        isDataValid = False