Beispiel #1
0
 def Fkondenz(self, _isTest):
     self.isTest = _isTest
     self.dweet = Dweet()
     try:
         self.ser = serial.Serial('/dev/ttyUSB0', 9600)
     except NameError:
         pass
Beispiel #2
0
    def __init__(self, _isTest):
        self.testData = None
        self.testData1 = None
        self.testData2 = None

        self.isTest = _isTest
        self.dweet = Dweet()
        try:
            self.ser = serial.Serial('/dev/ttyUSB0', 9600)
        except NameError:
            pass
Beispiel #3
0
class View(object):
    __dweet = Dweet()

    def __init__(self, database):
        self.__database = database

    def insertDataIntoDatabase(self, hum, temp):
        """
        Inserts the data into the database
        :param hum:
        :param temp:
        :return:
        """
        self.__database.insertDataBySensorID(StaticData.DHT_HUM_ID, hum)
        self.__database.insertDataBySensorID(StaticData.DHT_TEMP_ID, temp)

    def sendData(self, hum, temp, dist):
        """
        Sends the sensor data to dweet.io and returns 'success' on success and 'failed' on failure
        :param hum:
        :param temp:
        :param dist:
        :return:
        """
        try:
            resp = View.__dweet.dweet_by_name(name=StaticData.DWEET_ID, data={Sensor.STR_HUMIDITY: hum,
                                                                              Sensor.STR_TEMPERATURE: temp,
                                                                              Sensor.STR_DISTANCE: dist}
                                              )
            return resp['this']
        except requests.exceptions.ConnectionError:
            return "Connection error"

    def uploadToDweet(self, hum, temp, dist):
        """
        Test method wichi will print the data, send it to dweet.io and print the result
        :param hum:
        :param temp:
        :param dist:
        :return:
        """
        print "Sending"
        print "\tHumidity: ", hum
        print "\tTemperature: ", temp
        print "\tDistance: ", dist

        resp = self.sendData(hum, temp, dist)
        print "Result: " + resp + '\n'
Beispiel #4
0
    def test_e2e_readSensors_sendToDweet(self):
        fkond = Fkondenz(True)
        dweet = Dweet()

        testData = 1
        testData1 = 2
        testData2 = 3

        fkond.setTestData(testData)
        fkond.setTestData(testData1)
        fkond.setTestData(testData2)

        testData_, testData1_, testData2_ = fkond.readSensors()

        fkond.uploadToDweet(testData_, testData1_, testData2_)

        self.assertEqual(fkond.getTestData(), "Uploaded")
Beispiel #5
0
GPIO_CS = GPIO.gpio_id('GPIO_CS')
RELE = GPIO.gpio_id('GPIO_A')
BOTAO = GPIO.gpio_id('GPIO_C')

pins = ((GPIO_CS, 'out'), (RELE, 'out'), (BOTAO, 'in'))

#Definição de parâmetros para portas analógicas
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 10000
spi.mode = 0b00
spi.bits_per_word = 8

#Declaração de uma variável Dweet para interface com sistema
# de nuvem
dweet = Dweet()

#Declaração de variáveis
alarme_bebe = 0
reset_nuvem = 0
bam_nuvem = 0
ld_nuvem = 0
estado_am = 0


#Leitura e conversão da leitura do sensor para °C
def readtemp(gpio):

    gpio.digital_write(GPIO_CS, GPIO.HIGH)
    time.sleep(0.0002)
    gpio.digital_write(GPIO_CS, GPIO.LOW)
Beispiel #6
0
 if __name__ == "__main__":
    devicename='bits279'#default device name
    if len(sys.argv)>1:#checking for any command line args
        devicename=sys.argv[1]#if found then change the device name to the first command line argument
    prev=datetime.strptime("00:00:00","%H:%M:%S");# initialise the timestamp of the previous command to 0
    test=serial.Serial("/dev/ttyAMA0",9600)#initialise serial port at 9600 baudrate
   
    #initialise the GPIO Pins 
    GPIO.setmode(GPIO.BOARD)#use the board pin numberings
    GPIO.setup(7,GPIO.OUT)#set 7,11,13,and 15 pin as output for LED status
    GPIO.setup(11,GPIO.OUT)
    GPIO.setup(13,GPIO.OUT)
    GPIO.setup(15,GPIO.OUT)

    dweet = Dweet()#initialise dweet object


    while 1==1:#infinite loop/program loop
        GPIO.output(7,False);#turning off all LEDs
        GPIO.output(11,False);
        GPIO.output(13,False);
        GPIO.output(15,True);#LED 15 is the ON indicator. Indicates the program is running
        

        #receiving command from server
       
        try:
            rdata=dweet.latest_dweet(name=devicename) #checking for HTTP connection
        except Exception, e:#if error found
            print "Connection Error Occured" # dweet class is configured to only return a Connection Error so any error thrown is a Connection error
Beispiel #7
0
    cloud_enabled = cfg.getboolean("cloud", "enabled")
    cloud_server = cfg.get("cloud", "server")
    cloud_port = cfg.get("cloud", "port")
    cloud_url = cfg.get("cloud", "url")
    cloud_time_out = cfg.getint("cloud", "time_out")
    cloud = Cloud(cloud_enabled,
                  cloud_server,
                  cloud_port,
                  cloud_url,
                  timeout=cloud_time_out)

    enabled = cfg.getboolean("dweet", "enabled")
    dweet_server = cfg.get("dweet", "server")
    dweet_name = cfg.get("dweet", "name")
    dweet_time_out = cfg.getint("dweet", "time_out")
    dweet = Dweet(enabled, dweet_server, dweet_name, timeout=dweet_time_out)

    broker_host = cfg.get("mqtt_broker", "host")
    broker_port = cfg.get("mqtt_broker", "port")

    sub_enabled = cfg.getboolean("mqtt_subscribe", "enabled")
    sub_topics = cfg.get("mqtt_subscribe", "topics")
    sub_topics = sub_topics.split(",")
    sub_time_out = cfg.getint("mqtt_subscribe", "time_out")
    sub = MqttSub(sub_enabled,
                  broker_host,
                  broker_port,
                  sub_topics,
                  timeout=sub_time_out)
    sub.start()
    time.sleep(3)