{"id":1019,"date":"2025-12-01T11:47:54","date_gmt":"2025-12-01T11:47:54","guid":{"rendered":"https:\/\/tipcontrol.com\/?page_id=1019"},"modified":"2025-12-01T11:47:55","modified_gmt":"2025-12-01T11:47:55","slug":"mqtt-remote-control","status":"publish","type":"page","link":"https:\/\/tipcontrol.com\/?page_id=1019","title":{"rendered":"MQTT Remote Control"},"content":{"rendered":"\n<p>TipControl devices registered under your username can be controlled remotely using MQTT. \u00a0<\/p>\n\n\n\n<p>By publishing a message to the device, you can either:<\/p>\n\n\n\n<p>&#8211; Execute <strong>raw code<\/strong> directly on the device \u00a0<\/p>\n\n\n\n<p>&#8211; Run a <strong>macro<\/strong> that has already been installed<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Directions<\/h4>\n\n\n\n<p>To send executable code, publish to the following topic:<br>&lt;username>.&lt;projectname>.&lt;chipname>\/exec<\/p>\n\n\n\n<p>For example: <\/p>\n\n\n\n<p>demo.demo.esp32\/exec<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><br>Building the Request Payload<\/h4>\n\n\n\n<p>Every request body must start with `:{` and end with `}`. &nbsp;<\/p>\n\n\n\n<p>Inside, you can write either raw code or macro calls.<br><br><strong>Raw code<\/strong><\/p>\n\n\n\n<p><br>Here\u2019s an example that loops 25 times, generates random RGB values, and sets a NeoPixel LED:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly> String payload = \":{ \"                              \/\/ remember to start the code with :\n               \"for (i = 0, i &lt; 25, i += 1) { \"   \/\/ loop 25 times\n               \"red = lib.math.random(0,255); \"    \/\/ generate random red value\n               \"green = lib.math.random(0,255); \"  \/\/ generate random green value\n               \"blue = lib.math.random(0,255); \"   \/\/ generate random blue value\n               \"drv.neopixel.setLeds(red, green, blue, 1, 0); \" \/\/ set the neopixel LED colors\n               \"delay(1000);}; } \"; \/\/ wait 1 second before next iteration<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">String<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">payload<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;:{ &quot;<\/span><span style=\"color: #D4D4D4\">                              <\/span><span style=\"color: #6A9955\">\/\/ remember to start the code with :<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">               <\/span><span style=\"color: #CE9178\">&quot;for (i = 0, i &lt; 25, i += 1) { &quot;<\/span><span style=\"color: #D4D4D4\">   <\/span><span style=\"color: #6A9955\">\/\/ loop 25 times<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">               <\/span><span style=\"color: #CE9178\">&quot;red = lib.math.random(0,255); &quot;<\/span><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #6A9955\">\/\/ generate random red value<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">               <\/span><span style=\"color: #CE9178\">&quot;green = lib.math.random(0,255); &quot;<\/span><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #6A9955\">\/\/ generate random green value<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">               <\/span><span style=\"color: #CE9178\">&quot;blue = lib.math.random(0,255); &quot;<\/span><span style=\"color: #D4D4D4\">   <\/span><span style=\"color: #6A9955\">\/\/ generate random blue value<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">               <\/span><span style=\"color: #CE9178\">&quot;drv.neopixel.setLeds(red, green, blue, 1, 0); &quot;<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #6A9955\">\/\/ set the neopixel LED colors<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">               <\/span><span style=\"color: #CE9178\">&quot;delay(1000);}; } &quot;<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ wait 1 second before next iteration<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>the receiving device will execute this code immediately.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Run a Macro<\/h5>\n\n\n\n<p>Run the macro called Blink installed on the driver called LED<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>String body = \":{ \" \/\/ remember to start the code with :\n              \"drv.LED.Blink();}\"\/\/ end the line of code with ;\n              \/\/need to end with }<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">String<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">body<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;:{ &quot;<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #6A9955\">\/\/ remember to start the code with :<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">              <\/span><span style=\"color: #CE9178\">&quot;drv.LED.Blink();}&quot;<\/span><span style=\"color: #6A9955\">\/\/ end the line of code with ;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">              <\/span><span style=\"color: #6A9955\">\/\/need to end with }<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>the receiving device will find this macro and run the code within immediately <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Receive sensor data<\/h4>\n\n\n\n<p>You can also instruct the device to publish sensor values. &nbsp;<\/p>\n\n\n\n<p>For example, if you have an &#8220;environment&#8221; sensor with a &#8220;temperature variable:<\/p>\n\n\n\n<p>Example: if you had an environment sensor called &#8220;environment&#8221; that had the variable  &#8220;temperature&#8221; then to read that value you will publish the following code to the device. making sure you are subscribed to the device&#8217;s publish topic <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>String body = \":{ \" \/\/ remember to start the code with :\n              \"payload = \\\"{ temperature: \\\" + drv.environment.var.temperature\\\" + \\\"}\\\";\"\n              \/\/publish(topic,payload,qos)\n              \"drv.mqtt.publish(\\\"demo.sensors\/environment\\\",payload,qos);}\"\/\/ end the line of code with ;\n              \/\/need to end with }<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">String<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">body<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;:{ &quot;<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #6A9955\">\/\/ remember to start the code with :<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">              <\/span><span style=\"color: #CE9178\">&quot;payload = <\/span><span style=\"color: #D7BA7D\">\\&quot;<\/span><span style=\"color: #CE9178\">{ temperature: <\/span><span style=\"color: #D7BA7D\">\\&quot;<\/span><span style=\"color: #CE9178\"> + drv.environment.var.temperature<\/span><span style=\"color: #D7BA7D\">\\&quot;<\/span><span style=\"color: #CE9178\"> + <\/span><span style=\"color: #D7BA7D\">\\&quot;<\/span><span style=\"color: #CE9178\">}<\/span><span style=\"color: #D7BA7D\">\\&quot;<\/span><span style=\"color: #CE9178\">;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">              <\/span><span style=\"color: #6A9955\">\/\/publish(topic,payload,qos)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">              <\/span><span style=\"color: #CE9178\">&quot;drv.mqtt.publish(<\/span><span style=\"color: #D7BA7D\">\\&quot;<\/span><span style=\"color: #CE9178\">demo.sensors\/environment<\/span><span style=\"color: #D7BA7D\">\\&quot;<\/span><span style=\"color: #CE9178\">,payload,qos);}&quot;<\/span><span style=\"color: #6A9955\">\/\/ end the line of code with ;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">              <\/span><span style=\"color: #6A9955\">\/\/need to end with }<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><br>The device will publish the result to the topic, e.g.: <br>{ temperature: 30 }<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Key Points<\/h4>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<p>-Always start with `:{` and end with `}`. \u00a0<\/p>\n\n\n\n<p>&#8211; End each line of code with a semicolon `;`. &nbsp;<\/p>\n\n\n\n<p>&#8211; Make sure you are subscribed to the device\u2019s publish topic if you expect data back.&nbsp;<\/p>\n<\/div>\n\n\n\n<p>&#8211; The device can only send data to a topic defined as &lt;username>.&lt;something>\/&lt;something><\/p>\n","protected":false},"excerpt":{"rendered":"<p>TipControl devices registered under your username can be controlled remotely using MQTT. \u00a0 By publishing a message to the device, you can either: &#8211; Execute raw code directly on the device \u00a0 &#8211; Run a macro that has already been installed Directions To send executable code, publish to the following topic:&lt;username>.&lt;projectname>.&lt;chipname>\/exec For example: demo.demo.esp32\/exec Building [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1019","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages\/1019","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1019"}],"version-history":[{"count":4,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages\/1019\/revisions"}],"predecessor-version":[{"id":1024,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages\/1019\/revisions\/1024"}],"wp:attachment":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1019"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}