Publish message to specific subfolder












0















I'm trying to use Google Cloud Platform to make a little IoT project.



I've created a registry and a device in the "IoT Core" section and connected the registry to a default topic.
I've also specified three subfolders for that topic: "events", "config" and "status".
Now, I would like to connect a "Cloud Function" for the incoming messages but I can't find how to configure a single subfolder to monitor neither how to publish messages on them in the "Cloud Pub/Sub" section.



All the documentation talks about single topics so.... Am I missing some base concept on how it works?










share|improve this question

























  • Please consider to accept the answer that you found useful.

    – MonicaPC
    Nov 30 '18 at 0:02
















0















I'm trying to use Google Cloud Platform to make a little IoT project.



I've created a registry and a device in the "IoT Core" section and connected the registry to a default topic.
I've also specified three subfolders for that topic: "events", "config" and "status".
Now, I would like to connect a "Cloud Function" for the incoming messages but I can't find how to configure a single subfolder to monitor neither how to publish messages on them in the "Cloud Pub/Sub" section.



All the documentation talks about single topics so.... Am I missing some base concept on how it works?










share|improve this question

























  • Please consider to accept the answer that you found useful.

    – MonicaPC
    Nov 30 '18 at 0:02














0












0








0








I'm trying to use Google Cloud Platform to make a little IoT project.



I've created a registry and a device in the "IoT Core" section and connected the registry to a default topic.
I've also specified three subfolders for that topic: "events", "config" and "status".
Now, I would like to connect a "Cloud Function" for the incoming messages but I can't find how to configure a single subfolder to monitor neither how to publish messages on them in the "Cloud Pub/Sub" section.



All the documentation talks about single topics so.... Am I missing some base concept on how it works?










share|improve this question
















I'm trying to use Google Cloud Platform to make a little IoT project.



I've created a registry and a device in the "IoT Core" section and connected the registry to a default topic.
I've also specified three subfolders for that topic: "events", "config" and "status".
Now, I would like to connect a "Cloud Function" for the incoming messages but I can't find how to configure a single subfolder to monitor neither how to publish messages on them in the "Cloud Pub/Sub" section.



All the documentation talks about single topics so.... Am I missing some base concept on how it works?







google-cloud-platform google-cloud-functions iot google-cloud-pubsub






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 8:13









Jinjun

18219




18219










asked Nov 21 '18 at 10:21









Valerio CupelloniValerio Cupelloni

74




74













  • Please consider to accept the answer that you found useful.

    – MonicaPC
    Nov 30 '18 at 0:02



















  • Please consider to accept the answer that you found useful.

    – MonicaPC
    Nov 30 '18 at 0:02

















Please consider to accept the answer that you found useful.

– MonicaPC
Nov 30 '18 at 0:02





Please consider to accept the answer that you found useful.

– MonicaPC
Nov 30 '18 at 0:02












2 Answers
2






active

oldest

votes


















0














Need to back up a step. What are you trying to do with the various subfolders? This may be a misunderstanding with how communication works with the device to and from the Cloud.



So, there's 3 MQTT topics, those are the events/config/state (not status). Those DON'T map to Pub/Sub topics at all. They're each handled separately in IoT Core.



Events is device->Cloud, and gets put into the Pub/Sub topic you specify when creating the registry. Setting subfolders is all about splitting telemetry from the same device to multiple places for handling. So, e.g. you have temp data you want to go in one pub/sub topic, and pressure data you want into another. The other way to handle this would be to attach the function to the main pub/sub topic, parse the telemetry, and then re-issue a Pub/Sub message to different places depending on the payload itself.



Config is Cloud->device, and is initiated by calls to the IoT Core Admin SDK. If your device subscribes to the /config/ MQTT topic, then they'll get a callback on the MQTT client's on_message handler (exact code depends on library being used of course) when some external entity sends a config message to IoT Core for your device.



State is device->Cloud but is specially handled, and doesn't go to any Pub/Sub topic. The results can be retrieved by the IoT Core Admin SDK. It's a way for the device to report its state and then external processes/applications to get that status without having to call back down to the device itself. This is particularly useful when you have devices which don't remain connected, for example, but you still want to be able to do things based on the last known state.



So the only one that you can use Cloud Functions with is the /events/ topic. That's done by deploying a Cloud Function and choosing the Pub/Sub publish event hook as the firing mechanism for the function, and specifying the IoT Core's registry Pub/Sub topic as the source of the events. Then anytime your device publishes telemetry to the /events/ MQTT topic, it'll get published to that Pub/Sub topic (confusing I know because we call them both topics) and the Cloud Function will fire.



