毎回以下は一緒
kaluma bundle ./index.js 依存ライブラリがあろうとなかろうと
kaluma flash ./index.js --bundle こう書かんといかんようになっている
kalumas shell で .hi がでたらコードが自動開始される 実行は.loadでおこなう
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
コードと回路が以下にある
avascript.plainenglish.io/physical-computing-with-javascript-3-8-reading-state-of-switch-106137a2f9d6 :: reading state of button
const LED = 15;
const BTN = 14;
pinMode(LED,OUTPUT);
pinMode(BTN,INPUT_PULLUP);
setWatch(() => {
digitalToggle(LED);
},BTN,FALLING,10);
-------------------------------------------------------------------------
https://javascript.plainenglish.io/physical-computing-with-javascript-4-8-led-dimming-403696103d2f :: led dimming
const LED = 15;
const POT = 26;
setInterval(() => {
let v = analogRead(POT);
analogWrite(LED,v);
},100);
------------------以下はraspicoにした、raspicowはうまくいかん、リベンジ--------
https://github.com/niklauslee/dht で成功
const pin = 15;
const {DHT} = require('dht');
const dht = new DHT(pin, DHT.DHT11);
let result = dht.read();
if (result) {
console.log(result);
console.log("Humidity: " + dht.humidity + " %");
console.log("Temperature: " + dht.temperature + " C");
} else {
console.log('Failed to read');
}
kaluma shellで.loadするとOKだった
-----------------------------------------------------------
https://github.com/pankleks/picomqtt をインストしてnode_modules/picomqttにもぐる そこでkaluma bundle ./index.js --bundleしてブートモードにせずにkaluma shell & .load
const WiFi = require("wifi").WiFi,
{ PicoMQTT } = require("./picomqtt.min");
const wifi = new WiFi();
wifi.connect({ ssid: "your-ssid", password: "your-password" }, (ex) => {
if (ex)
console.error(ex);
else {
console.log("wifi connected");
const mqtt = new PicoMQTT("broker.hivemq.com", { clientId: board.uid });
mqtt.on("connected", () => {
console.log("mqtt connected");
mqtt.subscribe("test/topic");
mqtt.publish("test/topic", "you should get this");
mqtt.publish("test/topic", "you should also get this");
mqtt.unsubscribe("test/topic");
mqtt.publish("test/topic", "you should not get this");
});
mqtt.on("message", (msg) => {
console.log(`mqtt message -> ${msg.topic}: ${msg.message}`);
});
mqtt.on("error", (ex) => {
console.log(`mqtt error -> ${ex.message || ex}`);
});
mqtt.on("disconnected", (reconnect) => {
console.log(`mqtt disconnected, reconnect = ${reconnect}`);
// if reconnect is true, mqtt will try to reconnect
});
mqtt.connect();
setTimeout(() => {
mqtt.disconnect(); // stop mqtt
}, 1000 * 120);
}
});
wifi connected
mqtt connected
mqtt message -> test/topic: you should get this
mqtt message -> test/topic: you should also get this
mqtt disconnected, reconnect = false
0 件のコメント:
コメントを投稿