@DrAzzy For the sockets, I kept it pretty basic. I established a simple format where the Espruino listens for a certain pattern: D:RRRGGGBBB, where "D:" is the header and R G and B are 000 - 254 for the color values.
The Espruino code is very similar to how a HTTP server is set up:
server = require("net").createServer(function(socket) {
socket.on('data', function(data) {
parseData(data);
});
}).listen(9000);
After listening on an arbitrary port, 9000, the data is parsed and sent to the LEDs.
function parseData(data) {
var idx = data.indexOf('D:', data.length - 11);
tRGB[0] = data.substr(idx + 2, 3);
tRGB[1] = data.substr(idx + 5, 3);
tRGB[2] = data.substr(idx + 8, 3);
console.log('r: ' + tRGB[0] + ' g: ' + tRGB[1] + ' b: ' + tRGB[2]);
initColor(); // This fades the color a bit, and sends the pattern through SPI to the LED controller.
}
The Node.js code. Here's the crucial parts:
Note that in this implementation, the Web front-end is sending AJAX HTTP GET requests to Node.js, with the arguments in the URL looking like: ?r=#&g=#&b=# , where # is the color value.
// Helper function to format the string that we'll send to the Espruino
function padNumber(num) {
return ("0000" + num).slice(-3);
}
var url = require('url');
var net = require('net');
var esp = net.connect(9000, '192.168.1.15',
function() {
console.log('Connected to Espruino!');
});
var http = require('http');
http.createServer(function (req, res) {
var q = url.parse(req.url, true).query;
esp.write('D:' + padNumber(q.r) + padNumber(q.g) + padNumber(q.b));
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('OK');
}).listen(8888, '0.0.0.0');
@allObjects It's all standard HTML 5 in the browser. The code above contains all the main pieces, and I'll eventually post the whole thing on https://github.com/m6ao when I have time. I think I'll also rework the color picker as a standalone module. I tried a lot of existing color pickers before deciding to make my own, and I think mine might be better suited for light control.
@Gordon I wanted to use WebSockets initially, but saw that the ticket for WebSocket implementation on the Espruino is still open :P. While it would be really cool, I was debating on whether or not it would be practical, not knowing the limitations of the ESP8266, and what the performance penalty might be on the Espruino. It looks really promising though, since it looks like there's a SHA-1 hash implementation in hardware, which is required for the WebSocket handshake.
I found out about the cap and CH_PD via Google, which incidentally led me to this post (thanks DrAzzy for your comments). I'm not sure if they're always required, but adding a note about it would be useful. I picked up some hints on that ESP8266 page -- the wiring table shows the original Espruino board with CH_PD connected, and mentions of adding a cap was pretty consistent on dedicated ESP8266 forums too.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
@DrAzzy For the sockets, I kept it pretty basic. I established a simple format where the Espruino listens for a certain pattern: D:RRRGGGBBB, where "D:" is the header and R G and B are 000 - 254 for the color values.
The Espruino code is very similar to how a HTTP server is set up:
After listening on an arbitrary port, 9000, the data is parsed and sent to the LEDs.
The Node.js code. Here's the crucial parts:
Note that in this implementation, the Web front-end is sending AJAX HTTP GET requests to Node.js, with the arguments in the URL looking like: ?r=#&g=#&b=# , where # is the color value.
@allObjects It's all standard HTML 5 in the browser. The code above contains all the main pieces, and I'll eventually post the whole thing on https://github.com/m6ao when I have time. I think I'll also rework the color picker as a standalone module. I tried a lot of existing color pickers before deciding to make my own, and I think mine might be better suited for light control.
@Gordon I wanted to use WebSockets initially, but saw that the ticket for WebSocket implementation on the Espruino is still open :P. While it would be really cool, I was debating on whether or not it would be practical, not knowing the limitations of the ESP8266, and what the performance penalty might be on the Espruino. It looks really promising though, since it looks like there's a SHA-1 hash implementation in hardware, which is required for the WebSocket handshake.
I found out about the cap and CH_PD via Google, which incidentally led me to this post (thanks DrAzzy for your comments). I'm not sure if they're always required, but adding a note about it would be useful. I picked up some hints on that ESP8266 page -- the wiring table shows the original Espruino board with CH_PD connected, and mentions of adding a cap was pretty consistent on dedicated ESP8266 forums too.