Hopefully this clarifies what's going on? Or did I totally miss the question? :)






share|improve this answer
























  • Thank you for the explaination! I totally misunderstood the documentation, now is more clear. Just to be sure, in your example and without using a function, how can I split the telemetry message in one pub/sub topic and pressure data into another? Is there a way to configure this in IoT Core?

    – Valerio Cupelloni
    Dec 11 '18 at 10:38













  • You can yes. When you create the registry in IoT Core, and it asks for a telemetry topic, there's a link that reads "Add more telemetry topics". Expanding that gives an interface for adding topic and subfolder. You can specify individual (different) Pub/Sub topics associated with a subfolder. To then split the data, you'd send telemetry messages, for example, to /events/telemetry/ MQTT topic, and pressure data to /events/pressure/ MQTT topic. Then you can have separate actions on each Pub/Sub topic where they get routed.

    – GabeWeiss
    Dec 11 '18 at 17:46



















0














I believe the correct way to set this up would be to set up one pubsub topic for each subfolder. From the cloud iot core documentation:




Devices can publish data to separate Pub/Sub topics by specifying a subfolder in the MQTT topic. The subfolder is the subtopic after {device-id}/events. For example, if the device publishes to the MQTT topic /devices/{device-id}/events/alerts, the subfolder is the string alerts. This subfolder must be configured in the device registry resource's eventNotificationConfigs.subfolderMatches field with a matching Pub/Sub topic in the eventNotificationConfigs.pubsubTopicName field. When data is sent to a subfolder, it is published to the subfolder's matching Pub/Sub topic.




