IoTAClient, \ QuantumLeapClient # ## Parameters # ToDo: Enter your context broker url and port, e.g. http://localhost:1026 CB_URL = "http://localhost:1026" # ToDo: Enter your IoT-Agent url and port, e.g. http://localhost:4041 IOTA_URL = "http://localhost:4041" # ToDo: Enter your QuantumLeap url and port, e.g. http://localhost:8668 QL_URL = "http://localhost:8668" # ## Main script if __name__ == "__main__": # Create a single client for each service and check the service for # its version cbc = ContextBrokerClient(url=CB_URL) print(cbc.get_version()) iotac = ... qlc = ... # ToDo: Create a configuration object for a multi client config = HttpClientConfig(...) # ToDo: Create a multi client check again all services for their version multic = HttpClient(config=config) print(multic.cb.get_version()) ...
SERVICE_PATH = '/example' # Setting up logging logging.basicConfig(level='INFO', format='%(asctime)s %(name)s %(levelname)s: %(message)s') logger = logging.getLogger(__name__) if __name__ == "__main__": # # 1 Setup Client # # create the client, for more details view the example: e01_http_clients.py fiware_header = FiwareHeader(service=SERVICE, service_path=SERVICE_PATH) cb_client = ContextBrokerClient(url=CB_URL, fiware_header=fiware_header) # View version for key, value in cb_client.get_version().items(): logger.info("Context broker version" + value["version"] + " at url " + cb_client.base_url) # # 2 Create Entities # # ## 2.1 Build Models # # Entities can be created by: # # ### 2.1.1 Passing a dict: # room1 = { "id": "Room1", "type": "Room", "temperature": {
# FIWARE in the space given by the FiwareHeader. For more information see: # e01_http_clients.py fiware_header = FiwareHeader(service=SERVICE, service_path=SERVICE_PATH) # clear all existing data clear_all(fiware_header=fiware_header, cb_url=CB_URL, ql_url=QL_URL) ql_client = QuantumLeapClient(url=QL_URL, fiware_header=fiware_header) print("Quantum Leap " + ql_client.get_version()["version"] + " at url " + ql_client.base_url) cb_client = ContextBrokerClient(url=CB_URL, fiware_header=fiware_header) print("Context broker version " + cb_client.get_version()["orion"]["version"] + " at url " + cb_client.base_url) # ## 2 Interact with QL # # ### 2.1 Create a ContextEntity to work with # # for more details see: e01_ngsi_v2_context_basics.py hall = { "id": "Hall_1", "type": "Room", "temperature": { "value": random.randint(0, 100), "type": "Integer" }, }
""" # Example to show we can make use of python's logging when using filip. # The configuration is totally up to the user because FiLiP should not # interfere with the user's final application and preferences. # Each module has its own logger but does not configure any streams and # therefore reuses the streams of the root logger. """ # import python's build in logging implementation import logging # import an api client from filip as example from filip.clients.ngsi_v2 import ContextBrokerClient # setting up the basic configuration of the logging system. Please check the # official documentation and the functions docstrings for more details. # Handling for 'handlers' in the logging system is not trivial. # It is also import to know that this function should only be called once in # your application. Since FiLiP is an SDK that should help to implement other # services we do not call this function anywhere in our code. # Hence, it is up to the user to configure the logging system. # In this example we will simply change the log level and the log format. logging.basicConfig(level='DEBUG', format='%(asctime)s %(name)s %(levelname)s: %(message)s') # You need to change the output ocb = ContextBrokerClient(url='http://<PleaseChange.Me>') ocb.get_version()