Skip to content

Commit

Permalink
Token config, readme for it
Browse files Browse the repository at this point in the history
  • Loading branch information
elmot committed May 9, 2024
1 parent 95882a9 commit c997264
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 14 deletions.
28 changes: 22 additions & 6 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,29 @@ Software & SaaS services

* [Google Blockly](https://developers.google.com/blockly) is used to edit and run display programs online.
* The blocks are converted to JavaScript code to be run in the browser window
* The blocks are converted to Python code to be run on MCU side
* The blocks are converted to MicroPython code to be run on MCU side
* [GitHub pages](https://pages.github.com/) hosts the web part
* [EMQ Free Public MQTT Broker](https://broker.emqx.io) helps to exchange data between web- and hardware- part
* [Micropython](https://micropython.org/) is run on the ESP32 MCU and handles both the display and MQTT connection
* [MicroPython](https://micropython.org/) is run on the ESP32 MCU and handles both the display and MQTT connection

Technical details
----
Blocks are stored to browser's [local storage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage).

Data exchange is done through unsecure public MQTT broker, instances are separated by a text token.

Topics used:
* */<token>/keepalive* - MCU => Web, keep alive messages every 4 seconds, message body is ignored
* */<token>/python/run* - Web =>MCU, load, store, and run new MicroPython code from message body
* */<token>/python/restart* - Web =>MCU, restart latest uploaded MicroPython code, message body is ignored


How2Run
----
* Solder the Grove connector (shipped with the module) to M5 Stamp-C3U *Port A*
* Connect the display module to the MCU module
* Connect the MCU module to your computer
* Flash latest [Micropython](https://micropython.org/download/ESP32_GENERIC_C3/) to the MCU module.
* Connect the MCU module to your computer with USB cable. A COM port should appear
* Flash latest [MicroPython](https://micropython.org/download/ESP32_GENERIC_C3/) to the MCU module.
[JS ESPTool](https://espressif.github.io/esptool-js/) is a handy tool for it.
Note that *.bin* file should be flashed at address *0x0000*
* Write your own *secrets.py* file based on the template [secrets_template.py](micropython/src/secrets_template.py).
Expand All @@ -37,5 +49,9 @@ You may use either
[PyCharm](https://www.jetbrains.com/pycharm/) with
[MicroPython plugin](https://plugins.jetbrains.com/plugin/9777-micropython),
[Thonny](https://thonny.org/), or [mpremote](https://docs.micropython.org/en/latest/reference/mpremote.html)
* Upload [MicroPython code](micropython) to the MCU board
* **TBD** set token to the web part
* Upload [MicroPython code](micropython) to the MCU board. The tools are above
* Open [elmot.xyz/esp32-blockly-display/](https://www.elmot.xyz/esp32-blockly-display/)
* Click gear icon and enter your mqtt token, same as in MicroPython part
* If everything is done correctly, WiFi sign on the web page turns to be dark green


14 changes: 11 additions & 3 deletions comm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ const MqttClient = {
CONNECTED_COLOR: "darkgreen",
CONNECTION_ERROR_COLOR: "darkred",
WAIT_FOR_BOARD_COLOR: "lightblue",

mqttToken: "aaa3c72f-8e9e-40a4-b937-caf1c384e15",
keepAliveTimeout: null,
pingTimeout: null,

start: function () {
const s = window.localStorage.getItem("MQTT_TOKEN")
if(s != null) {
this.mqttToken = s;
}
this.connect()
},
mqttToken: "aaa3c72f-8e9e-40a4-b937-caf1c384e15b",
keepAliveTimeout: null,
pingTimeout: null,


setConnectStatus: function (color, tooltip) {
console.log(`MQTT: ${tooltip}`)
const img = document.getElementById("connect-indicator");
Expand Down
23 changes: 18 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,23 @@
border: darkslategrey 3px dashed;
border-radius: 1cqw;
padding: 2cqh;
display: flex;
align-items: center;
user-select: none;
}

#connectDiv {
grid-gap: 0.6cqw;
align-items: start;
*:last-child {
margin-left: auto;
}
}
img, embed {
height: 3cqmax;
width: 3cqmax;
}
}

#displayDiv {
display: flex;
align-items: center;
}

#displayDiv embed {
height: 12cqh;
Expand Down Expand Up @@ -196,6 +200,15 @@
MqttClient.restartPython()
});

document.getElementById("settings-board").addEventListener("click", function () {
const s = window.prompt("Please enter communication MQTT_TOKEN from secrets.py", MqttClient.mqttToken)
if(s !== null) {
window.localStorage.setItem("MQTT_TOKEN", s)
window.location.reload()
}

});


</script>

Expand Down

0 comments on commit c997264

Please sign in to comment.