https://cloud.google.com/iot/docs/how-tos/mqtt-bridge#publishing_telemetry_events_to_separate_pubsub_topics






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409910%2fpublish-message-to-specific-subfolder%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Need to back up a step. What are you trying to do with the various subfolders? This may be a misunderstanding with how communication works with the device to and from the Cloud.



    So, there's 3 MQTT topics, those are the events/config/state (not status). Those DON'T map to Pub/Sub topics at all. They're each handled separately in IoT Core.



    Events is device->Cloud, and gets put into the Pub/Sub topic you specify when creating the registry. Setting subfolders is all about splitting telemetry from the same device to multiple places for handling. So, e.g. you have temp data you want to go in one pub/sub topic, and pressure data you want into another. The other way to handle this would be to attach the function to the main pub/sub topic, parse the telemetry, and then re-issue a Pub/Sub message to different places depending on the payload itself.



    Config is Cloud->device, and is initiated by calls to the IoT Core Admin SDK. If your device subscribes to the /config/ MQTT topic, then they'll get a callback on the MQTT client's on_message handler (exact code depends on library being used of course) when some external entity sends a config message to IoT Core for your device.



    State is device->Cloud but is specially handled, and doesn't go to any Pub/Sub topic. The results can be retrieved by the IoT Core Admin SDK. It's a way for the device to report its state and then external processes/applications to get that status without having to call back down to the device itself. This is particularly useful when you have devices which don't remain connected, for example, but you still want to be able to do things based on the last known state.



    So the only one that you can use Cloud Functions with is the /events/ topic. That's done by deploying a Cloud Function and choosing the Pub/Sub publish event hook as the firing mechanism for the function, and specifying the IoT Core's registry Pub/Sub topic as the source of the events. Then anytime your device publishes telemetry to the /events/ MQTT topic, it'll get published to that Pub/Sub topic (confusing I know because we call them both topics) and the Cloud Function will fire.



    Hopefully this clarifies what's going on? Or did I totally miss the question? :)






    share|improve this answer
























    • Thank you for the explaination! I totally misunderstood the documentation, now is more clear. Just to be sure, in your example and without using a function, how can I split the telemetry message in one pub/sub topic and pressure data into another? Is there a way to configure this in IoT Core?

      – Valerio Cupelloni
      Dec 11 '18 at 10:38













    • You can yes. When you create the registry in IoT Core, and it asks for a telemetry topic, there's a link that reads "Add more telemetry topics". Expanding that gives an interface for adding topic and subfolder. You can specify individual (different) Pub/Sub topics associated with a subfolder. To then split the data, you'd send telemetry messages, for example, to /events/telemetry/ MQTT topic, and pressure data to /events/pressure/ MQTT topic. Then you can have separate actions on each Pub/Sub topic where they get routed.

      – GabeWeiss
      Dec 11 '18 at 17:46
















    0














    Need to back up a step. What are you trying to do with the various subfolders? This may be a misunderstanding with how communication works with the device to and from the Cloud.



    So, there's 3 MQTT topics, those are the events/config/state (not status). Those DON'T map to Pub/Sub topics at all. They're each handled separately in IoT Core.



    Events is device->Cloud, and gets put into the Pub/Sub topic you specify when creating the registry. Setting subfolders is all about splitting telemetry from the same device to multiple places for handling. So, e.g. you have temp data you want to go in one pub/sub topic, and pressure data you want into another. The other way to handle this would be to attach the function to the main pub/sub topic, parse the telemetry, and then re-issue a Pub/Sub message to different places depending on the payload itself.



    Config is Cloud->device, and is initiated by calls to the IoT Core Admin SDK. If your device subscribes to the /config/ MQTT topic, then they'll get a callback on the MQTT client's on_message handler (exact code depends on library being used of course) when some external entity sends a config message to IoT Core for your device.



    State is device->Cloud but is specially handled, and doesn't go to any Pub/Sub topic. The results can be retrieved by the IoT Core Admin SDK. It's a way for the device to report its state and then external processes/applications to get that status without having to call back down to the device itself. This is particularly useful when you have devices which don't remain connected, for example, but you still want to be able to do things based on the last known state.



    So the only one that you can use Cloud Functions with is the /events/ topic. That's done by deploying a Cloud Function and choosing the Pub/Sub publish event hook as the firing mechanism for the function, and specifying the IoT Core's registry Pub/Sub topic as the source of the events. Then anytime your device publishes telemetry to the /events/ MQTT topic, it'll get published to that Pub/Sub topic (confusing I know because we call them both topics) and the Cloud Function will fire.



    Hopefully this clarifies what's going on? Or did I totally miss the question? :)






    share|improve this answer
























    • Thank you for the explaination! I totally misunderstood the documentation, now is more clear. Just to be sure, in your example and without using a function, how can I split the telemetry message in one pub/sub topic and pressure data into another? Is there a way to configure this in IoT Core?

      – Valerio Cupelloni
      Dec 11 '18 at 10:38













    • You can yes. When you create the registry in IoT Core, and it asks for a telemetry topic, there's a link that reads "Add more telemetry topics". Expanding that gives an interface for adding topic and subfolder. You can specify individual (different) Pub/Sub topics associated with a subfolder. To then split the data, you'd send telemetry messages, for example, to /events/telemetry/ MQTT topic, and pressure data to /events/pressure/ MQTT topic. Then you can have separate actions on each Pub/Sub topic where they get routed.

      – GabeWeiss
      Dec 11 '18 at 17:46














    0












    0








    0







    Need to back up a step. What are you trying to do with the various subfolders? This may be a misunderstanding with how communication works with the device to and from the Cloud.



    So, there's 3 MQTT topics, those are the events/config/state (not status). Those DON'T map to Pub/Sub topics at all. They're each handled separately in IoT Core.



    Events is device->Cloud, and gets put into the Pub/Sub topic you specify when creating the registry. Setting subfolders is all about splitting telemetry from the same device to multiple places for handling. So, e.g. you have temp data you want to go in one pub/sub topic, and pressure data you want into another. The other way to handle this would be to attach the function to the main pub/sub topic, parse the telemetry, and then re-issue a Pub/Sub message to different places depending on the payload itself.



    Config is Cloud->device, and is initiated by calls to the IoT Core Admin SDK. If your device subscribes to the /config/ MQTT topic, then they'll get a callback on the MQTT client's on_message handler (exact code depends on library being used of course) when some external entity sends a config message to IoT Core for your device.



    State is device->Cloud but is specially handled, and doesn't go to any Pub/Sub topic. The results can be retrieved by the IoT Core Admin SDK. It's a way for the device to report its state and then external processes/applications to get that status without having to call back down to the device itself. This is particularly useful when you have devices which don't remain connected, for example, but you still want to be able to do things based on the last known state.



    So the only one that you can use Cloud Functions with is the /events/ topic. That's done by deploying a Cloud Function and choosing the Pub/Sub publish event hook as the firing mechanism for the function, and specifying the IoT Core's registry Pub/Sub topic as the source of the events. Then anytime your device publishes telemetry to the /events/ MQTT topic, it'll get published to that Pub/Sub topic (confusing I know because we call them both topics) and the Cloud Function will fire.



    Hopefully this clarifies what's going on? Or did I totally miss the question? :)






    share|improve this answer













    Need to back up a step. What are you trying to do with the various subfolders? This may be a misunderstanding with how communication works with the device to and from the Cloud.



    So, there's 3 MQTT topics, those are the events/config/state (not status). Those DON'T map to Pub/Sub topics at all. They're each handled separately in IoT Core.



    Events is device->Cloud, and gets put into the Pub/Sub topic you specify when creating the registry. Setting subfolders is all about splitting telemetry from the same device to multiple places for handling. So, e.g. you have temp data you want to go in one pub/sub topic, and pressure data you want into another. The other way to handle this would be to attach the function to the main pub/sub topic, parse the telemetry, and then re-issue a Pub/Sub message to different places depending on the payload itself.



    Config is Cloud->device, and is initiated by calls to the IoT Core Admin SDK. If your device subscribes to the /config/ MQTT topic, then they'll get a callback on the MQTT client's on_message handler (exact code depends on library being used of course) when some external entity sends a config message to IoT Core for your device.



    State is device->Cloud but is specially handled, and doesn't go to any Pub/Sub topic. The results can be retrieved by the IoT Core Admin SDK. It's a way for the device to report its state and then external processes/applications to get that status without having to call back down to the device itself. This is particularly useful when you have devices which don't remain connected, for example, but you still want to be able to do things based on the last known state.



    So the only one that you can use Cloud Functions with is the /events/ topic. That's done by deploying a Cloud Function and choosing the Pub/Sub publish event hook as the firing mechanism for the function, and specifying the IoT Core's registry Pub/Sub topic as the source of the events. Then anytime your device publishes telemetry to the /events/ MQTT topic, it'll get published to that Pub/Sub topic (confusing I know because we call them both topics) and the Cloud Function will fire.



    Hopefully this clarifies what's going on? Or did I totally miss the question? :)







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 26 '18 at 18:37









    GabeWeissGabeWeiss

    87168




    87168













    • Thank you for the explaination! I totally misunderstood the documentation, now is more clear. Just to be sure, in your example and without using a function, how can I split the telemetry message in one pub/sub topic and pressure data into another? Is there a way to configure this in IoT Core?

      – Valerio Cupelloni
      Dec 11 '18 at 10:38













    • You can yes. When you create the registry in IoT Core, and it asks for a telemetry topic, there's a link that reads "Add more telemetry topics". Expanding that gives an interface for adding topic and subfolder. You can specify individual (different) Pub/Sub topics associated with a subfolder. To then split the data, you'd send telemetry messages, for example, to /events/telemetry/ MQTT topic, and pressure data to /events/pressure/ MQTT topic. Then you can have separate actions on each Pub/Sub topic where they get routed.

      – GabeWeiss
      Dec 11 '18 at 17:46



















    • Thank you for the explaination! I totally misunderstood the documentation, now is more clear. Just to be sure, in your example and without using a function, how can I split the telemetry message in one pub/sub topic and pressure data into another? Is there a way to configure this in IoT Core?

      – Valerio Cupelloni
      Dec 11 '18 at 10:38













    • You can yes. When you create the registry in IoT Core, and it asks for a telemetry topic, there's a link that reads "Add more telemetry topics". Expanding that gives an interface for adding topic and subfolder. You can specify individual (different) Pub/Sub topics associated with a subfolder. To then split the data, you'd send telemetry messages, for example, to /events/telemetry/ MQTT topic, and pressure data to /events/pressure/ MQTT topic. Then you can have separate actions on each Pub/Sub topic where they get routed.

      – GabeWeiss
      Dec 11 '18 at 17:46

















    Thank you for the explaination! I totally misunderstood the documentation, now is more clear. Just to be sure, in your example and without using a function, how can I split the telemetry message in one pub/sub topic and pressure data into another? Is there a way to configure this in IoT Core?

    – Valerio Cupelloni
    Dec 11 '18 at 10:38







    Thank you for the explaination! I totally misunderstood the documentation, now is more clear. Just to be sure, in your example and without using a function, how can I split the telemetry message in one pub/sub topic and pressure data into another? Is there a way to configure this in IoT Core?

    – Valerio Cupelloni
    Dec 11 '18 at 10:38















    You can yes. When you create the registry in IoT Core, and it asks for a telemetry topic, there's a link that reads "Add more telemetry topics". Expanding that gives an interface for adding topic and subfolder. You can specify individual (different) Pub/Sub topics associated with a subfolder. To then split the data, you'd send telemetry messages, for example, to /events/telemetry/ MQTT topic, and pressure data to /events/pressure/ MQTT topic. Then you can have separate actions on each Pub/Sub topic where they get routed.

    – GabeWeiss
    Dec 11 '18 at 17:46





    You can yes. When you create the registry in IoT Core, and it asks for a telemetry topic, there's a link that reads "Add more telemetry topics". Expanding that gives an interface for adding topic and subfolder. You can specify individual (different) Pub/Sub topics associated with a subfolder. To then split the data, you'd send telemetry messages, for example, to /events/telemetry/ MQTT topic, and pressure data to /events/pressure/ MQTT topic. Then you can have separate actions on each Pub/Sub topic where they get routed.

    – GabeWeiss
    Dec 11 '18 at 17:46













    0














    I believe the correct way to set this up would be to set up one pubsub topic for each subfolder. From the cloud iot core documentation:




    Devices can publish data to separate Pub/Sub topics by specifying a subfolder in the MQTT topic. The subfolder is the subtopic after {device-id}/events. For example, if the device publishes to the MQTT topic /devices/{device-id}/events/alerts, the subfolder is the string alerts. This subfolder must be configured in the device registry resource's eventNotificationConfigs.subfolderMatches field with a matching Pub/Sub topic in the eventNotificationConfigs.pubsubTopicName field. When data is sent to a subfolder, it is published to the subfolder's matching Pub/Sub topic.




    https://cloud.google.com/iot/docs/how-tos/mqtt-bridge#publishing_telemetry_events_to_separate_pubsub_topics






    share|improve this answer




























      0














      I believe the correct way to set this up would be to set up one pubsub topic for each subfolder. From the cloud iot core documentation:




      Devices can publish data to separate Pub/Sub topics by specifying a subfolder in the MQTT topic. The subfolder is the subtopic after {device-id}/events. For example, if the device publishes to the MQTT topic /devices/{device-id}/events/alerts, the subfolder is the string alerts. This subfolder must be configured in the device registry resource's eventNotificationConfigs.subfolderMatches field with a matching Pub/Sub topic in the eventNotificationConfigs.pubsubTopicName field. When data is sent to a subfolder, it is published to the subfolder's matching Pub/Sub topic.




      https://cloud.google.com/iot/docs/how-tos/mqtt-bridge#publishing_telemetry_events_to_separate_pubsub_topics






      share|improve this answer


























        0












        0








        0







        I believe the correct way to set this up would be to set up one pubsub topic for each subfolder. From the cloud iot core documentation:




        Devices can publish data to separate Pub/Sub topics by specifying a subfolder in the MQTT topic. The subfolder is the subtopic after {device-id}/events. For example, if the device publishes to the MQTT topic /devices/{device-id}/events/alerts, the subfolder is the string alerts. This subfolder must be configured in the device registry resource's eventNotificationConfigs.subfolderMatches field with a matching Pub/Sub topic in the eventNotificationConfigs.pubsubTopicName field. When data is sent to a subfolder, it is published to the subfolder's matching Pub/Sub topic.




        https://cloud.google.com/iot/docs/how-tos/mqtt-bridge#publishing_telemetry_events_to_separate_pubsub_topics






        share|improve this answer













        I believe the correct way to set this up would be to set up one pubsub topic for each subfolder. From the cloud iot core documentation:




        Devices can publish data to separate Pub/Sub topics by specifying a subfolder in the MQTT topic. The subfolder is the subtopic after {device-id}/events. For example, if the device publishes to the MQTT topic /devices/{device-id}/events/alerts, the subfolder is the string alerts. This subfolder must be configured in the device registry resource's eventNotificationConfigs.subfolderMatches field with a matching Pub/Sub topic in the eventNotificationConfigs.pubsubTopicName field. When data is sent to a subfolder, it is published to the subfolder's matching Pub/Sub topic.




        https://cloud.google.com/iot/docs/how-tos/mqtt-bridge#publishing_telemetry_events_to_separate_pubsub_topics







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 23:51









        Daniel CollinsDaniel Collins

        862




        862






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409910%2fpublish-message-to-specific-subfolder%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy