Files
AI-on-the-edge-device-docs/MQTT-API/index.html
2023-09-16 20:27:23 +00:00

414 lines
19 KiB
HTML

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><link rel="canonical" href="https://jomjol.github.io/AI-on-the-edge-device-docs/MQTT-API/" />
<link rel="shortcut icon" href="../img/favicon.ico" />
<title>MQTT API - AI on the Edge Device</title>
<link rel="stylesheet" href="../css/theme.css" />
<link rel="stylesheet" href="../css/theme_extra.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github.min.css" />
<script>
// Current page data
var mkdocs_page_name = "MQTT API";
var mkdocs_page_input_path = "MQTT-API.md";
var mkdocs_page_url = "/AI-on-the-edge-device-docs/MQTT-API/";
</script>
<!--[if lt IE 9]>
<script src="../js/html5shiv.min.js"></script>
<![endif]-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<img src=https://jomjol.github.io/AI-on-the-edge-device-docs//img/logo.png>
<a href=".." class="icon icon-home"> AI on the Edge Device
</a><div role="search">
<form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" title="Type search term here" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption"><span class="caption-text">Getting Started</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="..">Welcome</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Installation/">Installation</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../initial-setup/">Initial Setup</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Hardware-Compatibility/">Hardware Compatibility</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Best-Practice/">Best Practice</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../FAQs/">Frequently Asked Questions</a>
</li>
</ul>
<p class="caption"><span class="caption-text">External Links</span></p>
<ul>
<li class="toctree-l1"><a class="" href="https://github.com/jomjol/AI-on-the-edge-device/releases">Releases</a>
</li>
<li class="toctree-l1"><a class="" href="https://jomjol.github.io/AI-on-the-edge-device/index.html">Web Installer/Console</a>
</li>
<li class="toctree-l1"><a class="" href="https://github.com/jomjol/AI-on-the-edge-device/issues">Create an Issue</a>
</li>
<li class="toctree-l1"><a class="" href="https://github.com/jomjol/AI-on-the-edge-device/discussions">Join a Discussion</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Configuration</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Reference-Image/">Reference Image</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Alignment/">Alignment References</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../ROI-Configuration/">ROIs (Regions of Interest)</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Configuration/">Graphical Configuration</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Choosing-the-Model/">Model Selection</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../ota/">Over-The-Air (OTA) Update</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Advanced</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Parameters/">Parameters</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Integration-Home-Assistant/">Integration into Home Assistant</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../External-LED/">External LED</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../data-logging/">Data Logging</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../rolling-installation/">Living on the Edge</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Watermeter-specific-analog---digital-transition/">Analog/Digital Transition on Water Meters</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../collect-new-images/">Collect images to improve the models</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Learn-models-with-your-own-images/">Learn a model with your own images</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Correction%20Algorithm/">Correction Algorithm</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Neural-Network-Types/">Neural Network Types</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Additional-Information/">Additional Information</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../New-Releases-Notification/">Notification about new Releases</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Troubleshooting</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Error-Codes/">Reduced webinterface (error codes)</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../StatusLED-BlinkCodes/">Board status LED (blink codes)</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../WLAN-disconnect-reason/">WLAN disconnect reasons</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Error-Debugging/">Often observed issues</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Frequent-Reboots/">Basic hardware/config issues</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Demo-Mode/">Demo mode</a>
</li>
</ul>
<p class="caption"><span class="caption-text">API's</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../REST-API/">REST API</a>
</li>
<li class="toctree-l1 current"><a class="reference internal current" href="./">MQTT API</a>
<ul class="current">
<li class="toctree-l2"><a class="reference internal" href="#published-topics">Published topics</a>
<ul>
<li class="toctree-l3"><a class="reference internal" href="#status">Status</a>
</li>
<li class="toctree-l3"><a class="reference internal" href="#result">Result</a>
</li>
<li class="toctree-l3"><a class="reference internal" href="#gpio">GPIO</a>
<ul>
<li class="toctree-l4"><a class="reference internal" href="#gpiogpiopinnumber">GPIO/GPIO{PinNumber}</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#subscribed-topics">Subscribed topics</a>
<ul>
<li class="toctree-l3"><a class="reference internal" href="#control">Control</a>
<ul>
<li class="toctree-l4"><a class="reference internal" href="#ctrlflow_start">ctrl/flow_start</a>
</li>
<li class="toctree-l4"><a class="reference internal" href="#ctrlset_prevalue">ctrl/set_prevalue</a>
</li>
<li class="toctree-l4"><a class="reference internal" href="#gpiogpiopinnumber_1">GPIO/GPIO{PinNumber}</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Influx-DB/">Influx DB</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Development</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Build-Instructions/">Build the Project</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Upload-files-by-script/">Scripted File Upload</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Testing/">Testing</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Release-creation/">Preparing for Release</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Old Pages (no longer maintained)</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../outdated--Integrated-Functions/">Integrated Functions</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Assorted Pages</span></p>
<ul>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="Mobile navigation menu">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="..">AI on the Edge Device</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content"><div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href=".." class="icon icon-home" aria-label="Docs"></a> &raquo;</li>
<li>API's &raquo;</li>
<li class="breadcrumb-item active">MQTT API</li>
<li class="wy-breadcrumbs-aside">
<a href="https://github.com/jomjol/AI-on-the-edge-device-docs/edit/main/docs/MQTT-API.md" class="icon icon-github"> Edit on GitHub</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div class="section" itemprop="articleBody">
<h1 id="mqtt-api">MQTT API</h1>
<p>The device is capable to register to a MQTT broker to publish data and subscribe to specific topics.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Only MQTT v3.1.1 is supported.</p>
</div>
<p>The MQTT service has to be enabled and configured properly in the device configuration via web interface (<code>Settings</code> -&gt; <code>Configuration</code> -&gt; section <code>MQTT</code>)</p>
<p>The following parameters have to be defined:
* URI
* MainTopic (optional, if not set, the hostname is used)
* ClientID (optional, if not set, <code>AIOTED-</code> + the MAC address gets used to make sure the ID is unique)
* User (optional)
* Password (optional)
* RetainFlag (optional)</p>
<h2 id="published-topics">Published topics</h2>
<h3 id="status">Status</h3>
<p>The following overhead data are available under the main topic (i.e. <code>watermeter</code>):</p>
<table>
<thead>
<tr>
<th>Topic</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>watermeter/MAC</code></td>
<td>The MAC address of the ESP module.</td>
</tr>
<tr>
<td><code>watermeter/IP</code></td>
<td>The IP address of the ESP module.</td>
</tr>
<tr>
<td><code>watermeter/Hostname</code></td>
<td>The network host name of the ESP module.</td>
</tr>
<tr>
<td><code>watermeter/Interval</code></td>
<td>The round interval as configured during setup or in <a href="https://jomjol.github.io/AI-on-the-edge-device-docs/Parameters/#section-autotimer">Parameters -&gt; Interval</a>.</td>
</tr>
<tr>
<td><code>watermeter/Connection</code></td>
<td>Network connection status.</td>
</tr>
<tr>
<td><code>watermeter/Uptime</code></td>
<td>Seconds up since last boot.</td>
</tr>
<tr>
<td><code>watermeter/FreeMem</code></td>
<td>Free memory in kB.</td>
</tr>
<tr>
<td><code>watermeter/wifiRSSI</code></td>
<td>Quality of WiFi signal.</td>
</tr>
<tr>
<td><code>watermeter/CPUTemp</code></td>
<td>Temperature of the ESP CPU in degrees celsius.</td>
</tr>
</tbody>
</table>
<h3 id="result">Result</h3>
<p>The following calculation data are available under the sup-topic <code>main</code> (i.e. <code>watermeter/main</code>):</p>
<table>
<thead>
<tr>
<th>Topic</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>watermeter/main/error</code></td>
<td>Informs about the flow status. On success, the value is <code>no error</code>.</td>
</tr>
<tr>
<td><code>watermeter/main/raw</code></td>
<td>The value <strong>before</strong> performing <a href="https://jomjol.github.io/AI-on-the-edge-device-docs/Parameters/section-postprocessing">post processing</a>.</td>
</tr>
<tr>
<td><code>watermeter/main/value</code></td>
<td>The value <strong>after</strong> performing <a href="https://jomjol.github.io/AI-on-the-edge-device-docs/Parameters/section-postprocessing">post processing</a>.</td>
</tr>
<tr>
<td><code>watermeter/main/rate</code></td>
<td>How much flow was consumed in one minute.</td>
</tr>
<tr>
<td><code>watermeter/main/rate_per_time_unit</code></td>
<td>How much flow was consumed in one minute. The time unit gets set with the Home Assistant Discovery, e.g. <code>h</code> (hours) or <code>m</code> (minutes).</td>
</tr>
<tr>
<td><code>watermeter/main/changeabsolut</code></td>
<td>Difference between the previous and actual read value.</td>
</tr>
<tr>
<td><code>watermeter/main/rate_per_digitalization_round</code></td>
<td>How much flow was consumed in one minute.</td>
</tr>
<tr>
<td><code>watermeter/main/timestamp</code></td>
<td>Timestamp of the last valid reading (equal to timestamp of previous value)</td>
</tr>
<tr>
<td><code>watermeter/main/Status</code></td>
<td>Informs about the last performed step of the watermeter (i.e. <code>Flow finished</code>).</td>
</tr>
<tr>
<td><code>watermeter/main/json</code></td>
<td>This is a JSON formatted object containing the following values: <code>value</code>, <code>raw</code>, <code>pre</code>, <code>error</code>, <code>rate</code>, <code>timestamp</code>.</td>
</tr>
</tbody>
</table>
<h3 id="gpio">GPIO</h3>
<p><code>MainTopic</code>/{GPIO topic}, e.g. <code>watermeter/GPIO/GPIO12</code></p>
<ul>
<li>
<h4 id="gpiogpiopinnumber">GPIO/GPIO{PinNumber}</h4>
Depending on device configuration (<code>Settings</code> --&gt; <code>Configuration</code> --&gt; section <code>GPIO</code>)</li>
</ul>
<h2 id="subscribed-topics">Subscribed topics</h2>
<p><code>MainTopic</code>/{subscribed topic}, e.g. <code>watermeter/ctrl/flow_start</code></p>
<h3 id="control">Control</h3>
<ul>
<li>
<h4 id="ctrlflow_start">ctrl/flow_start</h4>
Trigger a flow start by publishing to this topic <ul>
<li>Payload:</li>
<li>any character, length &gt; 0</li>
</ul>
</li>
<li>
<h4 id="ctrlset_prevalue">ctrl/set_prevalue</h4>
</li>
</ul>
<p>!!! Note
This feature is available since version <a href="https://github.com/jomjol/AI-on-the-edge-device/releases/tag/v15.2.0">15.2.0</a>!</p>
<p>Set the last valid value (previous value) to given value or the actual RAW value. Payload needs to be provided in JSON notation.
+ Payload:
- Set to given value (value &gt;= 0): <code>{"numbersname": "main", "value": 12345.67890}</code>
* <code>"numbersname":</code>Provide name of number sequence, e.g. <code>"main"</code><br />
* <code>"value":</code> provide the value to be set</p>
<pre><code> - Set to actual RAW value (value &lt; 0, a valid RAW value is mandatory): `{"numbersname": "main", "value": -1}`
* `"numbersname":` Provide name of number sequence, e.g. `"main"`
* `"value":` Provide any negative number
</code></pre>
<ul>
<li>
<h4 id="gpiogpiopinnumber_1">GPIO/GPIO{PinNumber}</h4>
Depending on device configuration (<code>Settings</code> --&gt; <code>Configuration</code> --&gt; section <code>GPIO</code>)</li>
</ul>
</div>
</div><footer>
<div class="rst-footer-buttons" role="navigation" aria-label="Footer Navigation">
<a href="../REST-API/" class="btn btn-neutral float-left" title="REST API"><span class="icon icon-circle-arrow-left"></span> Previous</a>
<a href="../Influx-DB/" class="btn btn-neutral float-right" title="Influx DB">Next <span class="icon icon-circle-arrow-right"></span></a>
</div>
<hr/>
<div role="contentinfo">
<!-- Copyright etc -->
</div>
Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<div class="rst-versions" role="note" aria-label="Versions">
<span class="rst-current-version" data-toggle="rst-current-version">
<span>
<a href="https://github.com/jomjol/AI-on-the-edge-device-docs" class="fa fa-github" style="color: #fcfcfc"> GitHub</a>
</span>
<span><a href="../REST-API/" style="color: #fcfcfc">&laquo; Previous</a></span>
<span><a href="../Influx-DB/" style="color: #fcfcfc">Next &raquo;</a></span>
</span>
</div>
<script src="../js/jquery-3.6.0.min.js"></script>
<script>var base_url = "..";</script>
<script src="../js/theme_extra.js"></script>
<script src="../js/theme.js"></script>
<script src="../search/main.js"></script>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>