Пример #1
0
    def test_config_file_init_specific_params(self):
        iot_client = FiwareIotClient.from_config_file(self._build_file_path('config.dummy.json'))

        self.assertEqual(iot_client.fiware_config.iota_host, 'iota_address')
        self.assertEqual(iot_client.fiware_config.iota_north_port, 2)
        self.assertEqual(iot_client.fiware_config.iota_protocol_port, 3)
        # check IOTA auth attr
        self.assertEqual(iot_client.fiware_config.api_key, '1a2b3c4d5e6f')

        self.assertEqual(iot_client.fiware_config.mqtt_broker_host, 'mqtt_broker_address')
        self.assertEqual(iot_client.fiware_config.mqtt_broker_port, 6)
Пример #2
0
    def _remove_all_devices():
        iot_client = FiwareIotClient.from_config_file(
            TestCommonMethods._build_file_path('config.json'))
        context_client = FiwareContextClient.from_config_file(
            TestCommonMethods._build_file_path('config.json'))

        response = iot_client.list_devices()
        data = response['response']
        devices = data['devices']

        for device in devices:
            # Remove devices
            iot_client.remove_device(device['device_id'])

            # Remove entity associated to each device
            context_client.remove_entity('thing', device['entity_name'])
Пример #3
0
    def test_config_file_init_inherited_params(self):
        iot_client = FiwareIotClient.from_config_file(self._build_file_path('config.dummy.json'))

        self.assertEqual(iot_client.fiware_config.service, 'service_name')
        self.assertEqual(iot_client.fiware_config.service_path, '/service_path')

        self.assertEqual(iot_client.fiware_config.cb_host, 'context_broker_address')
        self.assertEqual(iot_client.fiware_config.cb_port, 1)
        # TODO Check OAuth param

        # TODO Check these verifications
        self.assertEqual(iot_client.fiware_config.iota_aaa, False)
        # self.assertEqual(iot_client.token, '')
        # self.assertEqual(iot_client.expires_at, '')

        self.assertEqual(iot_client.fiware_config.host_id, 'b4:b6:30')
Пример #4
0
            print('Unknown parameter')
            client.publish(response_topic, payload_response_error)
    else:
        print('Unknown command')
        client.publish(response_topic, payload_response_error)


mqtt_client = mqtt.Client()
mqtt_client.on_connect = on_connect
mqtt_client.on_message = on_message

mqtt_client.connect(MQTT_BROKER_ADDRESS, 1883, 60)

mqtt_client.loop_start()

iot_client = FiwareIotClient("config.ini")
iot_client.set_service(SERVICE_NAME, SERVICE_PATH)
iot_client.set_api_key(SERVICE_API_KEY)

while True:
    presence_read = GPIO.input(11)
    presence = True if presence_read == 1 else False
    iot_client.send_observation(PIR_DEVICE_ID, {'p': presence},
                                protocol='MQTT')

    if not presence:  # when output from motion sensor is LOW
        print("No presence")
        GPIO.output(3, 0)  # turn OFF FAN
    else:  # when output from motion sensor is HIGH
        print("Presence detected")
        GPIO.output(3, 1)  # turn ON FAN
if __name__ == '__main__':
    arguments = []
    if len(sys.argv) > 1:
        arguments = sys.argv

    DEVICE_FILE_ROOT = "./devices/"

    LDR_DEVICE_ID = "UL_LDR"
    LDR_ENTITY_ID = "LDR001"
    LDR_FILE_PATH = DEVICE_FILE_ROOT + "LDR.json"

    LED_DEVICE_ID = "UL_LED"
    LED_ENTITY_ID = "LED001"
    LED_FILE_PATH = DEVICE_FILE_ROOT + "LED.json"

    client_iot = FiwareIotClient("config.ini")
    client_context = FiwareContextClient("config.ini")

    if '--no-register-device' not in arguments:
        client_iot.register_device(LDR_FILE_PATH, LDR_DEVICE_ID, LDR_ENTITY_ID)
        client_iot.register_device(LED_FILE_PATH, LED_DEVICE_ID, LED_ENTITY_ID)

    if '--no-subscribe-cygnus' not in arguments:
        client_context.subscribe_cygnus(LDR_ENTITY_ID, ["luminosity"])
        client_context.subscribe_cygnus(LED_ENTITY_ID, ["state"])

    if '--no-subscribe-sth' not in arguments:
        client_context.subscribe_historical_data(LDR_ENTITY_ID, ["luminosity"])

    try:
        while True:
    Device = "DHT.json"

    #diretório completo do dispositivo
    DHT_FILE_PATH = DEVICE_FILE_ROOT + Device

    #definição do sensor utilizado
    sensor = Adafruit_DHT.AM2302

    #definição do pino GPIO utilizado no Raspberry pi
    GPIOpin = '4'

    #definição do tempo entre medições
    DELAY_MEASUREMENT = 10

    #criando uma instância das classes iot e context da biblioteca fiotclient
    client_iot = FiwareIotClient("config.ini")
    client_context = FiwareContextClient("config.ini")

    #atribuindo o service e o service path
    if '--no-set-service' not in arguments:
        client_iot.set_service(SERVICE_NAME, SERVICE_PATH)

    #atribuindo a api_key
    if '--no-set-api-key' not in arguments:
        client_iot.set_api_key(API_KEY)

    #registrando o dispositivo
    if '--no-register-device' not in arguments:
        client_iot.register_device(DHT_FILE_PATH, DHT_DEVICE_ID, DHT_ENTITY_ID)

    #atribuindo a entidade
Пример #7
0
 def __init__(self, method_name):
     super().__init__(methodName=method_name)
     self.context_client = FiwareContextClient.from_config_file(
         TestCommonMethods._build_file_path('config.json'))
     self.iot_client = FiwareIotClient.from_config_file(
         TestCommonMethods._build_file_path('config.json'))
            print('Unknown parameter')
            client.publish(response_topic, payload_response_error)
    else:
        print('Unknown command')
        client.publish(response_topic, payload_response_error)


mqtt_client = mqtt.Client()
mqtt_client.on_connect = on_connect
mqtt_client.on_message = on_message

mqtt_client.connect(MQTT_BROKER_ADDRESS, MQTT_BROKER_PORT, 60)

mqtt_client.loop_start()

iot_client = FiwareIotClient.from_config_file("config.ini")
iot_client.set_service(SERVICE_NAME, SERVICE_PATH)
iot_client.set_api_key(SERVICE_API_KEY)

while True:
    presence = bool(random.getrandbits(1))
    temperature = random.randint(15, 40)
    humidity = random.randint(50, 100)

    payload = {'t': temperature, 'h': humidity, 'p': presence}
    print('publish {}'.format(payload))

    iot_client.send_observation(DEVICE_ID, payload, protocol='MQTT')

    time.sleep(5)  # wait for 5 seconds