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

add custom field #11

Closed
humansthatmake opened this issue Feb 16, 2020 · 7 comments
Closed

add custom field #11

humansthatmake opened this issue Feb 16, 2020 · 7 comments

Comments

@humansthatmake
Copy link

Is there a tutorial/documentation on how to work with this android studio app?

I recently added a custom endpoint on the provisioning manager example, but now I have no way to test its functionality unless I change the ESP BLE prov app by adding another input field.

@humansthatmake humansthatmake changed the title add custom endpoint add custom field Feb 16, 2020
@KhushbuShah25
Copy link
Contributor

KhushbuShah25 commented Feb 17, 2020

To send data to your endpoint , you can call "sendConfigData" method on BLE transport instance with your endpoint name in first argument (path).
For example,
Send data to "prov-scan" endpoint

@shahpiyushv
Copy link
Collaborator

@humansthatmake , as an alternative, just for testing, you can even check the esp_prov python tool in ESP IDF (https://github.com/espressif/esp-idf/tree/master/tools/esp_prov). This patch can be applied on top of it if you want to send some abstract non-protobuf data.

diff --git a/tools/esp_prov/esp_prov.py b/tools/esp_prov/esp_prov.py
index 52fb394f26..8ecae3b0dd 100644
--- a/tools/esp_prov/esp_prov.py
+++ b/tools/esp_prov/esp_prov.py
@@ -186,6 +186,16 @@ def custom_config(tp, sec, custom_info, custom_ver):
         return None
 
 
+def custom_data(tp, sec, custom_data):
+    try:
+        message = prov.custom_data_request(sec, custom_data)
+        response = tp.send_data('custom-data', message)
+        return (prov.custom_data_response(sec, response) == 0)
+    except RuntimeError as e:
+        on_except(e)
+        return None
+
+
 def scan_wifi_APs(sel_transport, tp, sec):
     APs = []
     group_channels = 0
@@ -328,6 +338,11 @@ if __name__ == '__main__':
                             'If Wi-Fi scanning is supported by the provisioning service, this need not '
                             'be specified'))
 
+    parser.add_argument("--custom_data", dest='custom_data', type=str, default='',
+                        help=desc_format(
+                            'This is an optional parameter, only intended for use with '
+                            '"examples/provisioning/wifi_prov_mgr_custom_data"'))
+
     parser.add_argument("--custom_config", action="store_true",
                         help=desc_format(
                             'This is an optional parameter, only intended for use with '
@@ -394,6 +409,13 @@ if __name__ == '__main__':
             exit(5)
         print("==== Custom config sent successfully ====")
 
+    if args.custom_data != '':
+        print("\n==== Sending Custom data to esp32 ====")
+        if not custom_data(obj_transport, obj_security, args.custom_data):
+            print("---- Error in custom data ----")
+            exit(5)
+        print("==== Custom data sent successfully ====")
+
     if args.ssid == '':
         if not has_capability(obj_transport, 'wifi_scan'):
             print("---- Wi-Fi Scan List is not supported by provisioning service ----")
diff --git a/tools/esp_prov/prov/custom_prov.py b/tools/esp_prov/prov/custom_prov.py
index fe611dbe92..06ec1ca717 100644
--- a/tools/esp_prov/prov/custom_prov.py
+++ b/tools/esp_prov/prov/custom_prov.py
@@ -44,3 +44,17 @@ def custom_config_response(security_ctx, response_data):
     cmd_resp.ParseFromString(decrypt)
     print_verbose(security_ctx, "CustomConfig status " + str(cmd_resp.status))
     return cmd_resp.status
+
+
+def custom_data_request(security_ctx, data):
+    # Encrypt the custom data
+    enc_cmd = security_ctx.encrypt_data(data)
+    print_verbose(security_ctx, "Client -> Device (CustomData cmd) " + utils.str_to_hexstr(enc_cmd))
+    return enc_cmd
+
+
+def custom_data_response(security_ctx, response_data):
+    # Decrypt response packet
+    decrypt = security_ctx.decrypt_data(tobytes(response_data))
+    print("CustomData response: " + str(decrypt))
+    return 0

@carlosamtech
Copy link

When we create a custom field using the wifi_prov_mgr_endpoint_create and _register, does the Protocomm layer take care of persisting the value of the custom field? If the answer is yes how can we access the custom field value at startup time?

@shahpiyushv
Copy link
Collaborator

@carlosamtech , I am not sure if I understand the question correctly. The APIs wifi_prov_mgr_endpoint_create/register just register the appropriate BLE/HTTP custom endpoints. The actual "custom data" will be received from your client (phone app) which will then be passed to your handler as is. So, there is no real question of "persisting the value".

Do let me know if I haven't understood your question correctly.

@carlosamtech
Copy link

Thank you for your response! My question is about the esp-idf provisioning library, not the mobile app

@shahpiyushv
Copy link
Collaborator

@carlosamtech, yes, I understand, and even my response is regarding the wifi_provisioning component of esp-idf :)

@shahpiyushv
Copy link
Collaborator

Closing this issue as it has been answered. @humansthatmake the new library has even cleaner APIs for this. Please let us know if you still need some help on that. @carlosamtech , I hope I have answered your query as well. If you have any more queries regarding the esp-idf provisioning library, please file an issue on esp-idf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants