Пример #1
0
def main() :
	try:
        global s
		# setup moisture sensor
		moistureSensor = BLEMoistureSensor()
		moistureSensor.setSensorDataAvailableEvent(processSensorData)

		# setup server socket
		if Debug == False :
			s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
			print("Socket created.")
			while True:
				try:
					s.connect((HOST, PORT));
					break;
				except socket.error as msg:
					print("Socket connection failed. Error Code : " + str(msg[0]) + " Message " + msg[1])
					time.sleep(CONNECT_RETRY_INTERVAL)
			print ("Socket connection succeeded.")

		# this will listen forever for advertising events and call processSensorData() when data arrives
		moistureSensor.Listen();

	except KeyboardInterrupt: 
		print("Continuous polling stopped")
def main():
    try:
        global s
        # setup moisture sensor
        moistureSensor = BLEMoistureSensor()
        moistureSensor.setSensorDataAvailableEvent(processSensorData)

        # setup server socket
        if Debug == False:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            print ("Socket created.")
            while True:
                try:
                    s.connect((HOST, PORT))
                    break
                except socket.error as msg:
                    print ("Socket connection failed. Error Code : " + str(msg[0]) + " Message " + msg[1])
                    time.sleep(CONNECT_RETRY_INTERVAL)
            print ("Socket connection succeeded.")

            # this will listen forever for advertising events and call processSensorData() when data arrives
        moistureSensor.Listen()

    except KeyboardInterrupt:
        print ("Continuous polling stopped")
Пример #3
0
def main():
    global s
    global deviceConfig
    global sensorAgentConfig

    # parse SensorAgent configuration CSV file
    try:
        with open('SensorAgentConfig.csv') as sensorAgentConfigFile:
            sensorAgentConfigSource = csv.DictReader(sensorAgentConfigFile)
            for row in sensorAgentConfigSource:
                sensorAgentConfig = row
                # we only care about first row in config file
                break
    except:
        print "Error reading config file. Please correct before continuing."
        sys.exit()

    # parse device configuration (BLE device) CSV file
    try:
        with open('DeviceConfig.csv') as deviceConfigFile:
            deviceConfigSource = csv.DictReader(deviceConfigFile)
            for row in deviceConfigSource:
                deviceConfig[row["MACAddress"]] = row
    except:
        print "Error reading config file. Please correct before continuing."
        sys.exit()

    try:
        # setup moisture sensor
        if sys.platform != 'cli':
            moistureSensor = BLEMoistureSensor()
            moistureSensor.setSensorDataAvailableEvent(processSensorData)

        # setup server socket
        if Debug == False:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            print "Socket created."
            while True:
                try:
                    s.connect((sensorAgentConfig["Host"],
                               int(sensorAgentConfig["Port"])))
                    break
                except socket.error as msg:
                    print "Socket connection failed. Error Code : " + str(
                        msg[0]) + " Message " + msg[1]
                    time.sleep(CONNECT_RETRY_INTERVAL)
                    print "Socket connection succeeded."

        # this will listen forever for advertising events and call
        # processSensorData() when data arrives
        if sys.platform != IronPythonPlatform:
            moistureSensor.Listen()

    except KeyboardInterrupt:
        print "Continuous polling stopped"
Пример #4
0
def main() :
    global s
    global deviceConfig
    global sensorAgentConfig

    # parse SensorAgent configuration CSV file
    try:
        with open('SensorAgentConfig.csv') as sensorAgentConfigFile:
            sensorAgentConfigSource = csv.DictReader(sensorAgentConfigFile) 
            for row in sensorAgentConfigSource :
                sensorAgentConfig = row
                # we only care about first row in config file
                break;
    except:
        print "Error reading config file. Please correct before continuing."
        sys.exit()


    # parse device configuration (BLE device) CSV file
    try:
        with open('DeviceConfig.csv') as deviceConfigFile:
            deviceConfigSource = csv.DictReader(deviceConfigFile) 
            for row in deviceConfigSource:
                deviceConfig[row["MACAddress"]] = row
    except:
        print "Error reading config file. Please correct before continuing."
        sys.exit()

    try:
        # setup moisture sensor
        if sys.platform != 'cli':
            moistureSensor = BLEMoistureSensor()
            moistureSensor.setSensorDataAvailableEvent(processSensorData)

        # setup server socket
        if Debug == False :
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            print "Socket created."
            while True:
                try:
                    s.connect((sensorAgentConfig["Host"], int(sensorAgentConfig["Port"])))
                    break
                except socket.error as msg:
                    print "Socket connection failed. Error Code : " + str(msg[0]) + " Message " + msg[1]
                    time.sleep(CONNECT_RETRY_INTERVAL)
                    print "Socket connection succeeded."

        # this will listen forever for advertising events and call
        # processSensorData() when data arrives
        if sys.platform != IronPythonPlatform:
            moistureSensor.Listen()

    except KeyboardInterrupt: 
        print "Continuous polling stopped"