Projects/ESP8266 Mqtt Comissioning: Difference between revisions

From Playful Exploration
Jump to navigation Jump to search
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 66: Line 66:
[[File:Node Console Stack.PNG|400px]]
[[File:Node Console Stack.PNG|400px]]


== Step 3: Web based MQTT console ==
== Step 3: Mqtt Commission Story ==
[[File:MQTT Commisioning Story.jpg|400px]]
 
== Step 4: Web based MQTT console ==
[[File:Node Console Web UI.PNG|400px]]
[[File:Node Console Web UI.PNG|400px]]
[[File:Node-green-whiteboard-2.jpg|400px]]
[[File:Node-green-whiteboard-1.jpg|400px]]

Latest revision as of 03:41, 16 June 2016

This is an attempt to build a browser based Lua editor for the ESP8266. How it will work:

  • The web browser uses WebSocket to talk to a MQTT broker with websocket support e.g. mosquitto.
  • The broker routes the WebSocket communication to MQTT
  • One or more ESP chips can be connected to the MQTT broker, each using a unique topic
  • Lua commands typed into the browser based editor are transmitted to the ESP chip
  • The results of a Lua command are transmitted from the ESP chip back to the browser using opposite route

The web browser effectively becomes a console for the ESP chip.

What does this enable that other approaches have limitations

The usual approach requires a USB-UART adapter to be connected to the ESP in order to reprogram it and see its log messages. Reprogramming an ESP in LUA typically means replacing files onto the ESP. For each additional ESP this needs repetition. In summary the steps needed to get 10 or ESPs up running, monitor them, keep them updated and/or reconfigure them is quite difficult.

With the MQTT commission approach many issues just go away:

  • Firmware needs to be flashed only once
  • The network setup is simply done by connecting to the chip (in access point mode) via a webbrowser and setup Wifi and Mqtt broker. These settings are persisted and not expected to change often.
  • All additional interaction will happen though a web console which features:
    • Monitor all connected devices on one screen. Give them friendly names and a description. See their status and which program they run.
    • Run LUA commands against any device for simple diagnosis or send a real task (i.e. every minute send temperature to database)
    • Simply persist a task as sticky topic when it works ok. That way the ESP will re-receive the task in case of reboot.
  • Provides a bases for higher lever ifttt like control.
  • Node lists could be shared for users to help each other.
  • A library of ready to use code can be provided to pick from.
  • An app-store / code-store can be developed around it.
  • The Lua code can be provided in compiled form to protect engineering knowledge of code in the code-store (this may cause trust issues though).

Requirements

  • support secure connection
  • configurable target MQTT broker
  • MQTT topic scheme for
    • list of connected devices including timestamp of last connection
    • commission code
    • mapping to friendly name and description
    • immediate commands
    • feedback from device
  • specialized view for effective user interaction

Step 1 - Browser subscribes to MQTT topic via WebSocket

This little HTML subscribes to all topics using the wildcard '#' and dumps any received MQTT messages to the browsers console.

<html>
<head>
    <script src="jquery-2.2.3.js"></script>
    <script src="mows.js"></script>
    <script>
        $( document ).ready(function(){
            var client = mows.createClient(9001,'www.playfulexploration.com', { username: 'peter', password: '********' });
            // pass an optional 'ws://localhost:port' here. 
            
            client.subscribe('#');
            //client.publish('presence', 'Hello mqtt');
            
            client.on('message', function (topic, message) {
                console.log(message);
                //client.end();
            });
        });
    </script>
</head>
<body>
    <h1>Look at the browser Console.</h1>
</body>
</html>

Step 2: Web based MQTT console Stack

Node Console Stack.PNG

Step 3: Mqtt Commission Story

MQTT Commisioning Story.jpg

Step 4: Web based MQTT console

Node Console Web UI.PNG

Node-green-whiteboard-2.jpg

Node-green-whiteboard-1.jpg