|
73 | 73 | from agrirouter.onboarding.enums import GateWays |
74 | 74 | from agrirouter.messaging.enums import CapabilityType |
75 | 75 | from agrirouter.generated.messaging.request.payload.endpoint.subscription_pb2 import Subscription |
| 76 | +from agrirouter.generated.messaging.request.payload.endpoint.capabilities_pb2 import CapabilitySpecification |
76 | 77 | from agrirouter.messaging.services.commons import HttpMessagingService, MqttMessagingService |
77 | 78 | from agrirouter import ListEndpointsParameters, ListEndpointsService, SubscriptionService, SubscriptionParameters, \ |
78 | | - QueryHeaderService, QueryHeaderParameters |
| 79 | + QueryHeaderService, QueryHeaderParameters, CapabilityService, CapabilityParameters |
79 | 80 | from agrirouter.utils.uuid_util import new_uuid |
80 | 81 |
|
81 | 82 |
|
82 | 83 | application_id = "8c947a45-c57d-42d2-affc-206e21d63a50" # # store here your application id. You can find it in AR UI |
83 | | - |
| 84 | +certification_version_id = "edd5d6b7-45bb-4471-898e-ff9c2a7bf56f" # # store here your certification version id. You can find it in AR UI |
84 | 85 |
|
85 | 86 | def example_auth(): |
86 | 87 | print("Authorization...\n") |
@@ -120,7 +121,6 @@ def example_onboarding(gateway_id): |
120 | 121 | print("Onboarding...\n") |
121 | 122 |
|
122 | 123 | id_ = "urn:myapp:snr00003234" # just unique |
123 | | - certification_version_id = "edd5d6b7-45bb-4471-898e-ff9c2a7bf56f" # get from AR UI |
124 | 124 | time_zone = "+03:00" |
125 | 125 |
|
126 | 126 | onboarding_client = ar.SoftwareOnboarding("QA", public_key=public_key, private_key=private_key) |
@@ -164,6 +164,27 @@ def example_list_endpoints_mqtt(onboarding_response_data, foo): |
164 | 164 | while True: |
165 | 165 | time.sleep(1) |
166 | 166 |
|
| 167 | +def example_set_capabilities(onboarding_response_data, mqtt_message_callback): |
| 168 | + onboarding_response = SoftwareOnboardingResponse() |
| 169 | + onboarding_response.json_deserialize(onboarding_response_data) |
| 170 | + messaging_service = MqttMessagingService( |
| 171 | + onboarding_response=onboarding_response, |
| 172 | + on_message_callback=mqtt_message_callback |
| 173 | + ) |
| 174 | + capabilities_parameters = CapabilityParameters( |
| 175 | + onboarding_response=onboarding_response, |
| 176 | + application_message_id=new_uuid(), |
| 177 | + application_message_seq_no=1, |
| 178 | + application_id=application_id, |
| 179 | + certification_version_id=certification_version_id, |
| 180 | + capability_parameters=[ |
| 181 | + CapabilitySpecification.Capability(technical_message_type = CapabilityType.ISO_11783_TASKDATA_ZIP.value, direction = "SEND_RECEIVE") |
| 182 | + ], |
| 183 | + enable_push_notification=True, |
| 184 | + ) |
| 185 | + capabilities_service = CapabilityService(messaging_service) |
| 186 | + capabilities_service.send(capabilities_parameters) |
| 187 | + |
167 | 188 |
|
168 | 189 | def example_list_endpoints_http(onboarding_response_data): |
169 | 190 | onboarding_response = SoftwareOnboardingResponse() |
@@ -303,6 +324,7 @@ def on_message_callback(client, userdata, msg): |
303 | 324 |
|
304 | 325 | if __name__ == "__main__": |
305 | 326 | onboarding_response_mqtt = example_onboarding(GateWays.MQTT.value) |
| 327 | + example_set_capabilities(onboarding_response_mqtt.json_serialize(), on_message_callback) |
306 | 328 | example_list_endpoints_mqtt(onboarding_response_mqtt.json_serialize(), on_message_callback) |
307 | 329 |
|
308 | 330 | # or for http |
|
0 commit comments