Commit 4a4524dd authored by Jiahang Chen's avatar Jiahang Chen
Browse files

update two notebooks

parent 2dbf12a2
Pipeline #338932 passed with stage
in 14 seconds
......@@ -33,7 +33,6 @@
headers={"Authorization": "Bearer {}".format(access_token),
"Content-Type": "application/json"},
data=json.dumps({}))
print(create_thing_resp.json())
dt_id = create_thing_resp.json().get("identifier", None)
print(dt_id)
create_cloud_copy_resp = requests.post(url="https://config.s3i.vswf.dev/things/{}/repository".format(dt_id),
......@@ -48,11 +47,12 @@
dt_secret = create_thing_resp.json().get("secret", None)
#dt_secret = "c49e4050-d194-4f08-90c5-e17fd5befba5"
dt_name = "test"
config_file_name = make_config_file(dt_id=dt_id, name=dt_name, roles="fml40::Harvester", features=["fml40::ProvidesProductionData",
"fml40::AcceptsFellingJobs"])
config_file_name = make_config_file(dt_id=dt_id, name=dt_name, roles="fml40::Harvester",
features=["fml40::ProvidesProductionData", "fml40::AcceptsFellingJobs"])
setup_logger(dt_name)
dt_model = load_config('configs/{}'.format(config_file_name))
dt_ref = create_dt_ref(model=dt_model, grant_type="password", secret=dt_secret, username=username, password=password,
is_broker_rest=True,
is_broker=True, is_repo=False)
dt_proxy = dt_ref.proxy()
dt_proxy.run_forever()
......
......@@ -4,7 +4,6 @@
from ml.tools import find_broker_endpoint, make_config_file, load_config
from ml.dt_factory import create_dt_ref
from ml.fml40.features.properties.values.documents.jobs.felling_job import FellingJob
import requests
import json, time
......@@ -16,91 +15,24 @@
config_file_name = make_config_file(dt_id=hmi_id, name="my HMI", roles="ml40::HMI")
hmi_model = load_config('configs/{}'.format(config_file_name))
hmi_ref = create_dt_ref(model=hmi_model, grant_type="password", secret=hmi_secret,
username=username, password=password, is_broker=True, is_repo=False)
username=username, password=password,
is_broker_rest=True, is_broker=True, is_repo=False)
hmi_proxy = hmi_ref.proxy()
hmi_proxy.run_forever()
s3i_dir = s3i.Directory(s3i_dir_url="https://dir.s3i.vswf.dev/api/2/", token=hmi_proxy.access_token.get())
hmi_json = s3i_dir.queryThingIDBased(thingID=hmi_id)
hmi_endpoints = hmi_json["attributes"].get("allEndpoints", None)
hmi_s3ib_ep = ""
for hmi_ep in hmi_endpoints:
if "s3ib" in hmi_ep:
hmi_s3ib_ep = hmi_ep
messageIds = list()
hmi_endpoint = find_broker_endpoint(hmi_proxy.dir.get(), hmi_id)
serv_req = s3i.messages.ServiceRequest()
receiver = input("[S³I]: Please enter the id of your digital twin: ")
job = FellingJob("", hmi_ref)
print(job.__dict__)
serv_req.fillServiceRequest(
senderUUID=hmi_id, receiverUUID=[receiver], sender_endpoint=hmi_s3ib_ep,
senderUUID=hmi_id, receiverUUID=[receiver], sender_endpoint=hmi_endpoint,
serviceType="AcceptsFellingJobs/my_accept_job_func",
parameters={"job": "fml40::FellingJob"},
msgUUID=str(uuid.uuid4())
)
receiver_endpoint = find_broker_endpoint(s3i_dir, thing_id=receiver)
service_req_response = requests.post(url="https://broker.s3i.vswf.dev/{}".format(receiver_endpoint),
data=json.dumps(serv_req.msg),
headers={'Content-Type': 'application/json',
'Authorization': 'Bearer ' + hmi_proxy.access_token.get()}
)
print(service_req_response.text)
"""Store the message id into message storage"""
messageIds.append(serv_req.msg["identifier"])
time.sleep(1)
response = requests.get(url="https://broker.s3i.vswf.dev/{}".format(hmi_s3ib_ep), headers={'Content-Type': 'application/json',
'Authorization': 'Bearer ' + hmi_proxy.access_token.get()})
print(response.text)
"""
def receive(msg_type):
access_token = s3i_identity_provider.get_token(s3i.TokenType.ACCESS_TOKEN)
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + access_token}
response = requests.get(url="https://broker.s3i.vswf.dev/{}".format(hmi_id), headers=headers)
msg_json = ""
value_json = ""
json_acceptable_string = response.text.replace("'", "\"")
if json_acceptable_string:
if check_message_encryption(response.text.strip('"')) == "pgp":
print_with_timestamp(
"You received a PGP message but this notebook can not decrypt PGP messages. Use the 03_inbox notebook to receive PGP messages.")
print_with_timestamp("PGP Message: " + response.text)
repeat(msg_type)
else:
msg_json = json.loads(json_acceptable_string)
if msg_json["replyingToMessage"] in messageIds and msg_json["messageType"] == msg_type:
if msg_type == "serviceReply":
value_json = msg_json["results"]
elif msg_type == "getValueReply":
value_json = msg_json["value"]
elif msg_type == "setValueReply":
value_json = msg_json["ok"]
messageIds.remove(msg_json["replyingToMessage"])
else:
repeat(msg_type)
else:
print_with_timestamp("The harvester did not respond yet.")
repeat(msg_type)
return msg_json, value_json
def repeat(msg_type):
decision = input("[S3I] Do you want to check for new messages again? [j/n]")
if decision in yes:
receive(msg_type)
elif decision in no:
print_with_timestamp(
"You do not want to check for more messages. If you want to check for new messages, just execute this cell again (Run button or SHIFT+RETURN)")
else:
print_with_timestamp(
"I could not understand your response. If you want to check for new messages, just execute this cell again (Run button or SHIFT+RETURN)")
"""
\ No newline at end of file
receiver_endpoint = find_broker_endpoint(hmi_proxy.dir.get(), thing_id=receiver)
resp = hmi_proxy.broker.get().send([receiver_endpoint], json.dumps(serv_req.msg))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment