Projects/ESP8266 Mqtt Comissioning: Difference between revisions

From Playful Exploration
Jump to navigation Jump to search
(Created page with "Category:Projects This is an attempt to build a browser based Lua editor for the ESP8266. The Browser uses WebSocket to talk to the MQTT broker. The broker routes the We...")
 
No edit summary
Line 1: Line 1:
[[Category:Projects]]
[[Category:Projects]]
This is an attempt to build a browser based Lua editor for the ESP8266.  The Browser uses WebSocket to talk to the MQTT broker. The broker routes the WebSocket communication to MQTT where one or more ESP chips can be connected.  That way any Lua commands typed into the browser based editor can be transmitted to an ESP chip and the results can be transmitted from the ESP chip back to the browser.
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.
The web browser effectively becomes a console for the ESP chip.



Revision as of 04:48, 17 April 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.

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>