JavaScript hardverprogramozás
Miért pont JavaScript?








A népszerű ESP8266



Espruino
- Espruino mikrovezérlők
- ESP8266 támogatása
- WEB IDE for Chrome
- Grafikus szerkesztő
- Jól dokumentált
- Rengeteg hardveres modult támogat
- Az ES5-ös JavaScript parancsok 95%-át kezeli
- Bizonyos ES6-os utasítások is elérhetőek (arrow functions, template strings, binary literals, forEach/etc on ArrayBuffers)
Web IDE

Alapok
- digitalWrite
- digitalRead
- analogWrite
- analogRead
- LEDx
- Dx
- Ax
- stb.
Első kódunk
// villogtassunk ledet
var toggle=1;
setInterval(function() {
toggle=!toggle;
LED1.write(toggle);
}, 500);
// csinaljunk fenyefektet
var leds = [LED1, LED2, LED3, LED4, LED5, LED6];
var states = [1,0,1,0,1,0];
setInterval(function() {
leds.forEach(function(elm, index) {
states[index] = ! states[index];
elm.write(states[index]);
});
}, 200);
// fenyfuzer
var leds = [LED1, LED2, LED3, LED4, LED5, LED6];
var states = [1,0,0,0,0,0];
var states2 = [1,0,1,0,1,0];
var states3 = [1,1,1,1,1,1];
var index = 0;
var run = 0;
setInterval(function() {
run++;
if(run < 13) {
leds.forEach(function(elm, index) {
elm.write(states[index]);
});
var next = ( index + 1 < 6 ? index + 1: 0);
states[index] = 0;
states[next] = 1;
index = next;
} else if(run < 25) {
leds.forEach(function(elm, index) {
states2[index] = ! states2[index];
elm.write(states2[index]);
});
} else {
leds.forEach(function(elm, index) {
states3[index] = ! states3[index];
elm.write(states3[index]);
});
}
if(run > 37) { run = 0; }
}, 200);
Használjunk gombokat
var toggle = 0;
setWatch(function(e) {
toggle = !toggle;
LED5.write(toggle);
}, BTNA, { repeat: true, edge: "rising" });Írhatunk a kijelzőre
g.clear();
g.setFontVector(25);
g.drawString("Emarsys",2,15);
g.flip();Használjunk szenzort
var dht = require("DHT11").connect(D1);
dht.read(function (a) {
console.log("Temp is "+a.temp.toString()+" and RH is "+a.rh.toString());
});Kérjük le az akku státuszt
Badge.getBatteryPercentage();Grafikus szerkesztő

Sonoff Basic



MQTT röviden
- Lightweight ISO standard
publish-subscribe-based messaging protocol - Fast
- Socket
- Retained message
- Secure
- Multi message format (simple text, json, file)
- Publisher creates topic
- Topic wildcards (single level +, multi level #)
- /topic/device
Live demo

Köszönöm a figyelmet!
- https://novucode.com
- https://www.meetup.com/Budapest-DIY-Smart-Home-Csinald-magad-okosotthon
- https://www.facebook.com/groups/diysmarthome/

JavaScript hardverprogramozás (belső)
By Zoltán Virág
JavaScript hardverprogramozás (belső)
DIY Smart Home Meetup
- 61