2026年5月6日水曜日

kaluma http and node express

 https://javascript.plainenglish.io/physical-computing-with-javascript-8-8-connecting-to-internet-151ba3dfce59にある例題

-----kalumajs----

storage.setItem('WIFI_SSID', 'Buffalo-2G-8340');

storage.setItem('WIFI_PASSWORD', '');

 storage.setItem('ADDRESS', '192.168.11.8');

storage.setItem('PORT', '3001');

const {DHT} = require('dht');

const {ESP8266HTTPClient}=require('esp8266-http-client');

const dht = new DHT(15,DHT.DHT11);

cons esp=new ESP8266HTTPClient();

const addr = store.getItem('ADDRESS');

function start(){

  setInterval(() => {

    dht.read();

   let t = dht.temperature.toFixed(1);

   let h = dht.humidity.toFixed(0);

   esp.http(`http://${addr}:${port}/update?`

 },10000);

}

esp.wifi().then(() => {

    console.log('wifi connected');

    start();

  }).catch(err =>{

     console.log('wifi connect failed');

     console.log(err);

  }

};

----- node.js ------

const express = require('express');

const ip = require('ip');

const app = express();

const addr=ip.address();

const port=3001;

const html = `

<html>

  <head></head>

  <body>

   <h1>{{t}}</h1>

   <h1>{{h}}</h1>

  </body>

 </html>

 `

let temperature='0.0'

let humidity='0';


app.get('/update',(req,res) => {

  temperature = req.query.t

  humidity = req.query.h

  res.status(200).send('OK')

})


app.get('/',(req,res) => {

  res.setHeader('content-type','text/html');

  res.send(html

    .replace('{{t}}',temperature)

    .replace('{{h}}',humidity))

})


app.listen(port,()=> {

  console.log(`app listen at htpp://${addr}:${port}`)

})

url/update?t=27.5&h=45で入力し url/で確認できた

2026年5月5日火曜日

開発系まとめ(platformなど)

 esp32はIDE1.8は遅くplatformIOが推奨(差分コンパイルなしのせいかだろう)

https://qiita.com/nextfp/items/f54b216212f08280d4e0にesp32 devkitcが詳述されている

unoR3/esp8266はIDE1.8は差分コンパイルなしだがコンパイルそこそこ早いので使用OK

unoR4はIDE2.3が必須、ubuntu では 

./arduino-ide_2.3.6_Linux_64bit.AppImage  --no-sandbox で!

2026年5月4日月曜日

Tinygo on windows11(unoR3)

 https://github.com/neildavis/pi_pico_tinygo_examples for pico

https://github.com/soypat/cyw43439/tree/main for picow

上記は例題サイト

ーーーーーーーーーーーーーーーーー

wslでないやりかた 簡単だった

https://qiita.com/ysaito8015@github/items/148a28ee20f5a48d3cb8

for /F "tokens=*" %x in ('tinygo env TINYGOROOT') do dir %x\src\examples

上記はcmdでないと動かんかった

tinygo targets    で       arduino-uno だった 

すでにArduino IDEある場合

avrdudeの場所をPATHに追加

典型パス(例):

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin

または新しいIDEだと: 私のは、こっちだった

C:\Users\ユーザー名\AppData\Local\Arduino15\packages\arduino\tools\avrdude\...\bin


tinygo flash --target=arduino-uno main.go で成功

2026年5月2日土曜日

Kalumajs LED問題(picoOKだが。。。)/tinygoではpicowでOKなおUNOR3ok

picowの場合ビルトインledは特殊なコードが必要(ドキュメントよめ)

以下はpico/picow両方でうごく

pinMode(15, OUTPUT); // Set the pin 1 to output mode.

digitalWrite(15, HIGH); // Set the pin 1 to HIGH.

// Toggle the LED.

const { LED } = require('led');

const led = new LED(28); // LED connected to pin 0.

led.on();

delay(1000); // wait for 1sec

led.off();

delay(1000); // wait for 1sec

led.toggle(); // on

delay(1000); // wait for 1sec

led.toggle(); // off

ーーーーーーーーtinygoならPICOW OKーーーーーーーーーーーーーーーーーーー

tinygo flash -target=pico-w main.go うまくいかんときはpicowをブートモードでやる!


package main


import (

"machine"

"time"

)


func main() {

led := machine.GPIO28

led.Configure(machine.PinConfig{Mode: machine.PinOutput})


for {

led.High() // ON

time.Sleep(1 * time.Second)


led.Low() // OFF

time.Sleep(1 * time.Second)

}

}

ーーーーーーーーー

tinygo target=arduino main.gで

package main


import (

"machine"

"time"

)


func main() {

led := machine.LED

led.Configure(machine.PinConfig{Mode: machine.PinOutput})

for {

led.Low()

time.Sleep(time.Millisecond * 900)

led.High()

time.Sleep(time.Millisecond * 500)

}

}

2026年4月23日木曜日

ラズピコ TinyGo-dht/MMBasic

 package main

import (

"fmt"

"machine"

"time"

"tinygo.org/x/drivers/dht"

)


func main() {

// ボードに合わせて変更(Picoなら machine.GP2, Arduinoなら machine.D2等)

pin := machine.GP2

sensor := dht.New(pin, dht.DHT11)

fmt.Println("--- DHT11 Reading Start ---")

for {

// 多くのバージョンで共通して実装されている ReadRaw (または RawRead) を試すか

// 最新の標準インターフェースに基づいた Measurements を使用します。

// それでもエラーが出る場合は、ドライバのバージョンが極端に古い可能性があります。

temp, humid, err := sensor.Measurements()

if err != nil {

fmt.Printf("Read Error: %v\n", err)

} else {

fmt.Printf("Temp: %.1f°C  Humid: %.1f%%\n", float32(temp)/10, float32(humid)/10)

}

time.Sleep(10* time.Second)

}

}

 tinygo flash -target=pico -monitor . でコマンドプロンプトで確認できた

データ読み取りに10秒間隔で正常なデータがでるようになった

湿度は正確だが、温度やや高めに推移(購入個体の問題か。。。)

----------------------------------------------------------------------

https://yumeiroandroid.blog.fc2.com/blog-entry-374.html ここでLチカ成功

2026年4月19日日曜日

Kalumajs ssd1351-draft/tone OK/picow softAP hello server OK/

ドラフト中

npm i https://github.com/niklauslee/ssd1351

アナログIO

tone(0, 200); // Generate 200Hz tone on the GPIO PIN0

delay(1000); // Wait for 1000ms (1sec)

noTone(0); // Stop the tone on the pin 0

ーーーーーーーーーーーーーーーーーーーーーーーーーーー

https://kalumajs.org/docs/api/wifi にあるコードばっちりうごいた 将来的に、これにdhtをくみあわせたい 

-----------------------------------------------------------------------------------

 let { WiFi } = require('wifi')

let wifi = new WiFi()

let http = require('http')

console.log('Starting...')

wifi.wifiApMode({ssid: 'PicoHTTPServer', password: 'password' }, (err) => {

    if (err) {

        console.error('err', err);

        return;

    }

    console.log('access point running')

    var message = '<h1>Hello</h1>';

    var port = 80;

    console.log(port);

    var server = http.createServer((req, res) => {

        console.log('Request path: ' + req.url);

        res.writeHead(200, 'OK', {

            'Content-Type': 'text/html',

            'Content-Length': message.length,

        });

        res.write(message);

        res.end();

    });

    console.log(server);

    console.log(server._dev.ip);

    server.listen(port, function () {

    console.log('HTTP server listening on ', server._dev.ip, ' port: ', port);

    console.log(server);

    });

})


// Show client list every 10 sec.

let show_cli_interval = setInterval(() => {

        console.log("AP Client")

        var clients = wifi.getWifiApClients();

        console.log(clients);

    }, 10*1000);


// Stop server after 10 min

let close_interval = setTimeout(() => {

        wifi.disableWifiApMode();

        clearTimeout(show_cli_interval);

        console.log("WIFI AP is disabled");

    }, 600*1000);


// User can access HTTP server with "http://192.168.4.1/

2026年4月16日木曜日

Go and Mutex vs RWMutex

 Cutajar:: chap4 で変更だけlock/unlockでおこない読み出しはrlock/runlock

でやるとコア数だけ応答性が改善した