├── .gitignore
├── Makefile
├── README.md
├── package.json
├── index.html
├── client.js
└── esp32-pi.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | bower_components
3 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | bower:
2 | bower install jquery jquery-ui
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Development environment and tooling running on Raspberry Pi
2 | for working with ESP32.
3 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "esp32-pi",
3 | "version": "1.0.0",
4 | "description": "ESP32 environment on Raspberry Pi",
5 | "main": "esp32-pi.js",
6 | "dependencies": {
7 | "express": "^4.14.0",
8 | "express-ws": "^2.0.0",
9 | "johnny-five": "^0.10.0",
10 | "raspi-io": "^6.1.0",
11 | "serialport": "^4.0.1"
12 | },
13 | "devDependencies": {},
14 | "scripts": {
15 | "test": "echo \"Error: no test specified\" && exit 1"
16 | },
17 | "keywords": [
18 | "esp32",
19 | "DevKitC",
20 | "raspberry-pi"
21 | ],
22 | "author": "Neil Kolban",
23 | "license": "ISC"
24 | }
25 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | ESP32 Workbench
8 |
9 |
10 |
11 |
12 |
13 |
14 |
23 |
24 |
25 |
26 | ESP32 Workbench
27 | Here is the ESP32 workbench
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/client.js:
--------------------------------------------------------------------------------
1 | $(function() {
2 | console.log("jQuery ready!");
3 | $("#flash").button().click(doFlash);
4 | $("#reboot").button().click(doReboot);
5 | $("#openConsole").button().click(function() {
6 | console.log("Request to open a console!");
7 | var ws = new WebSocket("ws://" + window.location.hostname + ":" + window.location.port + "/console");
8 | ws.onmessage = function(messageEvent) {
9 | console.log("We received data from the server!");
10 | $("#consoleTextarea").text($("#consoleTextarea").text() + messageEvent.data);
11 | if ($("#followCheckbox").is(":checked")) {
12 | $('#consoleTextarea').scrollTop($('#consoleTextarea')[0].scrollHeight);
13 | }
14 | };
15 | ws.onerror = function(error) {
16 | console.log("Error detected in web socket!");
17 | };
18 | ws.onclose = function() {
19 | console.log("Web socket closed!");
20 | };
21 | ws.onopen = function() {
22 | console.log("Web socket now open!");
23 | };
24 | });
25 | $("#followCheckbox").checkboxradio();
26 | });
27 |
28 | function doFlash() {
29 | console.log("Do flash!");
30 | jQuery.ajax({
31 | method: "GET",
32 | url: "/flash"
33 | });
34 | }
35 |
36 | function doReboot() {
37 | console.log("Do reboot!");
38 | jQuery.ajax({
39 | method: "GET",
40 | url: "/reboot"
41 | });
42 | }
43 |
--------------------------------------------------------------------------------
/esp32-pi.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | var five = require("johnny-five");
4 | var Raspi = require("raspi-io");
5 |
6 | var ESP32_EN;
7 | var ESP32_IO0;
8 |
9 | var express = require("express");
10 | var app = express();
11 | var expressWs = require("express-ws")(app);
12 | var wsConsole = null;
13 |
14 | app.use(express.static("."));
15 | app.get("/flash", function(request, response) {
16 | console.log("Request to flash!");
17 | response.end();
18 | rebootFlash();
19 | });
20 | app.get("/reboot", function(request, response) {
21 | console.log("Request to reboot!");
22 | response.end();
23 | rebootRun();
24 | });
25 | app.ws("/console", function(ws, req) {
26 | console.log("Request for console!");
27 | wsConsole = ws;
28 | ws.on('message', function(msg) {
29 | // Handle the message here
30 | console.log("Web socket message received!");
31 | });
32 | ws.on("close", function() {
33 | console.log("Closed!");
34 | wsConsole = null;
35 | });
36 | });
37 |
38 | var board = new five.Board({
39 | io: new Raspi()
40 | });
41 |
42 | board.on('ready', function() {
43 | // do Johnny-Five stuff
44 | console.log("Board ready!");
45 | ESP32_EN = new five.Pin("GPIO17", {"mode": five.Pin.OUTPUT});
46 | ESP32_IO0 = new five.Pin("GPIO27", {"mode": five.Pin.OUTPUT});
47 | ESP32_EN.high();
48 | ESP32_IO0.high();
49 | app.listen(3000, function() {
50 | console.log("ESP32 interface app started on port 3000");
51 | });
52 | rebootFlash();
53 | });
54 |
55 | var SerialPort = require("serialport");
56 | var port = new SerialPort("/dev/ttyUSB0", {
57 | baudRate: 115200
58 | });
59 | port.on("open", function() {
60 | console.log("Serial port is now open!");
61 | });
62 | port.on("error", function(err) {
63 | console.log("Serial port reported an error: " + err);
64 | });
65 | port.on("close", function() {
66 | console.log("Serial port was closed");
67 | setTimeout(function() {
68 | port.open();
69 | }, 1000);
70 | });
71 | port.on("data", function(buffer) {
72 | process.stdout.write(buffer.toString());
73 | if (wsConsole !== null) {
74 | wsConsole.send(buffer.toString());
75 | }
76 | });
77 |
78 | function rebootFlash() {
79 | ESP32_IO0.low();
80 | ESP32_EN.low();
81 | setTimeout(function() {ESP32_EN.high();}, 200);
82 | }
83 |
84 | function rebootRun() {
85 | console.log("rebootRun()");
86 | ESP32_IO0.high();
87 | ESP32_EN.low();
88 | setTimeout(function() {ESP32_EN.high();}, 200);
89 | }
90 |
--------------------------------------------------------------------------------