Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ngsi v2 tutorials are deprecated (#255) #259

Merged
merged 34 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1f03a38
chore: make exercise 2 solution more readable
Mar 2, 2024
8a58574
fix: change deprecated methods
Mar 3, 2024
30674f6
fix: change deprecated methods and fix typos
Mar 5, 2024
463ab68
attempt: fix deprecated methods
Mar 7, 2024
e5b7acd
feat: reduce time.sleep() and change x-axis plot result in exercise 1
Mar 7, 2024
4d16b24
fix: cbHost send "None" when no specifying
djs0109 Mar 19, 2024
50205bc
fix: replace "simtime" with "sim_time"
djs0109 Mar 19, 2024
c2fa9cf
chore: migrate to pydantic V2
djs0109 Mar 19, 2024
96d84a5
chore: change the convention for service_path and apikey
djs0109 Mar 19, 2024
529a89a
fix: fix parsing and deprecated methods in exercise 6 solution
Mar 27, 2024
78e9ad1
fix: fix parsing in exercise 7 solution
Mar 27, 2024
b910989
chore: make opening files consistent with as in other exercises
Mar 27, 2024
e4bfc59
chore: format e1_virtual_weatherstation exercise and solution
Apr 4, 2024
70112a6
chore: format e2_healthcheck exercise and solution
Apr 4, 2024
93e1665
chore: format e3_context_entities exercise and solution
Apr 4, 2024
b9acf77
chore: format e4_iot_thermal_zone_sensors exercise and solution
Apr 4, 2024
00ea4e0
chore: format e5_iot_thermal_zone_control exercise and solution
Apr 9, 2024
8416c70
chore: format e6_timeseries_data exercise and solution
Apr 10, 2024
17901f6
chore: format e7_semantic_iot exercise and solution
Apr 10, 2024
5fe9468
format: fix typo in exercise 1
Apr 10, 2024
0a610a5
fix: fix plotting in exercise 5
Apr 10, 2024
e029962
fix: syntax error
djs0109 Apr 11, 2024
cf1659c
chore: replace the deprecated qlc post_subscription with the one in cbc
djs0109 Apr 12, 2024
339a8f8
Merge branch 'master' into 255-ngsi_v2-tutorials-are-deprecated
Apr 16, 2024
3bd8e2f
fix: fix opening files for <python 3.10
Apr 16, 2024
17186e6
chore: make created files disjunct between exercises and solutions
Apr 16, 2024
01b6a90
chore: fix small typos and pep-8 errors in exercise 5 and 6
Apr 16, 2024
d2e228d
merge: solve merge conflicts
Apr 24, 2024
bc26f9e
fix: change the order of the clearing functions
djs0109 Apr 30, 2024
8317608
fix: revert changes to exercise 6
Apr 30, 2024
8a9a747
chore: remove some examples in e6
djs0109 Apr 30, 2024
3f816e9
Merge branch 'master' into 255-ngsi_v2-tutorials-are-deprecated
djs0109 Apr 30, 2024
fb18d6b
Merge branch 'master' into 255-ngsi_v2-tutorials-are-deprecated
djs0109 Apr 30, 2024
80eaa74
docs: changelog
djs0109 Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion filip/models/ngsi_v2/iot.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def validate_cbHost(cls, value):
Returns:
timezone
"""
return str(value)
return str(value) if value else value
lazy: Optional[List[LazyDeviceAttribute]] = Field(
default=[],
desription="list of common lazy attributes of the device. For each "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@
# import simulation model
from tutorials.ngsi_v2.simulation_model import SimulationModel

djs0109 marked this conversation as resolved.
Show resolved Hide resolved

# ## Parameters
# ToDo: Enter your mqtt broker url and port, e.g mqtt://test.mosquitto.org:1883
MQTT_BROKER_URL = "mqtt://test.mosquitto.org:1883"
MQTT_BROKER_URL = "mqtt://test.mosquitto.org:1883"
# ToDo: If required enter your username and password
MQTT_USER = ""
MQTT_PW = ""
MQTT_PW = ""

# ToDo: Create a unique topic that your weather station will publish on,
# e.g. by using a uuid
Expand All @@ -52,7 +51,6 @@
T_SIM_END = 24 * 60 * 60 # simulation end time in seconds
COM_STEP = 60 * 60 * 1 # 60 min communication step in seconds


# ## Main script
if __name__ == '__main__':
# instantiate simulation model
Expand All @@ -68,6 +66,7 @@
mqttc = mqtt.Client(protocol=mqtt.MQTTv5)
# set user data if required
mqttc.username_pw_set(username=MQTT_USER, password=MQTT_PW)

# ToDo: Define a callback function that will be executed when the client
# receives message on a subscribed topic. It should decode your message
# and store the information for later in our history
Expand All @@ -83,7 +82,6 @@ def on_message(client, userdata, msg):
history_weather_station.append(json.loads(payload))



# add your callback function to the client. You can either use a global
# or a topic specific callback with `mqttc.message_callback_add()`
mqttc.on_message = on_message
Expand Down Expand Up @@ -118,7 +116,7 @@ def on_message(client, userdata, msg):

# simulation step for next loop
sim_model.do_step(int(t_sim + COM_STEP))
time.sleep(1)
time.sleep(0.1)

# close the mqtt listening thread
mqttc.loop_stop()
Expand All @@ -127,9 +125,9 @@ def on_message(client, userdata, msg):

# plot results
fig, ax = plt.subplots()
t_simulation = [item["t_sim"] for item in history_weather_station]
t_simulation = [item["t_sim"]/3600 for item in history_weather_station]
temperature = [item["t_amb"] for item in history_weather_station]
ax.plot(t_simulation, temperature)
ax.set_xlabel('time in s')
ax.set_xlabel('time in h')
ax.set_ylabel('ambient temperature in °C')
plt.show()
12 changes: 6 additions & 6 deletions tutorials/ngsi_v2/e2_healthcheck/e2_healthcheck_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@
# ToDo: Create a single client for each service and check the service for
# its version
cbc = ContextBrokerClient(url=CB_URL)
print(cbc.get_version())
print(f"Context Broker Client: {cbc.get_version()}")

iotac = IoTAClient(url=IOTA_URL)
print(iotac.get_version())
print(f"IoTA Client: {iotac.get_version()}")

qlc = QuantumLeapClient(url=QL_URL)
print(qlc.get_version())
print(f"Quantum Leap Client: {qlc.get_version()}")

# ToDo: Create a configuration object for a multi client
config = HttpClientConfig(cb_url=CB_URL, iota_url=IOTA_URL, ql_url=QL_URL)

# ToDo: Create a multi client check again all services for their version
multic = HttpClient(config=config)

print(multic.cb.get_version())
print(multic.iota.get_version())
print(multic.timeseries.get_version())
print(f"Multi Client (Context Broker): {multic.cb.get_version()}\n"
f"Multi Client (IoTA): {multic.iota.get_version()}\n"
f"Multi Client (Quantum Leap): {multic.timeseries.get_version()}")
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

# FIWARE-Service
SERVICE = 'filip_tutorial'
# FIWARE-Servicepath
# FIWARE-Service path
# ToDo: Change the name of your service-path to something unique. If you run
# on a shared instance this very important in order to avoid user
# collisions. You will use this service path through the whole tutorial.
Expand Down Expand Up @@ -114,7 +114,7 @@
entity_type=building.type)

# print your `building model` as json
print(f"This is your building model: \n {building.json(indent=2)} \n")
print(f"This is your building model: \n {building.model_dump_json(indent=2)} \n")

# ToDo: create a `opening hours` property and add it to the building object
# in the context broker. Do not update the whole entity! In real
Expand All @@ -136,7 +136,7 @@
hours = cbc.get_attribute_value(entity_id=building.id,
entity_type=building.type,
attr_name=opening_hours.name)
print(f"Your opening hours: {hours} \n" )
print(f"Your opening hours: {hours} \n")

# ToDo: modify the `opening hours` of the building
cbc.update_attribute_value(entity_id=building.id,
Expand All @@ -152,7 +152,7 @@
entity_type=building.type)

# print your building
print(f"Your updated building model: \n {building.json(indent=2)}")
print(f"Your updated building model: \n {building.model_dump_json(indent=2)}")

# ToDo: Create an entity of thermal zone and add a description property
# to it
Expand All @@ -174,15 +174,15 @@

# print all relationships of your thermal zone
for relationship in thermal_zone.get_relationships():
print(f"Relationship properties of your thermal zone mdoel: \n "
f"{relationship.json(indent=2)} \n")
print(f"Relationship properties of your thermal zone model: \n "
f"{relationship.model_dump_json(indent=2)} \n")

# ToDo: Post your thermal zone model to the context broker
cbc.post_entity(entity=thermal_zone)
thermal_zone = cbc.get_entity(entity_id=thermal_zone.id,
entity_type=thermal_zone.type)

# ToDo: Create and a property that references your thermal zone. Use the
# ToDo: Create and add a property that references your thermal zone. Use the
# `Relationship` for type and `hasZone` for its name. Make sure that
# your local model and the server model are in sync afterwards.
ref_zone = NamedContextAttribute(name="hasZone",
Expand All @@ -203,7 +203,7 @@
query = QueryString(qs=("refBuilding", "==", building.id))
for entity in cbc.get_entity_list(q=query):
print(f"All entities referencing the building: "
f"\n {entity.json(indent=2)}\n")
f"\n {entity.model_dump_json(indent=2)}\n")

# ToDo: create a filter request that retrieves all entities from the
# server`that have `hasZone' attribute that references your thermal zone
Expand All @@ -214,14 +214,14 @@
query = QueryString(qs=("hasZone", "==", thermal_zone.id))
for entity in cbc.get_entity_list(q=query):
print(f"All entities referencing the thermal zone: "
f"\n {entity.json(indent=2)} \n")
f"\n {entity.model_dump_json(indent=2)} \n")

# write entities to file and clear server state
assert WRITE_ENTITIES_FILEPATH.suffix == '.json', \
f"Wrong file extension! {WRITE_ENTITIES_FILEPATH.suffix}"
WRITE_ENTITIES_FILEPATH.touch(exist_ok=True)
with WRITE_ENTITIES_FILEPATH.open('w', encoding='utf-8') as f:
entities = [item.dict() for item in cbc.get_entity_list()]
entities = [item.model_dump() for item in cbc.get_entity_list()]
json.dump(entities, f, ensure_ascii=False, indent=2)

clear_context_broker(url=CB_URL, fiware_header=fiware_header)
Loading