I am able to connect a browser to espruino and exchange messages, but I do not know how to catch the dash control events like onchange to send a message to espruino.
When the page is finished I will inline all files and store it in the flash.
Searching the forum for tinydash does not get me results. Is anybody else using it?
index.html
<html>
<head>
<meta name="viewport" content="width=640, initial-scale=1">
</head>
<body>
<link href="tinydash.css" rel="stylesheet">
<script src="tinydash.js"></script>
<script>
var ws;
setTimeout(function() {
var ws = new WebSocket('ws://192.168.25.4:8000',"protocolOne");
ws.onmessage = function (event) {
console.log("MSG:"+event.data);
//document.write("MSG:"+event.data);
};
setTimeout(function() {
ws.send("Hello to Espruino!");
}, 1000);
}, 1000);
var o = {
t:TD.toggle({x:10,y:150,width:200,height:60,label:"Toggle",value:1,name:"toggle"}),
v:TD.value({x:10,y:220,width:200,height:60,label:"Value",value:"1.234"}),
b:TD.button({x:10,y:290,width:200,height:100,label:"Press Me",value:0,name:"button",onchange:function(e){o.log.log("Pressed!");}}),
vs:TD.value({x:10,y:400,width:200,height:60,label:"Steppable Value",value:"1.2",min:1,step:0.1,max:2}),
};
for (var i in o)
document.body.appendChild(o[i]);
//TD.toggle.onchange = function(ev) {
ws.send(1);
//};
</script>
</body>
</html>
Espruino code:
ws.js
function wsConnect() {
var server = require('ws').createServer(onPageRequest);
server.listen(8000);
server.on("websocket", function(ws) {
ws.on('message',function(msg) {
print("WS: "+JSON.stringify(msg));
});
ws.send("WS: Hello from Espruino!");
});
}
function wifiConnect() {
wifi = require('Wifi');
wifi.connect(wifi_options.ssid, { password: wifi_options.password },
function(e) {
if (e) {
console.log("WIFI: " + e);
}
});
wifi.on('connected', function() {
console.log('WIFI:', wifi.getIP());
setTimeout(function() { wsConnect(); }, 1000);
});
wifi.on('disconnected', function() {
console.log("WIFI: Reconectando...");
wifi.connect(wifi_options.ssid, {password: wifi_options.password});
});
}
var page = '<html><body><script>var ws;setTimeout(function(){ws=new WebSocket("ws://"+location.host+"/my_websocket","protocolOne");ws.onmessage=function(event){console.log("MSG:"+event.data);};setTimeout(function(){ ws.send("Hello to Espruino!");},1000);},1000);</script></body></html>';
function onPageRequest(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(page);
}
function onInit() {
wifiConnect();
}
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.
Hello everybody,
I am working on getting the tinydash https://github.com/espruino/TinyDash working with espruino over websockets.
I am able to connect a browser to espruino and exchange messages, but I do not know how to catch the dash control events like onchange to send a message to espruino.
When the page is finished I will inline all files and store it in the flash.
Searching the forum for tinydash does not get me results. Is anybody else using it?
index.html
Espruino code:
ws.js