Title: Client subscribing in on_connect,but messages sent on config not received · Issue #2033 · GoogleCloudPlatform/python-docs-samples · GitHub
Open Graph Title: Client subscribing in on_connect,but messages sent on config not received · Issue #2033 · GoogleCloudPlatform/python-docs-samples
X Title: Client subscribing in on_connect,but messages sent on config not received · Issue #2033 · GoogleCloudPlatform/python-docs-samples
Description: Describe the issue In on_connect I'm trying to subscribe to the config topic, but it's not happening for some reason. When I do it in the main() in client.loop_forever() it works but then I'm not able to retreive the persisted messages w...
Open Graph Description: Describe the issue In on_connect I'm trying to subscribe to the config topic, but it's not happening for some reason. When I do it in the main() in client.loop_forever() it works but then I'm not a...
X Description: Describe the issue In on_connect I'm trying to subscribe to the config topic, but it's not happening for some reason. When I do it in the main() in client.loop_forever() it works but then I...
Opengraph URL: https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2033
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Client subscribing in on_connect,but messages sent on config not received ","articleBody":"## Describe the issue\r\nIn on_connect I'm trying to subscribe to the config topic, but it's not happening for some reason. When I do it in the main() in client.loop_forever() it works but then I'm not able to retreive the persisted messages when device re connects. \r\n\r\nBasic code is as given below:\r\n```\r\ndef on_connect(unused_client, unused_userdata, unused_flags, rc):\r\n\t\"\"\"Callback for when a device connects.\"\"\"\r\n\tdevice_id=unused_userdata\r\n\tprint('on_connect', error_str(rc))\r\n\tmqtt_config_topic = '/devices/{}/config'.format(args.device_id)\r\n\tprint('Subscribing to {}'.format(mqtt_config_topic))\r\n\tclient.subscribe(mqtt_config_topic, qos=1)\r\n\r\ndef main():\r\n\tglobal minimum_backoff_time\r\n\targs = parse_command_line_args()\r\n\trun_get(args)\r\n\t# Create our MQTT client. The client_id is a unique string that identifies\r\n\t# this device. For Google Cloud IoT Core, it must be in the format below.\r\n\tclient = mqtt.Client(client_id=(\t'projects/{}/locations/{}/registries/{}/devices/{}'\r\n\t\t\t\t\t.format(args.project_id, args.cloud_region,args.registry_id, args.device_id)), \r\n clean_session=False)\r\n\r\n\t# With Google Cloud IoT Core, the username field is ignored, and the\r\n\t# password field is used to transmit a JWT to authorize the device.\r\n\tclient.username_pw_set(\r\n\t\t\tusername='unused',\r\n\t\t\tpassword=create_jwt(\r\n\t\t\t\t\targs.project_id, args.private_key_file, args.algorithm))\r\n\r\n\t# Enable SSL/TLS support.\r\n\tclient.tls_set(ca_certs=args.ca_certs, tls_version=ssl.PROTOCOL_TLSv1_2)\r\n\r\n\tclient.on_connect = on_connect\r\n\tclient.on_publish = on_publish\r\n\tclient.on_message=on_message\r\n\tclient.on_disconnect = on_disconnect\r\n\r\n\tclient.user_data_set(args.device_id)\r\n\r\n\tclient.connect(args.mqtt_bridge_hostname, args.mqtt_bridge_port)\r\n\ttime.sleep(5)\r\n client.loop_forever()\r\n\r\n\r\n\r\n```","author":{"url":"https://github.com/ishitar","@type":"Person","name":"ishitar"},"datePublished":"2019-03-07T06:25:11Z","url":"https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2033"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b8da61f1-75c1-9419-47ca-4ddccd9a1658 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8592:7F6CC:292D72:37E8B0:6AFE1A49 |
| html-safe-nonce | d8550d869cef3f756730aef44df8fe96b30bdddaff54993ab5d328d64269873e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NTkyOjdGNkNDOjI5MkQ3MjozN0U4QjA6NkFGRTFBNDkiLCJ2aXNpdG9yX2lkIjoiOTY4ODE2MTk1NjYwNTUyNzc3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 084823625d2673e9bfe38f9a2bd6f778b31afd955382f21085365c7183265ad7 |
| hovercard-subject-tag | issue:418149113 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/GoogleCloudPlatform/python-docs-samples/2033/issue_layout |
| twitter:image | https://opengraph.githubassets.com/243e4c9fa6961a5ae0c7e6c926920674a1196a5b6dbd4e2e14003eb2dfdb440d/GoogleCloudPlatform/python-docs-samples/issues/2033 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/243e4c9fa6961a5ae0c7e6c926920674a1196a5b6dbd4e2e14003eb2dfdb440d/GoogleCloudPlatform/python-docs-samples/issues/2033 |
| og:image:alt | Describe the issue In on_connect I'm trying to subscribe to the config topic, but it's not happening for some reason. When I do it in the main() in client.loop_forever() it works but then I'm not a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ishitar |
| hostname | github.com |
| expected-hostname | github.com |
| None | d0525ab1464526bf4532a5551aa348cf100dff75ef808a96fc67a08b1d946aa9 |
| turbo-cache-control | no-preview |
| go-import | github.com/GoogleCloudPlatform/python-docs-samples git https://github.com/GoogleCloudPlatform/python-docs-samples.git |
| octolytics-dimension-user_id | 2810941 |
| octolytics-dimension-user_login | GoogleCloudPlatform |
| octolytics-dimension-repository_id | 35065876 |
| octolytics-dimension-repository_nwo | GoogleCloudPlatform/python-docs-samples |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 35065876 |
| octolytics-dimension-repository_network_root_nwo | GoogleCloudPlatform/python-docs-samples |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | fef3993a71fa20f7be8e167132fbf9619bc66e12 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width